From a80eb9832e7b86bf2697788926505cf3fab57101 Mon Sep 17 00:00:00 2001 From: Weijun Huang Date: Sun, 12 Feb 2023 16:40:40 +0100 Subject: [PATCH 01/92] MDEV-24538: JSON_LENGTH does not return error upon wrong number of parameters --- mysql-test/main/func_json.result | 7 +++++++ mysql-test/main/func_json.test | 9 +++++++++ sql/item_jsonfunc.h | 5 +++++ 3 files changed, 21 insertions(+) diff --git a/mysql-test/main/func_json.result b/mysql-test/main/func_json.result index 1e59256b517e4..415e367f45545 100644 --- a/mysql-test/main/func_json.result +++ b/mysql-test/main/func_json.result @@ -1289,5 +1289,12 @@ JSON_LOOSE(JSON_EXTRACT(a, '$**.analyzing_range_alternatives')) [{"range_scan_alternatives": [{"index": "a_b", "ranges": ["2 <= a <= 2 AND 4 <= b <= 4", "123"], "rowid_ordered": true, "using_mrr": false, "index_only": true, "rows": 1, "cost": 1.1752, "chosen": true}], "analyzing_roworder_intersect": {"cause": "too few roworder scans"}, "analyzing_index_merge_union": [], "test_one_line_array": ["123"]}] drop table t200; # +# MDEV-24538: JSON_LENGTH does not return error upon wrong number of parameters +# +SELECT JSON_LENGTH('{"a":"b"}','$','$', 'foo'); +ERROR 42000: Incorrect parameter count in the call to native function 'json_length' +SELECT JSON_LENGTH(); +ERROR 42000: Incorrect parameter count in the call to native function 'JSON_LENGTH' +# # End of 10.4 tests # diff --git a/mysql-test/main/func_json.test b/mysql-test/main/func_json.test index b3e19f7697207..56d90e9393615 100644 --- a/mysql-test/main/func_json.test +++ b/mysql-test/main/func_json.test @@ -665,6 +665,7 @@ SELECT 1 + JSON_VALUE('{"nulltest": null}', '$.nulltest'); SELECT NULL; SELECT JSON_EXTRACT('{"a":null, "b":10, "c":"null"}', '$.a'); + --echo # --echo # End of 10.3 tests --echo # @@ -816,6 +817,14 @@ select JSON_PRETTY(JSON_EXTRACT(a, '$**.analyzing_range_alternatives')) from t20 select JSON_LOOSE(JSON_EXTRACT(a, '$**.analyzing_range_alternatives')) from t200; drop table t200; +--echo # +--echo # MDEV-24538: JSON_LENGTH does not return error upon wrong number of parameters +--echo # +--error ER_WRONG_PARAMCOUNT_TO_NATIVE_FCT +SELECT JSON_LENGTH('{"a":"b"}','$','$', 'foo'); +--error ER_WRONG_PARAMCOUNT_TO_NATIVE_FCT +SELECT JSON_LENGTH(); + --echo # --echo # End of 10.4 tests --echo # diff --git a/sql/item_jsonfunc.h b/sql/item_jsonfunc.h index 798c5d502db40..b44207ec73fdd 100644 --- a/sql/item_jsonfunc.h +++ b/sql/item_jsonfunc.h @@ -310,6 +310,11 @@ class Item_func_json_length: public Item_long_func { bool check_arguments() const { + if (arg_count == 0 || arg_count > 2) + { + my_error(ER_WRONG_PARAMCOUNT_TO_NATIVE_FCT, MYF(0), func_name()); + return true; + } return args[0]->check_type_can_return_text(func_name()) || (arg_count > 1 && args[1]->check_type_general_purpose_string(func_name())); From 7170db3c3a1a1c59cd7beb591dcab25c69e02847 Mon Sep 17 00:00:00 2001 From: Sergei Petrunia Date: Mon, 13 Feb 2023 16:54:13 +0300 Subject: [PATCH 02/92] MDEV-30596: Assertion 'pushed_rowid_filter != __null ...' failed ha_partition doesn't forward Rowid Filter API calls to the storage engines handling partitions. An attempt to use rowid filtering with caused either - Rowid Filter being shown in EXPLAIN but not actually used - Assertion failure when subquery code tried to disable/enable rowid filter, which was not present. Fixed by returning correct flags from ha_partition::index_flags() --- mysql-test/main/partition.result | 38 +++++++++++++++++++++++++++++++ mysql-test/main/partition.test | 39 +++++++++++++++++++++++++++++++- sql/ha_partition.h | 13 ++++++++++- 3 files changed, 88 insertions(+), 2 deletions(-) diff --git a/mysql-test/main/partition.result b/mysql-test/main/partition.result index a1f7864e66059..79bfef652f43f 100644 --- a/mysql-test/main/partition.result +++ b/mysql-test/main/partition.result @@ -2816,3 +2816,41 @@ DROP TABLE t1,t2; # # End of 10.1 tests # +# +# MDEV-30596: Assertion 'pushed_rowid_filter != __null ...' failed +# +create table t1 (a int); +insert into t1 values (NULL),(1),(2); +create table t2 (a int); +insert into t2 select seq from seq_1_to_1000; +create table t3 ( +a1 int, +a2 int, +b int, +c int, +filler1 char(200), +filler2 char(200), +key(a1,a2), +key(b) +) partition by hash(a1) partitions 2; +insert into t3 select seq/100, seq/100, seq, seq, seq, seq from seq_1_to_10000; +analyze table t3 persistent for all; +Table Op Msg_type Msg_text +test.t3 analyze status Engine-independent statistics collected +test.t3 analyze status OK +set @tmp_os= @@optimizer_switch; +set optimizer_switch='materialization=off'; +# Must not show "Using rowid filter": +explain +select * +from t1 +where +t1.a not in (select straight_join t3.a1 +from t2, t3 +where t3.b < 3000 and t3.a2=t2.a); +id select_type table type possible_keys key key_len ref rows Extra +1 PRIMARY t1 ALL NULL NULL NULL NULL 3 Using where +2 DEPENDENT SUBQUERY t2 ALL NULL NULL NULL NULL 1000 Using where +2 DEPENDENT SUBQUERY t3 ref_or_null a1,b a1 10 func,test.t2.a 198 Using where; Full scan on NULL key +set optimizer_switch=@tmp_os; +drop table t1,t2,t3; diff --git a/mysql-test/main/partition.test b/mysql-test/main/partition.test index cc19bb834945a..40736d3a08fb5 100644 --- a/mysql-test/main/partition.test +++ b/mysql-test/main/partition.test @@ -3016,7 +3016,44 @@ INSERT INTO t2 VALUES (1),(2); UPDATE t1 SET a = 7 WHERE a = ( SELECT b FROM t2 ) ORDER BY a LIMIT 6; DROP TABLE t1,t2; - --echo # --echo # End of 10.1 tests --echo # + +--echo # +--echo # MDEV-30596: Assertion 'pushed_rowid_filter != __null ...' failed +--echo # +--source include/have_sequence.inc +create table t1 (a int); +insert into t1 values (NULL),(1),(2); +create table t2 (a int); +insert into t2 select seq from seq_1_to_1000; + +create table t3 ( + a1 int, + a2 int, + b int, + c int, + filler1 char(200), + filler2 char(200), + key(a1,a2), + key(b) +) partition by hash(a1) partitions 2; +insert into t3 select seq/100, seq/100, seq, seq, seq, seq from seq_1_to_10000; +analyze table t3 persistent for all; + +set @tmp_os= @@optimizer_switch; +set optimizer_switch='materialization=off'; + +--echo # Must not show "Using rowid filter": +explain +select * +from t1 +where + t1.a not in (select straight_join t3.a1 + from t2, t3 + where t3.b < 3000 and t3.a2=t2.a); +set optimizer_switch=@tmp_os; + +drop table t1,t2,t3; + diff --git a/sql/ha_partition.h b/sql/ha_partition.h index 9255df9d519a0..59dacd2cd7f1b 100644 --- a/sql/ha_partition.h +++ b/sql/ha_partition.h @@ -1294,7 +1294,18 @@ class ha_partition :public handler The following code is not safe if you are using different storage engines or different index types per partition. */ - return m_file[0]->index_flags(inx, part, all_parts); + ulong part_flags= m_file[0]->index_flags(inx, part, all_parts); + + /* + The underlying storage engine might support Rowid Filtering. But + ha_partition does not forward the needed SE API calls, so the feature + will not be used. + + Note: It's the same with IndexConditionPushdown, except for its variant + of IndexConditionPushdown+BatchedKeyAccess (that one works). Because of + that, we do not clear HA_DO_INDEX_COND_PUSHDOWN here. + */ + return part_flags & ~HA_DO_RANGE_FILTER_PUSHDOWN; } /** From 81faf41786cfcded18d5b20d341175367ef1453f Mon Sep 17 00:00:00 2001 From: Thirunarayanan Balathandayuthapani Date: Tue, 14 Feb 2023 14:20:48 +0530 Subject: [PATCH 03/92] MDEV-30597 Assertion `flag == 1' failed in row_build_index_entry_low - InnoDB tries to build the previous version of the record for the virtual index, but the undo log record doesn't contain virtual column information. This leads to assert failure while building the tuple. --- mysql-test/suite/gcol/r/gcol_rollback.result | 21 +++++++++++++++++- mysql-test/suite/gcol/t/gcol_rollback.test | 23 +++++++++++++++++++- storage/innobase/row/row0vers.cc | 18 +++++++++++++++ 3 files changed, 60 insertions(+), 2 deletions(-) diff --git a/mysql-test/suite/gcol/r/gcol_rollback.result b/mysql-test/suite/gcol/r/gcol_rollback.result index 5ee94d3ef446b..0bbf034122bd8 100644 --- a/mysql-test/suite/gcol/r/gcol_rollback.result +++ b/mysql-test/suite/gcol/r/gcol_rollback.result @@ -79,10 +79,29 @@ a b c d ROLLBACK; SET DEBUG_SYNC = 'now SIGNAL dml_done'; connection con1; -disconnect con1; connection default; SELECT * FROM t; a b d 9 10 29 DROP TABLE t; SET DEBUG_SYNC = 'RESET'; +# +# MDEV-30597 Assertion `flag == 1' failed in +# row_build_index_entry_low +# +CREATE TABLE t1 ( +col1 INT PRIMARY KEY, col_text TEXT, +col_text_g TEXT GENERATED ALWAYS AS (SUBSTR(col_text,1,499)) +) ENGINE = InnoDB ROW_FORMAT = Compact; +connection con1; +START TRANSACTION WITH CONSISTENT SNAPSHOT; +connection default; +INSERT INTO t1 (col1) VALUES (1) ; +DELETE FROM t1 WHERE col1 = 1; +ALTER TABLE t1 ADD UNIQUE INDEX (col_text_g(9)); +BEGIN; +INSERT INTO t1 (col1) VALUES (1); +ROLLBACK; +disconnect con1; +DROP TABLE t1; +# End of 10.4 tests diff --git a/mysql-test/suite/gcol/t/gcol_rollback.test b/mysql-test/suite/gcol/t/gcol_rollback.test index ba88dda45d7f2..888e6be861e5f 100644 --- a/mysql-test/suite/gcol/t/gcol_rollback.test +++ b/mysql-test/suite/gcol/t/gcol_rollback.test @@ -103,7 +103,6 @@ SET DEBUG_SYNC = 'now SIGNAL dml_done'; connection con1; reap; -disconnect con1; connection default; SELECT * FROM t; @@ -111,5 +110,27 @@ SELECT * FROM t; DROP TABLE t; SET DEBUG_SYNC = 'RESET'; +--echo # +--echo # MDEV-30597 Assertion `flag == 1' failed in +--echo # row_build_index_entry_low +--echo # +CREATE TABLE t1 ( +col1 INT PRIMARY KEY, col_text TEXT, +col_text_g TEXT GENERATED ALWAYS AS (SUBSTR(col_text,1,499)) +) ENGINE = InnoDB ROW_FORMAT = Compact; +connection con1; +START TRANSACTION WITH CONSISTENT SNAPSHOT; +connection default; +INSERT INTO t1 (col1) VALUES (1) ; +DELETE FROM t1 WHERE col1 = 1; +ALTER TABLE t1 ADD UNIQUE INDEX (col_text_g(9)); +BEGIN; +INSERT INTO t1 (col1) VALUES (1); +ROLLBACK; +disconnect con1; +DROP TABLE t1; + # Wait till all disconnects are completed --source include/wait_until_count_sessions.inc + +--echo # End of 10.4 tests diff --git a/storage/innobase/row/row0vers.cc b/storage/innobase/row/row0vers.cc index d1ff7bc540ed1..0679f8838974a 100644 --- a/storage/innobase/row/row0vers.cc +++ b/storage/innobase/row/row0vers.cc @@ -860,6 +860,20 @@ row_vers_build_cur_vrow( return(cur_vrow); } +/** Find out whether data tuple has missing data type +for virtualcolumn. +@param tuple data tuple +@return true if tuple has missing column type */ +static bool dtuple_vcol_data_missing(const dtuple_t &tuple) +{ + for (ulint i= 0; i < tuple.n_v_fields; i++) + { + if (tuple.v_fields[i].type.mtype == DATA_MISSING) + return true; + } + return false; +} + /** Finds out if a version of the record, where the version >= the current purge view, should have ientry as its secondary index entry. We check if there is any not delete marked version of the record where the trx @@ -1088,6 +1102,9 @@ row_vers_old_has_index_entry( if (dict_index_has_virtual(index)) { if (vrow) { + if (dtuple_vcol_data_missing(*vrow)) { + goto nochange_index; + } /* Keep the virtual row info for the next version, unless it is changed */ mem_heap_empty(v_heap); @@ -1098,6 +1115,7 @@ row_vers_old_has_index_entry( if (!cur_vrow) { /* Nothing for this index has changed, continue */ +nochange_index: version = prev_version; continue; } From 60f96b58e4b4d24708b63401ac12f1f058684ea7 Mon Sep 17 00:00:00 2001 From: Robin Newhouse Date: Thu, 8 Dec 2022 20:46:26 +0000 Subject: [PATCH 04/92] Backport GitLab CI to earlier branches Add .gitlab-ci.yml file to earliest supported branch to enable automated building and testing for all MariaDB major branches. For 10.4 we use the bundled SSL to build MariaDB when the platform does not have OpenSSL 1.1 available. This requires the installation of gnutls-devel as a dependency of MariaDB Connector/C. OpenSSL 3.0 support was backported to MariaDB 10.5 (see https://github.com/MariaDB/server/pull/2036, f0fa40ef, 8a9c1e9c) All new code of the whole pull request, including one or several files that are either new files or modified ones, are contributed under the BSD-new license. I am contributing on behalf of my employer Amazon Web Services, Inc. --- .gitlab-ci.yml | 494 +++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 494 insertions(+) create mode 100644 .gitlab-ci.yml diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml new file mode 100644 index 0000000000000..39dae0facb8e5 --- /dev/null +++ b/.gitlab-ci.yml @@ -0,0 +1,494 @@ +--- +# This Gitlab-CI pipeline offers basic validation that a commit did not +# introduce easily detectable regressions. Builds run primairly on a new Fedora, +# which has all the latest upstream build dependencies and thus is the primary +# testing target, as eventually everything in Fedora becomes the next CentOS and +# Red Hat releases. +# +# In addition test building on CentOS 7 and 8 to ensure that the code base +# remains reasonably backwards compatible. +# +# This is now intentionally simple, to keep it fast and accurate with minimal +# false positive failures. If one wants to extend it, see debian/salsa-ci.yml +# for inspiration on more integration tests to run. +# +# Also make sure the pipeline stays within the bounds of what CI workers on +# Gitlab-CI are capable of executing, thus ensuring that any potential +# contributor can at any point in time fork to their own Gitlab account and +# start working towards meaningful contributions! +# +# NOTE TO MERGERS: Most of the contents in the Gitlab-CI configuration has been +# tailored for a specific release or MariaDB. As a general rule, do not merge +# changes in this file across MariaDB branches to avoid breaking the CI. Updates +# the Gitlab-CI pipeline are most of the time better done manually per major +# release branch. + +stages: + - build + - test + - Salsa-CI + +default: + # Base image for builds and tests unless otherwise defined + image: fedora:latest + # Extend build jobs to have longer timeout as the default GitLab + # timeout (1h) is often not enough + timeout: 3h + +# Define common CMAKE_FLAGS for all builds. Skim down build by omitting all +# submodules (a commit in this repo does not affect their builds anyway) and +# many components that are otherwise slow to build. +variables: + CMAKE_FLAGS: "-DPLUGIN_COLUMNSTORE=NO -DPLUGIN_ROCKSDB=NO -DPLUGIN_S3=NO -DPLUGIN_MROONGA=NO -DPLUGIN_CONNECT=NO -DPLUGIN_MROONGA=NO -DPLUGIN_TOKUDB=NO -DPLUGIN_PERFSCHEMA=NO -DWITH_WSREP=OFF" + # Major version dictates which branches share the same ccache. E.g. 10.6-abc + # and 10.6-xyz will have the same cache. + MARIADB_MAJOR_VERSION: "10.6" + # NOTE! Currently ccache is only used on the Centos8 build. As each job has + # sufficiently different environments they are unable to benefit from each + # other's ccaches. As each build generates about 1 GB of ccache, having + # multiple caches would quickly consume all free storage on Gitlab-CI and + # grind all builds to a halt. Also the network overhead of download/upload + # decreases the benefit of ccache in Gitlab-CI, and current cache:when and + # cache:policy are not flexible enough to have a system where the cache is + # uploaded only once a week and not on every build. Having ccache on at least + # one build still helps ensure that ccache compatibility is at least tested + # and if the Centos 8 build is always significantly faster than all other + # builds (e.g. on self-hosted Gitlab instances) then users would at least be + # able to discover it. + # + # Most steps don't need the source code, only artifacts + GIT_STRATEGY: none + # Hack to satisfy directory name length requirement by CPackRPM in CMake 3.x + # https://cmake.org/cmake/help/v3.7/module/CPackRPM.html#variable:CPACK_RPM_BUILD_SOURCE_DIRS_PREFIX + GIT_CLONE_PATH: $CI_BUILDS_DIR/CPACK_BUILD_SOURCE_DIRS_LONG_NAME_REQUIREMENT + +# Define once, use many times +.rpm_listfiles: &rpm_listfiles + - | + echo "Generating rpmlist-$CI_JOB_NAME-$CI_COMMIT_REF_SLUG.log ..." + for package in *.rpm + do + echo "$package" + rpm -qlpv "$package" | awk '{print $1 " " $3 "/" $4 " ." $9 " " $10 " " $11}' | sort -k 3 + echo "------------------------------------------------" + done >> "../rpmlist-$CI_JOB_NAME-$CI_COMMIT_REF_SLUG.log" + # CPackRPM lists contents in build log, so no need to show the output of this, + # just store it as a build artifact that can be downloaded and diffed against + # other builds to detect which files where added/removed/moved + +fedora: + stage: build + variables: + GIT_STRATEGY: fetch + GIT_SUBMODULE_STRATEGY: normal + script: + - yum install -y yum-utils rpm-build openssl-devel graphviz clang gnutls-devel + # Accelerate builds with unsafe disk access, as we can afford to loose the entire build anyway + - yum install -y https://github.com/stewartsmith/libeatmydata/releases/download/v129/libeatmydata-129-1.fc33.x86_64.rpm + # This repository does not have any .spec files, so install dependencies based on Fedora spec file + - yum-builddep -y mariadb-server + - mkdir builddir; cd builddir + - cmake -DRPM=$CI_JOB_NAME $CMAKE_FLAGS -DWITH_SSL=bundled .. 2>&1 | tee -a ../build-$CI_JOB_NAME-$CI_COMMIT_REF_SLUG.log + - cmake --graphviz=../dependencies.dot .. && dot -Tpng -o ../dependencies.png ../dependencies.dot + - eatmydata make package -j 2 2>&1 | tee -a ../build-$CI_JOB_NAME-$CI_COMMIT_REF_SLUG.log + # @TODO: Don't use -j without the limit of 2 on Gitlab.com as builds just + # get stuck when running multi-proc and out of memory, see https://jira.mariadb.org/browse/MDEV-25968 + - make test + # - make test-force # mysql-test-runner takes too long, run MTR in a separate job instead + - *rpm_listfiles + - mkdir ../rpm; mv *.rpm ../rpm + artifacts: + when: always # Must be able to see logs + paths: + - build-$CI_JOB_NAME-$CI_COMMIT_REF_SLUG.log + - rpmlist-$CI_JOB_NAME-$CI_COMMIT_REF_SLUG.log + - rpm + - builddir/_CPack_Packages/Linux/RPM/SPECS/ + - dependencies.dot + - dependencies.png + +fedora-ninja: + stage: build + variables: + GIT_STRATEGY: fetch + GIT_SUBMODULE_STRATEGY: normal + script: + - yum install -y yum-utils rpm-build openssl-devel graphviz ninja-build gnutls-devel + # Accelerate builds with unsafe disk access, as we can afford to loose the entire build anyway + - yum install -y https://github.com/stewartsmith/libeatmydata/releases/download/v129/libeatmydata-129-1.fc33.x86_64.rpm + # This repository does not have any .spec files, so install dependencies based on Fedora spec file + - yum-builddep -y mariadb-server + - mkdir builddir; cd builddir + - cmake -DRPM=generic $CMAKE_FLAGS -DWITH_SSL=bundled -DCMAKE_BUILD_WITH_INSTALL_RPATH=ON -G Ninja .. 2>&1 | tee -a ../build-$CI_JOB_NAME-$CI_COMMIT_REF_SLUG.log + - ninja -t graph > ../dependencies.dot && dot -Tpng -o ../dependencies.png ../dependencies.dot + - eatmydata ninja package -j 2 --verbose 2>&1 | tee -a ../build-$CI_JOB_NAME-$CI_COMMIT_REF_SLUG.log + # @TODO: Unlike other builds, the Ninja builds using Gitlab.com runners don't get stuck, but they do get + # stuck on runners with more processors, see https://jira.mariadb.org/browse/MDEV-25968. + # Thus, use the same limitation on Ninja builds as well to ensure it never gets stuck due to this bug. + - ninja test + - *rpm_listfiles + - mkdir ../rpm; mv *.rpm ../rpm + artifacts: + when: always # Must be able to see logs + paths: + - build-$CI_JOB_NAME-$CI_COMMIT_REF_SLUG.log + - rpmlist-$CI_JOB_NAME-$CI_COMMIT_REF_SLUG.log + - rpm + - builddir/_CPack_Packages/Linux/RPM/SPECS/ + - dependencies.dot + - dependencies.png + +fedora-clang: + stage: build + variables: + GIT_STRATEGY: fetch + GIT_SUBMODULE_STRATEGY: normal + script: + - yum install -y yum-utils rpm-build openssl-devel graphviz clang gnutls-devel + # Accelerate builds with unsafe disk access, as we can afford to loose the entire build anyway + - yum install -y https://github.com/stewartsmith/libeatmydata/releases/download/v129/libeatmydata-129-1.fc33.x86_64.rpm + # This repository does not have any .spec files, so install dependencies based on Fedora spec file + - yum-builddep -y mariadb-server + - mkdir builddir; cd builddir + - export CXX=${CXX:-clang++} + - export CC=${CC:-clang} + - export CXX_FOR_BUILD=${CXX_FOR_BUILD:-clang++} + - export CC_FOR_BUILD=${CC_FOR_BUILD:-clang} + - export CFLAGS='-Wno-unused-command-line-argument' + - export CXXFLAGS='-Wno-unused-command-line-argument' + - cmake -DRPM=generic $CMAKE_FLAGS -DWITH_SSL=bundled .. 2>&1 | tee -a ../build-$CI_JOB_NAME-$CI_COMMIT_REF_SLUG.log + - cmake --graphviz=../dependencies.dot .. && dot -Tpng -o ../dependencies.png ../dependencies.dot + - eatmydata make package -j 2 2>&1 | tee -a ../build-$CI_JOB_NAME-$CI_COMMIT_REF_SLUG.log + # @TODO: Don't use -j without the limit of 2 on Gitlab.com as builds just + # get stuck when running multi-proc and out of memory, see https://jira.mariadb.org/browse/MDEV-25968 + - make test + # - make test-force # mysql-test-runner takes too long, run MTr in a separate job instead + - *rpm_listfiles + - mkdir ../rpm; mv *.rpm ../rpm + artifacts: + when: always # Must be able to see logs + paths: + - build-$CI_JOB_NAME-$CI_COMMIT_REF_SLUG.log + - rpmlist-$CI_JOB_NAME-$CI_COMMIT_REF_SLUG.log + - rpm + - builddir/_CPack_Packages/Linux/RPM/SPECS/ + - dependencies.dot + - dependencies.png + +fedora-sanitizer: + stage: build + variables: + GIT_STRATEGY: fetch + GIT_SUBMODULE_STRATEGY: normal + script: + - yum install -y yum-utils rpm-build openssl-devel clang gnutls-devel + - yum install -y libasan libtsan libubsan + # This repository does not have any .spec files, so install dependencies based on Fedora spec file + - yum-builddep -y mariadb-server + - mkdir builddir; cd builddir + - export CXX=${CXX:-clang++} + - export CC=${CC:-clang} + - export CXX_FOR_BUILD=${CXX_FOR_BUILD:-clang++} + - export CC_FOR_BUILD=${CC_FOR_BUILD:-clang} + - export CFLAGS='-Wno-unused-command-line-argument' + - export CXXFLAGS='-Wno-unused-command-line-argument' + - cmake -DRPM=$CI_JOB_NAME $CMAKE_FLAGS -DWITH_SSL=bundled $SANITIZER .. 2>&1 | tee -a ../build-$CI_JOB_NAME-$CI_COMMIT_REF_SLUG.log + # @TODO: the build will fail consistently at 24% when trying to make using eatmydata + - make package -j 2 2>&1 | tee -a ../build-$CI_JOB_NAME-$CI_COMMIT_REF_SLUG.log + - *rpm_listfiles + - mkdir ../rpm; mv *.rpm ../rpm + artifacts: + when: always # Must be able to see logs + paths: + - build-$CI_JOB_NAME-$CI_COMMIT_REF_SLUG.log + - rpmlist-$CI_JOB_NAME-$CI_COMMIT_REF_SLUG.log + - rpm + - builddir/_CPack_Packages/Linux/RPM/SPECS/ + parallel: + matrix: + - SANITIZER: [-DWITH_ASAN=YES, -DWITH_TSAN=YES, -DWITH_UBSAN=YES, -DWITH_MSAN=YES] + +centos8: + stage: build + image: quay.io/centos/centos:stream8 # CentOS 8 is deprecated, use this Stream8 instead + variables: + GIT_STRATEGY: fetch + GIT_SUBMODULE_STRATEGY: normal + script: + - yum install -y yum-utils rpm-build openssl-devel pcre2-devel + - yum install -y https://dl.fedoraproject.org/pub/epel/epel-release-latest-8.noarch.rpm + # dnf --enablerepo=powertools install Judy-devel #--> not found + - dnf config-manager --set-enabled powertools + # Error: + # Problem: conflicting requests + # - package Judy-devel-1.0.5-18.module_el8.3.0+757+d382997d.i686 is filtered out by modular filtering + # - package Judy-devel-1.0.5-18.module_el8.3.0+757+d382997d.x86_64 is filtered out by modular filtering + # Solution: install Judy-devel directly from downloaded rpm file: + - yum install -y http://vault.centos.org/centos/8/PowerTools/x86_64/os/Packages/Judy-devel-1.0.5-18.module_el8.3.0+757+d382997d.x86_64.rpm + # Use eatmydata to speed up build + - yum install -y https://github.com/stewartsmith/libeatmydata/releases/download/v129/libeatmydata-129-1.fc33.x86_64.rpm + - yum install -y ccache # From EPEL + - source /etc/profile.d/ccache.sh + - export CCACHE_DIR="$(pwd)/.ccache"; ccache --zero-stats + # This repository does not have any .spec files, so install dependencies based on CentOS spec file + - yum-builddep -y mariadb-server + - mkdir builddir; cd builddir + - cmake -DRPM=$CI_JOB_NAME $CMAKE_FLAGS -DWITH_SSL=system .. 2>&1 | tee -a ../build-$CI_JOB_NAME-$CI_COMMIT_REF_SLUG.log + - eatmydata make package -j 2 2>&1 | tee -a ../build-$CI_JOB_NAME-$CI_COMMIT_REF_SLUG.log + # @TODO: Don't use -j without the limit of 2 on Gitlab.com as builds just + # get stuck when running multi-proc and out of memory, see https://jira.mariadb.org/browse/MDEV-25968 + - make test + # - make test-force # mysql-test-runner takes too long, run it MTR a separate job instead + - *rpm_listfiles + - mkdir ../rpm; mv *.rpm ../rpm + - ccache -s + artifacts: + when: always # Must be able to see logs + paths: + - build-$CI_JOB_NAME-$CI_COMMIT_REF_SLUG.log + - rpmlist-$CI_JOB_NAME-$CI_COMMIT_REF_SLUG.log + - rpm + - builddir/_CPack_Packages/Linux/RPM/SPECS/ + cache: + key: $MARIADB_MAJOR_VERSION + paths: + - .ccache + +centos7: + stage: build + image: centos:7 + variables: + GIT_STRATEGY: fetch + GIT_SUBMODULE_STRATEGY: normal + script: + # This repository does not have any .spec files, so install dependencies based on Fedora spec file + - yum-builddep -y mariadb-server + # ..with a few extra ones, as CentOS 7 is very old and these are added in newer MariaDB releases + - yum install -y yum-utils rpm-build gcc gcc-c++ bison libxml2-devel libevent-devel openssl-devel pcre2-devel + - mkdir builddir; cd builddir + - cmake -DRPM=$CI_JOB_NAME $CMAKE_FLAGS -DWITH_SSL=system .. 2>&1 | tee -a ../build-$CI_JOB_NAME-$CI_COMMIT_REF_SLUG.log + - make package -j 2 2>&1 | tee -a ../build-$CI_JOB_NAME-$CI_COMMIT_REF_SLUG.log + # @TODO: Don't use -j without the limit of 2 on Gitlab.com as builds just + # get stuck when running multi-proc and out of memory, see https://jira.mariadb.org/browse/MDEV-25968 + - make test + # - make test-force # mysql-test-runner takes too long, run it in a separate job instead + - *rpm_listfiles + - mkdir ../rpm; mv *.rpm ../rpm + artifacts: + when: always # Must be able to see logs + paths: + - build-$CI_JOB_NAME-$CI_COMMIT_REF_SLUG.log + - rpmlist-$CI_JOB_NAME-$CI_COMMIT_REF_SLUG.log + - rpm + - builddir/_CPack_Packages/Linux/RPM/SPECS/ + +.mysql-test-run: &mysql-test-run-def + stage: test + script: + # Install packages so tests and the dependencies install + # @TODO: RPM missing 'patch' and 'diff' as dependency, so installing it manually for now + - yum install -y rpm/*.rpm patch diffutils + # @TODO: Fix on packaging level for /usr/share/mariadb to work and errormsg.sys be found + - rm -rf /usr/share/mariadb; ln -s /usr/share/mysql /usr/share/mariadb + # mtr expects to be launched in-place and with write access to it's own directories + - cd /usr/share/mysql-test + # Skip failing tests + - | + echo " + main.mysqldump : Field separator argument is not what is expected; check the manual when executing 'SELECT INTO OUTFILE' + main.flush_logs_not_windows : query 'flush logs' succeeded - should have failed with error ER_CANT_CREATE_FILE (1004) + main.mysql_upgrade_noengine : upgrade output order does not match the expected + " > skiplist + - ./mtr --suite=main --force --parallel=auto --xml-report=$CI_PROJECT_DIR/junit.xml --skip-test-list=skiplist $RESTART_POLICY + +mysql-test-run: + stage: test + dependencies: + - fedora + needs: + - fedora + <<: *mysql-test-run-def + artifacts: + when: always # Also show results when tests fail + reports: + junit: + - junit.xml + +# Duplicate of the above jobs, except we use sanitizer build jobs as a dependency. This is so we can keep +# sanitizer errors separate from functional test failures. Currently, there is no way to run the same +# job for different dependencies. +# +# Additionally, for each sanitizer MTR job, we enable --force-restart so that +# sanitizer errors can be traced to individual tests. The difference in test +# suite runtime as a result of this flag is negligable (~30s for the entire test suite). +# (see https://dev.mysql.com/doc/dev/mysql-server/latest/PAGE_MYSQL_TEST_RUN_PL.html) +mysql-test-run-asan: + stage: test + variables: + RESTART_POLICY: "--force-restart" + dependencies: + - "fedora-sanitizer: [-DWITH_ASAN=YES]" + needs: + - "fedora-sanitizer: [-DWITH_ASAN=YES]" + <<: *mysql-test-run-def + artifacts: + when: always # Also show results when tests fail + reports: + junit: + - junit.xml + +mysql-test-run-tsan: + stage: test + variables: + RESTART_POLICY: "--force-restart" + dependencies: + - "fedora-sanitizer: [-DWITH_TSAN=YES]" + needs: + - "fedora-sanitizer: [-DWITH_TSAN=YES]" + <<: *mysql-test-run-def + allow_failure: true + artifacts: + when: always # Also show results when tests fail + reports: + junit: + - junit.xml + +mysql-test-run-ubsan: + stage: test + variables: + RESTART_POLICY: "--force-restart" + dependencies: + - "fedora-sanitizer: [-DWITH_UBSAN=YES]" + needs: + - "fedora-sanitizer: [-DWITH_UBSAN=YES]" + <<: *mysql-test-run-def + allow_failure: true + artifacts: + when: always # Also show results when tests fail + reports: + junit: + - junit.xml + +mysql-test-run-msan: + stage: test + variables: + RESTART_POLICY: "--force-restart" + dependencies: + - "fedora-sanitizer: [-DWITH_MSAN=YES]" + needs: + - "fedora-sanitizer: [-DWITH_MSAN=YES]" + <<: *mysql-test-run-def + allow_failure: true + artifacts: + when: always # Also show results when tests fail + reports: + junit: + - junit.xml + +rpmlint: + stage: test + dependencies: + - fedora + needs: + - fedora + script: + - yum install -y rpmlint + - rm -f rpm/*debuginfo* # Not relevant in this test + # Limit output to 1000 lines as Gitlab-CI max output is 4194304 bytes + # Save everything in a log file so it can be viewed in full via artifacts + - rpmlint --info rpm/*.rpm | tee -a rpmlint-$CI_JOB_NAME-$CI_COMMIT_REF_SLUG.log + artifacts: + when: always # Also show results when tests fail + paths: + - rpmlint-$CI_JOB_NAME-$CI_COMMIT_REF_SLUG.log + allow_failure: true + # @TODO: The package is not rpmlint clean, must allow failure for now + +fedora install: + stage: test + dependencies: + - fedora + needs: + - fedora + script: + - rm -f rpm/*debuginfo* # Not relevant in this test + # Nothing provides galera-4 on Fedora, so this step fails if built with wsrep + - yum install -y rpm/*.rpm + # Fedora does not support running services in Docker (like Debian packages do) so start it manually + - /usr/bin/mariadb-install-db -u mysql + - sudo -u mysql /usr/sbin/mariadbd & sleep 10 + # Dump database contents as is before upgrade + - mariadb-dump --all-databases --all-tablespaces --triggers --routines --events --skip-extended-insert > installed-database.sql + # Since we did a manual start, we also need to run upgrade manually + - /usr/bin/mariadb-upgrade -u root + # Dump database contents as is after upgrade + - mariadb-dump --all-databases --all-tablespaces --triggers --routines --events --skip-extended-insert > upgraded-database.sql + - | + mariadb --skip-column-names -e "SELECT @@version, @@version_comment" | tee /tmp/version + grep $MARIADB_MAJOR_VERSION /tmp/version || echo "MariaDB didn't install properly" + - mariadb --table -e "SELECT * FROM mysql.global_priv; SHOW CREATE USER root@localhost; SHOW CREATE USER 'mariadb.sys'@localhost" + - mariadb --table -e "SELECT * FROM mysql.plugin; SHOW PLUGINS" + - mariadb -e "SHUTDOWN;" + - rm -rf /var/lib/mysql/* # Clear datadir before next run + # Start database without install-db step + - sudo -u mysql /usr/sbin/mariadbd --skip-network --skip-grant & sleep 10 + # Dump database contents in initial state + - mariadb-dump --all-databases --all-tablespaces --triggers --routines --events --skip-extended-insert > empty-database.sql + artifacts: + paths: + - installed-database.sql + - upgraded-database.sql + +fedora upgrade: + stage: test + dependencies: + - fedora + needs: + - fedora + script: + - dnf install -y mariadb-server + # Fedora does not support running services in Docker (like Debian packages do) so start it manually + - /usr/libexec/mariadb-check-socket + - /usr/libexec/mariadb-prepare-db-dir + - sudo -u mysql /usr/libexec/mariadbd --basedir=/usr & sleep 10 + # Dump database contents in installed state + - mariadb-dump --all-databases --all-tablespaces --triggers --routines --events --skip-extended-insert > old-installed-database.sql + - /usr/libexec/mariadb-check-upgrade + # Dump database contents in upgraded state + - mariadb-dump --all-databases --all-tablespaces --triggers --routines --events --skip-extended-insert > old-upgraded-database.sql + - mariadb --skip-column-names -e "SELECT @@version, @@version_comment" # Show version + # @TODO: Upgrade from Fedora 33 MariaDB 10.4 to MariaDB.org latest does not work + # so do this manual step to remove conflicts until packaging is fixed + - yum remove -y mariadb-server-utils mariadb-gssapi-server mariadb-cracklib-password-check mariadb-backup mariadb-connector-c-config + - rm -f rpm/*debuginfo* # Not relevant in this test + - yum install -y rpm/*.rpm + # nothing provides galera-4 on Fedora, so this step fails if built with wsrep + - mysql -e "SHUTDOWN;" + - /usr/bin/mariadb-install-db # This step should not do anything on upgrades, just exit + - sudo -u mysql /usr/sbin/mariadbd & sleep 10 + # Dump database contents in installed state + - mariadb-dump --all-databases --all-tablespaces --triggers --routines --events --skip-extended-insert > new-installed-database.sql || true + # The step above fails on: mariadb-dump: Couldn't execute 'show events': Cannot proceed, because event scheduler is disabled (1577) + # @TODO: Since we did a manual start, we also need to run upgrade manually + - /usr/bin/mariadb-upgrade + # Dump database contents in upgraded state + - mariadb-dump --all-databases --all-tablespaces --triggers --routines --events --skip-extended-insert > new-upgraded-database.sql + - | + mariadb --skip-column-names -e "SELECT @@version, @@version_comment" | tee /tmp/version + grep $MARIADB_MAJOR_VERSION /tmp/version || echo "MariaDB didn't upgrade properly" + - mariadb --table -e "SELECT * FROM mysql.global_priv; SHOW CREATE USER root@localhost; SHOW CREATE USER 'mariadb.sys'@localhost" + - mariadb --table -e "SELECT * FROM mysql.plugin; SHOW PLUGINS" + artifacts: + paths: + - old-installed-database.sql + - old-upgraded-database.sql + - new-installed-database.sql + - new-upgraded-database.sql + +# Once all RPM builds and tests have passed, also run the DEB builds and tests +# @NOTE: This is likely to work well only on salsa.debian.org as the Gitlab.com +# runners are too small for everything this stage does. +# build_deb: +# stage: Salsa-CI +# trigger: +# include: debian/salsa-ci.yml From fab166532f3317c9d04c6f0be17babe7e0927e52 Mon Sep 17 00:00:00 2001 From: Daniel Black Date: Thu, 9 Feb 2023 18:41:45 +1100 Subject: [PATCH 05/92] MDEV-30630 locale: Chinese error messages for ZH_CN MDEV-28227 added the error messages in simplified characters. Lets use these for those running a zh_CN profile. From Haidong Ji in the MDEV, Taiwan/Hong Kong (zh_TW/zh_HK) would expect traditional characters so this is left for when we have these. --- mysql-test/main/locale.result | 10 ++++++++++ mysql-test/main/locale.test | 14 ++++++++++++++ mysql-test/suite/plugins/r/locales.result | 4 ++-- sql/sql_locale.cc | 5 +++-- 4 files changed, 29 insertions(+), 4 deletions(-) diff --git a/mysql-test/main/locale.result b/mysql-test/main/locale.result index f136e9e99abe0..8ff5bde39e191 100644 --- a/mysql-test/main/locale.result +++ b/mysql-test/main/locale.result @@ -306,3 +306,13 @@ date_format('2001-01-06', '%w %a %W', 'de_CH') select date_format('2001-09-01', '%c %b %M', 'de_CH'); date_format('2001-09-01', '%c %b %M', 'de_CH') 9 Sep September +# +# MDEV-30630 locale: Chinese error message for ZH_CN +# +SET lc_messages=ZH_CN; +SELECT x; +ERROR 42S22: 未知列'x'在'field list' +SET lc_messages=DEFAULT; +# +# End of 10.4 tests +# diff --git a/mysql-test/main/locale.test b/mysql-test/main/locale.test index a9a507bc38798..7d9a07178eed3 100644 --- a/mysql-test/main/locale.test +++ b/mysql-test/main/locale.test @@ -181,3 +181,17 @@ select date_format('2001-10-01', '%c %b %M', 'rm_CH'); select date_format('2001-12-01', '%c %b %M', 'rm_CH'); select date_format('2001-01-06', '%w %a %W', 'de_CH'); select date_format('2001-09-01', '%c %b %M', 'de_CH'); + +--echo # +--echo # MDEV-30630 locale: Chinese error message for ZH_CN +--echo # + +SET lc_messages=ZH_CN; +--error ER_BAD_FIELD_ERROR +SELECT x; + +SET lc_messages=DEFAULT; + +--echo # +--echo # End of 10.4 tests +--echo # diff --git a/mysql-test/suite/plugins/r/locales.result b/mysql-test/suite/plugins/r/locales.result index e906d27c21ef0..5229b7ffaa885 100644 --- a/mysql-test/suite/plugins/r/locales.result +++ b/mysql-test/suite/plugins/r/locales.result @@ -57,7 +57,7 @@ ID NAME DESCRIPTION MAX_MONTH_NAME_LENGTH MAX_DAY_NAME_LENGTH DECIMAL_POINT THOU 53 uk_UA Ukrainian - Ukraine 8 9 , . ukrainian 54 ur_PK Urdu - Pakistan 6 6 . , english 55 vi_VN Vietnamese - Vietnam 16 11 , . english -56 zh_CN Chinese - Peoples Republic of China 3 3 . , english +56 zh_CN Chinese - Peoples Republic of China 3 3 . , chinese 57 zh_TW Chinese - Taiwan 3 2 . , english 58 ar_DZ Arabic - Algeria 6 8 . , english 59 ar_EG Arabic - Egypt 6 8 . , english @@ -170,7 +170,7 @@ Id Name Description Error_Message_Language 53 uk_UA Ukrainian - Ukraine ukrainian 54 ur_PK Urdu - Pakistan english 55 vi_VN Vietnamese - Vietnam english -56 zh_CN Chinese - Peoples Republic of China english +56 zh_CN Chinese - Peoples Republic of China chinese 57 zh_TW Chinese - Taiwan english 58 ar_DZ Arabic - Algeria english 59 ar_EG Arabic - Egypt english diff --git a/sql/sql_locale.cc b/sql/sql_locale.cc index dd19807dd6db2..60e7abc3fa23f 100644 --- a/sql/sql_locale.cc +++ b/sql/sql_locale.cc @@ -29,7 +29,7 @@ enum err_msgs_index { - en_US= 0, cs_CZ, da_DK, nl_NL, et_EE, fr_FR, de_DE, el_GR, hu_HU, it_IT, + en_US= 0, zh_CN, cs_CZ, da_DK, nl_NL, et_EE, fr_FR, de_DE, el_GR, hu_HU, it_IT, ja_JP, ko_KR, no_NO, nn_NO, pl_PL, pt_PT, ro_RO, ru_RU, sr_RS, sk_SK, es_ES, sv_SE, uk_UA, hi_IN } ERR_MSGS_INDEX; @@ -38,6 +38,7 @@ enum err_msgs_index MY_LOCALE_ERRMSGS global_errmsgs[]= { {"english", NULL}, + {"chinese", NULL}, {"czech", NULL}, {"danish", NULL}, {"dutch", NULL}, @@ -2095,7 +2096,7 @@ MY_LOCALE my_locale_zh_CN '.', /* decimal point zh_CN */ ',', /* thousands_sep zh_CN */ "\x03", /* grouping zh_CN */ - &global_errmsgs[en_US] + &global_errmsgs[zh_CN] ); /***** LOCALE END zh_CN *****/ From 03c9a4ef4a0363ba0ffd1843284332fb9c5fd692 Mon Sep 17 00:00:00 2001 From: Haidong Ji Date: Wed, 7 Dec 2022 16:54:27 +0000 Subject: [PATCH 06/92] MDEV-29091: Correct event_name in PFS for wait caused by FOR UPDATE When one session SELECT ... FOR UPDATE and holds the lock, subsequent sessions that SELECT ... FOR UPDATE will wait to get the lock. Currently, that event is labeled as `wait/io/table/sql/handler`, which is incorrect. Instead, it should have been `wait/lock/table/sql/handler`. Two factors contribute to this bug: 1. Instrumentation interface and the heavy usage of `TABLE_IO_WAIT` in `sql/handler.cc` file. See interface [^1] for better understanding; 2. The balancing act [^2] of doing instrumentation aggregration _AND_ having good performance. For example, EVENTS_WAITS_SUMMARY... is aggregated using EVENTS_WAITS_CURRENT. Aggregration needs to be based on the same wait class, and the code was overly aggressive in label a LOCK operation as an IO operation in this case. The proposed fix is pretty simple, but understanding the bug took a while. Hence the footnotes below. For future improvement and refactoring, we may want to consider renaming `TABLE_IO_WAIT` and making it less coarse and more targeted. Note that newly added test case, events_waits_current_MDEV-29091, initially didn't pass Buildbot CI for embedded build tests. Further research showed that other impacted tests all included not_embedded.inc. This oversight was fixed later. All new code of the whole pull request, including one or several files that are either new files or modified ones, are contributed under the BSD-new license. I am contributing on behalf of my employer Amazon Web Services, Inc. [^1]: To understand `performance_schema` instrumentation interface, I found this URL is the most helpful: https://dev.mysql.com/doc/dev/mysql-server/latest/PAGE_PFS_PSI.html [^2]: The best place to understand instrumentation projection, composition, and aggregration is through the source file. Although I prefer reading Doxygen produced html file, but for whatever reason, the rendering is not ideal. Here is link to 10.6's pfs.cc: https://github.com/MariaDB/server/blob/10.6/storage/perfschema/pfs.cc --- .../r/events_waits_current_MDEV-29091.result | 41 +++++ .../r/table_aggregate_hist_2u_2t.result | 114 ++++-------- .../r/table_aggregate_hist_2u_3t.result | 171 ++++++------------ .../r/table_aggregate_hist_4u_2t.result | 114 ++++-------- .../r/table_aggregate_hist_4u_3t.result | 171 ++++++------------ .../t/events_waits_current_MDEV-29091.test | 62 +++++++ storage/perfschema/pfs.cc | 3 +- 7 files changed, 295 insertions(+), 381 deletions(-) create mode 100644 mysql-test/suite/perfschema/r/events_waits_current_MDEV-29091.result create mode 100644 mysql-test/suite/perfschema/t/events_waits_current_MDEV-29091.test diff --git a/mysql-test/suite/perfschema/r/events_waits_current_MDEV-29091.result b/mysql-test/suite/perfschema/r/events_waits_current_MDEV-29091.result new file mode 100644 index 0000000000000..8f3a17a0fc51e --- /dev/null +++ b/mysql-test/suite/perfschema/r/events_waits_current_MDEV-29091.result @@ -0,0 +1,41 @@ +SET default_storage_engine=InnoDB; +SELECT @save_instrument_enabled := ENABLED +, @save_instrument_timed := TIMED +FROM performance_schema.setup_instruments +WHERE NAME = 'wait/lock/table/sql/handler'; +@save_instrument_enabled := ENABLED @save_instrument_timed := TIMED +YES YES +SELECT @save_consumer_enabled := ENABLED +FROM performance_schema.setup_consumers +WHERE NAME = 'events_waits_current'; +@save_consumer_enabled := ENABLED +YES +UPDATE performance_schema.setup_instruments +SET ENABLED = 'YES', TIMED = 'YES' +WHERE NAME = 'wait/lock/table/sql/handler'; +UPDATE performance_schema.setup_consumers +SET ENABLED = 'YES' +WHERE NAME = 'events_waits_current'; +CREATE TABLE t1 (id1 INT(11), col1 VARCHAR (200)); +INSERT INTO t1 VALUES (1, 'aa'); +INSERT INTO t1 VALUES (2, 'bb'); +connect con1,localhost,root,,test; +connect con2,localhost,root,,test; +connection con1; +START TRANSACTION; +connection con2; +START TRANSACTION; +SELECT id1 FROM t1 WHERE id1=1 FOR UPDATE; +connection default; +SELECT event_name FROM performance_schema.events_waits_current +WHERE event_name LIKE '%wait/lock/table/sql/handler%'; +event_name +UPDATE performance_schema.setup_instruments +SET ENABLED = @save_instrument_enabled, TIMED = @save_instrument_timed +WHERE NAME = 'wait/lock/table/sql/handler'; +UPDATE performance_schema.setup_consumers +SET ENABLED = @save_consumer_enabled +WHERE NAME = 'events_waits_current'; +disconnect con1; +disconnect con2; +DROP TABLE t1; diff --git a/mysql-test/suite/perfschema/r/table_aggregate_hist_2u_2t.result b/mysql-test/suite/perfschema/r/table_aggregate_hist_2u_2t.result index ee95e4c0417f0..ac0d5391fc022 100644 --- a/mysql-test/suite/perfschema/r/table_aggregate_hist_2u_2t.result +++ b/mysql-test/suite/perfschema/r/table_aggregate_hist_2u_2t.result @@ -215,10 +215,8 @@ wait/io/table/sql/handler 25 wait/lock/table/sql/handler 24 execute dump_waits_history; event_name count(event_name) object_type object_schema object_name -wait/io/table/sql/handler 8 TABLE test t1 -wait/lock/table/sql/handler 10 TABLE test t1 -wait/io/table/sql/handler 17 TABLE test t3 -wait/lock/table/sql/handler 14 TABLE test t3 +wait/lock/table/sql/handler 18 TABLE test t1 +wait/lock/table/sql/handler 31 TABLE test t3 execute dump_waits_index_io; object_type object_schema object_name index_name count_star count_read count_write count_fetch count_insert count_update count_delete TABLE test t1 NULL 6 4 2 4 1 1 0 @@ -287,10 +285,8 @@ wait/io/table/sql/handler 25 wait/lock/table/sql/handler 24 execute dump_waits_history; event_name count(event_name) object_type object_schema object_name -wait/io/table/sql/handler 8 TABLE test t1 -wait/lock/table/sql/handler 10 TABLE test t1 -wait/io/table/sql/handler 17 TABLE test t3 -wait/lock/table/sql/handler 14 TABLE test t3 +wait/lock/table/sql/handler 18 TABLE test t1 +wait/lock/table/sql/handler 31 TABLE test t3 execute dump_waits_index_io; object_type object_schema object_name index_name count_star count_read count_write count_fetch count_insert count_update count_delete TABLE test t1 NULL 6 4 2 4 1 1 0 @@ -394,10 +390,8 @@ wait/io/table/sql/handler 25 wait/lock/table/sql/handler 24 execute dump_waits_history; event_name count(event_name) object_type object_schema object_name -wait/io/table/sql/handler 8 TABLE test t1 -wait/lock/table/sql/handler 10 TABLE test t1 -wait/io/table/sql/handler 17 TABLE test t3 -wait/lock/table/sql/handler 14 TABLE test t3 +wait/lock/table/sql/handler 18 TABLE test t1 +wait/lock/table/sql/handler 31 TABLE test t3 execute dump_waits_index_io; object_type object_schema object_name index_name count_star count_read count_write count_fetch count_insert count_update count_delete TABLE test t1 NULL 6 4 2 4 1 1 0 @@ -471,10 +465,8 @@ wait/io/table/sql/handler 25 wait/lock/table/sql/handler 24 execute dump_waits_history; event_name count(event_name) object_type object_schema object_name -wait/io/table/sql/handler 8 TABLE test t1 -wait/lock/table/sql/handler 10 TABLE test t1 -wait/io/table/sql/handler 17 TABLE test t3 -wait/lock/table/sql/handler 14 TABLE test t3 +wait/lock/table/sql/handler 18 TABLE test t1 +wait/lock/table/sql/handler 31 TABLE test t3 execute dump_waits_index_io; object_type object_schema object_name index_name count_star count_read count_write count_fetch count_insert count_update count_delete TABLE test t1 NULL 6 4 2 4 1 1 0 @@ -590,10 +582,8 @@ wait/io/table/sql/handler 77 wait/lock/table/sql/handler 48 execute dump_waits_history; event_name count(event_name) object_type object_schema object_name -wait/io/table/sql/handler 23 TABLE test t1 -wait/lock/table/sql/handler 20 TABLE test t1 -wait/io/table/sql/handler 54 TABLE test t3 -wait/lock/table/sql/handler 28 TABLE test t3 +wait/lock/table/sql/handler 43 TABLE test t1 +wait/lock/table/sql/handler 82 TABLE test t3 execute dump_waits_index_io; object_type object_schema object_name index_name count_star count_read count_write count_fetch count_insert count_update count_delete TABLE test t1 NULL 18 12 6 12 2 4 0 @@ -672,10 +662,8 @@ wait/io/table/sql/handler 77 wait/lock/table/sql/handler 48 execute dump_waits_history; event_name count(event_name) object_type object_schema object_name -wait/io/table/sql/handler 23 TABLE test t1 -wait/lock/table/sql/handler 20 TABLE test t1 -wait/io/table/sql/handler 54 TABLE test t3 -wait/lock/table/sql/handler 28 TABLE test t3 +wait/lock/table/sql/handler 43 TABLE test t1 +wait/lock/table/sql/handler 82 TABLE test t3 execute dump_waits_index_io; object_type object_schema object_name index_name count_star count_read count_write count_fetch count_insert count_update count_delete TABLE test t1 NULL 18 12 6 12 2 4 0 @@ -803,10 +791,8 @@ wait/io/table/sql/handler 77 wait/lock/table/sql/handler 48 execute dump_waits_history; event_name count(event_name) object_type object_schema object_name -wait/io/table/sql/handler 23 TABLE test t1 -wait/lock/table/sql/handler 20 TABLE test t1 -wait/io/table/sql/handler 54 TABLE test t3 -wait/lock/table/sql/handler 28 TABLE test t3 +wait/lock/table/sql/handler 43 TABLE test t1 +wait/lock/table/sql/handler 82 TABLE test t3 execute dump_waits_index_io; object_type object_schema object_name index_name count_star count_read count_write count_fetch count_insert count_update count_delete TABLE test t1 NULL 18 12 6 12 2 4 0 @@ -886,10 +872,8 @@ wait/io/table/sql/handler 77 wait/lock/table/sql/handler 56 execute dump_waits_history; event_name count(event_name) object_type object_schema object_name -wait/io/table/sql/handler 23 TABLE test t1 -wait/lock/table/sql/handler 24 TABLE test t1 -wait/io/table/sql/handler 54 TABLE test t3 -wait/lock/table/sql/handler 32 TABLE test t3 +wait/lock/table/sql/handler 47 TABLE test t1 +wait/lock/table/sql/handler 86 TABLE test t3 execute dump_waits_index_io; object_type object_schema object_name index_name count_star count_read count_write count_fetch count_insert count_update count_delete TABLE test t1 NULL 18 12 6 12 2 4 0 @@ -966,10 +950,8 @@ wait/io/table/sql/handler 77 wait/lock/table/sql/handler 56 execute dump_waits_history; event_name count(event_name) object_type object_schema object_name -wait/io/table/sql/handler 23 TABLE test t1 -wait/lock/table/sql/handler 24 TABLE test t1 -wait/io/table/sql/handler 54 TABLE test t3 -wait/lock/table/sql/handler 32 TABLE test t3 +wait/lock/table/sql/handler 47 TABLE test t1 +wait/lock/table/sql/handler 86 TABLE test t3 execute dump_waits_index_io; object_type object_schema object_name index_name count_star count_read count_write count_fetch count_insert count_update count_delete TABLE test t1 NULL 18 12 6 12 2 4 0 @@ -1046,10 +1028,8 @@ wait/io/table/sql/handler 77 wait/lock/table/sql/handler 56 execute dump_waits_history; event_name count(event_name) object_type object_schema object_name -wait/io/table/sql/handler 23 TABLE test t1 -wait/lock/table/sql/handler 24 TABLE test t1 -wait/io/table/sql/handler 54 TABLE test t3 -wait/lock/table/sql/handler 32 TABLE test t3 +wait/lock/table/sql/handler 47 TABLE test t1 +wait/lock/table/sql/handler 86 TABLE test t3 execute dump_waits_index_io; object_type object_schema object_name index_name count_star count_read count_write count_fetch count_insert count_update count_delete TABLE test t1 NULL 18 12 6 12 2 4 0 @@ -1123,10 +1103,8 @@ wait/io/table/sql/handler 77 wait/lock/table/sql/handler 56 execute dump_waits_history; event_name count(event_name) object_type object_schema object_name -wait/io/table/sql/handler 23 TABLE test t1 -wait/lock/table/sql/handler 24 TABLE test t1 -wait/io/table/sql/handler 54 TABLE test t3 -wait/lock/table/sql/handler 32 TABLE test t3 +wait/lock/table/sql/handler 47 TABLE test t1 +wait/lock/table/sql/handler 86 TABLE test t3 execute dump_waits_index_io; object_type object_schema object_name index_name count_star count_read count_write count_fetch count_insert count_update count_delete TABLE test t1 NULL 18 12 6 12 2 4 0 @@ -1199,10 +1177,8 @@ wait/io/table/sql/handler 77 wait/lock/table/sql/handler 56 execute dump_waits_history; event_name count(event_name) object_type object_schema object_name -wait/io/table/sql/handler 23 TABLE test t1 -wait/lock/table/sql/handler 24 TABLE test t1 -wait/io/table/sql/handler 54 TABLE test t3 -wait/lock/table/sql/handler 32 TABLE test t3 +wait/lock/table/sql/handler 47 TABLE test t1 +wait/lock/table/sql/handler 86 TABLE test t3 execute dump_waits_index_io; object_type object_schema object_name index_name count_star count_read count_write count_fetch count_insert count_update count_delete TABLE test t1 NULL 18 12 6 12 2 4 0 @@ -1274,10 +1250,8 @@ wait/io/table/sql/handler 77 wait/lock/table/sql/handler 56 execute dump_waits_history; event_name count(event_name) object_type object_schema object_name -wait/io/table/sql/handler 23 TABLE test t1 -wait/lock/table/sql/handler 24 TABLE test t1 -wait/io/table/sql/handler 54 TABLE test t3 -wait/lock/table/sql/handler 32 TABLE test t3 +wait/lock/table/sql/handler 47 TABLE test t1 +wait/lock/table/sql/handler 86 TABLE test t3 execute dump_waits_index_io; object_type object_schema object_name index_name count_star count_read count_write count_fetch count_insert count_update count_delete TABLE test t1 NULL 18 12 6 12 2 4 0 @@ -1348,10 +1322,8 @@ wait/io/table/sql/handler 77 wait/lock/table/sql/handler 56 execute dump_waits_history; event_name count(event_name) object_type object_schema object_name -wait/io/table/sql/handler 23 TABLE test t1 -wait/lock/table/sql/handler 24 TABLE test t1 -wait/io/table/sql/handler 54 TABLE test t3 -wait/lock/table/sql/handler 32 TABLE test t3 +wait/lock/table/sql/handler 47 TABLE test t1 +wait/lock/table/sql/handler 86 TABLE test t3 execute dump_waits_index_io; object_type object_schema object_name index_name count_star count_read count_write count_fetch count_insert count_update count_delete TABLE test t1 NULL 18 12 6 12 2 4 0 @@ -1424,10 +1396,8 @@ wait/io/table/sql/handler 77 wait/lock/table/sql/handler 56 execute dump_waits_history; event_name count(event_name) object_type object_schema object_name -wait/io/table/sql/handler 23 TABLE test t1 -wait/lock/table/sql/handler 24 TABLE test t1 -wait/io/table/sql/handler 54 TABLE test t3 -wait/lock/table/sql/handler 32 TABLE test t3 +wait/lock/table/sql/handler 47 TABLE test t1 +wait/lock/table/sql/handler 86 TABLE test t3 execute dump_waits_index_io; object_type object_schema object_name index_name count_star count_read count_write count_fetch count_insert count_update count_delete TABLE test t1 NULL 18 12 6 12 2 4 0 @@ -1499,10 +1469,8 @@ wait/io/table/sql/handler 77 wait/lock/table/sql/handler 56 execute dump_waits_history; event_name count(event_name) object_type object_schema object_name -wait/io/table/sql/handler 23 TABLE test t1 -wait/lock/table/sql/handler 24 TABLE test t1 -wait/io/table/sql/handler 54 TABLE test t3 -wait/lock/table/sql/handler 32 TABLE test t3 +wait/lock/table/sql/handler 47 TABLE test t1 +wait/lock/table/sql/handler 86 TABLE test t3 execute dump_waits_index_io; object_type object_schema object_name index_name count_star count_read count_write count_fetch count_insert count_update count_delete TABLE test t1 NULL 18 12 6 12 2 4 0 @@ -1574,10 +1542,8 @@ wait/io/table/sql/handler 77 wait/lock/table/sql/handler 56 execute dump_waits_history; event_name count(event_name) object_type object_schema object_name -wait/io/table/sql/handler 23 TABLE test t1 -wait/lock/table/sql/handler 24 TABLE test t1 -wait/io/table/sql/handler 54 TABLE test t3 -wait/lock/table/sql/handler 32 TABLE test t3 +wait/lock/table/sql/handler 47 TABLE test t1 +wait/lock/table/sql/handler 86 TABLE test t3 execute dump_waits_index_io; object_type object_schema object_name index_name count_star count_read count_write count_fetch count_insert count_update count_delete TABLE test t1 NULL 18 12 6 12 2 4 0 @@ -1649,10 +1615,8 @@ wait/io/table/sql/handler 77 wait/lock/table/sql/handler 56 execute dump_waits_history; event_name count(event_name) object_type object_schema object_name -wait/io/table/sql/handler 23 TABLE test t1 -wait/lock/table/sql/handler 24 TABLE test t1 -wait/io/table/sql/handler 54 TABLE test t3 -wait/lock/table/sql/handler 32 TABLE test t3 +wait/lock/table/sql/handler 47 TABLE test t1 +wait/lock/table/sql/handler 86 TABLE test t3 execute dump_waits_index_io; object_type object_schema object_name index_name count_star count_read count_write count_fetch count_insert count_update count_delete TABLE test t1 NULL 18 12 6 12 2 4 0 @@ -1724,10 +1688,8 @@ wait/io/table/sql/handler 0 wait/lock/table/sql/handler 0 execute dump_waits_history; event_name count(event_name) object_type object_schema object_name -wait/io/table/sql/handler 23 TABLE test t1 -wait/lock/table/sql/handler 24 TABLE test t1 -wait/io/table/sql/handler 54 TABLE test t3 -wait/lock/table/sql/handler 32 TABLE test t3 +wait/lock/table/sql/handler 47 TABLE test t1 +wait/lock/table/sql/handler 86 TABLE test t3 execute dump_waits_index_io; object_type object_schema object_name index_name count_star count_read count_write count_fetch count_insert count_update count_delete TABLE test t1 NULL 0 0 0 0 0 0 0 diff --git a/mysql-test/suite/perfschema/r/table_aggregate_hist_2u_3t.result b/mysql-test/suite/perfschema/r/table_aggregate_hist_2u_3t.result index d6e4e674258ca..372bdc094f368 100644 --- a/mysql-test/suite/perfschema/r/table_aggregate_hist_2u_3t.result +++ b/mysql-test/suite/perfschema/r/table_aggregate_hist_2u_3t.result @@ -214,12 +214,9 @@ wait/io/table/sql/handler 37 wait/lock/table/sql/handler 36 execute dump_waits_history; event_name count(event_name) object_type object_schema object_name -wait/io/table/sql/handler 8 TABLE test t1 -wait/lock/table/sql/handler 10 TABLE test t1 -wait/io/table/sql/handler 12 TABLE test t2 -wait/lock/table/sql/handler 12 TABLE test t2 -wait/io/table/sql/handler 17 TABLE test t3 -wait/lock/table/sql/handler 14 TABLE test t3 +wait/lock/table/sql/handler 18 TABLE test t1 +wait/lock/table/sql/handler 24 TABLE test t2 +wait/lock/table/sql/handler 31 TABLE test t3 execute dump_waits_index_io; object_type object_schema object_name index_name count_star count_read count_write count_fetch count_insert count_update count_delete TABLE test t1 NULL 6 4 2 4 1 1 0 @@ -288,12 +285,9 @@ wait/io/table/sql/handler 37 wait/lock/table/sql/handler 36 execute dump_waits_history; event_name count(event_name) object_type object_schema object_name -wait/io/table/sql/handler 8 TABLE test t1 -wait/lock/table/sql/handler 10 TABLE test t1 -wait/io/table/sql/handler 12 TABLE test t2 -wait/lock/table/sql/handler 12 TABLE test t2 -wait/io/table/sql/handler 17 TABLE test t3 -wait/lock/table/sql/handler 14 TABLE test t3 +wait/lock/table/sql/handler 18 TABLE test t1 +wait/lock/table/sql/handler 24 TABLE test t2 +wait/lock/table/sql/handler 31 TABLE test t3 execute dump_waits_index_io; object_type object_schema object_name index_name count_star count_read count_write count_fetch count_insert count_update count_delete TABLE test t1 NULL 6 4 2 4 1 1 0 @@ -397,12 +391,9 @@ wait/io/table/sql/handler 37 wait/lock/table/sql/handler 36 execute dump_waits_history; event_name count(event_name) object_type object_schema object_name -wait/io/table/sql/handler 8 TABLE test t1 -wait/lock/table/sql/handler 10 TABLE test t1 -wait/io/table/sql/handler 12 TABLE test t2 -wait/lock/table/sql/handler 12 TABLE test t2 -wait/io/table/sql/handler 17 TABLE test t3 -wait/lock/table/sql/handler 14 TABLE test t3 +wait/lock/table/sql/handler 18 TABLE test t1 +wait/lock/table/sql/handler 24 TABLE test t2 +wait/lock/table/sql/handler 31 TABLE test t3 execute dump_waits_index_io; object_type object_schema object_name index_name count_star count_read count_write count_fetch count_insert count_update count_delete TABLE test t1 NULL 6 4 2 4 1 1 0 @@ -476,12 +467,9 @@ wait/io/table/sql/handler 37 wait/lock/table/sql/handler 36 execute dump_waits_history; event_name count(event_name) object_type object_schema object_name -wait/io/table/sql/handler 8 TABLE test t1 -wait/lock/table/sql/handler 10 TABLE test t1 -wait/io/table/sql/handler 12 TABLE test t2 -wait/lock/table/sql/handler 12 TABLE test t2 -wait/io/table/sql/handler 17 TABLE test t3 -wait/lock/table/sql/handler 14 TABLE test t3 +wait/lock/table/sql/handler 18 TABLE test t1 +wait/lock/table/sql/handler 24 TABLE test t2 +wait/lock/table/sql/handler 31 TABLE test t3 execute dump_waits_index_io; object_type object_schema object_name index_name count_star count_read count_write count_fetch count_insert count_update count_delete TABLE test t1 NULL 6 4 2 4 1 1 0 @@ -597,12 +585,9 @@ wait/io/table/sql/handler 113 wait/lock/table/sql/handler 72 execute dump_waits_history; event_name count(event_name) object_type object_schema object_name -wait/io/table/sql/handler 23 TABLE test t1 -wait/lock/table/sql/handler 20 TABLE test t1 -wait/io/table/sql/handler 36 TABLE test t2 -wait/lock/table/sql/handler 24 TABLE test t2 -wait/io/table/sql/handler 54 TABLE test t3 -wait/lock/table/sql/handler 28 TABLE test t3 +wait/lock/table/sql/handler 43 TABLE test t1 +wait/lock/table/sql/handler 60 TABLE test t2 +wait/lock/table/sql/handler 82 TABLE test t3 execute dump_waits_index_io; object_type object_schema object_name index_name count_star count_read count_write count_fetch count_insert count_update count_delete TABLE test t1 NULL 18 12 6 12 2 4 0 @@ -681,12 +666,9 @@ wait/io/table/sql/handler 113 wait/lock/table/sql/handler 72 execute dump_waits_history; event_name count(event_name) object_type object_schema object_name -wait/io/table/sql/handler 23 TABLE test t1 -wait/lock/table/sql/handler 20 TABLE test t1 -wait/io/table/sql/handler 36 TABLE test t2 -wait/lock/table/sql/handler 24 TABLE test t2 -wait/io/table/sql/handler 54 TABLE test t3 -wait/lock/table/sql/handler 28 TABLE test t3 +wait/lock/table/sql/handler 43 TABLE test t1 +wait/lock/table/sql/handler 60 TABLE test t2 +wait/lock/table/sql/handler 82 TABLE test t3 execute dump_waits_index_io; object_type object_schema object_name index_name count_star count_read count_write count_fetch count_insert count_update count_delete TABLE test t1 NULL 18 12 6 12 2 4 0 @@ -814,12 +796,9 @@ wait/io/table/sql/handler 113 wait/lock/table/sql/handler 72 execute dump_waits_history; event_name count(event_name) object_type object_schema object_name -wait/io/table/sql/handler 23 TABLE test t1 -wait/lock/table/sql/handler 20 TABLE test t1 -wait/io/table/sql/handler 36 TABLE test t2 -wait/lock/table/sql/handler 24 TABLE test t2 -wait/io/table/sql/handler 54 TABLE test t3 -wait/lock/table/sql/handler 28 TABLE test t3 +wait/lock/table/sql/handler 43 TABLE test t1 +wait/lock/table/sql/handler 60 TABLE test t2 +wait/lock/table/sql/handler 82 TABLE test t3 execute dump_waits_index_io; object_type object_schema object_name index_name count_star count_read count_write count_fetch count_insert count_update count_delete TABLE test t1 NULL 18 12 6 12 2 4 0 @@ -899,12 +878,9 @@ wait/io/table/sql/handler 113 wait/lock/table/sql/handler 84 execute dump_waits_history; event_name count(event_name) object_type object_schema object_name -wait/io/table/sql/handler 23 TABLE test t1 -wait/lock/table/sql/handler 24 TABLE test t1 -wait/io/table/sql/handler 36 TABLE test t2 -wait/lock/table/sql/handler 28 TABLE test t2 -wait/io/table/sql/handler 54 TABLE test t3 -wait/lock/table/sql/handler 32 TABLE test t3 +wait/lock/table/sql/handler 47 TABLE test t1 +wait/lock/table/sql/handler 64 TABLE test t2 +wait/lock/table/sql/handler 86 TABLE test t3 execute dump_waits_index_io; object_type object_schema object_name index_name count_star count_read count_write count_fetch count_insert count_update count_delete TABLE test t1 NULL 18 12 6 12 2 4 0 @@ -981,12 +957,9 @@ wait/io/table/sql/handler 113 wait/lock/table/sql/handler 84 execute dump_waits_history; event_name count(event_name) object_type object_schema object_name -wait/io/table/sql/handler 23 TABLE test t1 -wait/lock/table/sql/handler 24 TABLE test t1 -wait/io/table/sql/handler 36 TABLE test t2 -wait/lock/table/sql/handler 28 TABLE test t2 -wait/io/table/sql/handler 54 TABLE test t3 -wait/lock/table/sql/handler 32 TABLE test t3 +wait/lock/table/sql/handler 47 TABLE test t1 +wait/lock/table/sql/handler 64 TABLE test t2 +wait/lock/table/sql/handler 86 TABLE test t3 execute dump_waits_index_io; object_type object_schema object_name index_name count_star count_read count_write count_fetch count_insert count_update count_delete TABLE test t1 NULL 18 12 6 12 2 4 0 @@ -1063,12 +1036,9 @@ wait/io/table/sql/handler 113 wait/lock/table/sql/handler 84 execute dump_waits_history; event_name count(event_name) object_type object_schema object_name -wait/io/table/sql/handler 23 TABLE test t1 -wait/lock/table/sql/handler 24 TABLE test t1 -wait/io/table/sql/handler 36 TABLE test t2 -wait/lock/table/sql/handler 28 TABLE test t2 -wait/io/table/sql/handler 54 TABLE test t3 -wait/lock/table/sql/handler 32 TABLE test t3 +wait/lock/table/sql/handler 47 TABLE test t1 +wait/lock/table/sql/handler 64 TABLE test t2 +wait/lock/table/sql/handler 86 TABLE test t3 execute dump_waits_index_io; object_type object_schema object_name index_name count_star count_read count_write count_fetch count_insert count_update count_delete TABLE test t1 NULL 18 12 6 12 2 4 0 @@ -1142,12 +1112,9 @@ wait/io/table/sql/handler 113 wait/lock/table/sql/handler 84 execute dump_waits_history; event_name count(event_name) object_type object_schema object_name -wait/io/table/sql/handler 23 TABLE test t1 -wait/lock/table/sql/handler 24 TABLE test t1 -wait/io/table/sql/handler 36 TABLE test t2 -wait/lock/table/sql/handler 28 TABLE test t2 -wait/io/table/sql/handler 54 TABLE test t3 -wait/lock/table/sql/handler 32 TABLE test t3 +wait/lock/table/sql/handler 47 TABLE test t1 +wait/lock/table/sql/handler 64 TABLE test t2 +wait/lock/table/sql/handler 86 TABLE test t3 execute dump_waits_index_io; object_type object_schema object_name index_name count_star count_read count_write count_fetch count_insert count_update count_delete TABLE test t1 NULL 18 12 6 12 2 4 0 @@ -1220,12 +1187,9 @@ wait/io/table/sql/handler 113 wait/lock/table/sql/handler 84 execute dump_waits_history; event_name count(event_name) object_type object_schema object_name -wait/io/table/sql/handler 23 TABLE test t1 -wait/lock/table/sql/handler 24 TABLE test t1 -wait/io/table/sql/handler 36 TABLE test t2 -wait/lock/table/sql/handler 28 TABLE test t2 -wait/io/table/sql/handler 54 TABLE test t3 -wait/lock/table/sql/handler 32 TABLE test t3 +wait/lock/table/sql/handler 47 TABLE test t1 +wait/lock/table/sql/handler 64 TABLE test t2 +wait/lock/table/sql/handler 86 TABLE test t3 execute dump_waits_index_io; object_type object_schema object_name index_name count_star count_read count_write count_fetch count_insert count_update count_delete TABLE test t1 NULL 18 12 6 12 2 4 0 @@ -1297,12 +1261,9 @@ wait/io/table/sql/handler 113 wait/lock/table/sql/handler 84 execute dump_waits_history; event_name count(event_name) object_type object_schema object_name -wait/io/table/sql/handler 23 TABLE test t1 -wait/lock/table/sql/handler 24 TABLE test t1 -wait/io/table/sql/handler 36 TABLE test t2 -wait/lock/table/sql/handler 28 TABLE test t2 -wait/io/table/sql/handler 54 TABLE test t3 -wait/lock/table/sql/handler 32 TABLE test t3 +wait/lock/table/sql/handler 47 TABLE test t1 +wait/lock/table/sql/handler 64 TABLE test t2 +wait/lock/table/sql/handler 86 TABLE test t3 execute dump_waits_index_io; object_type object_schema object_name index_name count_star count_read count_write count_fetch count_insert count_update count_delete TABLE test t1 NULL 18 12 6 12 2 4 0 @@ -1373,12 +1334,9 @@ wait/io/table/sql/handler 113 wait/lock/table/sql/handler 84 execute dump_waits_history; event_name count(event_name) object_type object_schema object_name -wait/io/table/sql/handler 23 TABLE test t1 -wait/lock/table/sql/handler 24 TABLE test t1 -wait/io/table/sql/handler 36 TABLE test t2 -wait/lock/table/sql/handler 28 TABLE test t2 -wait/io/table/sql/handler 54 TABLE test t3 -wait/lock/table/sql/handler 32 TABLE test t3 +wait/lock/table/sql/handler 47 TABLE test t1 +wait/lock/table/sql/handler 64 TABLE test t2 +wait/lock/table/sql/handler 86 TABLE test t3 execute dump_waits_index_io; object_type object_schema object_name index_name count_star count_read count_write count_fetch count_insert count_update count_delete TABLE test t1 NULL 18 12 6 12 2 4 0 @@ -1451,12 +1409,9 @@ wait/io/table/sql/handler 113 wait/lock/table/sql/handler 84 execute dump_waits_history; event_name count(event_name) object_type object_schema object_name -wait/io/table/sql/handler 23 TABLE test t1 -wait/lock/table/sql/handler 24 TABLE test t1 -wait/io/table/sql/handler 36 TABLE test t2 -wait/lock/table/sql/handler 28 TABLE test t2 -wait/io/table/sql/handler 54 TABLE test t3 -wait/lock/table/sql/handler 32 TABLE test t3 +wait/lock/table/sql/handler 47 TABLE test t1 +wait/lock/table/sql/handler 64 TABLE test t2 +wait/lock/table/sql/handler 86 TABLE test t3 execute dump_waits_index_io; object_type object_schema object_name index_name count_star count_read count_write count_fetch count_insert count_update count_delete TABLE test t1 NULL 18 12 6 12 2 4 0 @@ -1528,12 +1483,9 @@ wait/io/table/sql/handler 113 wait/lock/table/sql/handler 84 execute dump_waits_history; event_name count(event_name) object_type object_schema object_name -wait/io/table/sql/handler 23 TABLE test t1 -wait/lock/table/sql/handler 24 TABLE test t1 -wait/io/table/sql/handler 36 TABLE test t2 -wait/lock/table/sql/handler 28 TABLE test t2 -wait/io/table/sql/handler 54 TABLE test t3 -wait/lock/table/sql/handler 32 TABLE test t3 +wait/lock/table/sql/handler 47 TABLE test t1 +wait/lock/table/sql/handler 64 TABLE test t2 +wait/lock/table/sql/handler 86 TABLE test t3 execute dump_waits_index_io; object_type object_schema object_name index_name count_star count_read count_write count_fetch count_insert count_update count_delete TABLE test t1 NULL 18 12 6 12 2 4 0 @@ -1605,12 +1557,9 @@ wait/io/table/sql/handler 113 wait/lock/table/sql/handler 84 execute dump_waits_history; event_name count(event_name) object_type object_schema object_name -wait/io/table/sql/handler 23 TABLE test t1 -wait/lock/table/sql/handler 24 TABLE test t1 -wait/io/table/sql/handler 36 TABLE test t2 -wait/lock/table/sql/handler 28 TABLE test t2 -wait/io/table/sql/handler 54 TABLE test t3 -wait/lock/table/sql/handler 32 TABLE test t3 +wait/lock/table/sql/handler 47 TABLE test t1 +wait/lock/table/sql/handler 64 TABLE test t2 +wait/lock/table/sql/handler 86 TABLE test t3 execute dump_waits_index_io; object_type object_schema object_name index_name count_star count_read count_write count_fetch count_insert count_update count_delete TABLE test t1 NULL 18 12 6 12 2 4 0 @@ -1682,12 +1631,9 @@ wait/io/table/sql/handler 113 wait/lock/table/sql/handler 84 execute dump_waits_history; event_name count(event_name) object_type object_schema object_name -wait/io/table/sql/handler 23 TABLE test t1 -wait/lock/table/sql/handler 24 TABLE test t1 -wait/io/table/sql/handler 36 TABLE test t2 -wait/lock/table/sql/handler 28 TABLE test t2 -wait/io/table/sql/handler 54 TABLE test t3 -wait/lock/table/sql/handler 32 TABLE test t3 +wait/lock/table/sql/handler 47 TABLE test t1 +wait/lock/table/sql/handler 64 TABLE test t2 +wait/lock/table/sql/handler 86 TABLE test t3 execute dump_waits_index_io; object_type object_schema object_name index_name count_star count_read count_write count_fetch count_insert count_update count_delete TABLE test t1 NULL 18 12 6 12 2 4 0 @@ -1759,12 +1705,9 @@ wait/io/table/sql/handler 0 wait/lock/table/sql/handler 0 execute dump_waits_history; event_name count(event_name) object_type object_schema object_name -wait/io/table/sql/handler 23 TABLE test t1 -wait/lock/table/sql/handler 24 TABLE test t1 -wait/io/table/sql/handler 36 TABLE test t2 -wait/lock/table/sql/handler 28 TABLE test t2 -wait/io/table/sql/handler 54 TABLE test t3 -wait/lock/table/sql/handler 32 TABLE test t3 +wait/lock/table/sql/handler 47 TABLE test t1 +wait/lock/table/sql/handler 64 TABLE test t2 +wait/lock/table/sql/handler 86 TABLE test t3 execute dump_waits_index_io; object_type object_schema object_name index_name count_star count_read count_write count_fetch count_insert count_update count_delete TABLE test t1 NULL 0 0 0 0 0 0 0 diff --git a/mysql-test/suite/perfschema/r/table_aggregate_hist_4u_2t.result b/mysql-test/suite/perfschema/r/table_aggregate_hist_4u_2t.result index 2d2a55efa7737..3643a854291bb 100644 --- a/mysql-test/suite/perfschema/r/table_aggregate_hist_4u_2t.result +++ b/mysql-test/suite/perfschema/r/table_aggregate_hist_4u_2t.result @@ -215,10 +215,8 @@ wait/io/table/sql/handler 25 wait/lock/table/sql/handler 24 execute dump_waits_history; event_name count(event_name) object_type object_schema object_name -wait/io/table/sql/handler 8 TABLE test t1 -wait/lock/table/sql/handler 10 TABLE test t1 -wait/io/table/sql/handler 17 TABLE test t3 -wait/lock/table/sql/handler 14 TABLE test t3 +wait/lock/table/sql/handler 18 TABLE test t1 +wait/lock/table/sql/handler 31 TABLE test t3 execute dump_waits_index_io; object_type object_schema object_name index_name count_star count_read count_write count_fetch count_insert count_update count_delete TABLE test t1 NULL 6 4 2 4 1 1 0 @@ -287,10 +285,8 @@ wait/io/table/sql/handler 25 wait/lock/table/sql/handler 24 execute dump_waits_history; event_name count(event_name) object_type object_schema object_name -wait/io/table/sql/handler 8 TABLE test t1 -wait/lock/table/sql/handler 10 TABLE test t1 -wait/io/table/sql/handler 17 TABLE test t3 -wait/lock/table/sql/handler 14 TABLE test t3 +wait/lock/table/sql/handler 18 TABLE test t1 +wait/lock/table/sql/handler 31 TABLE test t3 execute dump_waits_index_io; object_type object_schema object_name index_name count_star count_read count_write count_fetch count_insert count_update count_delete TABLE test t1 NULL 6 4 2 4 1 1 0 @@ -394,10 +390,8 @@ wait/io/table/sql/handler 64 wait/lock/table/sql/handler 48 execute dump_waits_history; event_name count(event_name) object_type object_schema object_name -wait/io/table/sql/handler 20 TABLE test t1 -wait/lock/table/sql/handler 20 TABLE test t1 -wait/io/table/sql/handler 44 TABLE test t3 -wait/lock/table/sql/handler 28 TABLE test t3 +wait/lock/table/sql/handler 40 TABLE test t1 +wait/lock/table/sql/handler 72 TABLE test t3 execute dump_waits_index_io; object_type object_schema object_name index_name count_star count_read count_write count_fetch count_insert count_update count_delete TABLE test t1 NULL 15 10 5 10 2 3 0 @@ -471,10 +465,8 @@ wait/io/table/sql/handler 64 wait/lock/table/sql/handler 48 execute dump_waits_history; event_name count(event_name) object_type object_schema object_name -wait/io/table/sql/handler 20 TABLE test t1 -wait/lock/table/sql/handler 20 TABLE test t1 -wait/io/table/sql/handler 44 TABLE test t3 -wait/lock/table/sql/handler 28 TABLE test t3 +wait/lock/table/sql/handler 40 TABLE test t1 +wait/lock/table/sql/handler 72 TABLE test t3 execute dump_waits_index_io; object_type object_schema object_name index_name count_star count_read count_write count_fetch count_insert count_update count_delete TABLE test t1 NULL 15 10 5 10 2 3 0 @@ -590,10 +582,8 @@ wait/io/table/sql/handler 116 wait/lock/table/sql/handler 72 execute dump_waits_history; event_name count(event_name) object_type object_schema object_name -wait/io/table/sql/handler 35 TABLE test t1 -wait/lock/table/sql/handler 30 TABLE test t1 -wait/io/table/sql/handler 81 TABLE test t3 -wait/lock/table/sql/handler 42 TABLE test t3 +wait/lock/table/sql/handler 65 TABLE test t1 +wait/lock/table/sql/handler 123 TABLE test t3 execute dump_waits_index_io; object_type object_schema object_name index_name count_star count_read count_write count_fetch count_insert count_update count_delete TABLE test t1 NULL 27 18 9 18 3 6 0 @@ -672,10 +662,8 @@ wait/io/table/sql/handler 116 wait/lock/table/sql/handler 72 execute dump_waits_history; event_name count(event_name) object_type object_schema object_name -wait/io/table/sql/handler 35 TABLE test t1 -wait/lock/table/sql/handler 30 TABLE test t1 -wait/io/table/sql/handler 81 TABLE test t3 -wait/lock/table/sql/handler 42 TABLE test t3 +wait/lock/table/sql/handler 65 TABLE test t1 +wait/lock/table/sql/handler 123 TABLE test t3 execute dump_waits_index_io; object_type object_schema object_name index_name count_star count_read count_write count_fetch count_insert count_update count_delete TABLE test t1 NULL 27 18 9 18 3 6 0 @@ -803,10 +791,8 @@ wait/io/table/sql/handler 181 wait/lock/table/sql/handler 96 execute dump_waits_history; event_name count(event_name) object_type object_schema object_name -wait/io/table/sql/handler 53 TABLE test t1 -wait/lock/table/sql/handler 40 TABLE test t1 -wait/io/table/sql/handler 128 TABLE test t3 -wait/lock/table/sql/handler 56 TABLE test t3 +wait/lock/table/sql/handler 93 TABLE test t1 +wait/lock/table/sql/handler 184 TABLE test t3 execute dump_waits_index_io; object_type object_schema object_name index_name count_star count_read count_write count_fetch count_insert count_update count_delete TABLE test t1 NULL 42 28 14 28 4 10 0 @@ -886,10 +872,8 @@ wait/io/table/sql/handler 181 wait/lock/table/sql/handler 104 execute dump_waits_history; event_name count(event_name) object_type object_schema object_name -wait/io/table/sql/handler 53 TABLE test t1 -wait/lock/table/sql/handler 44 TABLE test t1 -wait/io/table/sql/handler 128 TABLE test t3 -wait/lock/table/sql/handler 60 TABLE test t3 +wait/lock/table/sql/handler 97 TABLE test t1 +wait/lock/table/sql/handler 188 TABLE test t3 execute dump_waits_index_io; object_type object_schema object_name index_name count_star count_read count_write count_fetch count_insert count_update count_delete TABLE test t1 NULL 42 28 14 28 4 10 0 @@ -966,10 +950,8 @@ wait/io/table/sql/handler 181 wait/lock/table/sql/handler 104 execute dump_waits_history; event_name count(event_name) object_type object_schema object_name -wait/io/table/sql/handler 53 TABLE test t1 -wait/lock/table/sql/handler 44 TABLE test t1 -wait/io/table/sql/handler 128 TABLE test t3 -wait/lock/table/sql/handler 60 TABLE test t3 +wait/lock/table/sql/handler 97 TABLE test t1 +wait/lock/table/sql/handler 188 TABLE test t3 execute dump_waits_index_io; object_type object_schema object_name index_name count_star count_read count_write count_fetch count_insert count_update count_delete TABLE test t1 NULL 42 28 14 28 4 10 0 @@ -1046,10 +1028,8 @@ wait/io/table/sql/handler 181 wait/lock/table/sql/handler 104 execute dump_waits_history; event_name count(event_name) object_type object_schema object_name -wait/io/table/sql/handler 53 TABLE test t1 -wait/lock/table/sql/handler 44 TABLE test t1 -wait/io/table/sql/handler 128 TABLE test t3 -wait/lock/table/sql/handler 60 TABLE test t3 +wait/lock/table/sql/handler 97 TABLE test t1 +wait/lock/table/sql/handler 188 TABLE test t3 execute dump_waits_index_io; object_type object_schema object_name index_name count_star count_read count_write count_fetch count_insert count_update count_delete TABLE test t1 NULL 42 28 14 28 4 10 0 @@ -1123,10 +1103,8 @@ wait/io/table/sql/handler 181 wait/lock/table/sql/handler 104 execute dump_waits_history; event_name count(event_name) object_type object_schema object_name -wait/io/table/sql/handler 53 TABLE test t1 -wait/lock/table/sql/handler 44 TABLE test t1 -wait/io/table/sql/handler 128 TABLE test t3 -wait/lock/table/sql/handler 60 TABLE test t3 +wait/lock/table/sql/handler 97 TABLE test t1 +wait/lock/table/sql/handler 188 TABLE test t3 execute dump_waits_index_io; object_type object_schema object_name index_name count_star count_read count_write count_fetch count_insert count_update count_delete TABLE test t1 NULL 42 28 14 28 4 10 0 @@ -1199,10 +1177,8 @@ wait/io/table/sql/handler 181 wait/lock/table/sql/handler 104 execute dump_waits_history; event_name count(event_name) object_type object_schema object_name -wait/io/table/sql/handler 53 TABLE test t1 -wait/lock/table/sql/handler 44 TABLE test t1 -wait/io/table/sql/handler 128 TABLE test t3 -wait/lock/table/sql/handler 60 TABLE test t3 +wait/lock/table/sql/handler 97 TABLE test t1 +wait/lock/table/sql/handler 188 TABLE test t3 execute dump_waits_index_io; object_type object_schema object_name index_name count_star count_read count_write count_fetch count_insert count_update count_delete TABLE test t1 NULL 42 28 14 28 4 10 0 @@ -1274,10 +1250,8 @@ wait/io/table/sql/handler 181 wait/lock/table/sql/handler 104 execute dump_waits_history; event_name count(event_name) object_type object_schema object_name -wait/io/table/sql/handler 53 TABLE test t1 -wait/lock/table/sql/handler 44 TABLE test t1 -wait/io/table/sql/handler 128 TABLE test t3 -wait/lock/table/sql/handler 60 TABLE test t3 +wait/lock/table/sql/handler 97 TABLE test t1 +wait/lock/table/sql/handler 188 TABLE test t3 execute dump_waits_index_io; object_type object_schema object_name index_name count_star count_read count_write count_fetch count_insert count_update count_delete TABLE test t1 NULL 42 28 14 28 4 10 0 @@ -1348,10 +1322,8 @@ wait/io/table/sql/handler 181 wait/lock/table/sql/handler 104 execute dump_waits_history; event_name count(event_name) object_type object_schema object_name -wait/io/table/sql/handler 53 TABLE test t1 -wait/lock/table/sql/handler 44 TABLE test t1 -wait/io/table/sql/handler 128 TABLE test t3 -wait/lock/table/sql/handler 60 TABLE test t3 +wait/lock/table/sql/handler 97 TABLE test t1 +wait/lock/table/sql/handler 188 TABLE test t3 execute dump_waits_index_io; object_type object_schema object_name index_name count_star count_read count_write count_fetch count_insert count_update count_delete TABLE test t1 NULL 42 28 14 28 4 10 0 @@ -1424,10 +1396,8 @@ wait/io/table/sql/handler 181 wait/lock/table/sql/handler 104 execute dump_waits_history; event_name count(event_name) object_type object_schema object_name -wait/io/table/sql/handler 53 TABLE test t1 -wait/lock/table/sql/handler 44 TABLE test t1 -wait/io/table/sql/handler 128 TABLE test t3 -wait/lock/table/sql/handler 60 TABLE test t3 +wait/lock/table/sql/handler 97 TABLE test t1 +wait/lock/table/sql/handler 188 TABLE test t3 execute dump_waits_index_io; object_type object_schema object_name index_name count_star count_read count_write count_fetch count_insert count_update count_delete TABLE test t1 NULL 42 28 14 28 4 10 0 @@ -1499,10 +1469,8 @@ wait/io/table/sql/handler 181 wait/lock/table/sql/handler 104 execute dump_waits_history; event_name count(event_name) object_type object_schema object_name -wait/io/table/sql/handler 53 TABLE test t1 -wait/lock/table/sql/handler 44 TABLE test t1 -wait/io/table/sql/handler 128 TABLE test t3 -wait/lock/table/sql/handler 60 TABLE test t3 +wait/lock/table/sql/handler 97 TABLE test t1 +wait/lock/table/sql/handler 188 TABLE test t3 execute dump_waits_index_io; object_type object_schema object_name index_name count_star count_read count_write count_fetch count_insert count_update count_delete TABLE test t1 NULL 42 28 14 28 4 10 0 @@ -1574,10 +1542,8 @@ wait/io/table/sql/handler 181 wait/lock/table/sql/handler 104 execute dump_waits_history; event_name count(event_name) object_type object_schema object_name -wait/io/table/sql/handler 53 TABLE test t1 -wait/lock/table/sql/handler 44 TABLE test t1 -wait/io/table/sql/handler 128 TABLE test t3 -wait/lock/table/sql/handler 60 TABLE test t3 +wait/lock/table/sql/handler 97 TABLE test t1 +wait/lock/table/sql/handler 188 TABLE test t3 execute dump_waits_index_io; object_type object_schema object_name index_name count_star count_read count_write count_fetch count_insert count_update count_delete TABLE test t1 NULL 42 28 14 28 4 10 0 @@ -1649,10 +1615,8 @@ wait/io/table/sql/handler 181 wait/lock/table/sql/handler 104 execute dump_waits_history; event_name count(event_name) object_type object_schema object_name -wait/io/table/sql/handler 53 TABLE test t1 -wait/lock/table/sql/handler 44 TABLE test t1 -wait/io/table/sql/handler 128 TABLE test t3 -wait/lock/table/sql/handler 60 TABLE test t3 +wait/lock/table/sql/handler 97 TABLE test t1 +wait/lock/table/sql/handler 188 TABLE test t3 execute dump_waits_index_io; object_type object_schema object_name index_name count_star count_read count_write count_fetch count_insert count_update count_delete TABLE test t1 NULL 42 28 14 28 4 10 0 @@ -1724,10 +1688,8 @@ wait/io/table/sql/handler 0 wait/lock/table/sql/handler 0 execute dump_waits_history; event_name count(event_name) object_type object_schema object_name -wait/io/table/sql/handler 53 TABLE test t1 -wait/lock/table/sql/handler 44 TABLE test t1 -wait/io/table/sql/handler 128 TABLE test t3 -wait/lock/table/sql/handler 60 TABLE test t3 +wait/lock/table/sql/handler 97 TABLE test t1 +wait/lock/table/sql/handler 188 TABLE test t3 execute dump_waits_index_io; object_type object_schema object_name index_name count_star count_read count_write count_fetch count_insert count_update count_delete TABLE test t1 NULL 0 0 0 0 0 0 0 diff --git a/mysql-test/suite/perfschema/r/table_aggregate_hist_4u_3t.result b/mysql-test/suite/perfschema/r/table_aggregate_hist_4u_3t.result index de8fc4702a6bd..90adf00b73471 100644 --- a/mysql-test/suite/perfschema/r/table_aggregate_hist_4u_3t.result +++ b/mysql-test/suite/perfschema/r/table_aggregate_hist_4u_3t.result @@ -214,12 +214,9 @@ wait/io/table/sql/handler 37 wait/lock/table/sql/handler 36 execute dump_waits_history; event_name count(event_name) object_type object_schema object_name -wait/io/table/sql/handler 8 TABLE test t1 -wait/lock/table/sql/handler 10 TABLE test t1 -wait/io/table/sql/handler 12 TABLE test t2 -wait/lock/table/sql/handler 12 TABLE test t2 -wait/io/table/sql/handler 17 TABLE test t3 -wait/lock/table/sql/handler 14 TABLE test t3 +wait/lock/table/sql/handler 18 TABLE test t1 +wait/lock/table/sql/handler 24 TABLE test t2 +wait/lock/table/sql/handler 31 TABLE test t3 execute dump_waits_index_io; object_type object_schema object_name index_name count_star count_read count_write count_fetch count_insert count_update count_delete TABLE test t1 NULL 6 4 2 4 1 1 0 @@ -288,12 +285,9 @@ wait/io/table/sql/handler 37 wait/lock/table/sql/handler 36 execute dump_waits_history; event_name count(event_name) object_type object_schema object_name -wait/io/table/sql/handler 8 TABLE test t1 -wait/lock/table/sql/handler 10 TABLE test t1 -wait/io/table/sql/handler 12 TABLE test t2 -wait/lock/table/sql/handler 12 TABLE test t2 -wait/io/table/sql/handler 17 TABLE test t3 -wait/lock/table/sql/handler 14 TABLE test t3 +wait/lock/table/sql/handler 18 TABLE test t1 +wait/lock/table/sql/handler 24 TABLE test t2 +wait/lock/table/sql/handler 31 TABLE test t3 execute dump_waits_index_io; object_type object_schema object_name index_name count_star count_read count_write count_fetch count_insert count_update count_delete TABLE test t1 NULL 6 4 2 4 1 1 0 @@ -397,12 +391,9 @@ wait/io/table/sql/handler 94 wait/lock/table/sql/handler 72 execute dump_waits_history; event_name count(event_name) object_type object_schema object_name -wait/io/table/sql/handler 20 TABLE test t1 -wait/lock/table/sql/handler 20 TABLE test t1 -wait/io/table/sql/handler 30 TABLE test t2 -wait/lock/table/sql/handler 24 TABLE test t2 -wait/io/table/sql/handler 44 TABLE test t3 -wait/lock/table/sql/handler 28 TABLE test t3 +wait/lock/table/sql/handler 40 TABLE test t1 +wait/lock/table/sql/handler 54 TABLE test t2 +wait/lock/table/sql/handler 72 TABLE test t3 execute dump_waits_index_io; object_type object_schema object_name index_name count_star count_read count_write count_fetch count_insert count_update count_delete TABLE test t1 NULL 15 10 5 10 2 3 0 @@ -476,12 +467,9 @@ wait/io/table/sql/handler 94 wait/lock/table/sql/handler 72 execute dump_waits_history; event_name count(event_name) object_type object_schema object_name -wait/io/table/sql/handler 20 TABLE test t1 -wait/lock/table/sql/handler 20 TABLE test t1 -wait/io/table/sql/handler 30 TABLE test t2 -wait/lock/table/sql/handler 24 TABLE test t2 -wait/io/table/sql/handler 44 TABLE test t3 -wait/lock/table/sql/handler 28 TABLE test t3 +wait/lock/table/sql/handler 40 TABLE test t1 +wait/lock/table/sql/handler 54 TABLE test t2 +wait/lock/table/sql/handler 72 TABLE test t3 execute dump_waits_index_io; object_type object_schema object_name index_name count_star count_read count_write count_fetch count_insert count_update count_delete TABLE test t1 NULL 15 10 5 10 2 3 0 @@ -597,12 +585,9 @@ wait/io/table/sql/handler 170 wait/lock/table/sql/handler 108 execute dump_waits_history; event_name count(event_name) object_type object_schema object_name -wait/io/table/sql/handler 35 TABLE test t1 -wait/lock/table/sql/handler 30 TABLE test t1 -wait/io/table/sql/handler 54 TABLE test t2 -wait/lock/table/sql/handler 36 TABLE test t2 -wait/io/table/sql/handler 81 TABLE test t3 -wait/lock/table/sql/handler 42 TABLE test t3 +wait/lock/table/sql/handler 65 TABLE test t1 +wait/lock/table/sql/handler 90 TABLE test t2 +wait/lock/table/sql/handler 123 TABLE test t3 execute dump_waits_index_io; object_type object_schema object_name index_name count_star count_read count_write count_fetch count_insert count_update count_delete TABLE test t1 NULL 27 18 9 18 3 6 0 @@ -681,12 +666,9 @@ wait/io/table/sql/handler 170 wait/lock/table/sql/handler 108 execute dump_waits_history; event_name count(event_name) object_type object_schema object_name -wait/io/table/sql/handler 35 TABLE test t1 -wait/lock/table/sql/handler 30 TABLE test t1 -wait/io/table/sql/handler 54 TABLE test t2 -wait/lock/table/sql/handler 36 TABLE test t2 -wait/io/table/sql/handler 81 TABLE test t3 -wait/lock/table/sql/handler 42 TABLE test t3 +wait/lock/table/sql/handler 65 TABLE test t1 +wait/lock/table/sql/handler 90 TABLE test t2 +wait/lock/table/sql/handler 123 TABLE test t3 execute dump_waits_index_io; object_type object_schema object_name index_name count_star count_read count_write count_fetch count_insert count_update count_delete TABLE test t1 NULL 27 18 9 18 3 6 0 @@ -814,12 +796,9 @@ wait/io/table/sql/handler 265 wait/lock/table/sql/handler 144 execute dump_waits_history; event_name count(event_name) object_type object_schema object_name -wait/io/table/sql/handler 53 TABLE test t1 -wait/lock/table/sql/handler 40 TABLE test t1 -wait/io/table/sql/handler 84 TABLE test t2 -wait/lock/table/sql/handler 48 TABLE test t2 -wait/io/table/sql/handler 128 TABLE test t3 -wait/lock/table/sql/handler 56 TABLE test t3 +wait/lock/table/sql/handler 93 TABLE test t1 +wait/lock/table/sql/handler 132 TABLE test t2 +wait/lock/table/sql/handler 184 TABLE test t3 execute dump_waits_index_io; object_type object_schema object_name index_name count_star count_read count_write count_fetch count_insert count_update count_delete TABLE test t1 NULL 42 28 14 28 4 10 0 @@ -899,12 +878,9 @@ wait/io/table/sql/handler 265 wait/lock/table/sql/handler 156 execute dump_waits_history; event_name count(event_name) object_type object_schema object_name -wait/io/table/sql/handler 53 TABLE test t1 -wait/lock/table/sql/handler 44 TABLE test t1 -wait/io/table/sql/handler 84 TABLE test t2 -wait/lock/table/sql/handler 52 TABLE test t2 -wait/io/table/sql/handler 128 TABLE test t3 -wait/lock/table/sql/handler 60 TABLE test t3 +wait/lock/table/sql/handler 97 TABLE test t1 +wait/lock/table/sql/handler 136 TABLE test t2 +wait/lock/table/sql/handler 188 TABLE test t3 execute dump_waits_index_io; object_type object_schema object_name index_name count_star count_read count_write count_fetch count_insert count_update count_delete TABLE test t1 NULL 42 28 14 28 4 10 0 @@ -981,12 +957,9 @@ wait/io/table/sql/handler 265 wait/lock/table/sql/handler 156 execute dump_waits_history; event_name count(event_name) object_type object_schema object_name -wait/io/table/sql/handler 53 TABLE test t1 -wait/lock/table/sql/handler 44 TABLE test t1 -wait/io/table/sql/handler 84 TABLE test t2 -wait/lock/table/sql/handler 52 TABLE test t2 -wait/io/table/sql/handler 128 TABLE test t3 -wait/lock/table/sql/handler 60 TABLE test t3 +wait/lock/table/sql/handler 97 TABLE test t1 +wait/lock/table/sql/handler 136 TABLE test t2 +wait/lock/table/sql/handler 188 TABLE test t3 execute dump_waits_index_io; object_type object_schema object_name index_name count_star count_read count_write count_fetch count_insert count_update count_delete TABLE test t1 NULL 42 28 14 28 4 10 0 @@ -1063,12 +1036,9 @@ wait/io/table/sql/handler 265 wait/lock/table/sql/handler 156 execute dump_waits_history; event_name count(event_name) object_type object_schema object_name -wait/io/table/sql/handler 53 TABLE test t1 -wait/lock/table/sql/handler 44 TABLE test t1 -wait/io/table/sql/handler 84 TABLE test t2 -wait/lock/table/sql/handler 52 TABLE test t2 -wait/io/table/sql/handler 128 TABLE test t3 -wait/lock/table/sql/handler 60 TABLE test t3 +wait/lock/table/sql/handler 97 TABLE test t1 +wait/lock/table/sql/handler 136 TABLE test t2 +wait/lock/table/sql/handler 188 TABLE test t3 execute dump_waits_index_io; object_type object_schema object_name index_name count_star count_read count_write count_fetch count_insert count_update count_delete TABLE test t1 NULL 42 28 14 28 4 10 0 @@ -1142,12 +1112,9 @@ wait/io/table/sql/handler 265 wait/lock/table/sql/handler 156 execute dump_waits_history; event_name count(event_name) object_type object_schema object_name -wait/io/table/sql/handler 53 TABLE test t1 -wait/lock/table/sql/handler 44 TABLE test t1 -wait/io/table/sql/handler 84 TABLE test t2 -wait/lock/table/sql/handler 52 TABLE test t2 -wait/io/table/sql/handler 128 TABLE test t3 -wait/lock/table/sql/handler 60 TABLE test t3 +wait/lock/table/sql/handler 97 TABLE test t1 +wait/lock/table/sql/handler 136 TABLE test t2 +wait/lock/table/sql/handler 188 TABLE test t3 execute dump_waits_index_io; object_type object_schema object_name index_name count_star count_read count_write count_fetch count_insert count_update count_delete TABLE test t1 NULL 42 28 14 28 4 10 0 @@ -1220,12 +1187,9 @@ wait/io/table/sql/handler 265 wait/lock/table/sql/handler 156 execute dump_waits_history; event_name count(event_name) object_type object_schema object_name -wait/io/table/sql/handler 53 TABLE test t1 -wait/lock/table/sql/handler 44 TABLE test t1 -wait/io/table/sql/handler 84 TABLE test t2 -wait/lock/table/sql/handler 52 TABLE test t2 -wait/io/table/sql/handler 128 TABLE test t3 -wait/lock/table/sql/handler 60 TABLE test t3 +wait/lock/table/sql/handler 97 TABLE test t1 +wait/lock/table/sql/handler 136 TABLE test t2 +wait/lock/table/sql/handler 188 TABLE test t3 execute dump_waits_index_io; object_type object_schema object_name index_name count_star count_read count_write count_fetch count_insert count_update count_delete TABLE test t1 NULL 42 28 14 28 4 10 0 @@ -1297,12 +1261,9 @@ wait/io/table/sql/handler 265 wait/lock/table/sql/handler 156 execute dump_waits_history; event_name count(event_name) object_type object_schema object_name -wait/io/table/sql/handler 53 TABLE test t1 -wait/lock/table/sql/handler 44 TABLE test t1 -wait/io/table/sql/handler 84 TABLE test t2 -wait/lock/table/sql/handler 52 TABLE test t2 -wait/io/table/sql/handler 128 TABLE test t3 -wait/lock/table/sql/handler 60 TABLE test t3 +wait/lock/table/sql/handler 97 TABLE test t1 +wait/lock/table/sql/handler 136 TABLE test t2 +wait/lock/table/sql/handler 188 TABLE test t3 execute dump_waits_index_io; object_type object_schema object_name index_name count_star count_read count_write count_fetch count_insert count_update count_delete TABLE test t1 NULL 42 28 14 28 4 10 0 @@ -1373,12 +1334,9 @@ wait/io/table/sql/handler 265 wait/lock/table/sql/handler 156 execute dump_waits_history; event_name count(event_name) object_type object_schema object_name -wait/io/table/sql/handler 53 TABLE test t1 -wait/lock/table/sql/handler 44 TABLE test t1 -wait/io/table/sql/handler 84 TABLE test t2 -wait/lock/table/sql/handler 52 TABLE test t2 -wait/io/table/sql/handler 128 TABLE test t3 -wait/lock/table/sql/handler 60 TABLE test t3 +wait/lock/table/sql/handler 97 TABLE test t1 +wait/lock/table/sql/handler 136 TABLE test t2 +wait/lock/table/sql/handler 188 TABLE test t3 execute dump_waits_index_io; object_type object_schema object_name index_name count_star count_read count_write count_fetch count_insert count_update count_delete TABLE test t1 NULL 42 28 14 28 4 10 0 @@ -1451,12 +1409,9 @@ wait/io/table/sql/handler 265 wait/lock/table/sql/handler 156 execute dump_waits_history; event_name count(event_name) object_type object_schema object_name -wait/io/table/sql/handler 53 TABLE test t1 -wait/lock/table/sql/handler 44 TABLE test t1 -wait/io/table/sql/handler 84 TABLE test t2 -wait/lock/table/sql/handler 52 TABLE test t2 -wait/io/table/sql/handler 128 TABLE test t3 -wait/lock/table/sql/handler 60 TABLE test t3 +wait/lock/table/sql/handler 97 TABLE test t1 +wait/lock/table/sql/handler 136 TABLE test t2 +wait/lock/table/sql/handler 188 TABLE test t3 execute dump_waits_index_io; object_type object_schema object_name index_name count_star count_read count_write count_fetch count_insert count_update count_delete TABLE test t1 NULL 42 28 14 28 4 10 0 @@ -1528,12 +1483,9 @@ wait/io/table/sql/handler 265 wait/lock/table/sql/handler 156 execute dump_waits_history; event_name count(event_name) object_type object_schema object_name -wait/io/table/sql/handler 53 TABLE test t1 -wait/lock/table/sql/handler 44 TABLE test t1 -wait/io/table/sql/handler 84 TABLE test t2 -wait/lock/table/sql/handler 52 TABLE test t2 -wait/io/table/sql/handler 128 TABLE test t3 -wait/lock/table/sql/handler 60 TABLE test t3 +wait/lock/table/sql/handler 97 TABLE test t1 +wait/lock/table/sql/handler 136 TABLE test t2 +wait/lock/table/sql/handler 188 TABLE test t3 execute dump_waits_index_io; object_type object_schema object_name index_name count_star count_read count_write count_fetch count_insert count_update count_delete TABLE test t1 NULL 42 28 14 28 4 10 0 @@ -1605,12 +1557,9 @@ wait/io/table/sql/handler 265 wait/lock/table/sql/handler 156 execute dump_waits_history; event_name count(event_name) object_type object_schema object_name -wait/io/table/sql/handler 53 TABLE test t1 -wait/lock/table/sql/handler 44 TABLE test t1 -wait/io/table/sql/handler 84 TABLE test t2 -wait/lock/table/sql/handler 52 TABLE test t2 -wait/io/table/sql/handler 128 TABLE test t3 -wait/lock/table/sql/handler 60 TABLE test t3 +wait/lock/table/sql/handler 97 TABLE test t1 +wait/lock/table/sql/handler 136 TABLE test t2 +wait/lock/table/sql/handler 188 TABLE test t3 execute dump_waits_index_io; object_type object_schema object_name index_name count_star count_read count_write count_fetch count_insert count_update count_delete TABLE test t1 NULL 42 28 14 28 4 10 0 @@ -1682,12 +1631,9 @@ wait/io/table/sql/handler 265 wait/lock/table/sql/handler 156 execute dump_waits_history; event_name count(event_name) object_type object_schema object_name -wait/io/table/sql/handler 53 TABLE test t1 -wait/lock/table/sql/handler 44 TABLE test t1 -wait/io/table/sql/handler 84 TABLE test t2 -wait/lock/table/sql/handler 52 TABLE test t2 -wait/io/table/sql/handler 128 TABLE test t3 -wait/lock/table/sql/handler 60 TABLE test t3 +wait/lock/table/sql/handler 97 TABLE test t1 +wait/lock/table/sql/handler 136 TABLE test t2 +wait/lock/table/sql/handler 188 TABLE test t3 execute dump_waits_index_io; object_type object_schema object_name index_name count_star count_read count_write count_fetch count_insert count_update count_delete TABLE test t1 NULL 42 28 14 28 4 10 0 @@ -1759,12 +1705,9 @@ wait/io/table/sql/handler 0 wait/lock/table/sql/handler 0 execute dump_waits_history; event_name count(event_name) object_type object_schema object_name -wait/io/table/sql/handler 53 TABLE test t1 -wait/lock/table/sql/handler 44 TABLE test t1 -wait/io/table/sql/handler 84 TABLE test t2 -wait/lock/table/sql/handler 52 TABLE test t2 -wait/io/table/sql/handler 128 TABLE test t3 -wait/lock/table/sql/handler 60 TABLE test t3 +wait/lock/table/sql/handler 97 TABLE test t1 +wait/lock/table/sql/handler 136 TABLE test t2 +wait/lock/table/sql/handler 188 TABLE test t3 execute dump_waits_index_io; object_type object_schema object_name index_name count_star count_read count_write count_fetch count_insert count_update count_delete TABLE test t1 NULL 0 0 0 0 0 0 0 diff --git a/mysql-test/suite/perfschema/t/events_waits_current_MDEV-29091.test b/mysql-test/suite/perfschema/t/events_waits_current_MDEV-29091.test new file mode 100644 index 0000000000000..d9330ee5a9d4b --- /dev/null +++ b/mysql-test/suite/perfschema/t/events_waits_current_MDEV-29091.test @@ -0,0 +1,62 @@ +# +# proper event name wait/lock/table/sql/handler recorded in +# PERFORMANCE_SCHEMA.EVENTS_WAITS_CURRENT. Before this fix, it was +# labeled as wait/io/table/sql/handler. +# + +--source include/have_innodb.inc +--source include/have_perfschema.inc +--source include/not_embedded.inc + +SET default_storage_engine=InnoDB; + +SELECT @save_instrument_enabled := ENABLED +, @save_instrument_timed := TIMED +FROM performance_schema.setup_instruments +WHERE NAME = 'wait/lock/table/sql/handler'; + +SELECT @save_consumer_enabled := ENABLED +FROM performance_schema.setup_consumers +WHERE NAME = 'events_waits_current'; + +UPDATE performance_schema.setup_instruments +SET ENABLED = 'YES', TIMED = 'YES' +WHERE NAME = 'wait/lock/table/sql/handler'; + +UPDATE performance_schema.setup_consumers +SET ENABLED = 'YES' +WHERE NAME = 'events_waits_current'; + +CREATE TABLE t1 (id1 INT(11), col1 VARCHAR (200)); +INSERT INTO t1 VALUES (1, 'aa'); +INSERT INTO t1 VALUES (2, 'bb'); + +connect (con1,localhost,root,,test); +connect (con2,localhost,root,,test); + +connection con1; +START TRANSACTION; +let $wait_condition= + SELECT id1 FROM t1 WHERE id1=1 FOR UPDATE; +--source include/wait_condition.inc + +connection con2; +START TRANSACTION; +send SELECT id1 FROM t1 WHERE id1=1 FOR UPDATE; + +connection default; +SELECT event_name FROM performance_schema.events_waits_current +WHERE event_name LIKE '%wait/lock/table/sql/handler%'; + +# clean up +UPDATE performance_schema.setup_instruments +SET ENABLED = @save_instrument_enabled, TIMED = @save_instrument_timed +WHERE NAME = 'wait/lock/table/sql/handler'; + +UPDATE performance_schema.setup_consumers +SET ENABLED = @save_consumer_enabled +WHERE NAME = 'events_waits_current'; + +disconnect con1; +disconnect con2; +DROP TABLE t1; diff --git a/storage/perfschema/pfs.cc b/storage/perfschema/pfs.cc index 44bcbad87d73d..63b406f065b29 100644 --- a/storage/perfschema/pfs.cc +++ b/storage/perfschema/pfs.cc @@ -2610,7 +2610,8 @@ start_table_io_wait_v1(PSI_table_locker_state *state, PFS_table_share *share= pfs_table->m_share; wait->m_thread= pfs_thread; - wait->m_class= &global_table_io_class; + if (wait->m_class == NULL || wait->m_class->m_type != PFS_CLASS_TABLE_LOCK) + wait->m_class= &global_table_io_class; wait->m_timer_start= timer_start; wait->m_timer_end= 0; wait->m_object_instance_addr= pfs_table->m_identity; From d1a46c68cd4f6557cbb76de22cd6faee50e41725 Mon Sep 17 00:00:00 2001 From: Igor Babaev Date: Tue, 31 Jan 2023 13:14:53 -0800 Subject: [PATCH 07/92] MDEV-30218 Incorrect optimization for rowid_filtering Correction over the last patch for this MDEV. --- mysql-test/main/join_nested_jcl6.result | 2 +- mysql-test/main/opt_trace.result | 13 +- .../main/opt_trace_index_merge_innodb.result | 1 - mysql-test/main/range.result | 2 +- mysql-test/main/rowid_filter.result | 189 ++++++++++-------- mysql-test/main/rowid_filter_innodb.result | 102 +++++++--- mysql-test/main/select.result | 2 +- mysql-test/main/select_jcl6.result | 2 +- mysql-test/main/select_pkeycache.result | 2 +- mysql-test/main/selectivity.result | 2 +- sql/sql_select.cc | 132 ++++++------ 11 files changed, 251 insertions(+), 198 deletions(-) diff --git a/mysql-test/main/join_nested_jcl6.result b/mysql-test/main/join_nested_jcl6.result index 7226a5d62b1b3..91fe367c378fd 100644 --- a/mysql-test/main/join_nested_jcl6.result +++ b/mysql-test/main/join_nested_jcl6.result @@ -2085,7 +2085,7 @@ ON t6.b >= 2 AND t5.b=t7.b AND (t8.a > 0 OR t8.c IS NULL) AND t6.a>0 AND t7.a>0; id select_type table type possible_keys key key_len ref rows Extra 1 SIMPLE t5 ALL NULL NULL NULL NULL 3 -1 SIMPLE t7 ref PRIMARY,b_i b_i 5 test.t5.b 2 Using where; Using join buffer (flat, BKA join); Key-ordered Rowid-ordered scan +1 SIMPLE t7 ref|filter PRIMARY,b_i b_i|PRIMARY 5|4 test.t5.b 2 (29%) Using where; Using join buffer (flat, BKA join); Key-ordered Rowid-ordered scan; Using rowid filter 1 SIMPLE t6 range PRIMARY,b_i PRIMARY 4 NULL 3 Using where; Rowid-ordered scan; Using join buffer (incremental, BNL join) 1 SIMPLE t8 ref b_i b_i 5 test.t5.b 2 Using where; Using join buffer (incremental, BKA join); Key-ordered Rowid-ordered scan SELECT t5.a,t5.b,t6.a,t6.b,t7.a,t7.b,t8.a,t8.b diff --git a/mysql-test/main/opt_trace.result b/mysql-test/main/opt_trace.result index 2eef0da62bb27..92cd3eb784812 100644 --- a/mysql-test/main/opt_trace.result +++ b/mysql-test/main/opt_trace.result @@ -1016,7 +1016,6 @@ explain select * from t1,t2 where t1.a=t2.b+2 and t2.a= t1.b { "index": "a", "used_range_estimates": false, "cause": "not available", - "rowid_filter_skipped": "cost_factor <= 0", "rows": 1, "cost": 200, "chosen": true @@ -1073,7 +1072,6 @@ explain select * from t1,t2 where t1.a=t2.b+2 and t2.a= t1.b { "index": "a", "used_range_estimates": false, "cause": "not available", - "rowid_filter_skipped": "cost_factor <= 0", "rows": 1, "cost": 200, "chosen": true @@ -2120,7 +2118,6 @@ explain select * from t1 where a=1 and b=2 order by c limit 1 { "access_type": "ref", "index": "a_c", "used_range_estimates": true, - "rowid_filter_skipped": "worst/max seeks clipping", "rows": 180, "cost": 92, "chosen": true @@ -3346,7 +3343,6 @@ explain select * from t1 where pk = 2 and a=5 and b=1 { "access_type": "ref", "index": "pk", "used_range_estimates": true, - "rowid_filter_skipped": "cost_factor <= 0", "rows": 1, "cost": 2, "chosen": true @@ -3355,7 +3351,6 @@ explain select * from t1 where pk = 2 and a=5 and b=1 { "access_type": "ref", "index": "pk_a", "used_range_estimates": true, - "rowid_filter_skipped": "cost_factor <= 0", "rows": 1, "cost": 2, "chosen": false, @@ -3365,7 +3360,6 @@ explain select * from t1 where pk = 2 and a=5 and b=1 { "access_type": "ref", "index": "pk_a_b", "used_range_estimates": true, - "rowid_filter_skipped": "cost_factor <= 0", "rows": 1, "cost": 1.0043, "chosen": true @@ -3974,6 +3968,7 @@ explain delete t0,t1 from t0, t1 where t0.a=t1.a and t1.a<3 { "best_access_path": { "considered_access_paths": [ { + "rowid_filter_skipped": "cost_factor <= 0", "access_type": "range", "resulting_rows": 3, "cost": 1.407, @@ -4000,7 +3995,6 @@ explain delete t0,t1 from t0, t1 where t0.a=t1.a and t1.a<3 { "index": "a", "used_range_estimates": false, "cause": "not better than ref estimates", - "rowid_filter_skipped": "cost_factor <= 0", "rows": 1, "cost": 3.007, "chosen": true @@ -4030,6 +4024,7 @@ explain delete t0,t1 from t0, t1 where t0.a=t1.a and t1.a<3 { "best_access_path": { "considered_access_paths": [ { + "rowid_filter_skipped": "cost_factor <= 0", "access_type": "range", "resulting_rows": 3, "cost": 1.407, @@ -4056,7 +4051,6 @@ explain delete t0,t1 from t0, t1 where t0.a=t1.a and t1.a<3 { "index": "a", "used_range_estimates": false, "cause": "not better than ref estimates", - "rowid_filter_skipped": "worst/max seeks clipping", "rows": 2, "cost": 3.014, "chosen": true @@ -8069,7 +8063,6 @@ JSON_DETAILED(JSON_EXTRACT(trace, '$**.considered_execution_plans')) "index": "b", "used_range_estimates": false, "cause": "not available", - "rowid_filter_skipped": "cost_factor <= 0", "rows": 1, "cost": 20, "chosen": true @@ -8273,7 +8266,6 @@ JSON_DETAILED(JSON_EXTRACT(trace, '$**.considered_execution_plans')) "index": "a", "used_range_estimates": false, "cause": "not available", - "rowid_filter_skipped": "cost_factor <= 0", "rows": 1, "cost": 20, "chosen": true @@ -8341,7 +8333,6 @@ JSON_DETAILED(JSON_EXTRACT(trace, '$**.considered_execution_plans')) "index": "a", "used_range_estimates": false, "cause": "not available", - "rowid_filter_skipped": "cost_factor <= 0", "rows": 1, "cost": 200, "chosen": true diff --git a/mysql-test/main/opt_trace_index_merge_innodb.result b/mysql-test/main/opt_trace_index_merge_innodb.result index 82f09dffa145d..5786f7419964f 100644 --- a/mysql-test/main/opt_trace_index_merge_innodb.result +++ b/mysql-test/main/opt_trace_index_merge_innodb.result @@ -208,7 +208,6 @@ explain select * from t1 where pk1 != 0 and key1 = 1 { "access_type": "ref", "index": "key1", "used_range_estimates": true, - "rowid_filter_skipped": "cost_factor <= 0", "rows": 1, "cost": 2, "chosen": true diff --git a/mysql-test/main/range.result b/mysql-test/main/range.result index a3ce10fe38a34..0e728d76a3e22 100644 --- a/mysql-test/main/range.result +++ b/mysql-test/main/range.result @@ -281,7 +281,7 @@ INSERT INTO t1 VALUES (33,5),(33,5),(33,5),(33,5),(34,5),(35,5); EXPLAIN SELECT * FROM t1 WHERE a IN(1,2) AND b=5; id select_type table type possible_keys key key_len ref rows Extra -1 SIMPLE t1 range a,b a 5 NULL 2 Using index condition; Using where +1 SIMPLE t1 ref|filter a,b b|a 5|5 const 15 (5%) Using where; Using rowid filter SELECT * FROM t1 WHERE a IN(1,2) AND b=5; a b DROP TABLE t1; diff --git a/mysql-test/main/rowid_filter.result b/mysql-test/main/rowid_filter.result index b35021b8513ec..efe1fe16283d3 100644 --- a/mysql-test/main/rowid_filter.result +++ b/mysql-test/main/rowid_filter.result @@ -335,8 +335,8 @@ FROM orders JOIN lineitem ON o_orderkey=l_orderkey WHERE l_shipdate BETWEEN '1997-01-01' AND '1997-01-31' AND o_totalprice between 200000 and 230000; id select_type table type possible_keys key key_len ref rows Extra -1 SIMPLE lineitem range PRIMARY,i_l_shipdate,i_l_orderkey,i_l_orderkey_quantity i_l_shipdate 4 NULL 98 Using index condition -1 SIMPLE orders eq_ref|filter PRIMARY,i_o_totalprice PRIMARY|i_o_totalprice 4|9 dbt3_s001.lineitem.l_orderkey 1 (5%) Using where; Using rowid filter +1 SIMPLE orders range PRIMARY,i_o_totalprice i_o_totalprice 9 NULL 69 Using index condition +1 SIMPLE lineitem ref|filter PRIMARY,i_l_shipdate,i_l_orderkey,i_l_orderkey_quantity i_l_orderkey|i_l_shipdate 4|4 dbt3_s001.orders.o_orderkey 4 (2%) Using where; Using rowid filter set statement optimizer_switch='rowid_filter=on' for EXPLAIN FORMAT=JSON SELECT o_orderkey, l_linenumber, l_shipdate, o_totalprice FROM orders JOIN lineitem ON o_orderkey=l_orderkey WHERE l_shipdate BETWEEN '1997-01-01' AND '1997-01-31' AND @@ -346,40 +346,40 @@ EXPLAIN "query_block": { "select_id": 1, "table": { - "table_name": "lineitem", + "table_name": "orders", "access_type": "range", + "possible_keys": ["PRIMARY", "i_o_totalprice"], + "key": "i_o_totalprice", + "key_length": "9", + "used_key_parts": ["o_totalprice"], + "rows": 69, + "filtered": 100, + "index_condition": "orders.o_totalprice between 200000 and 230000" + }, + "table": { + "table_name": "lineitem", + "access_type": "ref", "possible_keys": [ "PRIMARY", "i_l_shipdate", "i_l_orderkey", "i_l_orderkey_quantity" ], - "key": "i_l_shipdate", - "key_length": "4", - "used_key_parts": ["l_shipDATE"], - "rows": 98, - "filtered": 100, - "index_condition": "lineitem.l_shipDATE between '1997-01-01' and '1997-01-31'" - }, - "table": { - "table_name": "orders", - "access_type": "eq_ref", - "possible_keys": ["PRIMARY", "i_o_totalprice"], - "key": "PRIMARY", + "key": "i_l_orderkey", "key_length": "4", - "used_key_parts": ["o_orderkey"], - "ref": ["dbt3_s001.lineitem.l_orderkey"], + "used_key_parts": ["l_orderkey"], + "ref": ["dbt3_s001.orders.o_orderkey"], "rowid_filter": { "range": { - "key": "i_o_totalprice", - "used_key_parts": ["o_totalprice"] + "key": "i_l_shipdate", + "used_key_parts": ["l_shipDATE"] }, - "rows": 69, - "selectivity_pct": 4.6 + "rows": 98, + "selectivity_pct": 1.632 }, - "rows": 1, - "filtered": 4.6, - "attached_condition": "orders.o_totalprice between 200000 and 230000" + "rows": 4, + "filtered": 1.632, + "attached_condition": "lineitem.l_shipDATE between '1997-01-01' and '1997-01-31'" } } } @@ -388,8 +388,8 @@ FROM orders JOIN lineitem ON o_orderkey=l_orderkey WHERE l_shipdate BETWEEN '1997-01-01' AND '1997-01-31' AND o_totalprice between 200000 and 230000; id select_type table type possible_keys key key_len ref rows r_rows filtered r_filtered Extra -1 SIMPLE lineitem range PRIMARY,i_l_shipdate,i_l_orderkey,i_l_orderkey_quantity i_l_shipdate 4 NULL 98 98.00 100.00 100.00 Using index condition -1 SIMPLE orders eq_ref|filter PRIMARY,i_o_totalprice PRIMARY|i_o_totalprice 4|9 dbt3_s001.lineitem.l_orderkey 1 (5%) 0.11 (10%) 4.60 100.00 Using where; Using rowid filter +1 SIMPLE orders range PRIMARY,i_o_totalprice i_o_totalprice 9 NULL 69 71.00 100.00 100.00 Using index condition +1 SIMPLE lineitem ref|filter PRIMARY,i_l_shipdate,i_l_orderkey,i_l_orderkey_quantity i_l_orderkey|i_l_shipdate 4|4 dbt3_s001.orders.o_orderkey 4 (2%) 0.15 (2%) 1.63 100.00 Using where; Using rowid filter set statement optimizer_switch='rowid_filter=on' for ANALYZE FORMAT=JSON SELECT o_orderkey, l_linenumber, l_shipdate, o_totalprice FROM orders JOIN lineitem ON o_orderkey=l_orderkey WHERE l_shipdate BETWEEN '1997-01-01' AND '1997-01-31' AND @@ -401,53 +401,53 @@ ANALYZE "r_loops": 1, "r_total_time_ms": "REPLACED", "table": { - "table_name": "lineitem", + "table_name": "orders", "access_type": "range", - "possible_keys": [ - "PRIMARY", - "i_l_shipdate", - "i_l_orderkey", - "i_l_orderkey_quantity" - ], - "key": "i_l_shipdate", - "key_length": "4", - "used_key_parts": ["l_shipDATE"], + "possible_keys": ["PRIMARY", "i_o_totalprice"], + "key": "i_o_totalprice", + "key_length": "9", + "used_key_parts": ["o_totalprice"], "r_loops": 1, - "rows": 98, - "r_rows": 98, + "rows": 69, + "r_rows": 71, "r_total_time_ms": "REPLACED", "filtered": 100, "r_filtered": 100, - "index_condition": "lineitem.l_shipDATE between '1997-01-01' and '1997-01-31'" + "index_condition": "orders.o_totalprice between 200000 and 230000" }, "table": { - "table_name": "orders", - "access_type": "eq_ref", - "possible_keys": ["PRIMARY", "i_o_totalprice"], - "key": "PRIMARY", + "table_name": "lineitem", + "access_type": "ref", + "possible_keys": [ + "PRIMARY", + "i_l_shipdate", + "i_l_orderkey", + "i_l_orderkey_quantity" + ], + "key": "i_l_orderkey", "key_length": "4", - "used_key_parts": ["o_orderkey"], - "ref": ["dbt3_s001.lineitem.l_orderkey"], + "used_key_parts": ["l_orderkey"], + "ref": ["dbt3_s001.orders.o_orderkey"], "rowid_filter": { "range": { - "key": "i_o_totalprice", - "used_key_parts": ["o_totalprice"] + "key": "i_l_shipdate", + "used_key_parts": ["l_shipDATE"] }, - "rows": 69, - "selectivity_pct": 4.6, - "r_rows": 71, - "r_lookups": 96, - "r_selectivity_pct": 10.417, + "rows": 98, + "selectivity_pct": 1.632, + "r_rows": 98, + "r_lookups": 476, + "r_selectivity_pct": 2.3109, "r_buffer_size": "REPLACED", "r_filling_time_ms": "REPLACED" }, - "r_loops": 98, - "rows": 1, - "r_rows": 0.1122, + "r_loops": 71, + "rows": 4, + "r_rows": 0.1549, "r_total_time_ms": "REPLACED", - "filtered": 4.6, + "filtered": 1.632, "r_filtered": 100, - "attached_condition": "orders.o_totalprice between 200000 and 230000" + "attached_condition": "lineitem.l_shipDATE between '1997-01-01' and '1997-01-31'" } } } @@ -2072,7 +2072,7 @@ EXPLAIN EXTENDED SELECT * FROM t1 INNER JOIN t2 ON ( pk1+1 = pk2+2 AND a1 = a2 ) WHERE b1 <= ( SELECT MAX(b2) FROM t2 WHERE pk2 <= 1 ); id select_type table type possible_keys key key_len ref rows filtered Extra 1 PRIMARY t2 ALL NULL NULL NULL NULL 101 100.00 Using where -1 PRIMARY t1 ref a1,b1 a1 5 test.t2.a2 36 28.75 Using where +1 PRIMARY t1 ref|filter a1,b1 a1|b1 5|4 test.t2.a2 36 (29%) 28.75 Using where; Using rowid filter 2 SUBQUERY t2 range PRIMARY PRIMARY 4 NULL 1 100.00 Using index condition Warnings: Note 1003 /* select#1 */ select `test`.`t1`.`pk1` AS `pk1`,`test`.`t1`.`a1` AS `a1`,`test`.`t1`.`b1` AS `b1`,`test`.`t2`.`pk2` AS `pk2`,`test`.`t2`.`a2` AS `a2`,`test`.`t2`.`b2` AS `b2` from `test`.`t1` join `test`.`t2` where `test`.`t1`.`a1` = `test`.`t2`.`a2` and `test`.`t1`.`b1` <= (/* select#2 */ select max(`test`.`t2`.`b2`) from `test`.`t2` where `test`.`t2`.`pk2` <= 1) and `test`.`t1`.`pk1` + 1 = `test`.`t2`.`pk2` + 2 @@ -2097,6 +2097,14 @@ EXPLAIN "key_length": "5", "used_key_parts": ["a1"], "ref": ["test.t2.a2"], + "rowid_filter": { + "range": { + "key": "b1", + "used_key_parts": ["b1"] + }, + "rows": 115, + "selectivity_pct": 28.75 + }, "rows": 36, "filtered": 28.75, "attached_condition": "t1.b1 <= (subquery#2) and t1.pk1 + 1 = t2.pk2 + 2" @@ -2179,7 +2187,7 @@ test.t1 analyze status OK explain SELECT * FROM t1 WHERE a > 0 AND b=0; id select_type table type possible_keys key key_len ref rows Extra -1 SIMPLE t1 ref a,b b 5 const 151 Using where +1 SIMPLE t1 ref|filter a,b b|a 5|5 const 151 (17%) Using where; Using rowid filter SELECT * FROM t1 WHERE a > 0 AND b=0; a b 1 0 @@ -2514,19 +2522,32 @@ ANALYZE "r_total_time_ms": "REPLACED", "table": { "table_name": "t1", - "access_type": "range", + "access_type": "ref", "possible_keys": ["idx1", "idx2"], - "key": "idx1", - "key_length": "35", - "used_key_parts": ["nm"], + "key": "idx2", + "key_length": "5", + "used_key_parts": ["fl2"], + "ref": ["const"], + "rowid_filter": { + "range": { + "key": "idx1", + "used_key_parts": ["nm"] + }, + "rows": 44, + "selectivity_pct": 0.44, + "r_rows": 44, + "r_lookups": 1000, + "r_selectivity_pct": 0, + "r_buffer_size": "REPLACED", + "r_filling_time_ms": "REPLACED" + }, "r_loops": 1, - "rows": 44, - "r_rows": 44, + "rows": 921, + "r_rows": 0, "r_total_time_ms": "REPLACED", - "filtered": 9.21, - "r_filtered": 0, - "index_condition": "t1.nm like '3400%' or t1.nm like '3402%' or t1.nm like '3403%' or t1.nm like '3404%' or t1.nm like '3405%' or t1.nm like '3406%' or t1.nm like '3407%' or t1.nm like '3409%' or t1.nm like '3411%' or t1.nm like '3412%' or t1.nm like '3413%' or t1.nm like '3414%' or t1.nm like '3415%' or t1.nm like '3416%' or t1.nm like '3417%' or t1.nm like '3418%' or t1.nm like '3419%' or t1.nm like '3421%' or t1.nm like '3422%' or t1.nm like '3423%' or t1.nm like '3424%' or t1.nm like '3425%' or t1.nm like '3426%' or t1.nm like '3427%' or t1.nm like '3428%' or t1.nm like '3429%' or t1.nm like '3430%' or t1.nm like '3431%' or t1.nm like '3432%' or t1.nm like '3433%' or t1.nm like '3434%' or t1.nm like '3435%' or t1.nm like '3436%' or t1.nm like '3437%' or t1.nm like '3439%' or t1.nm like '3440%' or t1.nm like '3441%' or t1.nm like '3442%' or t1.nm like '3443%' or t1.nm like '3444%' or t1.nm like '3445%' or t1.nm like '3446%' or t1.nm like '3447%' or t1.nm like '3448%'", - "attached_condition": "t1.fl2 = 0" + "filtered": 0.44, + "r_filtered": 100, + "attached_condition": "t1.nm like '3400%' or t1.nm like '3402%' or t1.nm like '3403%' or t1.nm like '3404%' or t1.nm like '3405%' or t1.nm like '3406%' or t1.nm like '3407%' or t1.nm like '3409%' or t1.nm like '3411%' or t1.nm like '3412%' or t1.nm like '3413%' or t1.nm like '3414%' or t1.nm like '3415%' or t1.nm like '3416%' or t1.nm like '3417%' or t1.nm like '3418%' or t1.nm like '3419%' or t1.nm like '3421%' or t1.nm like '3422%' or t1.nm like '3423%' or t1.nm like '3424%' or t1.nm like '3425%' or t1.nm like '3426%' or t1.nm like '3427%' or t1.nm like '3428%' or t1.nm like '3429%' or t1.nm like '3430%' or t1.nm like '3431%' or t1.nm like '3432%' or t1.nm like '3433%' or t1.nm like '3434%' or t1.nm like '3435%' or t1.nm like '3436%' or t1.nm like '3437%' or t1.nm like '3439%' or t1.nm like '3440%' or t1.nm like '3441%' or t1.nm like '3442%' or t1.nm like '3443%' or t1.nm like '3444%' or t1.nm like '3445%' or t1.nm like '3446%' or t1.nm like '3447%' or t1.nm like '3448%'" } } } @@ -2559,19 +2580,31 @@ ANALYZE "r_total_time_ms": "REPLACED", "table": { "table_name": "t1", - "access_type": "range", + "access_type": "ref", "possible_keys": ["idx1", "idx2"], - "key": "idx1", - "key_length": "35", - "used_key_parts": ["nm"], + "key": "idx2", + "key_length": "5", + "used_key_parts": ["fl2"], + "ref": ["const"], + "rowid_filter": { + "range": { + "key": "idx1", + "used_key_parts": ["nm"] + }, + "rows": 44, + "selectivity_pct": 0.44, + "r_rows": 0, + "r_lookups": 0, + "r_selectivity_pct": 0, + "r_buffer_size": "REPLACED", + "r_filling_time_ms": "REPLACED" + }, "r_loops": 1, - "rows": 44, + "rows": 911, "r_rows": 0, - "r_total_time_ms": "REPLACED", - "filtered": 9.11, + "filtered": 0.44, "r_filtered": 100, - "index_condition": "t1.nm like '3400%' or t1.nm like '3402%' or t1.nm like '3403%' or t1.nm like '3404%' or t1.nm like '3405%' or t1.nm like '3406%' or t1.nm like '3407%' or t1.nm like '3409%' or t1.nm like '3411%' or t1.nm like '3412%' or t1.nm like '3413%' or t1.nm like '3414%' or t1.nm like '3415%' or t1.nm like '3416%' or t1.nm like '3417%' or t1.nm like '3418%' or t1.nm like '3419%' or t1.nm like '3421%' or t1.nm like '3422%' or t1.nm like '3423%' or t1.nm like '3424%' or t1.nm like '3425%' or t1.nm like '3426%' or t1.nm like '3427%' or t1.nm like '3428%' or t1.nm like '3429%' or t1.nm like '3430%' or t1.nm like '3431%' or t1.nm like '3432%' or t1.nm like '3433%' or t1.nm like '3434%' or t1.nm like '3435%' or t1.nm like '3436%' or t1.nm like '3437%' or t1.nm like '3439%' or t1.nm like '3440%' or t1.nm like '3441%' or t1.nm like '3442%' or t1.nm like '3443%' or t1.nm like '3444%' or t1.nm like '3445%' or t1.nm like '3446%' or t1.nm like '3447%' or t1.nm like '3448%'", - "attached_condition": "t1.fl2 = 0" + "attached_condition": "t1.nm like '3400%' or t1.nm like '3402%' or t1.nm like '3403%' or t1.nm like '3404%' or t1.nm like '3405%' or t1.nm like '3406%' or t1.nm like '3407%' or t1.nm like '3409%' or t1.nm like '3411%' or t1.nm like '3412%' or t1.nm like '3413%' or t1.nm like '3414%' or t1.nm like '3415%' or t1.nm like '3416%' or t1.nm like '3417%' or t1.nm like '3418%' or t1.nm like '3419%' or t1.nm like '3421%' or t1.nm like '3422%' or t1.nm like '3423%' or t1.nm like '3424%' or t1.nm like '3425%' or t1.nm like '3426%' or t1.nm like '3427%' or t1.nm like '3428%' or t1.nm like '3429%' or t1.nm like '3430%' or t1.nm like '3431%' or t1.nm like '3432%' or t1.nm like '3433%' or t1.nm like '3434%' or t1.nm like '3435%' or t1.nm like '3436%' or t1.nm like '3437%' or t1.nm like '3439%' or t1.nm like '3440%' or t1.nm like '3441%' or t1.nm like '3442%' or t1.nm like '3443%' or t1.nm like '3444%' or t1.nm like '3445%' or t1.nm like '3446%' or t1.nm like '3447%' or t1.nm like '3448%'" } } } diff --git a/mysql-test/main/rowid_filter_innodb.result b/mysql-test/main/rowid_filter_innodb.result index 1bf63d9a3789b..d7f1fe4a0d3e8 100644 --- a/mysql-test/main/rowid_filter_innodb.result +++ b/mysql-test/main/rowid_filter_innodb.result @@ -1997,7 +1997,7 @@ EXPLAIN EXTENDED SELECT * FROM t1 INNER JOIN t2 ON ( pk1+1 = pk2+2 AND a1 = a2 ) WHERE b1 <= ( SELECT MAX(b2) FROM t2 WHERE pk2 <= 1 ); id select_type table type possible_keys key key_len ref rows filtered Extra 1 PRIMARY t2 ALL NULL NULL NULL NULL 101 100.00 Using where -1 PRIMARY t1 ref a1,b1 a1 5 test.t2.a2 36 28.75 Using where +1 PRIMARY t1 ref|filter a1,b1 a1|b1 5|4 test.t2.a2 36 (29%) 28.75 Using where; Using rowid filter 2 SUBQUERY t2 range PRIMARY PRIMARY 4 NULL 1 100.00 Using index condition Warnings: Note 1003 /* select#1 */ select `test`.`t1`.`pk1` AS `pk1`,`test`.`t1`.`a1` AS `a1`,`test`.`t1`.`b1` AS `b1`,`test`.`t2`.`pk2` AS `pk2`,`test`.`t2`.`a2` AS `a2`,`test`.`t2`.`b2` AS `b2` from `test`.`t1` join `test`.`t2` where `test`.`t1`.`a1` = `test`.`t2`.`a2` and `test`.`t1`.`b1` <= (/* select#2 */ select max(`test`.`t2`.`b2`) from `test`.`t2` where `test`.`t2`.`pk2` <= 1) and `test`.`t1`.`pk1` + 1 = `test`.`t2`.`pk2` + 2 @@ -2022,6 +2022,14 @@ EXPLAIN "key_length": "5", "used_key_parts": ["a1"], "ref": ["test.t2.a2"], + "rowid_filter": { + "range": { + "key": "b1", + "used_key_parts": ["b1"] + }, + "rows": 115, + "selectivity_pct": 28.75 + }, "rows": 36, "filtered": 28.75, "attached_condition": "t1.b1 <= (subquery#2) and t1.pk1 + 1 = t2.pk2 + 2" @@ -2104,7 +2112,7 @@ test.t1 analyze status OK explain SELECT * FROM t1 WHERE a > 0 AND b=0; id select_type table type possible_keys key key_len ref rows Extra -1 SIMPLE t1 ref a,b b 5 const 128 Using where +1 SIMPLE t1 ref|filter a,b b|a 5|5 const 128 (14%) Using where; Using rowid filter SELECT * FROM t1 WHERE a > 0 AND b=0; a b 1 0 @@ -2439,19 +2447,32 @@ ANALYZE "r_total_time_ms": "REPLACED", "table": { "table_name": "t1", - "access_type": "range", + "access_type": "ref", "possible_keys": ["idx1", "idx2"], - "key": "idx1", - "key_length": "35", - "used_key_parts": ["nm"], + "key": "idx2", + "key_length": "5", + "used_key_parts": ["fl2"], + "ref": ["const"], + "rowid_filter": { + "range": { + "key": "idx1", + "used_key_parts": ["nm"] + }, + "rows": 44, + "selectivity_pct": 0.44, + "r_rows": 44, + "r_lookups": 1000, + "r_selectivity_pct": 0, + "r_buffer_size": "REPLACED", + "r_filling_time_ms": "REPLACED" + }, "r_loops": 1, - "rows": 44, - "r_rows": 44, + "rows": 921, + "r_rows": 0, "r_total_time_ms": "REPLACED", - "filtered": 9.21, - "r_filtered": 0, - "index_condition": "t1.nm like '3400%' or t1.nm like '3402%' or t1.nm like '3403%' or t1.nm like '3404%' or t1.nm like '3405%' or t1.nm like '3406%' or t1.nm like '3407%' or t1.nm like '3409%' or t1.nm like '3411%' or t1.nm like '3412%' or t1.nm like '3413%' or t1.nm like '3414%' or t1.nm like '3415%' or t1.nm like '3416%' or t1.nm like '3417%' or t1.nm like '3418%' or t1.nm like '3419%' or t1.nm like '3421%' or t1.nm like '3422%' or t1.nm like '3423%' or t1.nm like '3424%' or t1.nm like '3425%' or t1.nm like '3426%' or t1.nm like '3427%' or t1.nm like '3428%' or t1.nm like '3429%' or t1.nm like '3430%' or t1.nm like '3431%' or t1.nm like '3432%' or t1.nm like '3433%' or t1.nm like '3434%' or t1.nm like '3435%' or t1.nm like '3436%' or t1.nm like '3437%' or t1.nm like '3439%' or t1.nm like '3440%' or t1.nm like '3441%' or t1.nm like '3442%' or t1.nm like '3443%' or t1.nm like '3444%' or t1.nm like '3445%' or t1.nm like '3446%' or t1.nm like '3447%' or t1.nm like '3448%'", - "attached_condition": "t1.fl2 = 0" + "filtered": 0.44, + "r_filtered": 100, + "attached_condition": "t1.nm like '3400%' or t1.nm like '3402%' or t1.nm like '3403%' or t1.nm like '3404%' or t1.nm like '3405%' or t1.nm like '3406%' or t1.nm like '3407%' or t1.nm like '3409%' or t1.nm like '3411%' or t1.nm like '3412%' or t1.nm like '3413%' or t1.nm like '3414%' or t1.nm like '3415%' or t1.nm like '3416%' or t1.nm like '3417%' or t1.nm like '3418%' or t1.nm like '3419%' or t1.nm like '3421%' or t1.nm like '3422%' or t1.nm like '3423%' or t1.nm like '3424%' or t1.nm like '3425%' or t1.nm like '3426%' or t1.nm like '3427%' or t1.nm like '3428%' or t1.nm like '3429%' or t1.nm like '3430%' or t1.nm like '3431%' or t1.nm like '3432%' or t1.nm like '3433%' or t1.nm like '3434%' or t1.nm like '3435%' or t1.nm like '3436%' or t1.nm like '3437%' or t1.nm like '3439%' or t1.nm like '3440%' or t1.nm like '3441%' or t1.nm like '3442%' or t1.nm like '3443%' or t1.nm like '3444%' or t1.nm like '3445%' or t1.nm like '3446%' or t1.nm like '3447%' or t1.nm like '3448%'" } } } @@ -2484,19 +2505,31 @@ ANALYZE "r_total_time_ms": "REPLACED", "table": { "table_name": "t1", - "access_type": "range", + "access_type": "ref", "possible_keys": ["idx1", "idx2"], - "key": "idx1", - "key_length": "35", - "used_key_parts": ["nm"], + "key": "idx2", + "key_length": "5", + "used_key_parts": ["fl2"], + "ref": ["const"], + "rowid_filter": { + "range": { + "key": "idx1", + "used_key_parts": ["nm"] + }, + "rows": 44, + "selectivity_pct": 0.44, + "r_rows": 0, + "r_lookups": 0, + "r_selectivity_pct": 0, + "r_buffer_size": "REPLACED", + "r_filling_time_ms": "REPLACED" + }, "r_loops": 1, - "rows": 44, + "rows": 911, "r_rows": 0, - "r_total_time_ms": "REPLACED", - "filtered": 9.11, + "filtered": 0.44, "r_filtered": 100, - "index_condition": "t1.nm like '3400%' or t1.nm like '3402%' or t1.nm like '3403%' or t1.nm like '3404%' or t1.nm like '3405%' or t1.nm like '3406%' or t1.nm like '3407%' or t1.nm like '3409%' or t1.nm like '3411%' or t1.nm like '3412%' or t1.nm like '3413%' or t1.nm like '3414%' or t1.nm like '3415%' or t1.nm like '3416%' or t1.nm like '3417%' or t1.nm like '3418%' or t1.nm like '3419%' or t1.nm like '3421%' or t1.nm like '3422%' or t1.nm like '3423%' or t1.nm like '3424%' or t1.nm like '3425%' or t1.nm like '3426%' or t1.nm like '3427%' or t1.nm like '3428%' or t1.nm like '3429%' or t1.nm like '3430%' or t1.nm like '3431%' or t1.nm like '3432%' or t1.nm like '3433%' or t1.nm like '3434%' or t1.nm like '3435%' or t1.nm like '3436%' or t1.nm like '3437%' or t1.nm like '3439%' or t1.nm like '3440%' or t1.nm like '3441%' or t1.nm like '3442%' or t1.nm like '3443%' or t1.nm like '3444%' or t1.nm like '3445%' or t1.nm like '3446%' or t1.nm like '3447%' or t1.nm like '3448%'", - "attached_condition": "t1.fl2 = 0" + "attached_condition": "t1.nm like '3400%' or t1.nm like '3402%' or t1.nm like '3403%' or t1.nm like '3404%' or t1.nm like '3405%' or t1.nm like '3406%' or t1.nm like '3407%' or t1.nm like '3409%' or t1.nm like '3411%' or t1.nm like '3412%' or t1.nm like '3413%' or t1.nm like '3414%' or t1.nm like '3415%' or t1.nm like '3416%' or t1.nm like '3417%' or t1.nm like '3418%' or t1.nm like '3419%' or t1.nm like '3421%' or t1.nm like '3422%' or t1.nm like '3423%' or t1.nm like '3424%' or t1.nm like '3425%' or t1.nm like '3426%' or t1.nm like '3427%' or t1.nm like '3428%' or t1.nm like '3429%' or t1.nm like '3430%' or t1.nm like '3431%' or t1.nm like '3432%' or t1.nm like '3433%' or t1.nm like '3434%' or t1.nm like '3435%' or t1.nm like '3436%' or t1.nm like '3437%' or t1.nm like '3439%' or t1.nm like '3440%' or t1.nm like '3441%' or t1.nm like '3442%' or t1.nm like '3443%' or t1.nm like '3444%' or t1.nm like '3445%' or t1.nm like '3446%' or t1.nm like '3447%' or t1.nm like '3448%'" } } } @@ -2671,7 +2704,7 @@ count(*) 5 explain extended select count(*) from t1 where a between 21 and 30 and b=2; id select_type table type possible_keys key key_len ref rows filtered Extra -1 SIMPLE t1 ref b,a b 5 const 24 9.60 Using where +1 SIMPLE t1 ref|filter b,a b|a 5|5 const 24 (10%) 9.60 Using where; Using rowid filter Warnings: Note 1003 select count(0) AS `count(*)` from `test`.`t1` where `test`.`t1`.`b` = 2 and `test`.`t1`.`a` between 21 and 30 select * from t1 where a between 21 and 30 and b=2; @@ -3133,7 +3166,7 @@ WHERE 1 = 1 AND domain = 'www.mailhost.i-dev.fr' AND timestamp >= DATE_ADD('2017-01-30 08:24:51', INTERVAL -1 MONTH) ORDER BY timestamp DESC; id select_type table type possible_keys key key_len ref rows filtered Extra -1 SIMPLE t1 ref ixEventWhoisDomainDomain,ixEventWhoisDomainTimestamp ixEventWhoisDomainDomain 98 const 40 33.33 Using index condition; Using where; Using filesort +1 SIMPLE t1 ref|filter ixEventWhoisDomainDomain,ixEventWhoisDomainTimestamp ixEventWhoisDomainDomain|ixEventWhoisDomainTimestamp 98|4 const 40 (33%) 33.33 Using index condition; Using where; Using filesort; Using rowid filter Warnings: Note 1003 select `test`.`t1`.`id` AS `id`,`test`.`t1`.`domain` AS `domain`,`test`.`t1`.`registrant_name` AS `registrant_name`,`test`.`t1`.`registrant_organization` AS `registrant_organization`,`test`.`t1`.`registrant_street1` AS `registrant_street1`,`test`.`t1`.`registrant_street2` AS `registrant_street2`,`test`.`t1`.`registrant_street3` AS `registrant_street3`,`test`.`t1`.`registrant_street4` AS `registrant_street4`,`test`.`t1`.`registrant_street5` AS `registrant_street5`,`test`.`t1`.`registrant_city` AS `registrant_city`,`test`.`t1`.`registrant_postal_code` AS `registrant_postal_code`,`test`.`t1`.`registrant_country` AS `registrant_country`,`test`.`t1`.`registrant_email` AS `registrant_email`,`test`.`t1`.`registrant_telephone` AS `registrant_telephone`,`test`.`t1`.`administrative_name` AS `administrative_name`,`test`.`t1`.`administrative_organization` AS `administrative_organization`,`test`.`t1`.`administrative_street1` AS `administrative_street1`,`test`.`t1`.`administrative_street2` AS `administrative_street2`,`test`.`t1`.`administrative_street3` AS `administrative_street3`,`test`.`t1`.`administrative_street4` AS `administrative_street4`,`test`.`t1`.`administrative_street5` AS `administrative_street5`,`test`.`t1`.`administrative_city` AS `administrative_city`,`test`.`t1`.`administrative_postal_code` AS `administrative_postal_code`,`test`.`t1`.`administrative_country` AS `administrative_country`,`test`.`t1`.`administrative_email` AS `administrative_email`,`test`.`t1`.`administrative_telephone` AS `administrative_telephone`,`test`.`t1`.`technical_name` AS `technical_name`,`test`.`t1`.`technical_organization` AS `technical_organization`,`test`.`t1`.`technical_street1` AS `technical_street1`,`test`.`t1`.`technical_street2` AS `technical_street2`,`test`.`t1`.`technical_street3` AS `technical_street3`,`test`.`t1`.`technical_street4` AS `technical_street4`,`test`.`t1`.`technical_street5` AS `technical_street5`,`test`.`t1`.`technical_city` AS `technical_city`,`test`.`t1`.`technical_postal_code` AS `technical_postal_code`,`test`.`t1`.`technical_country` AS `technical_country`,`test`.`t1`.`technical_email` AS `technical_email`,`test`.`t1`.`technical_telephone` AS `technical_telephone`,`test`.`t1`.`json` AS `json`,`test`.`t1`.`timestamp` AS `timestamp` from `test`.`t1` where `test`.`t1`.`domain` = 'www.mailhost.i-dev.fr' and `test`.`t1`.`timestamp` >= ('2017-01-30 08:24:51' + interval -1 month) order by `test`.`t1`.`timestamp` desc SET optimizer_switch=@save_optimizer_switch; @@ -3382,7 +3415,7 @@ fi.fh in (6311439873746261694,-397087483897438286, id select_type table type possible_keys key key_len ref rows filtered Extra 1 SIMPLE t index_merge PRIMARY,acli_rid,acli_tp acli_tp,acli_rid 2,767 NULL 2 100.00 Using intersect(acli_tp,acli_rid); Using where; Using index 1 SIMPLE a ref PRIMARY,acei_aclid acei_aclid 8 test.t.id 1 100.00 Using where -1 SIMPLE fi ref filt_aceid,filt_fh filt_aceid 8 test.a.id 24 14.46 Using where +1 SIMPLE fi ref|filter filt_aceid,filt_fh filt_aceid|filt_fh 8|8 test.a.id 24 (14%) 14.46 Using where; Using rowid filter Warnings: Note 1003 select `test`.`t`.`id` AS `id`,`test`.`fi`.`id` AS `id`,`test`.`fi`.`aceid` AS `aceid`,`test`.`fi`.`clid` AS `clid`,`test`.`fi`.`fh` AS `fh` from `test`.`acli` `t` join `test`.`acei` `a` join `test`.`filt` `fi` where `test`.`t`.`tp` = 121 and `test`.`a`.`atp` = 1 and `test`.`fi`.`aceid` = `test`.`a`.`id` and `test`.`a`.`aclid` = `test`.`t`.`id` and `test`.`t`.`rid` = 'B5FCC8C7111E4E3CBC21AAF5012F59C2' and `test`.`fi`.`fh` in (6311439873746261694,-397087483897438286,8518228073041491534,-5420422472375069774) set statement optimizer_switch='rowid_filter=on' for select t.id, fi.* @@ -3498,7 +3531,7 @@ fi.fh in (6311439873746261694,-397087483897438286, id select_type table type possible_keys key key_len ref rows filtered Extra 1 SIMPLE t index_merge PRIMARY,acli_rid,acli_tp acli_tp,acli_rid 2,767 NULL 2 100.00 Using intersect(acli_tp,acli_rid); Using where; Using index 1 SIMPLE a ref PRIMARY,acei_aclid acei_aclid 8 test.t.id 1 100.00 Using where; Using join buffer (flat, BKA join); Rowid-ordered scan -1 SIMPLE fi ref filt_aceid,filt_fh filt_aceid 8 test.a.id 24 14.46 Using where; Using join buffer (incremental, BKA join); Rowid-ordered scan +1 SIMPLE fi ref|filter filt_aceid,filt_fh filt_aceid|filt_fh 8|8 test.a.id 24 (14%) 14.46 Using where; Using join buffer (incremental, BKA join); Rowid-ordered scan; Using rowid filter Warnings: Note 1003 select `test`.`t`.`id` AS `id`,`test`.`fi`.`id` AS `id`,`test`.`fi`.`aceid` AS `aceid`,`test`.`fi`.`clid` AS `clid`,`test`.`fi`.`fh` AS `fh` from `test`.`acli` `t` join `test`.`acei` `a` join `test`.`filt` `fi` where `test`.`t`.`tp` = 121 and `test`.`a`.`atp` = 1 and `test`.`fi`.`aceid` = `test`.`a`.`id` and `test`.`a`.`aclid` = `test`.`t`.`id` and `test`.`t`.`rid` = 'B5FCC8C7111E4E3CBC21AAF5012F59C2' and `test`.`fi`.`fh` in (6311439873746261694,-397087483897438286,8518228073041491534,-5420422472375069774) set statement optimizer_switch='rowid_filter=on' for select t.id, fi.* @@ -3616,9 +3649,22 @@ ANALYZE "key_length": "8", "used_key_parts": ["aceid"], "ref": ["test.a.id"], + "rowid_filter": { + "range": { + "key": "filt_fh", + "used_key_parts": ["fh"] + }, + "rows": 81, + "selectivity_pct": 14.464, + "r_rows": 80, + "r_lookups": 80, + "r_selectivity_pct": 40, + "r_buffer_size": "REPLACED", + "r_filling_time_ms": "REPLACED" + }, "r_loops": 1, "rows": 24, - "r_rows": 80, + "r_rows": 32, "r_total_time_ms": "REPLACED", "filtered": 14.464, "r_filtered": 100 @@ -3628,7 +3674,7 @@ ANALYZE "join_type": "BKA", "mrr_type": "Rowid-ordered scan", "attached_condition": "fi.fh in (6311439873746261694,-397087483897438286,8518228073041491534,-5420422472375069774)", - "r_filtered": 40 + "r_filtered": 100 } } } @@ -3732,7 +3778,7 @@ WHERE t1.c1 NOT IN (SELECT t2.c1 FROM t2, t1 AS a1 WHERE t2.i1 = t1.pk AND t2.i1 BETWEEN 3 AND 5); id select_type table type possible_keys key key_len ref rows filtered Extra 1 PRIMARY t1 ALL NULL NULL NULL NULL 60 100.00 Using where -2 DEPENDENT SUBQUERY t2 ref c1,i1 i1 5 test.t1.pk 20 100.00 Using index condition; Using where +2 DEPENDENT SUBQUERY t2 ref|filter c1,i1 c1|i1 3|5 func 38 (25%) 25.00 Using where; Full scan on NULL key; Using rowid filter 2 DEPENDENT SUBQUERY a1 ALL NULL NULL NULL NULL 60 100.00 Using join buffer (flat, BNL join) Warnings: Note 1276 Field or reference 'test.t1.pk' of SELECT #2 was resolved in SELECT #1 diff --git a/mysql-test/main/select.result b/mysql-test/main/select.result index fc3a29094ae86..6652b1a637563 100644 --- a/mysql-test/main/select.result +++ b/mysql-test/main/select.result @@ -3744,7 +3744,7 @@ EXPLAIN SELECT * FROM t1 WHERE ID_better=1 AND ID1_with_null IS NULL AND (ID2_with_null=1 OR ID2_with_null=2); id select_type table type possible_keys key key_len ref rows Extra -1 SIMPLE t1 ref idx1,idx2 idx2 4 const 2 Using where +1 SIMPLE t1 ref|filter idx1,idx2 idx1|idx2 5|4 const 2 (1%) Using index condition; Using where; Using rowid filter DROP TABLE t1; CREATE TABLE t1 (a INT, ts TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP, KEY ts(ts)); INSERT INTO t1 VALUES (30,"2006-01-03 23:00:00"), (31,"2006-01-03 23:00:00"); diff --git a/mysql-test/main/select_jcl6.result b/mysql-test/main/select_jcl6.result index e7c2e3e480780..cef6e0fcf2ad0 100644 --- a/mysql-test/main/select_jcl6.result +++ b/mysql-test/main/select_jcl6.result @@ -3755,7 +3755,7 @@ EXPLAIN SELECT * FROM t1 WHERE ID_better=1 AND ID1_with_null IS NULL AND (ID2_with_null=1 OR ID2_with_null=2); id select_type table type possible_keys key key_len ref rows Extra -1 SIMPLE t1 ref idx1,idx2 idx2 4 const 2 Using where +1 SIMPLE t1 ref|filter idx1,idx2 idx1|idx2 5|4 const 2 (1%) Using index condition; Using where; Using rowid filter DROP TABLE t1; CREATE TABLE t1 (a INT, ts TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP, KEY ts(ts)); INSERT INTO t1 VALUES (30,"2006-01-03 23:00:00"), (31,"2006-01-03 23:00:00"); diff --git a/mysql-test/main/select_pkeycache.result b/mysql-test/main/select_pkeycache.result index fc3a29094ae86..6652b1a637563 100644 --- a/mysql-test/main/select_pkeycache.result +++ b/mysql-test/main/select_pkeycache.result @@ -3744,7 +3744,7 @@ EXPLAIN SELECT * FROM t1 WHERE ID_better=1 AND ID1_with_null IS NULL AND (ID2_with_null=1 OR ID2_with_null=2); id select_type table type possible_keys key key_len ref rows Extra -1 SIMPLE t1 ref idx1,idx2 idx2 4 const 2 Using where +1 SIMPLE t1 ref|filter idx1,idx2 idx1|idx2 5|4 const 2 (1%) Using index condition; Using where; Using rowid filter DROP TABLE t1; CREATE TABLE t1 (a INT, ts TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP, KEY ts(ts)); INSERT INTO t1 VALUES (30,"2006-01-03 23:00:00"), (31,"2006-01-03 23:00:00"); diff --git a/mysql-test/main/selectivity.result b/mysql-test/main/selectivity.result index 4113779a11ed6..7e3202337ec87 100644 --- a/mysql-test/main/selectivity.result +++ b/mysql-test/main/selectivity.result @@ -1661,7 +1661,7 @@ Note 1003 select `test`.`t1`.`a` AS `a`,`test`.`t1`.`b` AS `b` from `test`.`t1` # gives selectivity data explain extended select * from t1 where a in (17,51,5) and b=2; id select_type table type possible_keys key key_len ref rows filtered Extra -1 SIMPLE t1 ref b,a b 5 const 58 2.90 Using where +1 SIMPLE t1 ref|filter b,a b|a 5|5 const 58 (3%) 2.90 Using where; Using rowid filter Warnings: Note 1003 select `test`.`t1`.`a` AS `a`,`test`.`t1`.`b` AS `b` from `test`.`t1` where `test`.`t1`.`b` = 2 and `test`.`t1`.`a` in (17,51,5) drop table t1; diff --git a/sql/sql_select.cc b/sql/sql_select.cc index 0f8ead46ffccb..4bdfb659513ae 100644 --- a/sql/sql_select.cc +++ b/sql/sql_select.cc @@ -7557,7 +7557,6 @@ best_access_path(JOIN *join, rec= MATCHING_ROWS_IN_OTHER_TABLE; // Fix for small tables Json_writer_object trace_access_idx(thd); - double eq_ref_rows= 0; /* full text keys require special treatment */ @@ -7596,8 +7595,7 @@ best_access_path(JOIN *join, type= JT_EQ_REF; trace_access_idx.add("access_type", join_type_str[type]) .add("index", keyinfo->name); - eq_ref_rows= tmp = prev_record_reads(join_positions, idx, - found_ref); + tmp = prev_record_reads(join_positions, idx, found_ref); records=1.0; } else @@ -7904,28 +7902,7 @@ best_access_path(JOIN *join, (s->table->file->index_flags(start_key->key,0,1) & HA_DO_RANGE_FILTER_PUSHDOWN)) { - double rows; - if (type == JT_EQ_REF) - { - /* - Treat EQ_REF access in a special way: - 1. We have no cost for index-only read. Assume its cost is 50% of - the cost of the full read. - - 2. A regular ref access will do #record_count lookups, but eq_ref - has "lookup cache" which reduces the number of lookups made. - The estimation code uses prev_record_reads() call to estimate: - - tmp = prev_record_reads(join_positions, idx, found_ref); - - Set the effective number of rows from "tmp" here. - */ - keyread_tmp= COST_ADD(eq_ref_rows / 2, s->startup_cost); - rows= eq_ref_rows; - } - else - rows= record_count * records; - + double rows= record_count * records; /* If we use filter F with selectivity s the the cost of fetching data by key using this filter will be @@ -7947,46 +7924,53 @@ best_access_path(JOIN *join, cost_of_fetching_1_row = tmp/rows cost_of_fetching_1_key_tuple = keyread_tmp/rows - access_cost_factor is the gain we expect for using rowid filter. - An access_cost_factor of 1.0 means that keyread_tmp is 0 - (using key read is infinitely fast) and the gain for each row when - using filter is great. - An access_cost_factor if 0.0 means that using keyread has the - same cost as reading rows, so there is no gain to get with - filter. - access_cost_factor should never be bigger than 1.0 (if all - calculations are correct) as the cost of keyread should always be - smaller than the cost of fetching the same number of keys + rows. - access_cost_factor should also never be smaller than 0.0. - The one exception is if number of records is 1 (eq_ref), then - because we are comparing rows to cost of keyread_tmp, keyread_tmp - is higher by 1.0. This is a big that will be fixed in a later - version. - - If we have limited the cost (=tmp) of reading rows with 'worst_seek' - we cannot use filters as the cost calculation below would cause - tmp to become negative. The future resultion is to not limit - cost with worst_seek. + Here's a more detailed explanation that uses the formulas behind + the function the call filter->get_adjusted_gain(). The function + takes as a parameter the number of probes/look-ups into the filter + that is equal to the number of fetched key entries that is equal to + the number of row fetches when no filter is used (assuming no + index condition pushdown is employed for the used key access). + Let this number be N. Then the total gain from using the filter is + N*a_adj - b where b is the cost of building the filter and + a_adj is calcilated as follows: + a - (1-access_cost_factor)*(1-s) = + (1+1_cond_eval_cost)*(1-s)-1_probe_cost - (1-access_cost_factor)*(1-s) + = (1-s)*(1_cond_eval_cost+access_cost_factor) - 1_probe_cost. + Here ((1-s)*(1_cond_eval_cost) * N is the gain from checking less + conditions pushed into the table, 1_probe_cost*N is the cost of the + probes and (1*s) * access_cost_factor * N must be the gain from + accessing less rows. + It does not matter how we calculate the cost of N full row fetches + cost_of_fetching_N_rows or + how we calculate the cost of fetching N key entries + cost_of_fetching_N_key_entries + the gain from less row fetches will be + (cost_of_fetching_N_rows - cost_of_fetching_N_key_entries) * (1-s) + and this should be equal to (1*s) * access_cost_factor * N. + Thus access_cost_factor must be calculated as + (cost_of_fetching_N_rows - cost_of_fetching_N_key_entries) / N. + + For safety we clip cost_of_fetching_N_key_entries by the value + of cost_of_fetching_N_row though formally it's not necessary. */ - double access_cost_factor= MY_MIN((rows - keyread_tmp) / rows, 1.0); - if (!(records < s->worst_seeks && - records <= thd->variables.max_seeks_for_key)) - trace_access_idx.add("rowid_filter_skipped", "worst/max seeks clipping"); - else if (access_cost_factor <= 0.0) - trace_access_idx.add("rowid_filter_skipped", "cost_factor <= 0"); - else + /* + For eq_ref access we assume that the cost of fetching N key entries + is equal to the half of fetching N rows + */ + double key_access_cost= + type == JT_EQ_REF ? 0.5 * tmp : MY_MIN(tmp, keyread_tmp); + double access_cost_factor= MY_MIN((tmp - key_access_cost) / rows, 1.0); + + filter= + table->best_range_rowid_filter_for_partial_join(start_key->key, + rows, + access_cost_factor); + if (filter) { - filter= - table->best_range_rowid_filter_for_partial_join(start_key->key, - rows, - access_cost_factor); - if (filter) - { - tmp-= filter->get_adjusted_gain(rows) - filter->get_cmp_gain(rows); - DBUG_ASSERT(tmp >= 0); - trace_access_idx.add("rowid_filter_key", + tmp-= filter->get_adjusted_gain(rows) - filter->get_cmp_gain(rows); + DBUG_ASSERT(tmp >= 0); + trace_access_idx.add("rowid_filter_key", s->table->key_info[filter->key_no].name); - } } } trace_access_idx.add("rows", records).add("cost", tmp); @@ -8139,19 +8123,19 @@ best_access_path(JOIN *join, uint key_no= s->quick->index; /* See the comment concerning using rowid filter for with ref access */ - keyread_tmp= s->table->quick_index_only_costs[key_no] * record_count; - double access_cost_factor= MY_MIN((rows - keyread_tmp) / rows, 1.0); - if (access_cost_factor > 0.0) + double row_access_cost= s->quick->read_time * record_count; + double key_access_cost= + MY_MIN(row_access_cost, + s->table->quick_index_only_costs[key_no] * record_count); + double access_cost_factor= MY_MIN((row_access_cost - key_access_cost) / + rows, 1.0); + filter= + s->table->best_range_rowid_filter_for_partial_join(key_no, rows, + access_cost_factor); + if (filter) { - filter= - s->table-> - best_range_rowid_filter_for_partial_join(key_no, rows, - access_cost_factor); - if (filter) - { - tmp-= filter->get_adjusted_gain(rows); - DBUG_ASSERT(tmp >= 0); - } + tmp-= filter->get_adjusted_gain(rows); + DBUG_ASSERT(tmp >= 0); } else trace_access_scan.add("rowid_filter_skipped", "cost_factor <= 0"); From 2e6872791af2aab48490c24279ca3e24b64e377c Mon Sep 17 00:00:00 2001 From: Sergei Petrunia Date: Thu, 2 Feb 2023 17:12:39 +0200 Subject: [PATCH 08/92] MDEV-30218: Incorrect optimization for rowid_filtering, correction Final corrections: - Remove incorrect tracing, "rowid_filter_skipped" - Put the worst_seeks sanity check back --- mysql-test/main/join_nested_jcl6.result | 2 +- mysql-test/main/opt_trace.result | 4 +- mysql-test/main/range.result | 2 +- mysql-test/main/rowid_filter.result | 75 +++++---------- mysql-test/main/rowid_filter_innodb.result | 102 ++++++--------------- mysql-test/main/selectivity.result | 2 +- sql/sql_select.cc | 20 ++-- 7 files changed, 68 insertions(+), 139 deletions(-) diff --git a/mysql-test/main/join_nested_jcl6.result b/mysql-test/main/join_nested_jcl6.result index 91fe367c378fd..7226a5d62b1b3 100644 --- a/mysql-test/main/join_nested_jcl6.result +++ b/mysql-test/main/join_nested_jcl6.result @@ -2085,7 +2085,7 @@ ON t6.b >= 2 AND t5.b=t7.b AND (t8.a > 0 OR t8.c IS NULL) AND t6.a>0 AND t7.a>0; id select_type table type possible_keys key key_len ref rows Extra 1 SIMPLE t5 ALL NULL NULL NULL NULL 3 -1 SIMPLE t7 ref|filter PRIMARY,b_i b_i|PRIMARY 5|4 test.t5.b 2 (29%) Using where; Using join buffer (flat, BKA join); Key-ordered Rowid-ordered scan; Using rowid filter +1 SIMPLE t7 ref PRIMARY,b_i b_i 5 test.t5.b 2 Using where; Using join buffer (flat, BKA join); Key-ordered Rowid-ordered scan 1 SIMPLE t6 range PRIMARY,b_i PRIMARY 4 NULL 3 Using where; Rowid-ordered scan; Using join buffer (incremental, BNL join) 1 SIMPLE t8 ref b_i b_i 5 test.t5.b 2 Using where; Using join buffer (incremental, BKA join); Key-ordered Rowid-ordered scan SELECT t5.a,t5.b,t6.a,t6.b,t7.a,t7.b,t8.a,t8.b diff --git a/mysql-test/main/opt_trace.result b/mysql-test/main/opt_trace.result index 92cd3eb784812..a97d0074d241a 100644 --- a/mysql-test/main/opt_trace.result +++ b/mysql-test/main/opt_trace.result @@ -2118,6 +2118,7 @@ explain select * from t1 where a=1 and b=2 order by c limit 1 { "access_type": "ref", "index": "a_c", "used_range_estimates": true, + "rowid_filter_skipped": "worst/max seeks clipping", "rows": 180, "cost": 92, "chosen": true @@ -3968,7 +3969,6 @@ explain delete t0,t1 from t0, t1 where t0.a=t1.a and t1.a<3 { "best_access_path": { "considered_access_paths": [ { - "rowid_filter_skipped": "cost_factor <= 0", "access_type": "range", "resulting_rows": 3, "cost": 1.407, @@ -4024,7 +4024,6 @@ explain delete t0,t1 from t0, t1 where t0.a=t1.a and t1.a<3 { "best_access_path": { "considered_access_paths": [ { - "rowid_filter_skipped": "cost_factor <= 0", "access_type": "range", "resulting_rows": 3, "cost": 1.407, @@ -4051,6 +4050,7 @@ explain delete t0,t1 from t0, t1 where t0.a=t1.a and t1.a<3 { "index": "a", "used_range_estimates": false, "cause": "not better than ref estimates", + "rowid_filter_skipped": "worst/max seeks clipping", "rows": 2, "cost": 3.014, "chosen": true diff --git a/mysql-test/main/range.result b/mysql-test/main/range.result index 0e728d76a3e22..a3ce10fe38a34 100644 --- a/mysql-test/main/range.result +++ b/mysql-test/main/range.result @@ -281,7 +281,7 @@ INSERT INTO t1 VALUES (33,5),(33,5),(33,5),(33,5),(34,5),(35,5); EXPLAIN SELECT * FROM t1 WHERE a IN(1,2) AND b=5; id select_type table type possible_keys key key_len ref rows Extra -1 SIMPLE t1 ref|filter a,b b|a 5|5 const 15 (5%) Using where; Using rowid filter +1 SIMPLE t1 range a,b a 5 NULL 2 Using index condition; Using where SELECT * FROM t1 WHERE a IN(1,2) AND b=5; a b DROP TABLE t1; diff --git a/mysql-test/main/rowid_filter.result b/mysql-test/main/rowid_filter.result index efe1fe16283d3..2cd45748675f2 100644 --- a/mysql-test/main/rowid_filter.result +++ b/mysql-test/main/rowid_filter.result @@ -2072,7 +2072,7 @@ EXPLAIN EXTENDED SELECT * FROM t1 INNER JOIN t2 ON ( pk1+1 = pk2+2 AND a1 = a2 ) WHERE b1 <= ( SELECT MAX(b2) FROM t2 WHERE pk2 <= 1 ); id select_type table type possible_keys key key_len ref rows filtered Extra 1 PRIMARY t2 ALL NULL NULL NULL NULL 101 100.00 Using where -1 PRIMARY t1 ref|filter a1,b1 a1|b1 5|4 test.t2.a2 36 (29%) 28.75 Using where; Using rowid filter +1 PRIMARY t1 ref a1,b1 a1 5 test.t2.a2 36 28.75 Using where 2 SUBQUERY t2 range PRIMARY PRIMARY 4 NULL 1 100.00 Using index condition Warnings: Note 1003 /* select#1 */ select `test`.`t1`.`pk1` AS `pk1`,`test`.`t1`.`a1` AS `a1`,`test`.`t1`.`b1` AS `b1`,`test`.`t2`.`pk2` AS `pk2`,`test`.`t2`.`a2` AS `a2`,`test`.`t2`.`b2` AS `b2` from `test`.`t1` join `test`.`t2` where `test`.`t1`.`a1` = `test`.`t2`.`a2` and `test`.`t1`.`b1` <= (/* select#2 */ select max(`test`.`t2`.`b2`) from `test`.`t2` where `test`.`t2`.`pk2` <= 1) and `test`.`t1`.`pk1` + 1 = `test`.`t2`.`pk2` + 2 @@ -2097,14 +2097,6 @@ EXPLAIN "key_length": "5", "used_key_parts": ["a1"], "ref": ["test.t2.a2"], - "rowid_filter": { - "range": { - "key": "b1", - "used_key_parts": ["b1"] - }, - "rows": 115, - "selectivity_pct": 28.75 - }, "rows": 36, "filtered": 28.75, "attached_condition": "t1.b1 <= (subquery#2) and t1.pk1 + 1 = t2.pk2 + 2" @@ -2187,7 +2179,7 @@ test.t1 analyze status OK explain SELECT * FROM t1 WHERE a > 0 AND b=0; id select_type table type possible_keys key key_len ref rows Extra -1 SIMPLE t1 ref|filter a,b b|a 5|5 const 151 (17%) Using where; Using rowid filter +1 SIMPLE t1 ref a,b b 5 const 151 Using where SELECT * FROM t1 WHERE a > 0 AND b=0; a b 1 0 @@ -2522,32 +2514,19 @@ ANALYZE "r_total_time_ms": "REPLACED", "table": { "table_name": "t1", - "access_type": "ref", + "access_type": "range", "possible_keys": ["idx1", "idx2"], - "key": "idx2", - "key_length": "5", - "used_key_parts": ["fl2"], - "ref": ["const"], - "rowid_filter": { - "range": { - "key": "idx1", - "used_key_parts": ["nm"] - }, - "rows": 44, - "selectivity_pct": 0.44, - "r_rows": 44, - "r_lookups": 1000, - "r_selectivity_pct": 0, - "r_buffer_size": "REPLACED", - "r_filling_time_ms": "REPLACED" - }, + "key": "idx1", + "key_length": "35", + "used_key_parts": ["nm"], "r_loops": 1, - "rows": 921, - "r_rows": 0, + "rows": 44, + "r_rows": 44, "r_total_time_ms": "REPLACED", - "filtered": 0.44, - "r_filtered": 100, - "attached_condition": "t1.nm like '3400%' or t1.nm like '3402%' or t1.nm like '3403%' or t1.nm like '3404%' or t1.nm like '3405%' or t1.nm like '3406%' or t1.nm like '3407%' or t1.nm like '3409%' or t1.nm like '3411%' or t1.nm like '3412%' or t1.nm like '3413%' or t1.nm like '3414%' or t1.nm like '3415%' or t1.nm like '3416%' or t1.nm like '3417%' or t1.nm like '3418%' or t1.nm like '3419%' or t1.nm like '3421%' or t1.nm like '3422%' or t1.nm like '3423%' or t1.nm like '3424%' or t1.nm like '3425%' or t1.nm like '3426%' or t1.nm like '3427%' or t1.nm like '3428%' or t1.nm like '3429%' or t1.nm like '3430%' or t1.nm like '3431%' or t1.nm like '3432%' or t1.nm like '3433%' or t1.nm like '3434%' or t1.nm like '3435%' or t1.nm like '3436%' or t1.nm like '3437%' or t1.nm like '3439%' or t1.nm like '3440%' or t1.nm like '3441%' or t1.nm like '3442%' or t1.nm like '3443%' or t1.nm like '3444%' or t1.nm like '3445%' or t1.nm like '3446%' or t1.nm like '3447%' or t1.nm like '3448%'" + "filtered": 9.21, + "r_filtered": 0, + "index_condition": "t1.nm like '3400%' or t1.nm like '3402%' or t1.nm like '3403%' or t1.nm like '3404%' or t1.nm like '3405%' or t1.nm like '3406%' or t1.nm like '3407%' or t1.nm like '3409%' or t1.nm like '3411%' or t1.nm like '3412%' or t1.nm like '3413%' or t1.nm like '3414%' or t1.nm like '3415%' or t1.nm like '3416%' or t1.nm like '3417%' or t1.nm like '3418%' or t1.nm like '3419%' or t1.nm like '3421%' or t1.nm like '3422%' or t1.nm like '3423%' or t1.nm like '3424%' or t1.nm like '3425%' or t1.nm like '3426%' or t1.nm like '3427%' or t1.nm like '3428%' or t1.nm like '3429%' or t1.nm like '3430%' or t1.nm like '3431%' or t1.nm like '3432%' or t1.nm like '3433%' or t1.nm like '3434%' or t1.nm like '3435%' or t1.nm like '3436%' or t1.nm like '3437%' or t1.nm like '3439%' or t1.nm like '3440%' or t1.nm like '3441%' or t1.nm like '3442%' or t1.nm like '3443%' or t1.nm like '3444%' or t1.nm like '3445%' or t1.nm like '3446%' or t1.nm like '3447%' or t1.nm like '3448%'", + "attached_condition": "t1.fl2 = 0" } } } @@ -2580,31 +2559,19 @@ ANALYZE "r_total_time_ms": "REPLACED", "table": { "table_name": "t1", - "access_type": "ref", + "access_type": "range", "possible_keys": ["idx1", "idx2"], - "key": "idx2", - "key_length": "5", - "used_key_parts": ["fl2"], - "ref": ["const"], - "rowid_filter": { - "range": { - "key": "idx1", - "used_key_parts": ["nm"] - }, - "rows": 44, - "selectivity_pct": 0.44, - "r_rows": 0, - "r_lookups": 0, - "r_selectivity_pct": 0, - "r_buffer_size": "REPLACED", - "r_filling_time_ms": "REPLACED" - }, + "key": "idx1", + "key_length": "35", + "used_key_parts": ["nm"], "r_loops": 1, - "rows": 911, + "rows": 44, "r_rows": 0, - "filtered": 0.44, + "r_total_time_ms": "REPLACED", + "filtered": 9.11, "r_filtered": 100, - "attached_condition": "t1.nm like '3400%' or t1.nm like '3402%' or t1.nm like '3403%' or t1.nm like '3404%' or t1.nm like '3405%' or t1.nm like '3406%' or t1.nm like '3407%' or t1.nm like '3409%' or t1.nm like '3411%' or t1.nm like '3412%' or t1.nm like '3413%' or t1.nm like '3414%' or t1.nm like '3415%' or t1.nm like '3416%' or t1.nm like '3417%' or t1.nm like '3418%' or t1.nm like '3419%' or t1.nm like '3421%' or t1.nm like '3422%' or t1.nm like '3423%' or t1.nm like '3424%' or t1.nm like '3425%' or t1.nm like '3426%' or t1.nm like '3427%' or t1.nm like '3428%' or t1.nm like '3429%' or t1.nm like '3430%' or t1.nm like '3431%' or t1.nm like '3432%' or t1.nm like '3433%' or t1.nm like '3434%' or t1.nm like '3435%' or t1.nm like '3436%' or t1.nm like '3437%' or t1.nm like '3439%' or t1.nm like '3440%' or t1.nm like '3441%' or t1.nm like '3442%' or t1.nm like '3443%' or t1.nm like '3444%' or t1.nm like '3445%' or t1.nm like '3446%' or t1.nm like '3447%' or t1.nm like '3448%'" + "index_condition": "t1.nm like '3400%' or t1.nm like '3402%' or t1.nm like '3403%' or t1.nm like '3404%' or t1.nm like '3405%' or t1.nm like '3406%' or t1.nm like '3407%' or t1.nm like '3409%' or t1.nm like '3411%' or t1.nm like '3412%' or t1.nm like '3413%' or t1.nm like '3414%' or t1.nm like '3415%' or t1.nm like '3416%' or t1.nm like '3417%' or t1.nm like '3418%' or t1.nm like '3419%' or t1.nm like '3421%' or t1.nm like '3422%' or t1.nm like '3423%' or t1.nm like '3424%' or t1.nm like '3425%' or t1.nm like '3426%' or t1.nm like '3427%' or t1.nm like '3428%' or t1.nm like '3429%' or t1.nm like '3430%' or t1.nm like '3431%' or t1.nm like '3432%' or t1.nm like '3433%' or t1.nm like '3434%' or t1.nm like '3435%' or t1.nm like '3436%' or t1.nm like '3437%' or t1.nm like '3439%' or t1.nm like '3440%' or t1.nm like '3441%' or t1.nm like '3442%' or t1.nm like '3443%' or t1.nm like '3444%' or t1.nm like '3445%' or t1.nm like '3446%' or t1.nm like '3447%' or t1.nm like '3448%'", + "attached_condition": "t1.fl2 = 0" } } } diff --git a/mysql-test/main/rowid_filter_innodb.result b/mysql-test/main/rowid_filter_innodb.result index d7f1fe4a0d3e8..1bf63d9a3789b 100644 --- a/mysql-test/main/rowid_filter_innodb.result +++ b/mysql-test/main/rowid_filter_innodb.result @@ -1997,7 +1997,7 @@ EXPLAIN EXTENDED SELECT * FROM t1 INNER JOIN t2 ON ( pk1+1 = pk2+2 AND a1 = a2 ) WHERE b1 <= ( SELECT MAX(b2) FROM t2 WHERE pk2 <= 1 ); id select_type table type possible_keys key key_len ref rows filtered Extra 1 PRIMARY t2 ALL NULL NULL NULL NULL 101 100.00 Using where -1 PRIMARY t1 ref|filter a1,b1 a1|b1 5|4 test.t2.a2 36 (29%) 28.75 Using where; Using rowid filter +1 PRIMARY t1 ref a1,b1 a1 5 test.t2.a2 36 28.75 Using where 2 SUBQUERY t2 range PRIMARY PRIMARY 4 NULL 1 100.00 Using index condition Warnings: Note 1003 /* select#1 */ select `test`.`t1`.`pk1` AS `pk1`,`test`.`t1`.`a1` AS `a1`,`test`.`t1`.`b1` AS `b1`,`test`.`t2`.`pk2` AS `pk2`,`test`.`t2`.`a2` AS `a2`,`test`.`t2`.`b2` AS `b2` from `test`.`t1` join `test`.`t2` where `test`.`t1`.`a1` = `test`.`t2`.`a2` and `test`.`t1`.`b1` <= (/* select#2 */ select max(`test`.`t2`.`b2`) from `test`.`t2` where `test`.`t2`.`pk2` <= 1) and `test`.`t1`.`pk1` + 1 = `test`.`t2`.`pk2` + 2 @@ -2022,14 +2022,6 @@ EXPLAIN "key_length": "5", "used_key_parts": ["a1"], "ref": ["test.t2.a2"], - "rowid_filter": { - "range": { - "key": "b1", - "used_key_parts": ["b1"] - }, - "rows": 115, - "selectivity_pct": 28.75 - }, "rows": 36, "filtered": 28.75, "attached_condition": "t1.b1 <= (subquery#2) and t1.pk1 + 1 = t2.pk2 + 2" @@ -2112,7 +2104,7 @@ test.t1 analyze status OK explain SELECT * FROM t1 WHERE a > 0 AND b=0; id select_type table type possible_keys key key_len ref rows Extra -1 SIMPLE t1 ref|filter a,b b|a 5|5 const 128 (14%) Using where; Using rowid filter +1 SIMPLE t1 ref a,b b 5 const 128 Using where SELECT * FROM t1 WHERE a > 0 AND b=0; a b 1 0 @@ -2447,32 +2439,19 @@ ANALYZE "r_total_time_ms": "REPLACED", "table": { "table_name": "t1", - "access_type": "ref", + "access_type": "range", "possible_keys": ["idx1", "idx2"], - "key": "idx2", - "key_length": "5", - "used_key_parts": ["fl2"], - "ref": ["const"], - "rowid_filter": { - "range": { - "key": "idx1", - "used_key_parts": ["nm"] - }, - "rows": 44, - "selectivity_pct": 0.44, - "r_rows": 44, - "r_lookups": 1000, - "r_selectivity_pct": 0, - "r_buffer_size": "REPLACED", - "r_filling_time_ms": "REPLACED" - }, + "key": "idx1", + "key_length": "35", + "used_key_parts": ["nm"], "r_loops": 1, - "rows": 921, - "r_rows": 0, + "rows": 44, + "r_rows": 44, "r_total_time_ms": "REPLACED", - "filtered": 0.44, - "r_filtered": 100, - "attached_condition": "t1.nm like '3400%' or t1.nm like '3402%' or t1.nm like '3403%' or t1.nm like '3404%' or t1.nm like '3405%' or t1.nm like '3406%' or t1.nm like '3407%' or t1.nm like '3409%' or t1.nm like '3411%' or t1.nm like '3412%' or t1.nm like '3413%' or t1.nm like '3414%' or t1.nm like '3415%' or t1.nm like '3416%' or t1.nm like '3417%' or t1.nm like '3418%' or t1.nm like '3419%' or t1.nm like '3421%' or t1.nm like '3422%' or t1.nm like '3423%' or t1.nm like '3424%' or t1.nm like '3425%' or t1.nm like '3426%' or t1.nm like '3427%' or t1.nm like '3428%' or t1.nm like '3429%' or t1.nm like '3430%' or t1.nm like '3431%' or t1.nm like '3432%' or t1.nm like '3433%' or t1.nm like '3434%' or t1.nm like '3435%' or t1.nm like '3436%' or t1.nm like '3437%' or t1.nm like '3439%' or t1.nm like '3440%' or t1.nm like '3441%' or t1.nm like '3442%' or t1.nm like '3443%' or t1.nm like '3444%' or t1.nm like '3445%' or t1.nm like '3446%' or t1.nm like '3447%' or t1.nm like '3448%'" + "filtered": 9.21, + "r_filtered": 0, + "index_condition": "t1.nm like '3400%' or t1.nm like '3402%' or t1.nm like '3403%' or t1.nm like '3404%' or t1.nm like '3405%' or t1.nm like '3406%' or t1.nm like '3407%' or t1.nm like '3409%' or t1.nm like '3411%' or t1.nm like '3412%' or t1.nm like '3413%' or t1.nm like '3414%' or t1.nm like '3415%' or t1.nm like '3416%' or t1.nm like '3417%' or t1.nm like '3418%' or t1.nm like '3419%' or t1.nm like '3421%' or t1.nm like '3422%' or t1.nm like '3423%' or t1.nm like '3424%' or t1.nm like '3425%' or t1.nm like '3426%' or t1.nm like '3427%' or t1.nm like '3428%' or t1.nm like '3429%' or t1.nm like '3430%' or t1.nm like '3431%' or t1.nm like '3432%' or t1.nm like '3433%' or t1.nm like '3434%' or t1.nm like '3435%' or t1.nm like '3436%' or t1.nm like '3437%' or t1.nm like '3439%' or t1.nm like '3440%' or t1.nm like '3441%' or t1.nm like '3442%' or t1.nm like '3443%' or t1.nm like '3444%' or t1.nm like '3445%' or t1.nm like '3446%' or t1.nm like '3447%' or t1.nm like '3448%'", + "attached_condition": "t1.fl2 = 0" } } } @@ -2505,31 +2484,19 @@ ANALYZE "r_total_time_ms": "REPLACED", "table": { "table_name": "t1", - "access_type": "ref", + "access_type": "range", "possible_keys": ["idx1", "idx2"], - "key": "idx2", - "key_length": "5", - "used_key_parts": ["fl2"], - "ref": ["const"], - "rowid_filter": { - "range": { - "key": "idx1", - "used_key_parts": ["nm"] - }, - "rows": 44, - "selectivity_pct": 0.44, - "r_rows": 0, - "r_lookups": 0, - "r_selectivity_pct": 0, - "r_buffer_size": "REPLACED", - "r_filling_time_ms": "REPLACED" - }, + "key": "idx1", + "key_length": "35", + "used_key_parts": ["nm"], "r_loops": 1, - "rows": 911, + "rows": 44, "r_rows": 0, - "filtered": 0.44, + "r_total_time_ms": "REPLACED", + "filtered": 9.11, "r_filtered": 100, - "attached_condition": "t1.nm like '3400%' or t1.nm like '3402%' or t1.nm like '3403%' or t1.nm like '3404%' or t1.nm like '3405%' or t1.nm like '3406%' or t1.nm like '3407%' or t1.nm like '3409%' or t1.nm like '3411%' or t1.nm like '3412%' or t1.nm like '3413%' or t1.nm like '3414%' or t1.nm like '3415%' or t1.nm like '3416%' or t1.nm like '3417%' or t1.nm like '3418%' or t1.nm like '3419%' or t1.nm like '3421%' or t1.nm like '3422%' or t1.nm like '3423%' or t1.nm like '3424%' or t1.nm like '3425%' or t1.nm like '3426%' or t1.nm like '3427%' or t1.nm like '3428%' or t1.nm like '3429%' or t1.nm like '3430%' or t1.nm like '3431%' or t1.nm like '3432%' or t1.nm like '3433%' or t1.nm like '3434%' or t1.nm like '3435%' or t1.nm like '3436%' or t1.nm like '3437%' or t1.nm like '3439%' or t1.nm like '3440%' or t1.nm like '3441%' or t1.nm like '3442%' or t1.nm like '3443%' or t1.nm like '3444%' or t1.nm like '3445%' or t1.nm like '3446%' or t1.nm like '3447%' or t1.nm like '3448%'" + "index_condition": "t1.nm like '3400%' or t1.nm like '3402%' or t1.nm like '3403%' or t1.nm like '3404%' or t1.nm like '3405%' or t1.nm like '3406%' or t1.nm like '3407%' or t1.nm like '3409%' or t1.nm like '3411%' or t1.nm like '3412%' or t1.nm like '3413%' or t1.nm like '3414%' or t1.nm like '3415%' or t1.nm like '3416%' or t1.nm like '3417%' or t1.nm like '3418%' or t1.nm like '3419%' or t1.nm like '3421%' or t1.nm like '3422%' or t1.nm like '3423%' or t1.nm like '3424%' or t1.nm like '3425%' or t1.nm like '3426%' or t1.nm like '3427%' or t1.nm like '3428%' or t1.nm like '3429%' or t1.nm like '3430%' or t1.nm like '3431%' or t1.nm like '3432%' or t1.nm like '3433%' or t1.nm like '3434%' or t1.nm like '3435%' or t1.nm like '3436%' or t1.nm like '3437%' or t1.nm like '3439%' or t1.nm like '3440%' or t1.nm like '3441%' or t1.nm like '3442%' or t1.nm like '3443%' or t1.nm like '3444%' or t1.nm like '3445%' or t1.nm like '3446%' or t1.nm like '3447%' or t1.nm like '3448%'", + "attached_condition": "t1.fl2 = 0" } } } @@ -2704,7 +2671,7 @@ count(*) 5 explain extended select count(*) from t1 where a between 21 and 30 and b=2; id select_type table type possible_keys key key_len ref rows filtered Extra -1 SIMPLE t1 ref|filter b,a b|a 5|5 const 24 (10%) 9.60 Using where; Using rowid filter +1 SIMPLE t1 ref b,a b 5 const 24 9.60 Using where Warnings: Note 1003 select count(0) AS `count(*)` from `test`.`t1` where `test`.`t1`.`b` = 2 and `test`.`t1`.`a` between 21 and 30 select * from t1 where a between 21 and 30 and b=2; @@ -3166,7 +3133,7 @@ WHERE 1 = 1 AND domain = 'www.mailhost.i-dev.fr' AND timestamp >= DATE_ADD('2017-01-30 08:24:51', INTERVAL -1 MONTH) ORDER BY timestamp DESC; id select_type table type possible_keys key key_len ref rows filtered Extra -1 SIMPLE t1 ref|filter ixEventWhoisDomainDomain,ixEventWhoisDomainTimestamp ixEventWhoisDomainDomain|ixEventWhoisDomainTimestamp 98|4 const 40 (33%) 33.33 Using index condition; Using where; Using filesort; Using rowid filter +1 SIMPLE t1 ref ixEventWhoisDomainDomain,ixEventWhoisDomainTimestamp ixEventWhoisDomainDomain 98 const 40 33.33 Using index condition; Using where; Using filesort Warnings: Note 1003 select `test`.`t1`.`id` AS `id`,`test`.`t1`.`domain` AS `domain`,`test`.`t1`.`registrant_name` AS `registrant_name`,`test`.`t1`.`registrant_organization` AS `registrant_organization`,`test`.`t1`.`registrant_street1` AS `registrant_street1`,`test`.`t1`.`registrant_street2` AS `registrant_street2`,`test`.`t1`.`registrant_street3` AS `registrant_street3`,`test`.`t1`.`registrant_street4` AS `registrant_street4`,`test`.`t1`.`registrant_street5` AS `registrant_street5`,`test`.`t1`.`registrant_city` AS `registrant_city`,`test`.`t1`.`registrant_postal_code` AS `registrant_postal_code`,`test`.`t1`.`registrant_country` AS `registrant_country`,`test`.`t1`.`registrant_email` AS `registrant_email`,`test`.`t1`.`registrant_telephone` AS `registrant_telephone`,`test`.`t1`.`administrative_name` AS `administrative_name`,`test`.`t1`.`administrative_organization` AS `administrative_organization`,`test`.`t1`.`administrative_street1` AS `administrative_street1`,`test`.`t1`.`administrative_street2` AS `administrative_street2`,`test`.`t1`.`administrative_street3` AS `administrative_street3`,`test`.`t1`.`administrative_street4` AS `administrative_street4`,`test`.`t1`.`administrative_street5` AS `administrative_street5`,`test`.`t1`.`administrative_city` AS `administrative_city`,`test`.`t1`.`administrative_postal_code` AS `administrative_postal_code`,`test`.`t1`.`administrative_country` AS `administrative_country`,`test`.`t1`.`administrative_email` AS `administrative_email`,`test`.`t1`.`administrative_telephone` AS `administrative_telephone`,`test`.`t1`.`technical_name` AS `technical_name`,`test`.`t1`.`technical_organization` AS `technical_organization`,`test`.`t1`.`technical_street1` AS `technical_street1`,`test`.`t1`.`technical_street2` AS `technical_street2`,`test`.`t1`.`technical_street3` AS `technical_street3`,`test`.`t1`.`technical_street4` AS `technical_street4`,`test`.`t1`.`technical_street5` AS `technical_street5`,`test`.`t1`.`technical_city` AS `technical_city`,`test`.`t1`.`technical_postal_code` AS `technical_postal_code`,`test`.`t1`.`technical_country` AS `technical_country`,`test`.`t1`.`technical_email` AS `technical_email`,`test`.`t1`.`technical_telephone` AS `technical_telephone`,`test`.`t1`.`json` AS `json`,`test`.`t1`.`timestamp` AS `timestamp` from `test`.`t1` where `test`.`t1`.`domain` = 'www.mailhost.i-dev.fr' and `test`.`t1`.`timestamp` >= ('2017-01-30 08:24:51' + interval -1 month) order by `test`.`t1`.`timestamp` desc SET optimizer_switch=@save_optimizer_switch; @@ -3415,7 +3382,7 @@ fi.fh in (6311439873746261694,-397087483897438286, id select_type table type possible_keys key key_len ref rows filtered Extra 1 SIMPLE t index_merge PRIMARY,acli_rid,acli_tp acli_tp,acli_rid 2,767 NULL 2 100.00 Using intersect(acli_tp,acli_rid); Using where; Using index 1 SIMPLE a ref PRIMARY,acei_aclid acei_aclid 8 test.t.id 1 100.00 Using where -1 SIMPLE fi ref|filter filt_aceid,filt_fh filt_aceid|filt_fh 8|8 test.a.id 24 (14%) 14.46 Using where; Using rowid filter +1 SIMPLE fi ref filt_aceid,filt_fh filt_aceid 8 test.a.id 24 14.46 Using where Warnings: Note 1003 select `test`.`t`.`id` AS `id`,`test`.`fi`.`id` AS `id`,`test`.`fi`.`aceid` AS `aceid`,`test`.`fi`.`clid` AS `clid`,`test`.`fi`.`fh` AS `fh` from `test`.`acli` `t` join `test`.`acei` `a` join `test`.`filt` `fi` where `test`.`t`.`tp` = 121 and `test`.`a`.`atp` = 1 and `test`.`fi`.`aceid` = `test`.`a`.`id` and `test`.`a`.`aclid` = `test`.`t`.`id` and `test`.`t`.`rid` = 'B5FCC8C7111E4E3CBC21AAF5012F59C2' and `test`.`fi`.`fh` in (6311439873746261694,-397087483897438286,8518228073041491534,-5420422472375069774) set statement optimizer_switch='rowid_filter=on' for select t.id, fi.* @@ -3531,7 +3498,7 @@ fi.fh in (6311439873746261694,-397087483897438286, id select_type table type possible_keys key key_len ref rows filtered Extra 1 SIMPLE t index_merge PRIMARY,acli_rid,acli_tp acli_tp,acli_rid 2,767 NULL 2 100.00 Using intersect(acli_tp,acli_rid); Using where; Using index 1 SIMPLE a ref PRIMARY,acei_aclid acei_aclid 8 test.t.id 1 100.00 Using where; Using join buffer (flat, BKA join); Rowid-ordered scan -1 SIMPLE fi ref|filter filt_aceid,filt_fh filt_aceid|filt_fh 8|8 test.a.id 24 (14%) 14.46 Using where; Using join buffer (incremental, BKA join); Rowid-ordered scan; Using rowid filter +1 SIMPLE fi ref filt_aceid,filt_fh filt_aceid 8 test.a.id 24 14.46 Using where; Using join buffer (incremental, BKA join); Rowid-ordered scan Warnings: Note 1003 select `test`.`t`.`id` AS `id`,`test`.`fi`.`id` AS `id`,`test`.`fi`.`aceid` AS `aceid`,`test`.`fi`.`clid` AS `clid`,`test`.`fi`.`fh` AS `fh` from `test`.`acli` `t` join `test`.`acei` `a` join `test`.`filt` `fi` where `test`.`t`.`tp` = 121 and `test`.`a`.`atp` = 1 and `test`.`fi`.`aceid` = `test`.`a`.`id` and `test`.`a`.`aclid` = `test`.`t`.`id` and `test`.`t`.`rid` = 'B5FCC8C7111E4E3CBC21AAF5012F59C2' and `test`.`fi`.`fh` in (6311439873746261694,-397087483897438286,8518228073041491534,-5420422472375069774) set statement optimizer_switch='rowid_filter=on' for select t.id, fi.* @@ -3649,22 +3616,9 @@ ANALYZE "key_length": "8", "used_key_parts": ["aceid"], "ref": ["test.a.id"], - "rowid_filter": { - "range": { - "key": "filt_fh", - "used_key_parts": ["fh"] - }, - "rows": 81, - "selectivity_pct": 14.464, - "r_rows": 80, - "r_lookups": 80, - "r_selectivity_pct": 40, - "r_buffer_size": "REPLACED", - "r_filling_time_ms": "REPLACED" - }, "r_loops": 1, "rows": 24, - "r_rows": 32, + "r_rows": 80, "r_total_time_ms": "REPLACED", "filtered": 14.464, "r_filtered": 100 @@ -3674,7 +3628,7 @@ ANALYZE "join_type": "BKA", "mrr_type": "Rowid-ordered scan", "attached_condition": "fi.fh in (6311439873746261694,-397087483897438286,8518228073041491534,-5420422472375069774)", - "r_filtered": 100 + "r_filtered": 40 } } } @@ -3778,7 +3732,7 @@ WHERE t1.c1 NOT IN (SELECT t2.c1 FROM t2, t1 AS a1 WHERE t2.i1 = t1.pk AND t2.i1 BETWEEN 3 AND 5); id select_type table type possible_keys key key_len ref rows filtered Extra 1 PRIMARY t1 ALL NULL NULL NULL NULL 60 100.00 Using where -2 DEPENDENT SUBQUERY t2 ref|filter c1,i1 c1|i1 3|5 func 38 (25%) 25.00 Using where; Full scan on NULL key; Using rowid filter +2 DEPENDENT SUBQUERY t2 ref c1,i1 i1 5 test.t1.pk 20 100.00 Using index condition; Using where 2 DEPENDENT SUBQUERY a1 ALL NULL NULL NULL NULL 60 100.00 Using join buffer (flat, BNL join) Warnings: Note 1276 Field or reference 'test.t1.pk' of SELECT #2 was resolved in SELECT #1 diff --git a/mysql-test/main/selectivity.result b/mysql-test/main/selectivity.result index 7e3202337ec87..0b9226099166d 100644 --- a/mysql-test/main/selectivity.result +++ b/mysql-test/main/selectivity.result @@ -1661,7 +1661,7 @@ Note 1003 select `test`.`t1`.`a` AS `a`,`test`.`t1`.`b` AS `b` from `test`.`t1` # gives selectivity data explain extended select * from t1 where a in (17,51,5) and b=2; id select_type table type possible_keys key key_len ref rows filtered Extra -1 SIMPLE t1 ref|filter b,a b|a 5|5 const 58 (3%) 2.90 Using where; Using rowid filter +1 SIMPLE t1 range|filter b,a a|b 5|5 NULL 29 (6%) 5.80 Using index condition; Using where; Using rowid filter Warnings: Note 1003 select `test`.`t1`.`a` AS `a`,`test`.`t1`.`b` AS `b` from `test`.`t1` where `test`.`t1`.`b` = 2 and `test`.`t1`.`a` in (17,51,5) drop table t1; diff --git a/sql/sql_select.cc b/sql/sql_select.cc index 4bdfb659513ae..3f02d21ad0bff 100644 --- a/sql/sql_select.cc +++ b/sql/sql_select.cc @@ -7961,10 +7961,20 @@ best_access_path(JOIN *join, type == JT_EQ_REF ? 0.5 * tmp : MY_MIN(tmp, keyread_tmp); double access_cost_factor= MY_MIN((tmp - key_access_cost) / rows, 1.0); - filter= - table->best_range_rowid_filter_for_partial_join(start_key->key, - rows, - access_cost_factor); + if (!(records < s->worst_seeks && + records <= thd->variables.max_seeks_for_key)) + { + // Don't use rowid filter + trace_access_idx.add("rowid_filter_skipped", "worst/max seeks clipping"); + filter= NULL; + } + else + { + filter= + table->best_range_rowid_filter_for_partial_join(start_key->key, + rows, + access_cost_factor); + } if (filter) { tmp-= filter->get_adjusted_gain(rows) - filter->get_cmp_gain(rows); @@ -8137,8 +8147,6 @@ best_access_path(JOIN *join, tmp-= filter->get_adjusted_gain(rows); DBUG_ASSERT(tmp >= 0); } - else - trace_access_scan.add("rowid_filter_skipped", "cost_factor <= 0"); type= JT_RANGE; } From 702d1af32c563146d2c2d1bef1a5c53bb9644a7b Mon Sep 17 00:00:00 2001 From: Thirunarayanan Balathandayuthapani Date: Wed, 15 Feb 2023 01:18:26 +0530 Subject: [PATCH 09/92] MDEV-30615 Can't read from I_S.INNODB_SYS_INDEXES when having a discarded tablesace - MY_I_S_MAYBE_NULL field attributes is added PAGE_NO and SPACE in innodb_sys_index table. By doing this, InnoDB can set null for these fields when it encounters discarded tablespace --- mysql-test/suite/innodb/r/full_crc32_import.result | 11 +++++++++++ mysql-test/suite/innodb/t/full_crc32_import.test | 10 ++++++++++ storage/innobase/handler/i_s.cc | 8 +++++--- 3 files changed, 26 insertions(+), 3 deletions(-) diff --git a/mysql-test/suite/innodb/r/full_crc32_import.result b/mysql-test/suite/innodb/r/full_crc32_import.result index 0cfcf6f4ddb9d..07c8571945f64 100644 --- a/mysql-test/suite/innodb/r/full_crc32_import.result +++ b/mysql-test/suite/innodb/r/full_crc32_import.result @@ -173,6 +173,17 @@ UNLOCK TABLES; SET GLOBAL innodb_compression_algorithm=0; ALTER TABLE t1 FORCE; ALTER TABLE t1 DISCARD TABLESPACE; +# Display the discarded table name by using SPACE and PAGE_NO +# column in INNODB_SYS_INDEXES and discard doesn't affect the +# SPACE in INNODB_SYS_TABLES +SELECT t.NAME, t.SPACE BETWEEN 1 and 0xFFFFFFEF as SYS_TABLE_SPACE_RANGE +FROM INFORMATION_SCHEMA.INNODB_SYS_TABLES t +WHERE t.TABLE_ID IN ( +SELECT i.TABLE_ID FROM +INFORMATION_SCHEMA.INNODB_SYS_INDEXES i WHERE +i.PAGE_NO IS NULL and i.SPACE IS NULL); +NAME SYS_TABLE_SPACE_RANGE +test/t1 1 db.opt t1.frm restore: t1 .ibd and .cfg files diff --git a/mysql-test/suite/innodb/t/full_crc32_import.test b/mysql-test/suite/innodb/t/full_crc32_import.test index c9195111c058b..481db2f4ec764 100644 --- a/mysql-test/suite/innodb/t/full_crc32_import.test +++ b/mysql-test/suite/innodb/t/full_crc32_import.test @@ -195,6 +195,16 @@ SET GLOBAL innodb_compression_algorithm=0; ALTER TABLE t1 FORCE; ALTER TABLE t1 DISCARD TABLESPACE; +--echo # Display the discarded table name by using SPACE and PAGE_NO +--echo # column in INNODB_SYS_INDEXES and discard doesn't affect the +--echo # SPACE in INNODB_SYS_TABLES +SELECT t.NAME, t.SPACE BETWEEN 1 and 0xFFFFFFEF as SYS_TABLE_SPACE_RANGE +FROM INFORMATION_SCHEMA.INNODB_SYS_TABLES t +WHERE t.TABLE_ID IN ( + SELECT i.TABLE_ID FROM + INFORMATION_SCHEMA.INNODB_SYS_INDEXES i WHERE + i.PAGE_NO IS NULL and i.SPACE IS NULL); + --list_files $MYSQLD_DATADIR/test perl; do "$ENV{MTR_SUITE_DIR}/include/innodb-util.pl"; diff --git a/storage/innobase/handler/i_s.cc b/storage/innobase/handler/i_s.cc index bc9d24cd00f64..f01c41627015e 100644 --- a/storage/innobase/handler/i_s.cc +++ b/storage/innobase/handler/i_s.cc @@ -5430,10 +5430,10 @@ static ST_FIELD_INFO innodb_sysindex_fields_info[]= 0, 0, "", SKIP_OPEN_TABLE}, #define SYS_INDEX_PAGE_NO 5 {"PAGE_NO", MY_INT32_NUM_DECIMAL_DIGITS, MYSQL_TYPE_LONG, - 0, 0, "", SKIP_OPEN_TABLE}, + 0, MY_I_S_MAYBE_NULL, "", SKIP_OPEN_TABLE}, #define SYS_INDEX_SPACE 6 {"SPACE", MY_INT32_NUM_DECIMAL_DIGITS, MYSQL_TYPE_LONG, - 0, 0, "", SKIP_OPEN_TABLE}, + 0, MY_I_S_MAYBE_NULL, "", SKIP_OPEN_TABLE}, #define SYS_INDEX_MERGE_THRESHOLD 7 {"MERGE_THRESHOLD", MY_INT32_NUM_DECIMAL_DIGITS, MYSQL_TYPE_LONG, 0, 0, "", SKIP_OPEN_TABLE}, @@ -5483,12 +5483,14 @@ i_s_dict_fill_sys_indexes( if (index->page == FIL_NULL) { fields[SYS_INDEX_PAGE_NO]->set_null(); } else { + fields[SYS_INDEX_PAGE_NO]->set_notnull(); OK(fields[SYS_INDEX_PAGE_NO]->store(index->page, true)); } - if (space_id == ULINT_UNDEFINED) { + if (space_id == FIL_NULL) { fields[SYS_INDEX_SPACE]->set_null(); } else { + fields[SYS_INDEX_SPACE]->set_notnull(); OK(fields[SYS_INDEX_SPACE]->store(space_id, true)); } From 9ab16e7f3e3d9fe5980605464e91e6f3da30cbc1 Mon Sep 17 00:00:00 2001 From: Fabrice Fontaine Date: Sun, 15 Jan 2023 19:12:05 +0100 Subject: [PATCH 10/92] include/ssl_compat.h: fix build with libressl >= 3.5.0 Fix the following build failure with libressl >= 3.5.0: In file included from /tmp/instance-10/output-1/build/mariadb-10.3.36/vio/viosslfactories.c:18: /tmp/instance-10/output-1/build/mariadb-10.3.36/vio/viosslfactories.c: In function 'get_dh2048': /tmp/instance-10/output-1/build/mariadb-10.3.36/include/ssl_compat.h:68:45: error: invalid use of incomplete typedef 'DH' {aka 'struct dh_st'} 68 | #define DH_set0_pqg(D,P,Q,G) ((D)->p= (P), (D)->g= (G)) | ^~ Fixes: - http://autobuild.buildroot.org/results/524198344aafca58d214537af64c5961c407b0f8 Signed-off-by: Fabrice Fontaine --- include/ssl_compat.h | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/include/ssl_compat.h b/include/ssl_compat.h index 8dc1225407ed2..9541a68cbdc5c 100644 --- a/include/ssl_compat.h +++ b/include/ssl_compat.h @@ -19,7 +19,8 @@ /* OpenSSL version specific definitions */ #if defined(OPENSSL_VERSION_NUMBER) -#if OPENSSL_VERSION_NUMBER >= 0x10100000L && !defined(LIBRESSL_VERSION_NUMBER) +#if OPENSSL_VERSION_NUMBER >= 0x10100000L && \ + !(defined(LIBRESSL_VERSION_NUMBER) && LIBRESSL_VERSION_NUMBER < 0x30500000L) #define HAVE_OPENSSL11 1 #define SSL_LIBRARY OpenSSL_version(OPENSSL_VERSION) #define ERR_remove_state(X) ERR_clear_error() From 560c15c44be665e5d73194d84411c69acf8606a1 Mon Sep 17 00:00:00 2001 From: Anel Husakovic Date: Sat, 4 Feb 2023 22:10:49 +0100 Subject: [PATCH 11/92] MDBF-534: Coverity scan: fix client folder --------------------------------- File: `mysql` --------------------------------- - Coverity (RESOURCE_LEAK): https://scan5.scan.coverity.com/reports.htm#v58936/p10357/fileInstanceId=231728394&defectInstanceId=53073025&mergedDefectId=1520090&eventId=53073025-15 `mysql`: memory allocated by `mysql_fetch_row` is not freed. - FALSE POSITIVES: - Coverity (TAINTED_SCALAR): - https://scan5.scan.coverity.com/reports.htm#v58936/p10357/fileInstanceId=231728394&defectInstanceId=53074559&mergedDefectId=1520403 - Coverity (COPY_PASTE_ERROR): https://scan5.scan.coverity.com/reports.htm#v58936/p10357/fileInstanceId=231728394&defectInstanceId=53074521&mergedDefectId=1520300 - Coverity (STRING_NULL): https://scan5.scan.coverity.com/reports.htm#v58936/p10357/fileInstanceId=231728394&defectInstanceId=53072524&mergedDefectId=1519374 - Coverity (CHECKED_RETURN): https://scan5.scan.coverity.com/reports.htm#v58936/p10357/fileInstanceId=231728394&defectInstanceId=53074932&mergedDefectId=971708 - INTENTIONAL: - Coverity (UNINIT): https://scan5.scan.coverity.com/reports.htm#v58936/p10357/fileInstanceId=231728394&defectInstanceId=53074758&mergedDefectId=1519932 https://scan5.scan.coverity.com/reports.htm#v58936/p10357/fileInstanceId=231728394&defectInstanceId=53073939&mergedDefectId=1519738 - Coverity(BAD_FREE): https://scan5.scan.coverity.com/reports.htm#v58936/p10357/fileInstanceId=231728394&defectInstanceId=53073938&mergedDefectId=1519491 https://scan5.scan.coverity.com/reports.htm#v58936/p10357/fileInstanceId=231728394&defectInstanceId=53074819&mergedDefectId=1519462 --------------------------------- File: `mysql_plugin` --------------------------------- - Coverity (FORWARD_NULL): https://scan5.scan.coverity.com/reports.htm#v58936/p10357/fileInstanceId=231728420&defectInstanceId=53074485&mergedDefectId=971915 Dereference after null check when using `fclose`. - FALSE POSITIVES: - Coverity (STRING_OVERFLOW): https://scan5.scan.coverity.com/reports.htm#v58936/p10357/fileInstanceId=231728420&defectInstanceId=53075014&mergedDefectId=972410 - Additionally fix typo --- client/mysql.cc | 1 + sql/sql_string.cc | 2 +- 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/client/mysql.cc b/client/mysql.cc index 02ffacc722faa..b1042d1be0051 100644 --- a/client/mysql.cc +++ b/client/mysql.cc @@ -5357,6 +5357,7 @@ static void init_username() full_username=my_strdup(cur[0],MYF(MY_WME)); part_username=my_strdup(strtok(cur[0],"@"),MYF(MY_WME)); (void) mysql_fetch_row(result); // Read eof + mysql_free_result(result); } } diff --git a/sql/sql_string.cc b/sql/sql_string.cc index 68a15d65d1b64..c6b7f3e68ed02 100644 --- a/sql/sql_string.cc +++ b/sql/sql_string.cc @@ -553,7 +553,7 @@ bool String::append(const char *s,size_t size) } /* - For an ASCII compatinble string we can just append. + For an ASCII compatible string we can just append. */ return Binary_string::append(s, arg_length); } From 487889119386cdab9923c570e0eb23b6c7e002ea Mon Sep 17 00:00:00 2001 From: Anel Husakovic Date: Wed, 8 Feb 2023 03:18:14 +0100 Subject: [PATCH 12/92] MDBF-534: Coverity scan: fix client folder --------------------------------- File: `mysqladmin` --------------------------------- - Coverity (PRINTF_ARGS): https://scan5.scan.coverity.com/reports.htm#v58936/p10357/fileInstanceId=231728412&defectInstanceId=53073308&mergedDefectId=1520228&eventId=53073308-0 `mysql_upgrade` - extra argument to printf format specifiera - Coverity (TAINTED_SCALAR) - FAlSE POSITIVE: https://scan5.scan.coverity.com/reports.htm#v58936/p10357/fileInstanceId=231728412&defectInstanceId=53072897&mergedDefectId=1519349 --- client/mysql_upgrade.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/client/mysql_upgrade.c b/client/mysql_upgrade.c index cd70f14e94a68..99c9e7415a729 100644 --- a/client/mysql_upgrade.c +++ b/client/mysql_upgrade.c @@ -848,8 +848,7 @@ static int upgrade_already_done(int silent) "There is no need to run mysql_upgrade again for %s.", upgrade_from_version, version); if (!opt_check_upgrade) - verbose("You can use --force if you still want to run mysql_upgrade", - upgrade_from_version, version); + verbose("You can use --force if you still want to run mysql_upgrade"); } return 0; } From f0ea22a1e22c84affa91ec0e596fbd387d11ff8a Mon Sep 17 00:00:00 2001 From: Anel Husakovic Date: Wed, 8 Feb 2023 05:16:29 +0100 Subject: [PATCH 13/92] MDBF-534: Coverity scan: fix client folder --------------------------------- File: `mysqlbinlog` --------------------------------- - Coverity (FORWARD_NULL): https://scan5.scan.coverity.com/reports.htm#v58936/p10357/fileInstanceId=231728438&defectInstanceId=53074517&mergedDefectId=1519690&eventId=53074517-46 `mysqlbinlog` - for `opt_raw_mode` file is set to 0, make sure it opened before. --- client/mysqlbinlog.cc | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/client/mysqlbinlog.cc b/client/mysqlbinlog.cc index aa994df75576e..2810892253846 100644 --- a/client/mysqlbinlog.cc +++ b/client/mysqlbinlog.cc @@ -3169,7 +3169,7 @@ int main(int argc, char** argv) /* Set delimiter back to semicolon */ if (retval != ERROR_STOP) { - if (!stop_event_string.is_empty()) + if (!stop_event_string.is_empty() && result_file) fprintf(result_file, "%s", stop_event_string.ptr()); if (!opt_raw_mode && opt_flashback) fprintf(result_file, "DELIMITER ;\n"); From ff7e0977f3cd9a7c6cf61dcfe874378bc72e20dd Mon Sep 17 00:00:00 2001 From: Anel Husakovic Date: Wed, 8 Feb 2023 05:26:34 +0100 Subject: [PATCH 14/92] MDBF-534: Coverity scan: fix client folder --------------------------------- File: `mysqlcheck` --------------------------------- - Coverity (FORWARD_NULL): https://scan5.scan.coverity.com/reports.htm#v58936/p10357/fileInstanceId=231728409&defectInstanceId=53075052&mergedDefectId=1520314&eventId=53075052-7 `mysqlcheck` - make sure `op` is non-null - Coverity (TAINTED_SCALAR) - FALSE POSITIVES: https://scan5.scan.coverity.com/reports.htm#v58936/p10357/fileInstanceId=231728409&defectInstanceId=53074482&mergedDefectId=1519904 --- client/mysqlcheck.c | 1 + 1 file changed, 1 insertion(+) diff --git a/client/mysqlcheck.c b/client/mysqlcheck.c index 3e341f13e5a86..b32e21ff18f93 100644 --- a/client/mysqlcheck.c +++ b/client/mysqlcheck.c @@ -942,6 +942,7 @@ static int handle_request_for_tables(char *tables, size_t length, DBUG_RETURN(1); if (dont_quote) { + DBUG_ASSERT(op); DBUG_ASSERT(strlen(op)+strlen(tables)+strlen(options)+8+1 <= query_size); /* No backticks here as we added them before */ From 023bb2fc201eb53017a505e621ae40df28abf9e0 Mon Sep 17 00:00:00 2001 From: Anel Husakovic Date: Mon, 13 Feb 2023 13:39:25 +0100 Subject: [PATCH 15/92] MDBF-534: Coverity scan: fix client folder -------------------------------- File: `mysqldump`: -------------------------------- -Coverity (`BAD_SHIFT`): https://scan5.scan.coverity.com/reports.htm#v58936/p10357/fileInstanceId=231728415&defectInstanceId=53073433&mergedDefectId=1211186&eventId=53073433-25 `mysqldump` - Error obtained by coverity is implication of type conversion. It may happen that function `find_type` returns -1 which is assigned to `uint` that gets converted by compiler to max (UINT_32/64). In that situation left bit shift may lead to UB. Converting from `uint` to `int` will solve the problem. - Coverity (`RESOURCE_LEAK`): - https://scan5.scan.coverity.com/reports.htm#v58936/p10357/fileInstanceId=231728415&defectInstanceId=53072912&mergedDefectId=1519239 - https://scan5.scan.coverity.com/reports.htm#v58936/p10357/fileInstanceId=231728415&defectInstanceId=53073706&mergedDefectId=1519368 - https://scan5.scan.coverity.com/reports.htm#v58936/p10357/fileInstanceId=231728415&defectInstanceId=53073560&mergedDefectId=1519655 - https://scan5.scan.coverity.com/reports.htm#v58936/p10357/fileInstanceId=231728415&defectInstanceId=53074494&mergedDefectId=1519822&fileStart=4001&fileEnd=4250 - https://scan5.scan.coverity.com/reports.htm#v58936/p10357/fileInstanceId=231728415&defectInstanceId=53074999&mergedDefectId=1519915&eventId=53074999-53 - https://scan5.scan.coverity.com/reports.htm#v58936/p10357/fileInstanceId=231728415&defectInstanceId=53075060&mergedDefectId=1519964 - https://scan5.scan.coverity.com/reports.htm#v58936/p10357/fileInstanceId=231728415&defectInstanceId=53073268&mergedDefectId=1519967 - https://scan5.scan.coverity.com/reports.htm#v58936/p10357/fileInstanceId=231728415&defectInstanceId=53073015&mergedDefectId=1520164 `mysqldump` - in case of error memory should be freeed. - Coverity (`UNINT`) - FALSE POSITIVES: - https://scan5.scan.coverity.com/reports.htm#v58936/p10357/fileInstanceId=231728415&defectInstanceId=53074364&mergedDefectId=1519587&eventId=53074364-10 - https://scan5.scan.coverity.com/reports.htm#v58936/p10357/fileInstanceId=231728415&defectInstanceId=53072619&mergedDefectId=1519684&eventId=53072619-1 - https://scan5.scan.coverity.com/reports.htm#v58936/p10357/fileInstanceId=231728415&defectInstanceId=53073256&mergedDefectId=1519722 - https://scan5.scan.coverity.com/reports.htm#v58936/p10357/fileInstanceId=231728415&defectInstanceId=53074251&mergedDefectId=1519979 - https://scan5.scan.coverity.com/reports.htm#v58936/p10357/fileInstanceId=231728415&defectInstanceId=53074996&mergedDefectId=1520021 - https://scan5.scan.coverity.com/reports.htm#v58936/p10357/fileInstanceId=231728415&defectInstanceId=53073425&mergedDefectId=1520166&eventId=53073425-9 --------------------------------- File: `mysqladmin` --------------------------------- - Coverity (PRECEDANCE_ERROR) a.k.a MDEV-15736: https://scan5.scan.coverity.com/reports.htm#v58936/p10357/fileInstanceId=231728425&defectInstanceId=53074187&mergedDefectId=1519944 - Coverity (BAD_FREE) - FALSE POSITIVE: https://scan5.scan.coverity.com/reports.htm#v58936/p10357/fileInstanceId=231728425&defectInstanceId=53074614&mergedDefectId=1520042 --------------------------------- File: `mysqlimport` --------------------------------- - FALSE POSITIVES - Coverity (TAINTED_SCALAR): https://scan5.scan.coverity.com/reports.htm#v58936/p10357/ fileInstanceId=231728411&defectInstanceId=53074012&mergedDefectId=1519158&eventId=53074012-6 - Coverity (UNINT): https://scan5.scan.coverity.com/reports.htm#v58936/p10357/fileInstanceId=231728411&defectInstanceId=53072860&mergedDefectId=1520020 --------------------------------- File: `mysqlshow` --------------------------------- - FALSE POSITIVES - Coverity (TAINTED_SCALAR): https://scan5.scan.coverity.com/reports.htm#v58936/p10357/fileInstanceId=231728418&defectInstanceId=53074361&mergedDefectId=1519232&eventId=53074361-4 - Coverity (UNINT): https://scan5.scan.coverity.com/reports.htm#v58936/p10357/fileInstanceId=231728411&defectInstanceId=53072860&mergedDefectId=1520020 - Coverity (BAD_FREE): https://scan5.scan.coverity.com/reports.htm#v58936/p10357/fileInstanceId=231728418&defectInstanceId=53073408&mergedDefectId=1519972 --- client/mysqladmin.cc | 3 ++- client/mysqldump.c | 33 ++++++++++++++++++++++++++------- 2 files changed, 28 insertions(+), 8 deletions(-) diff --git a/client/mysqladmin.cc b/client/mysqladmin.cc index 6cf553c2ca9a5..fadefaed449aa 100644 --- a/client/mysqladmin.cc +++ b/client/mysqladmin.cc @@ -1589,7 +1589,8 @@ static void print_relative_row_vert(MYSQL_RES *result __attribute__((unused)), llstr((tmp - last_values[row]), buff)); /* Find the minimum row length needed to output the relative value */ - if ((length=(uint) strlen(buff) > ex_val_max_len[row]) && ex_status_printed) + length=(uint) strlen(buff); + if (length > ex_val_max_len[row] && ex_status_printed) ex_val_max_len[row] = length; last_values[row] = tmp; } diff --git a/client/mysqldump.c b/client/mysqldump.c index 010679b6ff2f7..cf94391808497 100644 --- a/client/mysqldump.c +++ b/client/mysqldump.c @@ -2480,7 +2480,10 @@ static uint dump_events_for_db(char *db) /* Get database collation. */ if (fetch_db_collation(db_name_buff, db_cl_name, sizeof (db_cl_name))) + { + mysql_free_result(event_list_res); DBUG_RETURN(1); + } } if (switch_character_set_results(mysql, "binary")) @@ -3262,7 +3265,10 @@ static uint get_table_structure(const char *table, const char *db, char *table_t if (path) { if (!(sql_file= open_sql_file_for_table(table, O_WRONLY))) + { + mysql_free_result(result); DBUG_RETURN(0); + } write_header(sql_file, db); } @@ -3663,7 +3669,7 @@ static int dump_triggers_for_table(char *table_name, char *db_name) char name_buff[NAME_LEN*4+3]; char query_buff[QUERY_LENGTH]; uint old_opt_compatible_mode= opt_compatible_mode; - MYSQL_RES *show_triggers_rs; + MYSQL_RES *show_triggers_rs= NULL; MYSQL_ROW row; FILE *sql_file= md_result_file; @@ -3747,8 +3753,6 @@ static int dump_triggers_for_table(char *table_name, char *db_name) } skip: - mysql_free_result(show_triggers_rs); - if (switch_character_set_results(mysql, default_charset)) goto done; @@ -3763,7 +3767,7 @@ static int dump_triggers_for_table(char *table_name, char *db_name) done: if (path) my_fclose(sql_file, MYF(0)); - + mysql_free_result(show_triggers_rs); DBUG_RETURN(ret); } @@ -3869,7 +3873,7 @@ static void dump_table(const char *table, const char *db, const uchar *hash_key, uint num_fields; size_t total_length, init_length; - MYSQL_RES *res; + MYSQL_RES *res= NULL; MYSQL_FIELD *field; MYSQL_ROW row; DBUG_ENTER("dump_table"); @@ -4055,6 +4059,8 @@ static void dump_table(const char *table, const char *db, const uchar *hash_key, fprintf(stderr,"%s: Error in field count for table: %s ! Aborting.\n", my_progname_short, result_table); error= EX_CONSCHECK; + if (!quick) + mysql_free_result(res); goto err; } @@ -4354,6 +4360,7 @@ static void dump_table(const char *table, const char *db, const uchar *hash_key, err: dynstr_free(&query_string); maybe_exit(error); + mysql_free_result(res); DBUG_VOID_RETURN; } /* dump_table */ @@ -4619,7 +4626,11 @@ static int dump_all_users_roles_and_grants() " '@', QUOTE(DEFAULT_ROLE_HOST))) as r," " CONCAT(QUOTE(mu.USER),'@',QUOTE(mu.HOST)) as u " "FROM mysql.user mu LEFT JOIN mysql.default_roles using (USER, HOST)")) + { + mysql_free_result(tableres); return 1; + } + while ((row= mysql_fetch_row(tableres))) { if (dump_grants(row[1])) @@ -5696,7 +5707,8 @@ static int get_sys_var_lower_case_table_names() lower_case_table_names= atoi(row[1]); mysql_free_result(table_res); } - + if (!row) + mysql_free_result(table_res); return lower_case_table_names; } @@ -5939,7 +5951,11 @@ static int do_show_master_status(MYSQL *mysql_con, int consistent_binlog_pos, } if (have_mariadb_gtid && get_gtid_pos(gtid_pos, 1)) + { + mysql_free_result(master); return 1; + } + } /* SHOW MASTER STATUS reports file and position */ @@ -6061,7 +6077,10 @@ static int do_show_slave_status(MYSQL *mysql_con, int use_gtid, { char gtid_pos[MAX_GTID_LENGTH]; if (have_mariadb_gtid && get_gtid_pos(gtid_pos, 0)) + { + mysql_free_result(slave); return 1; + } if (opt_comments) fprintf(md_result_file, "\n--\n-- Gtid position to start replication " "from\n--\n\n"); @@ -6257,7 +6276,7 @@ static ulong find_set(TYPELIB *lib, const char *x, size_t length, { const char *end= x + length; ulong found= 0; - uint find; + int find; char buff[255]; *err_pos= 0; /* No error yet */ From 24911a34b3409e0f18cf4ff7f695c902e39a9644 Mon Sep 17 00:00:00 2001 From: Anel Husakovic Date: Wed, 8 Feb 2023 12:24:25 +0100 Subject: [PATCH 16/92] MDBF-534: Coverity scan: fix client folder --------------------------------- File: `mysqlslap` --------------------------------- - Coverity (CHECKED_RETURN): https://scan5.scan.coverity.com/reports.htm#v58936/p10357/fileInstanceId=231728428&defectInstanceId=53073524&mergedDefectId=1520114 - FALSE POSITIVES - Coverity (DC.WEAK_CRYPTO) (`random()`): https://scan5.scan.coverity.com/reports.htm#v58936/p10357/fileInstanceId=231728428&defectInstanceId=53073112&mergedDefectId=1225806 https://scan5.scan.coverity.com/reports.htm#v58936/p10357/fileInstanceId=231728428&defectInstanceId=53074491&mergedDefectId=1409160 https://scan5.scan.coverity.com/reports.htm#v58936/p10357/fileInstanceId=231728428&defectInstanceId=53074151&mergedDefectId=1409180 https://scan5.scan.coverity.com/reports.htm#v58936/p10357/fileInstanceId=231728428&defectInstanceId=53073799&mergedDefectId=1409183 - Coverity (TAINTED_SCALAR): https://scan5.scan.coverity.com/reports.htm#v58936/p10357/fileInstanceId=231728428&defectInstanceId=53074667&mergedDefectId=1519586 - Coverity (UNINT): - Coverity (BAD_FREE): https://scan5.scan.coverity.com/reports.htm#v58936/p10357/fileInstanceId=231728428&defectInstanceId=53074415&mergedDefectId=1520371 --- client/mysqlslap.c | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/client/mysqlslap.c b/client/mysqlslap.c index 8c65dccbb4369..78e9b6aa6460d 100644 --- a/client/mysqlslap.c +++ b/client/mysqlslap.c @@ -1768,6 +1768,7 @@ run_scheduler(stats *sptr, statement *stmts, uint concur, ulonglong limit) uint x; struct timeval start_time, end_time; thread_context con; + int error; pthread_t mainthread; /* Thread descriptor */ pthread_attr_t attr; /* Thread attributes */ DBUG_ENTER("run_scheduler"); @@ -1776,8 +1777,11 @@ run_scheduler(stats *sptr, statement *stmts, uint concur, ulonglong limit) con.limit= limit; pthread_attr_init(&attr); - pthread_attr_setdetachstate(&attr, - PTHREAD_CREATE_DETACHED); + if ((error= pthread_attr_setdetachstate(&attr, PTHREAD_CREATE_DETACHED))) + { + printf("Got error: %d from pthread_attr_setdetachstate\n", error); + exit(1); + } pthread_mutex_lock(&counter_mutex); thread_counter= 0; From bd0d7ea540b9ee57b583b721ddbe6c606f2f75c9 Mon Sep 17 00:00:00 2001 From: Anel Husakovic Date: Wed, 8 Feb 2023 12:57:03 +0100 Subject: [PATCH 17/92] MDBF-534: Coverity scan: fix client folder --------------------------------- File: `mysqltest` --------------------------------- - Coverity (SIZEOF_MISMATCH): - https://scan5.scan.coverity.com/reports.htm#v58936/p10357/fileInstanceId=231728385&defectInstanceId=53074863&mergedDefectId=972322 Function `qsort` have to use size of element that is `uchar *` - Coverity (REVERSE_INULL): - https://scan5.scan.coverity.com/reports.htm#v58936/p10357/fileInstanceId=231728385&defectInstanceId=53074524&mergedDefectId=1519693&fileStart=3376&fileEnd=3625 First check if null and then use `strlen`, not reversed. - FALSE POSITIVES - Coverity (TAINTED_SCALAR): https://scan5.scan.coverity.com/reports.htm#v58936/p10357/fileInstanceId=231728385&defectInstanceId=53074760&mergedDefectId=1519321 - Coverity (CHECKED_RETURN): - https://scan5.scan.coverity.com/reports.htm#v58936/p10357/fileInstanceId=231728385&defectInstanceId=53074692&mergedDefectId=971714 - https://scan5.scan.coverity.com/reports.htm#v58936/p10357/fileInstanceId=231728385&defectInstanceId=53072839&mergedDefectId=971715 - Coverity (FORWARD_NULL): There is already issued DBUG_ASSERT(query_end) few lines before https://scan5.scan.coverity.com/reports.htm#v58936/p10357/fileInstanceId=231728385&defectInstanceId=53074002&mergedDefectId=971916&eventId=53074002-5 - Coverity (OVERRUN): - https://scan5.scan.coverity.com/reports.htm#v58936/p10357/fileInstanceId=231728385&defectInstanceId=53074470&mergedDefectId=1519697 - https://scan5.scan.coverity.com/reports.htm#v58936/p10357/fileInstanceId=231728385&defectInstanceId=53074862&mergedDefectId=1520391 `uint64_max` and `SIZE_MAX` (max for `size_t`) are same as `count` argument for `memcmp`. - Coverity (RESOURCE_LEAK): - https://scan5.scan.coverity.com/reports.htm#v58936/p10357/fileInstanceId=231728385&defectInstanceId=53074163&mergedDefectId=1519889&eventId=53074163-446 - INTENTION: - Coverity (SIZEOF_MISMATCH): - https://scan5.scan.coverity.com/reports.htm#v58936/p10357/fileInstanceId=231728385&defectInstanceId=53074650&mergedDefectId=1520109 `len` argument is used only in printing so it is not making impact (may be removed as an alternative). In this example size of pointer (8B) is used, that is not the size of value that pointer points to. --- client/mysqltest.cc | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/client/mysqltest.cc b/client/mysqltest.cc index 05a26fed05969..214b7542374f2 100644 --- a/client/mysqltest.cc +++ b/client/mysqltest.cc @@ -3563,9 +3563,11 @@ void do_system(struct st_command *command) /* returns TRUE if path is inside a sandbox */ bool is_sub_path(const char *path, size_t plen, const char *sandbox) { - size_t len= strlen(sandbox); - if (!sandbox || !len || plen <= len || memcmp(path, sandbox, len - 1) - || path[len] != '/') + size_t len; + if (!sandbox) + return false; + len= strlen(sandbox); + if (plen <= len || memcmp(path, sandbox, len-1) || path[len] != '/') return false; return true; } @@ -11696,7 +11698,7 @@ void dynstr_append_sorted(DYNAMIC_STRING* ds, DYNAMIC_STRING *ds_input, /* Sort array */ qsort(lines.buffer, lines.elements, - sizeof(char**), (qsort_cmp)comp_lines); + sizeof(uchar *), (qsort_cmp)comp_lines); /* Create new result */ for (i= 0; i < lines.elements ; i++) From 476b24d084e7e717310155bb986eb086d3c1e1a6 Mon Sep 17 00:00:00 2001 From: Monty Date: Thu, 16 Feb 2023 14:19:33 +0200 Subject: [PATCH 18/92] MDEV-20057 Distinct SUM on CROSS JOIN and grouped returns wrong result SELECT DISTINCT did not work with expressions with sum functions. Distinct was only done on the values stored in the intermediate temporary tables, which only stored the value of each sum function. In other words: SELECT DISTINCT sum(a),sum(b),avg(c) ... worked. SELECT DISTINCT sum(a),sum(b) > 2,sum(c)+sum(d) would not work. The later query would do ONLY apply distinct on the sum(a) part. Reviewer: Sergei Petrunia This was fixed by extending remove_dup_with_hash_index() and remove_dup_with_compare() to take into account the columns in the result list that where not stored in the temporary table. Note that in many cases the above dup removal functions are not used as the optimizer may be able to either remove duplicates early or it will discover that duplicate remove is not needed. The later happens for example if the group by fields is part of the result. Other things: - Backported from 11.0 the change of Sort_param.tmp_buffer from char* to String. - Changed Type_handler::make_sort_key() to take String as a parameter instead of Sort_param. This was done to allow make_sort_key() functions to be reused by distinct elimination functions. This makes Type_handler_string_result::make_sort_key() similar to code in 11.0 - Simplied error handling in remove_dup_with_compare() to remove code duplication. --- mysql-test/main/distinct.result | 37 +++++++ mysql-test/main/distinct.test | 23 ++++ sql/filesort.cc | 42 ++++---- sql/sql_select.cc | 184 +++++++++++++++++++++++++------- sql/sql_sort.h | 11 +- sql/sql_type.h | 16 +-- 6 files changed, 242 insertions(+), 71 deletions(-) diff --git a/mysql-test/main/distinct.result b/mysql-test/main/distinct.result index 93a1ea834df35..331b57faa27f2 100644 --- a/mysql-test/main/distinct.result +++ b/mysql-test/main/distinct.result @@ -1070,3 +1070,40 @@ UNION 1 drop table t1; End of 5.5 tests +# +# MDEV-20057 Distinct SUM on CROSS JOIN and grouped returns wrong result +# +create table t1 (c int, d int); +insert into t1 values (5, 1), (0, 3); +select distinct sum(distinct 1), sum(t1.d) > 2 from (t1 e join t1) group by t1.c; +sum(distinct 1) sum(t1.d) > 2 +1 1 +1 0 +select distinct sum(distinct 1), sum(t1.d) > 2, t1.c from (t1 e join t1) group by t1.c; +sum(distinct 1) sum(t1.d) > 2 c +1 1 0 +1 0 5 +insert into t1 values (6,6); +select distinct sum(distinct 1), sum(t1.d) > 5 from (t1 e join t1) group by t1.c; +sum(distinct 1) sum(t1.d) > 5 +1 1 +1 0 +select distinct sum(distinct 1), sum(t1.d) > 5, t1.c from (t1 e join t1) group by t1.c; +sum(distinct 1) sum(t1.d) > 5 c +1 1 0 +1 0 5 +1 1 6 +set @@sort_buffer_size=1024; +insert into t1 select -seq,-seq from seq_1_to_100; +select distinct sum(distinct 1), sum(t1.d) > 2, length(group_concat(t1.d)) > 1000 from (t1 e join t1) group by t1.c having t1.c > -2 ; +sum(distinct 1) sum(t1.d) > 2 length(group_concat(t1.d)) > 1000 +1 0 0 +1 1 0 +select distinct sum(distinct 1), sum(t1.d) > 2, length(group_concat(t1.d)) > 1000,t1.c from (t1 e join t1) group by t1.c having t1.c > -2; +sum(distinct 1) sum(t1.d) > 2 length(group_concat(t1.d)) > 1000 c +1 0 0 -1 +1 1 0 0 +1 1 0 5 +1 1 0 6 +drop table t1; +# End of 10.4 tests diff --git a/mysql-test/main/distinct.test b/mysql-test/main/distinct.test index da12c7273b2b2..a2a0f14e00840 100644 --- a/mysql-test/main/distinct.test +++ b/mysql-test/main/distinct.test @@ -4,6 +4,7 @@ # --source include/default_optimizer_switch.inc +--source include/have_sequence.inc --disable_warnings drop table if exists t1,t2,t3; --enable_warnings @@ -818,3 +819,25 @@ UNION drop table t1; --echo End of 5.5 tests + +--echo # +--echo # MDEV-20057 Distinct SUM on CROSS JOIN and grouped returns wrong result +--echo # + +create table t1 (c int, d int); +insert into t1 values (5, 1), (0, 3); +select distinct sum(distinct 1), sum(t1.d) > 2 from (t1 e join t1) group by t1.c; +select distinct sum(distinct 1), sum(t1.d) > 2, t1.c from (t1 e join t1) group by t1.c; + +insert into t1 values (6,6); +select distinct sum(distinct 1), sum(t1.d) > 5 from (t1 e join t1) group by t1.c; +select distinct sum(distinct 1), sum(t1.d) > 5, t1.c from (t1 e join t1) group by t1.c; + +# Force usage of remove_dup_with_compare() algorithm +set @@sort_buffer_size=1024; +insert into t1 select -seq,-seq from seq_1_to_100; +select distinct sum(distinct 1), sum(t1.d) > 2, length(group_concat(t1.d)) > 1000 from (t1 e join t1) group by t1.c having t1.c > -2 ; +select distinct sum(distinct 1), sum(t1.d) > 2, length(group_concat(t1.d)) > 1000,t1.c from (t1 e join t1) group by t1.c having t1.c > -2; +drop table t1; + +--echo # End of 10.4 tests diff --git a/sql/filesort.cc b/sql/filesort.cc index ee19dfcb3862f..79c8f6fb234f5 100644 --- a/sql/filesort.cc +++ b/sql/filesort.cc @@ -159,7 +159,7 @@ SORT_INFO *filesort(THD *thd, TABLE *table, Filesort *filesort, MYSQL_FILESORT_START(table->s->db.str, table->s->table_name.str); DEBUG_SYNC(thd, "filesort_start"); - if (!(sort= new SORT_INFO)) + if (!(sort= new SORT_INFO)) // Note that this is not automatically freed! return 0; if (subselect && subselect->filesort_buffer.is_allocated()) @@ -186,10 +186,6 @@ SORT_INFO *filesort(THD *thd, TABLE *table, Filesort *filesort, sort->addon_buf= param.addon_buf; sort->addon_field= param.addon_field; sort->unpack= unpack_addon_fields; - if (multi_byte_charset && - !(param.tmp_buffer= (char*) my_malloc(param.sort_length, - MYF(MY_WME | MY_THREAD_SPECIFIC)))) - goto err; if (select && select->quick) thd->inc_status_sort_range(); @@ -254,6 +250,9 @@ SORT_INFO *filesort(THD *thd, TABLE *table, Filesort *filesort, tracker->report_sort_buffer_size(sort->sort_buffer_size()); } + if (param.tmp_buffer.alloc(param.sort_length)) + goto err; + if (open_cached_file(&buffpek_pointers,mysql_tmpdir,TEMP_PREFIX, DISK_BUFFER_SIZE, MYF(MY_WME))) goto err; @@ -337,7 +336,7 @@ SORT_INFO *filesort(THD *thd, TABLE *table, Filesort *filesort, error= 0; err: - my_free(param.tmp_buffer); + param.tmp_buffer.free(); if (!subselect || !subselect->is_uncacheable()) { sort->free_sort_buffer(); @@ -977,17 +976,15 @@ static inline void store_length(uchar *to, uint length, uint pack_length) void Type_handler_string_result::make_sort_key(uchar *to, Item *item, const SORT_FIELD_ATTR *sort_field, - Sort_param *param) const + String *tmp_buffer) const { CHARSET_INFO *cs= item->collation.collation; bool maybe_null= item->maybe_null; if (maybe_null) *to++= 1; - char *tmp_buffer= param->tmp_buffer ? param->tmp_buffer : (char*) to; - String tmp(tmp_buffer, param->tmp_buffer ? param->sort_length : - sort_field->length, cs); - String *res= item->str_result(&tmp); + + Binary_string *res= item->str_result(tmp_buffer); if (!res) { if (maybe_null) @@ -1015,11 +1012,11 @@ Type_handler_string_result::make_sort_key(uchar *to, Item *item, size_t tmp_length= #endif cs->coll->strnxfrm(cs, to, sort_field->length, - item->max_char_length() * - cs->strxfrm_multiply, - (uchar*) res->ptr(), res->length(), - MY_STRXFRM_PAD_WITH_SPACE | - MY_STRXFRM_PAD_TO_MAXLEN); + item->max_char_length() * + cs->strxfrm_multiply, + (uchar*) res->ptr(), res->length(), + MY_STRXFRM_PAD_WITH_SPACE | + MY_STRXFRM_PAD_TO_MAXLEN); DBUG_ASSERT(tmp_length == sort_field->length); } else @@ -1050,7 +1047,7 @@ Type_handler_string_result::make_sort_key(uchar *to, Item *item, void Type_handler_int_result::make_sort_key(uchar *to, Item *item, const SORT_FIELD_ATTR *sort_field, - Sort_param *param) const + String *tmp_buffer) const { longlong value= item->val_int_result(); make_sort_key_longlong(to, item->maybe_null, item->null_value, @@ -1061,7 +1058,7 @@ Type_handler_int_result::make_sort_key(uchar *to, Item *item, void Type_handler_temporal_result::make_sort_key(uchar *to, Item *item, const SORT_FIELD_ATTR *sort_field, - Sort_param *param) const + String *tmp_buffer) const { MYSQL_TIME buf; // This is a temporal type. No nanoseconds. Rounding mode is not important. @@ -1083,7 +1080,7 @@ Type_handler_temporal_result::make_sort_key(uchar *to, Item *item, void Type_handler_timestamp_common::make_sort_key(uchar *to, Item *item, const SORT_FIELD_ATTR *sort_field, - Sort_param *param) const + String *tmp_buffer) const { THD *thd= current_thd; uint binlen= my_timestamp_binary_length(item->decimals); @@ -1147,7 +1144,7 @@ Type_handler::make_sort_key_longlong(uchar *to, void Type_handler_decimal_result::make_sort_key(uchar *to, Item *item, const SORT_FIELD_ATTR *sort_field, - Sort_param *param) const + String *tmp_buffer) const { my_decimal dec_buf, *dec_val= item->val_decimal_result(&dec_buf); if (item->maybe_null) @@ -1167,7 +1164,7 @@ Type_handler_decimal_result::make_sort_key(uchar *to, Item *item, void Type_handler_real_result::make_sort_key(uchar *to, Item *item, const SORT_FIELD_ATTR *sort_field, - Sort_param *param) const + String *tmp_buffer) const { double value= item->val_result(); if (item->maybe_null) @@ -1205,7 +1202,8 @@ static void make_sortkey(Sort_param *param, uchar *to, uchar *ref_pos) else { // Item sort_field->item->type_handler()->make_sort_key(to, sort_field->item, - sort_field, param); + sort_field, + ¶m->tmp_buffer); if ((maybe_null= sort_field->item->maybe_null)) to++; } diff --git a/sql/sql_select.cc b/sql/sql_select.cc index 3f02d21ad0bff..f83bf32130e9c 100644 --- a/sql/sql_select.cc +++ b/sql/sql_select.cc @@ -244,10 +244,12 @@ static bool find_field_in_item_list (Field *field, void *data); static bool find_field_in_order_list (Field *field, void *data); int create_sort_index(THD *thd, JOIN *join, JOIN_TAB *tab, Filesort *fsort); static int remove_dup_with_compare(THD *thd, TABLE *entry, Field **field, - Item *having); + SORT_FIELD *sortorder, ulong keylength, + Item *having); static int remove_dup_with_hash_index(THD *thd,TABLE *table, - uint field_count, Field **first_field, - ulong key_length,Item *having); + uint field_count, Field **first_field, + SORT_FIELD *sortorder, + ulong key_length,Item *having); static bool cmp_buffer_with_ref(THD *thd, TABLE *table, TABLE_REF *tab_ref); static bool setup_new_fields(THD *thd, List &fields, List &all_fields, ORDER *new_order); @@ -24208,39 +24210,70 @@ JOIN_TAB::remove_duplicates() { bool error; - ulong keylength= 0; - uint field_count; + ulong keylength= 0, sort_field_keylength= 0; + uint field_count, item_count; List *fields= (this-1)->fields; + Item *item; THD *thd= join->thd; - + SORT_FIELD *sortorder, *sorder; DBUG_ENTER("remove_duplicates"); DBUG_ASSERT(join->aggr_tables > 0 && table->s->tmp_table != NO_TMP_TABLE); THD_STAGE_INFO(join->thd, stage_removing_duplicates); - //join->explain->ops_tracker.report_duplicate_removal(); - - table->reginfo.lock_type=TL_WRITE; + if (!(sortorder= (SORT_FIELD*) my_malloc((fields->elements+1) * + sizeof(SORT_FIELD), + MYF(MY_WME)))) + DBUG_RETURN(TRUE); /* Calculate how many saved fields there is in list */ - field_count=0; + field_count= item_count= 0; + List_iterator it(*fields); - Item *item; - while ((item=it++)) + for (sorder= sortorder ; (item=it++) ;) { - if (item->get_tmp_table_field() && ! item->const_item()) - field_count++; + if (!item->const_item()) + { + if (item->get_tmp_table_field()) + { + /* Field is stored in temporary table, skipp */ + field_count++; + } + else + { + /* Item is not stored in temporary table, remember it */ + sorder->field= 0; // Safety, not used + sorder->item= item; + /* Calculate sorder->length */ + item->type_handler()->sortlength(thd, item, sorder); + sorder++; + item_count++; + } + } } + sorder->item= 0; // End marker - if (!field_count && !(join->select_options & OPTION_FOUND_ROWS) && !having) - { // only const items with no OPTION_FOUND_ROWS + if ((field_count + item_count == 0) && ! having && + !(join->select_options & OPTION_FOUND_ROWS)) + { + // only const items with no OPTION_FOUND_ROWS join->unit->select_limit_cnt= 1; // Only send first row + my_free(sortorder); DBUG_RETURN(false); } + /* + The table contains first fields that will be in the output, then + temporary results pointed to by the fields list. + Example: SELECT DISTINCT sum(a), sum(d) > 2 FROM ... + In this case the temporary table contains sum(a), sum(d). + */ + Field **first_field=table->field+table->s->fields - field_count; for (Field **ptr=first_field; *ptr; ptr++) keylength+= (*ptr)->sort_length() + (*ptr)->maybe_null(); + for (SORT_FIELD *ptr= sortorder ; ptr->item ; ptr++) + sort_field_keylength+= ptr->length + (ptr->item->maybe_null ? 1 : 0); /* Disable LIMIT ROWS EXAMINED in order to avoid interrupting prematurely @@ -24251,30 +24284,79 @@ JOIN_TAB::remove_duplicates() thd->reset_killed(); table->file->info(HA_STATUS_VARIABLE); + table->reginfo.lock_type=TL_WRITE; + if (table->s->db_type() == heap_hton || (!table->s->blob_fields && ((ALIGN_SIZE(keylength) + HASH_OVERHEAD) * table->file->stats.records < thd->variables.sortbuff_size))) - error=remove_dup_with_hash_index(join->thd, table, field_count, first_field, - keylength, having); + error= remove_dup_with_hash_index(join->thd, table, field_count, + first_field, sortorder, + keylength + sort_field_keylength, having); else - error=remove_dup_with_compare(join->thd, table, first_field, having); + error=remove_dup_with_compare(join->thd, table, first_field, sortorder, + sort_field_keylength, having); if (join->select_lex != join->select_lex->master_unit()->fake_select_lex) thd->lex->set_limit_rows_examined(); free_blobs(first_field); + my_free(sortorder); DBUG_RETURN(error); } +/* + Create a sort/compare key from items + + Key is of fixed length and binary comparable +*/ + +static uchar *make_sort_key(SORT_FIELD *sortorder, uchar *key_buffer, + String *tmp_value) +{ + for (SORT_FIELD *ptr= sortorder ; ptr->item ; ptr++) + { + ptr->item->type_handler()->make_sort_key(key_buffer, + ptr->item, + ptr, tmp_value); + key_buffer+= (ptr->item->maybe_null ? 1 : 0) + ptr->length; + } + return key_buffer; +} + + +/* + Remove duplicates by comparing all rows with all other rows + + @param thd THD + @param table Temporary table + @param first_field Pointer to fields in temporary table that are part of + distinct, ends with null pointer + @param sortorder An array of Items part of distsinct. Terminated with an + element N with sortorder[N]->item=NULL. + @param keylength Length of key produced by sortorder + @param having Having expression (NULL if no having) +*/ + static int remove_dup_with_compare(THD *thd, TABLE *table, Field **first_field, + SORT_FIELD *sortorder, ulong keylength, Item *having) { handler *file=table->file; - uchar *record=table->record[0]; + uchar *record=table->record[0], *key_buffer, *key_buffer2; + char *tmp_buffer; int error; + String tmp_value; DBUG_ENTER("remove_dup_with_compare"); + if (unlikely(!my_multi_malloc(MYF(MY_WME), + &key_buffer, keylength, + &key_buffer2, keylength, + &tmp_buffer, keylength+1, + NullS))) + DBUG_RETURN(1); + tmp_value.set(tmp_buffer, keylength, &my_charset_bin); + if (unlikely(file->ha_rnd_init_with_error(1))) DBUG_RETURN(1); @@ -24283,8 +24365,8 @@ static int remove_dup_with_compare(THD *thd, TABLE *table, Field **first_field, { if (unlikely(thd->check_killed())) { - error=0; - goto err; + error= 1; + goto end; } if (unlikely(error)) { @@ -24303,9 +24385,10 @@ static int remove_dup_with_compare(THD *thd, TABLE *table, Field **first_field, { my_message(ER_OUTOFMEMORY, ER_THD(thd,ER_OUTOFMEMORY), MYF(ME_FATAL)); - error=0; - goto err; + error= 1; + goto end; } + make_sort_key(sortorder, key_buffer, &tmp_value); store_record(table,record[1]); /* Read through rest of file and mark duplicated rows deleted */ @@ -24318,7 +24401,10 @@ static int remove_dup_with_compare(THD *thd, TABLE *table, Field **first_field, break; goto err; } - if (compare_record(table, first_field) == 0) + make_sort_key(sortorder, key_buffer2, &tmp_value); + if (compare_record(table, first_field) == 0 && + (!keylength || + memcmp(key_buffer, key_buffer2, keylength) == 0)) { if (unlikely((error= file->ha_delete_row(record)))) goto err; @@ -24337,38 +24423,52 @@ static int remove_dup_with_compare(THD *thd, TABLE *table, Field **first_field, goto err; } + error= 0; +end: + my_free(key_buffer); file->extra(HA_EXTRA_NO_CACHE); (void) file->ha_rnd_end(); - DBUG_RETURN(0); + DBUG_RETURN(error); + err: - file->extra(HA_EXTRA_NO_CACHE); - (void) file->ha_rnd_end(); - if (error) - file->print_error(error,MYF(0)); - DBUG_RETURN(1); + DBUG_ASSERT(error); + file->print_error(error,MYF(0)); + goto end; } /** - Generate a hash index for each row to quickly find duplicate rows. + Generate a hash index for each row to quickly find duplicate rows. + + @param thd THD + @param table Temporary table + @param field_count Number of fields part of distinct + @param first_field Pointer to fields in temporary table that are part of + distinct, ends with null pointer + @param sortorder An array of Items part of distsinct. Terminated with an + element N with sortorder[N]->item=NULL. + @param keylength Length of hash key + @param having Having expression (NULL if no having) - @note - Note that this will not work on tables with blobs! + @note + Note that this will not work on tables with blobs! */ static int remove_dup_with_hash_index(THD *thd, TABLE *table, uint field_count, Field **first_field, + SORT_FIELD *sortorder, ulong key_length, Item *having) { uchar *key_buffer, *key_pos, *record=table->record[0]; + char *tmp_buffer; int error; handler *file= table->file; ulong extra_length= ALIGN_SIZE(key_length)-key_length; uint *field_lengths, *field_length; HASH hash; - Field **ptr; + String tmp_value; DBUG_ENTER("remove_dup_with_hash_index"); if (unlikely(!my_multi_malloc(MYF(MY_WME), @@ -24376,11 +24476,14 @@ static int remove_dup_with_hash_index(THD *thd, TABLE *table, (uint) ((key_length + extra_length) * (long) file->stats.records), &field_lengths, - (uint) (field_count*sizeof(*field_lengths)), + (uint) (field_count * sizeof(*field_lengths)), + &tmp_buffer, key_length+1, NullS))) DBUG_RETURN(1); - for (ptr= first_field, field_length=field_lengths ; *ptr ; ptr++) + tmp_value.set(tmp_buffer, key_length, &my_charset_bin); + field_length= field_lengths; + for (Field **ptr= first_field ; *ptr ; ptr++) (*field_length++)= (*ptr)->sort_length(); if (unlikely(my_hash_init(&hash, &my_charset_bin, @@ -24394,7 +24497,7 @@ static int remove_dup_with_hash_index(THD *thd, TABLE *table, if (unlikely((error= file->ha_rnd_init(1)))) goto err; - key_pos=key_buffer; + key_pos= key_buffer; for (;;) { uchar *org_key_pos; @@ -24419,11 +24522,14 @@ static int remove_dup_with_hash_index(THD *thd, TABLE *table, /* copy fields to key buffer */ org_key_pos= key_pos; field_length=field_lengths; - for (ptr= first_field ; *ptr ; ptr++) + for (Field **ptr= first_field ; *ptr ; ptr++) { (*ptr)->make_sort_key(key_pos, *field_length); key_pos+= (*ptr)->maybe_null() + *field_length++; } + /* Copy result fields not stored in table to key buffer */ + key_pos= make_sort_key(sortorder, key_pos, &tmp_value); + /* Check if it exists before */ if (my_hash_search(&hash, org_key_pos, key_length)) { diff --git a/sql/sql_sort.h b/sql/sql_sort.h index 7abbc808632f8..5d5d1a0b988c4 100644 --- a/sql/sql_sort.h +++ b/sql/sql_sort.h @@ -19,6 +19,7 @@ #include "my_base.h" /* ha_rows */ #include /* qsort2_cmp */ #include "queues.h" +#include "sql_string.h" typedef struct st_buffpek BUFFPEK; @@ -82,14 +83,20 @@ class Sort_param { uchar *unique_buff; bool not_killable; - char* tmp_buffer; + String tmp_buffer; // The fields below are used only by Unique class. qsort2_cmp compare; BUFFPEK_COMPARE_CONTEXT cmp_context; Sort_param() { - memset(this, 0, sizeof(*this)); + memset(reinterpret_cast(this), 0, sizeof(*this)); + tmp_buffer.set_thread_specific(); + /* + Fix memset() clearing the charset. + TODO: The constructor should be eventually rewritten not to use memset(). + */ + tmp_buffer.set_charset(&my_charset_bin); } void init_for_filesort(uint sortlen, TABLE *table, ha_rows maxrows, bool sort_positions); diff --git a/sql/sql_type.h b/sql/sql_type.h index 1e44be37d525b..bf76806c44a54 100644 --- a/sql/sql_type.h +++ b/sql/sql_type.h @@ -3734,7 +3734,7 @@ class Type_handler virtual void make_sort_key(uchar *to, Item *item, const SORT_FIELD_ATTR *sort_field, - Sort_param *param) const= 0; + String *tmp) const= 0; virtual void sortlength(THD *thd, const Type_std_attributes *item, SORT_FIELD_ATTR *attr) const= 0; @@ -4120,7 +4120,7 @@ class Type_handler_row: public Type_handler const Bit_addr &bit, const Column_definition_attributes *attr, uint32 flags) const override; - void make_sort_key(uchar *, Item *, const SORT_FIELD_ATTR *, Sort_param *) + void make_sort_key(uchar *, Item *, const SORT_FIELD_ATTR *, String *tmp) const override { MY_ASSERT_UNREACHABLE(); @@ -4431,7 +4431,7 @@ class Type_handler_real_result: public Type_handler_numeric const Item *outer, bool is_in_predicate) const; void make_sort_key(uchar *to, Item *item, const SORT_FIELD_ATTR *sort_field, - Sort_param *param) const; + String *tmp) const; void sortlength(THD *thd, const Type_std_attributes *item, SORT_FIELD_ATTR *attr) const; @@ -4519,7 +4519,7 @@ class Type_handler_decimal_result: public Type_handler_numeric bool is_in_predicate) const; Field *make_num_distinct_aggregator_field(MEM_ROOT *, const Item *) const; void make_sort_key(uchar *to, Item *item, const SORT_FIELD_ATTR *sort_field, - Sort_param *param) const; + String *tmp) const; void sortlength(THD *thd, const Type_std_attributes *item, SORT_FIELD_ATTR *attr) const; @@ -4745,7 +4745,7 @@ class Type_handler_int_result: public Type_handler_numeric bool is_in_predicate) const; Field *make_num_distinct_aggregator_field(MEM_ROOT *, const Item *) const; void make_sort_key(uchar *to, Item *item, const SORT_FIELD_ATTR *sort_field, - Sort_param *param) const; + String *tmp) const; void sortlength(THD *thd, const Type_std_attributes *item, SORT_FIELD_ATTR *attr) const; @@ -4834,7 +4834,7 @@ class Type_handler_temporal_result: public Type_handler Item_result cmp_type() const { return TIME_RESULT; } virtual ~Type_handler_temporal_result() = default; void make_sort_key(uchar *to, Item *item, const SORT_FIELD_ATTR *sort_field, - Sort_param *param) const; + String *tmp) const; void sortlength(THD *thd, const Type_std_attributes *item, SORT_FIELD_ATTR *attr) const; @@ -4921,7 +4921,7 @@ class Type_handler_string_result: public Type_handler type_handler_adjusted_to_max_octet_length(uint max_octet_length, CHARSET_INFO *cs) const; void make_sort_key(uchar *to, Item *item, const SORT_FIELD_ATTR *sort_field, - Sort_param *param) const; + String *tmp) const; void sortlength(THD *thd, const Type_std_attributes *item, SORT_FIELD_ATTR *attr) const; @@ -5953,7 +5953,7 @@ class Type_handler_timestamp_common: public Type_handler_temporal_with_date cmp_item *make_cmp_item(THD *thd, CHARSET_INFO *cs) const; in_vector *make_in_vector(THD *thd, const Item_func_in *f, uint nargs) const; void make_sort_key(uchar *to, Item *item, const SORT_FIELD_ATTR *sort_field, - Sort_param *param) const; + String *tmp) const; void sortlength(THD *thd, const Type_std_attributes *item, SORT_FIELD_ATTR *attr) const; From 358635bbad5082026603deda0cff93427a38c069 Mon Sep 17 00:00:00 2001 From: Andrew Hutchings Date: Mon, 31 Oct 2022 15:51:00 +0000 Subject: [PATCH 19/92] MDEV-29782 CONNECT YEAR type conversion fix When using the MySQL table type the CONNECT engine converted the YEAR datatype to DATETIME for INSERT queries. This is incorrect, causing an error on the INSERT. It should be SHORT instead. --- storage/connect/mysql-test/connect/r/mysql.result | 11 +++++++++++ storage/connect/mysql-test/connect/t/mysql.test | 15 +++++++++++++++ storage/connect/myutil.cpp | 2 +- 3 files changed, 27 insertions(+), 1 deletion(-) diff --git a/storage/connect/mysql-test/connect/r/mysql.result b/storage/connect/mysql-test/connect/r/mysql.result index d3c244b277ac8..1dcbca88a7b5e 100644 --- a/storage/connect/mysql-test/connect/r/mysql.result +++ b/storage/connect/mysql-test/connect/r/mysql.result @@ -364,5 +364,16 @@ hex(col) DROP TABLE t2; DROP TABLE t1; # +# MDEV-29782 CONNECT engine converted YEAR to DATETIME, causing INSERT to fail +# +CREATE TABLE t1 (id year); +CREATE TABLE t2 ENGINE=CONNECT TABLE_TYPE=MYSQL DBNAME='test' TABNAME='t1' OPTION_LIST='host=localhost,user=root,port=PORT'; +INSERT INTO t2 VALUES (1999); +SELECT * FROM t2; +id +1999 +DROP TABLE t2; +DROP TABLE t1; +# # End of 10.3 tests # diff --git a/storage/connect/mysql-test/connect/t/mysql.test b/storage/connect/mysql-test/connect/t/mysql.test index a50db4a645731..cd52f78fb302a 100644 --- a/storage/connect/mysql-test/connect/t/mysql.test +++ b/storage/connect/mysql-test/connect/t/mysql.test @@ -533,6 +533,21 @@ DROP TABLE t2; DROP TABLE t1; +--echo # +--echo # MDEV-29782 CONNECT engine converted YEAR to DATETIME, causing INSERT to fail +--echo # + +CREATE TABLE t1 (id year); + +--replace_result $PORT PORT +--eval CREATE TABLE t2 ENGINE=CONNECT TABLE_TYPE=MYSQL DBNAME='test' TABNAME='t1' OPTION_LIST='host=localhost,user=root,port=$PORT' + +INSERT INTO t2 VALUES (1999); +SELECT * FROM t2; + +DROP TABLE t2; +DROP TABLE t1; + --echo # --echo # End of 10.3 tests --echo # diff --git a/storage/connect/myutil.cpp b/storage/connect/myutil.cpp index c49db48bfb3ae..45b2c46e21724 100644 --- a/storage/connect/myutil.cpp +++ b/storage/connect/myutil.cpp @@ -183,6 +183,7 @@ int MYSQLtoPLG(int mytype, char *var) switch (mytype) { case MYSQL_TYPE_SHORT: + case MYSQL_TYPE_YEAR: type = TYPE_SHORT; break; case MYSQL_TYPE_LONG: @@ -209,7 +210,6 @@ int MYSQLtoPLG(int mytype, char *var) case MYSQL_TYPE_TIMESTAMP: case MYSQL_TYPE_DATE: case MYSQL_TYPE_DATETIME: - case MYSQL_TYPE_YEAR: case MYSQL_TYPE_TIME: type = TYPE_DATE; break; From 3c6f108540862ef91889ee2bf975fad64237dabb Mon Sep 17 00:00:00 2001 From: Sergei Golubchik Date: Tue, 31 Jan 2023 16:07:27 +0100 Subject: [PATCH 20/92] Revert "ignore changes in submodules when committing everything" This reverts commit d78ac04ee609b0b63bb688be2a837a6ca7670392. The benefits of `ignore=all` are that submodules are omitted from `git status` and `git citool`. The drawbacks are - submodules are not omitted from `git commit -a` *and* they are omitted from `git diff` and `git show` output. As a result one can unintentionally commit changes to submodules and not see it in the history. Thus drawbacks outweigh benefits here. --- .gitmodules | 4 ---- 1 file changed, 4 deletions(-) diff --git a/.gitmodules b/.gitmodules index 30f950b00e78a..921a4782f4f41 100644 --- a/.gitmodules +++ b/.gitmodules @@ -1,17 +1,13 @@ [submodule "libmariadb"] path = libmariadb url = https://github.com/MariaDB/mariadb-connector-c.git - ignore = all [submodule "storage/rocksdb/rocksdb"] path = storage/rocksdb/rocksdb url = https://github.com/facebook/rocksdb.git - ignore = all [submodule "wsrep-lib"] path = wsrep-lib url = https://github.com/codership/wsrep-lib.git branch = master - ignore = all [submodule "extra/wolfssl/wolfssl"] path = extra/wolfssl/wolfssl url = https://github.com/wolfSSL/wolfssl.git - ignore = all From 2e6a9886a9f0aea55035dbdcf74bf09c0f7e2a30 Mon Sep 17 00:00:00 2001 From: Sergei Golubchik Date: Wed, 1 Feb 2023 18:56:10 +0100 Subject: [PATCH 21/92] MDEV-30526 Assertion `rights == merged->cols' failed in update_role_columns another case of the antipattern "iterate the HASH and delete elements as we go" --- mysql-test/suite/roles/role_grant_propagate.result | 13 +++++++++++++ mysql-test/suite/roles/role_grant_propagate.test | 11 +++++++++++ sql/sql_acl.cc | 2 ++ 3 files changed, 26 insertions(+) diff --git a/mysql-test/suite/roles/role_grant_propagate.result b/mysql-test/suite/roles/role_grant_propagate.result index 7804b7b7a3c0c..111fd4dbc28c7 100644 --- a/mysql-test/suite/roles/role_grant_propagate.result +++ b/mysql-test/suite/roles/role_grant_propagate.result @@ -163,5 +163,18 @@ drop role student; drop role admin; drop database crm; # +# MDEV-30526 Assertion `rights == merged->cols' failed in update_role_columns +# +create table t1 ( pk int, i int); +create role a; +grant select (i), update (pk) on t1 to a; +revoke update (pk) on t1 from a; +show grants for a; +Grants for a +GRANT USAGE ON *.* TO `a` +GRANT SELECT (`i`) ON `test`.`t1` TO `a` +drop role a; +drop table t1; +# # End of 10.3 tests # diff --git a/mysql-test/suite/roles/role_grant_propagate.test b/mysql-test/suite/roles/role_grant_propagate.test index bf20bc008097c..02d451f0afdcb 100644 --- a/mysql-test/suite/roles/role_grant_propagate.test +++ b/mysql-test/suite/roles/role_grant_propagate.test @@ -196,6 +196,17 @@ drop role student; drop role admin; drop database crm; +--echo # +--echo # MDEV-30526 Assertion `rights == merged->cols' failed in update_role_columns +--echo # +create table t1 ( pk int, i int); +create role a; +grant select (i), update (pk) on t1 to a; +revoke update (pk) on t1 from a; +show grants for a; +drop role a; +drop table t1; + --echo # --echo # End of 10.3 tests --echo # diff --git a/sql/sql_acl.cc b/sql/sql_acl.cc index c6b1631523cb5..54ad81f94cec1 100644 --- a/sql/sql_acl.cc +++ b/sql/sql_acl.cc @@ -6550,6 +6550,7 @@ static int update_role_columns(GRANT_TABLE *merged, } } +restart: for (uint i=0 ; i < mh->records ; i++) { GRANT_COLUMN *col = (GRANT_COLUMN *)my_hash_element(mh, i); @@ -6558,6 +6559,7 @@ static int update_role_columns(GRANT_TABLE *merged, { changed= 1; my_hash_delete(mh, (uchar*)col); + goto restart; } } DBUG_ASSERT(rights == merged->cols); From 90c39c5a500278d19240550f7c4bf370c441c100 Mon Sep 17 00:00:00 2001 From: Sergei Golubchik Date: Wed, 1 Feb 2023 20:20:57 +0100 Subject: [PATCH 22/92] hopefully the last case of walk-and-delete HASH antipattern here global_index_stats is expected to be big, so we don't restart the search, but use a two-pass approach --- sql/handler.cc | 18 +++++++----------- 1 file changed, 7 insertions(+), 11 deletions(-) diff --git a/sql/handler.cc b/sql/handler.cc index 42bfec6652fd2..d90522f0a13c3 100644 --- a/sql/handler.cc +++ b/sql/handler.cc @@ -7233,11 +7233,13 @@ static int del_global_index_stats_for_table(THD *thd, uchar* cache_key, size_t cache_key_length) { int res = 0; + uint to_delete_counter= 0; + INDEX_STATS *index_stats_to_delete[MAX_INDEXES]; DBUG_ENTER("del_global_index_stats_for_table"); mysql_mutex_lock(&LOCK_global_index_stats); - for (uint i= 0; i < global_index_stats.records;) + for (uint i= 0; i < global_index_stats.records; i++) { INDEX_STATS *index_stats = (INDEX_STATS*) my_hash_element(&global_index_stats, i); @@ -7247,19 +7249,13 @@ int del_global_index_stats_for_table(THD *thd, uchar* cache_key, size_t cache_ke index_stats->index_name_length >= cache_key_length && !memcmp(index_stats->index, cache_key, cache_key_length)) { - res= my_hash_delete(&global_index_stats, (uchar*)index_stats); - /* - In our HASH implementation on deletion one elements - is moved into a place where a deleted element was, - and the last element is moved into the empty space. - Thus we need to re-examine the current element, but - we don't have to restart the search from the beginning. - */ + index_stats_to_delete[to_delete_counter++]= index_stats; } - else - i++; } + for (uint i= 0; i < to_delete_counter; i++) + res= my_hash_delete(&global_index_stats, (uchar*)index_stats_to_delete[i]); + mysql_mutex_unlock(&LOCK_global_index_stats); DBUG_RETURN(res); } From a777a8a6a3c71ede8b88d20ab5c1a95590138611 Mon Sep 17 00:00:00 2001 From: Sergei Golubchik Date: Thu, 2 Feb 2023 19:29:03 +0100 Subject: [PATCH 23/92] KILL USER and missing privileges note that `KILL USER foo` should *not* fail with ER_KILL_DENIED_ERROR when SHOW PROCESSLIST doesn't show connections of that user. Because no connections exist or because the caller has no PROCESS - doesn't matter. also, fix the error message to make sense ("You are not owner of thread " is ridiculous) --- mysql-test/main/kill-2.result | 31 +++++++++++++++++++++++++++++++ mysql-test/main/kill-2.test | 27 +++++++++++++++++++++++++++ sql/sql_parse.cc | 9 +++++++-- 3 files changed, 65 insertions(+), 2 deletions(-) diff --git a/mysql-test/main/kill-2.result b/mysql-test/main/kill-2.result index daaba2c092a9b..919078f3efb28 100644 --- a/mysql-test/main/kill-2.result +++ b/mysql-test/main/kill-2.result @@ -10,3 +10,34 @@ foo root kill user foo@'127.0.0.1'; drop user foo@'127.0.0.1'; +# +# KILL USER and missing privileges +# +create user a@'127.0.0.1'; +create user b@'127.0.0.1'; +grant process on *.* to a@'127.0.0.1'; +grant select on *.* to b@'127.0.0.1'; +connect a,127.0.0.1,a; +show grants; +Grants for a@127.0.0.1 +GRANT PROCESS ON *.* TO `a`@`127.0.0.1` +connect b,127.0.0.1,b; +show processlist; +Id User Host db Command Time State Info Progress +# b # test # # Init show processlist # +kill user a; +kill user x; +connection a; +show processlist; +Id User Host db Command Time State Info Progress +# root # test # # # # # +# a # test # # # # # +# b # test # # # # # +kill user b; +ERROR HY000: Operation KILL USER failed for b@% +connection default; +drop user a@'127.0.0.1'; +drop user b@'127.0.0.1'; +# +# End of 10.3 tests +# diff --git a/mysql-test/main/kill-2.test b/mysql-test/main/kill-2.test index a30324fac4448..1bbe395371c6d 100644 --- a/mysql-test/main/kill-2.test +++ b/mysql-test/main/kill-2.test @@ -28,3 +28,30 @@ let $wait_condition= --source include/wait_condition.inc drop user foo@'127.0.0.1'; --enable_service_connection + +--echo # +--echo # KILL USER and missing privileges +--echo # +create user a@'127.0.0.1'; +create user b@'127.0.0.1'; +grant process on *.* to a@'127.0.0.1'; +grant select on *.* to b@'127.0.0.1'; +--connect a,127.0.0.1,a +show grants; +--connect b,127.0.0.1,b +--replace_column 1 # 3 # 5 # 6 # 9 # +show processlist; +kill user a; # existing connection, but not visible to current_user +kill user x; # not existing connection +--connection a +--replace_column 1 # 3 # 5 # 6 # 7 # 8 # 9 # +show processlist; +--error ER_KILL_DENIED_ERROR +kill user b; +--connection default +drop user a@'127.0.0.1'; +drop user b@'127.0.0.1'; + +--echo # +--echo # End of 10.3 tests +--echo # diff --git a/sql/sql_parse.cc b/sql/sql_parse.cc index a00e5b82b1297..1f1962a5d44bd 100644 --- a/sql/sql_parse.cc +++ b/sql/sql_parse.cc @@ -9258,7 +9258,9 @@ static my_bool kill_threads_callback(THD *thd, kill_threads_callback_arg *arg) { if (!(arg->thd->security_ctx->master_access & SUPER_ACL) && !arg->thd->security_ctx->user_matches(thd->security_ctx)) - return 1; + { + return MY_TEST(arg->thd->security_ctx->master_access & PROCESS_ACL); + } if (!arg->threads_to_kill.push_back(thd, arg->thd->mem_root)) { mysql_mutex_lock(&thd->LOCK_thd_kill); // Lock from delete @@ -9380,7 +9382,10 @@ void sql_kill_user(THD *thd, LEX_USER *user, killed_state state) my_ok(thd, rows); break; case ER_KILL_DENIED_ERROR: - my_error(error, MYF(0), (long long) thd->thread_id); + char buf[DEFINER_LENGTH+1]; + strxnmov(buf, sizeof(buf), user->user.str, "@", user->host.str, NULL); + my_printf_error(ER_KILL_DENIED_ERROR, ER_THD(thd, ER_CANNOT_USER), MYF(0), + "KILL USER", buf); break; case ER_OUT_OF_RESOURCES: default: From 839c7fcf38ef17f9627f63ebec3e82d814912973 Mon Sep 17 00:00:00 2001 From: Thirunarayanan Balathandayuthapani Date: Thu, 23 Feb 2023 19:56:07 +0530 Subject: [PATCH 24/92] MDEV-30597 Assertion `flag == 1' failed in row_build_index_entry_low - dtuple_vcol_data_missing() should check the DATA_MISSING only for indexed virtual column. --- storage/innobase/row/row0vers.cc | 22 ++++++++++++++++------ 1 file changed, 16 insertions(+), 6 deletions(-) diff --git a/storage/innobase/row/row0vers.cc b/storage/innobase/row/row0vers.cc index 0679f8838974a..9d2e6654c460b 100644 --- a/storage/innobase/row/row0vers.cc +++ b/storage/innobase/row/row0vers.cc @@ -861,15 +861,25 @@ row_vers_build_cur_vrow( } /** Find out whether data tuple has missing data type -for virtualcolumn. +for indexed virtual column. @param tuple data tuple +@param index virtual index @return true if tuple has missing column type */ -static bool dtuple_vcol_data_missing(const dtuple_t &tuple) +static bool dtuple_vcol_data_missing(const dtuple_t &tuple, + dict_index_t *index) { - for (ulint i= 0; i < tuple.n_v_fields; i++) + for (ulint i= 0; i < index->n_uniq; i++) { - if (tuple.v_fields[i].type.mtype == DATA_MISSING) - return true; + dict_col_t *col= index->fields[i].col; + if (!col->is_virtual()) + continue; + dict_v_col_t *vcol= reinterpret_cast(col); + for (ulint j= 0; j < index->table->n_v_cols; j++) + { + if (vcol == &index->table->v_cols[j] + && tuple.v_fields[j].type.mtype == DATA_MISSING) + return true; + } } return false; } @@ -1102,7 +1112,7 @@ row_vers_old_has_index_entry( if (dict_index_has_virtual(index)) { if (vrow) { - if (dtuple_vcol_data_missing(*vrow)) { + if (dtuple_vcol_data_missing(*vrow, index)) { goto nochange_index; } /* Keep the virtual row info for the next From 841e8877ccb8ef5d692a22b4447383a360557326 Mon Sep 17 00:00:00 2001 From: Igor Babaev Date: Mon, 27 Feb 2023 10:51:22 -0800 Subject: [PATCH 25/92] MDEV-28603 Invalid view when its definition uses TVC as single-value subquery Subselect_single_value_engine cannot handle table value constructor used as subquery. That's why any table value constructor TVC used as subquery is converted into a select over derived table whose specification is TVC. Currently the names of the columns of the derived table DT are taken from the first element of TVC and if the k-th component of the element happens to be a subquery the text representation of this subquery serves as the name of the k-th column of the derived table. References of all columns of the derived table DT compose the select list of the result of the conversion. If a definition of a view contained a table value constructor used as a subquery and the view was registered after this conversion had been applied we could register an invalid view definition if the first element of TVC contained a subquery as its component: the name of this component was taken from the original subquery, while the name of the corresponding column of the derived table was taken from the text representation of the subquery produced by the function SELECT_LEX::print() and these names were usually differ from each other. To avoid registration of such invalid views the function SELECT_LEX::print() now prints the original TVC instead of the select in which this TVC has been wrapped. Now the specification of registered view looks like as if no conversions from TVC to selects were done. Approved by Oleksandr Byelkin --- mysql-test/main/table_value_constr.result | 119 ++++++++++++++++++++++ mysql-test/main/table_value_constr.test | 74 ++++++++++++++ sql/mysqld.h | 2 + sql/sql_lex.cc | 1 + sql/sql_lex.h | 3 +- sql/sql_select.cc | 6 ++ sql/sql_show.cc | 3 +- sql/sql_tvc.cc | 1 + sql/sql_view.cc | 6 +- 9 files changed, 211 insertions(+), 4 deletions(-) diff --git a/mysql-test/main/table_value_constr.result b/mysql-test/main/table_value_constr.result index c8e6363c110f2..bd0aac5edce61 100644 --- a/mysql-test/main/table_value_constr.result +++ b/mysql-test/main/table_value_constr.result @@ -3133,5 +3133,124 @@ INSERT INTO t1 (VALUES (IGNORE) UNION VALUES (IGNORE)); ERROR HY000: 'ignore' is not allowed in this context DROP TABLE t1; # +# MDEV-28603: VIEW with table value constructor used as single-value +# subquery contains subquery as its first element +# +create table t1 (a int); +insert into t1 values (3), (7), (1); +create table t2 (b int); +insert into t2 values (1), (2); +create view v as select (values ((select * from t1 where a > 5))) as m from t2; +select (values ((select * from t1 where a > 5))) as m from t2; +m +7 +7 +select * from v; +m +7 +7 +with cte as ( select (values ((select * from t1 where a > 5))) as m from t2 ) select * from cte; +m +7 +7 +explain select (values ((select * from t1 where a > 5))) as m from t2; +id select_type table type possible_keys key key_len ref rows Extra +1 PRIMARY t2 ALL NULL NULL NULL NULL 2 +4 SUBQUERY ALL NULL NULL NULL NULL 2 +2 DERIVED NULL NULL NULL NULL NULL NULL NULL No tables used +3 SUBQUERY t1 ALL NULL NULL NULL NULL 3 Using where +explain select * from v; +id select_type table type possible_keys key key_len ref rows Extra +1 PRIMARY t2 ALL NULL NULL NULL NULL 2 +5 SUBQUERY ALL NULL NULL NULL NULL 2 +3 DERIVED NULL NULL NULL NULL NULL NULL NULL No tables used +4 SUBQUERY t1 ALL NULL NULL NULL NULL 3 Using where +explain with cte as ( select (values ((select * from t1 where a > 5))) as m from t2 ) select * from cte; +id select_type table type possible_keys key key_len ref rows Extra +1 PRIMARY t2 ALL NULL NULL NULL NULL 2 +5 SUBQUERY ALL NULL NULL NULL NULL 2 +3 DERIVED NULL NULL NULL NULL NULL NULL NULL No tables used +4 SUBQUERY t1 ALL NULL NULL NULL NULL 3 Using where +prepare stmt from "select (values ((select * from t1 where a > 5))) as m from t2"; +execute stmt; +m +7 +7 +execute stmt; +m +7 +7 +deallocate prepare stmt; +prepare stmt from "select * from v"; +execute stmt; +m +7 +7 +execute stmt; +m +7 +7 +deallocate prepare stmt; +prepare stmt from "with cte as ( select (values ((select * from t1 where a > 5))) as m from t2 ) select * from cte"; +execute stmt; +m +7 +7 +execute stmt; +m +7 +7 +deallocate prepare stmt; +show create view v; +View Create View character_set_client collation_connection +v CREATE ALGORITHM=UNDEFINED DEFINER=`root`@`localhost` SQL SECURITY DEFINER VIEW `v` AS select (values ((select `t1`.`a` from `t1` where `t1`.`a` > 5))) AS `m` from `t2` latin1 latin1_swedish_ci +drop view v; +prepare stmt from "create view v as select (values ((select * from t1 where a > 5))) as m from t2"; +execute stmt; +show create view v; +View Create View character_set_client collation_connection +v CREATE ALGORITHM=UNDEFINED DEFINER=`root`@`localhost` SQL SECURITY DEFINER VIEW `v` AS select (values ((select `t1`.`a` from `t1` where `t1`.`a` > 5))) AS `m` from `t2` latin1 latin1_swedish_ci +select * from v; +m +7 +7 +drop view v; +execute stmt; +show create view v; +View Create View character_set_client collation_connection +v CREATE ALGORITHM=UNDEFINED DEFINER=`root`@`localhost` SQL SECURITY DEFINER VIEW `v` AS select (values ((select `t1`.`a` from `t1` where `t1`.`a` > 5))) AS `m` from `t2` latin1 latin1_swedish_ci +select * from v; +m +7 +7 +deallocate prepare stmt; +prepare stmt from "show create view v"; +execute stmt; +View Create View character_set_client collation_connection +v CREATE ALGORITHM=UNDEFINED DEFINER=`root`@`localhost` SQL SECURITY DEFINER VIEW `v` AS select (values ((select `t1`.`a` from `t1` where `t1`.`a` > 5))) AS `m` from `t2` latin1 latin1_swedish_ci +execute stmt; +View Create View character_set_client collation_connection +v CREATE ALGORITHM=UNDEFINED DEFINER=`root`@`localhost` SQL SECURITY DEFINER VIEW `v` AS select (values ((select `t1`.`a` from `t1` where `t1`.`a` > 5))) AS `m` from `t2` latin1 latin1_swedish_ci +deallocate prepare stmt; +drop view v; +create view v as select (values ((select * from t1 where a > 5 +union +select * from t1 where a > 7))) as m from t2; +select (values ((select * from t1 where a > 5 +union +select * from t1 where a > 7))) as m from t2; +m +7 +7 +select * from v; +m +7 +7 +show create view v; +View Create View character_set_client collation_connection +v CREATE ALGORITHM=UNDEFINED DEFINER=`root`@`localhost` SQL SECURITY DEFINER VIEW `v` AS select (values ((select `t1`.`a` from `t1` where `t1`.`a` > 5 union select `t1`.`a` from `t1` where `t1`.`a` > 7))) AS `m` from `t2` latin1 latin1_swedish_ci +drop view v; +drop table t1,t2; +# # End of 10.4 tests # diff --git a/mysql-test/main/table_value_constr.test b/mysql-test/main/table_value_constr.test index 19af93e013714..1d58cd0819d30 100644 --- a/mysql-test/main/table_value_constr.test +++ b/mysql-test/main/table_value_constr.test @@ -1736,6 +1736,80 @@ INSERT INTO t1 (VALUES (DEFAULT) UNION VALUES (DEFAULT)); INSERT INTO t1 (VALUES (IGNORE) UNION VALUES (IGNORE)); DROP TABLE t1; +--echo # +--echo # MDEV-28603: VIEW with table value constructor used as single-value +--echo # subquery contains subquery as its first element +--echo # + +create table t1 (a int); +insert into t1 values (3), (7), (1); +create table t2 (b int); +insert into t2 values (1), (2); + +let $q= +select (values ((select * from t1 where a > 5))) as m from t2; + +eval create view v as $q; + +eval $q; +eval select * from v; +eval with cte as ( $q ) select * from cte; + +eval explain $q; +eval explain select * from v; +eval explain with cte as ( $q ) select * from cte; + +eval prepare stmt from "$q"; +execute stmt; +execute stmt; +deallocate prepare stmt; + +eval prepare stmt from "select * from v"; +execute stmt; +execute stmt; +deallocate prepare stmt; + +eval prepare stmt from "with cte as ( $q ) select * from cte"; +execute stmt; +execute stmt; +deallocate prepare stmt; + +show create view v; + +drop view v; + +eval prepare stmt from "create view v as $q"; +execute stmt; +show create view v; +select * from v; +drop view v; +execute stmt; +show create view v; +select * from v; +deallocate prepare stmt; + +prepare stmt from "show create view v"; +execute stmt; +execute stmt; +deallocate prepare stmt; + +drop view v; + +let $q= +select (values ((select * from t1 where a > 5 + union + select * from t1 where a > 7))) as m from t2; + +eval create view v as $q; + +eval $q; +eval select * from v; + +show create view v; + +drop view v; +drop table t1,t2; + --echo # --echo # End of 10.4 tests --echo # diff --git a/sql/mysqld.h b/sql/mysqld.h index 60afb0b9dbae7..f521ea2363888 100644 --- a/sql/mysqld.h +++ b/sql/mysqld.h @@ -755,6 +755,8 @@ enum enum_query_type // it evaluates to. Should be used for error messages, so that they // don't reveal values. QT_NO_DATA_EXPANSION= (1 << 9), + // Remove wrappers added for TVC when creating or showing view + QT_NO_WRAPPERS_FOR_TVC_IN_VIEW= (1 << 11), }; diff --git a/sql/sql_lex.cc b/sql/sql_lex.cc index 24958b5adcc55..62c7556dcd642 100644 --- a/sql/sql_lex.cc +++ b/sql/sql_lex.cc @@ -2487,6 +2487,7 @@ void st_select_lex::init_select() curr_tvc_name= 0; in_tvc= false; versioned_tables= 0; + is_tvc_wrapper= false; } /* diff --git a/sql/sql_lex.h b/sql/sql_lex.h index 3545a4e8d7457..8f25426a09c7b 100644 --- a/sql/sql_lex.h +++ b/sql/sql_lex.h @@ -1132,7 +1132,8 @@ class st_select_lex: public st_select_lex_node st_select_lex. */ uint curr_tvc_name; - + /* true <=> select has been created a TVC wrapper */ + bool is_tvc_wrapper; /* Needed to correctly generate 'PRIMARY' or 'SIMPLE' for select_type column of EXPLAIN diff --git a/sql/sql_select.cc b/sql/sql_select.cc index f83bf32130e9c..2c12d1c4c6500 100644 --- a/sql/sql_select.cc +++ b/sql/sql_select.cc @@ -27992,6 +27992,12 @@ void st_select_lex::print(THD *thd, String *str, enum_query_type query_type) return; } + if (is_tvc_wrapper && (query_type & QT_NO_WRAPPERS_FOR_TVC_IN_VIEW)) + { + first_inner_unit()->first_select()->print(thd, str, query_type); + return; + } + if ((query_type & QT_SHOW_SELECT_NUMBER) && thd->lex->all_selects_list && thd->lex->all_selects_list->link_next && diff --git a/sql/sql_show.cc b/sql/sql_show.cc index 9fee8ce5a6c36..1ad20ac759303 100644 --- a/sql/sql_show.cc +++ b/sql/sql_show.cc @@ -2707,7 +2707,8 @@ static int show_create_view(THD *thd, TABLE_LIST *table, String *buff) a different syntax, like when ANSI_QUOTES is defined. */ table->view->unit.print(buff, enum_query_type(QT_VIEW_INTERNAL | - QT_ITEM_ORIGINAL_FUNC_NULLIF)); + QT_ITEM_ORIGINAL_FUNC_NULLIF | + QT_NO_WRAPPERS_FOR_TVC_IN_VIEW)); if (table->with_check != VIEW_CHECK_NONE) { diff --git a/sql/sql_tvc.cc b/sql/sql_tvc.cc index d8e6770465d1c..71377d3661d19 100644 --- a/sql/sql_tvc.cc +++ b/sql/sql_tvc.cc @@ -673,6 +673,7 @@ st_select_lex *wrap_tvc(THD *thd, st_select_lex *tvc_sl, wrapper_sl->parent_lex= lex; /* Used in init_query. */ wrapper_sl->init_query(); wrapper_sl->init_select(); + wrapper_sl->is_tvc_wrapper= true; wrapper_sl->nest_level= tvc_sl->nest_level; wrapper_sl->parsing_place= tvc_sl->parsing_place; diff --git a/sql/sql_view.cc b/sql/sql_view.cc index 1efbc68fb8ad2..54debf98eff20 100644 --- a/sql/sql_view.cc +++ b/sql/sql_view.cc @@ -956,10 +956,12 @@ static int mysql_register_view(THD *thd, TABLE_LIST *view, thd->variables.sql_mode&= ~MODE_ANSI_QUOTES; lex->unit.print(&view_query, enum_query_type(QT_VIEW_INTERNAL | - QT_ITEM_ORIGINAL_FUNC_NULLIF)); + QT_ITEM_ORIGINAL_FUNC_NULLIF | + QT_NO_WRAPPERS_FOR_TVC_IN_VIEW)); lex->unit.print(&is_query, enum_query_type(QT_TO_SYSTEM_CHARSET | QT_WITHOUT_INTRODUCERS | - QT_ITEM_ORIGINAL_FUNC_NULLIF)); + QT_ITEM_ORIGINAL_FUNC_NULLIF | + QT_NO_WRAPPERS_FOR_TVC_IN_VIEW)); thd->variables.sql_mode|= sql_mode; } From 965bdf3e66a9265345003c6e172aad7b1864e280 Mon Sep 17 00:00:00 2001 From: Alexander Barkov Date: Tue, 28 Feb 2023 10:49:25 +0400 Subject: [PATCH 26/92] MDEV-30746 Regression in ucs2_general_mysql500_ci 1. Adding a separate MY_COLLATION_HANDLER my_collation_ucs2_general_mysql500_ci_handler implementing a proper order for ucs2_general_mysql500_ci The problem happened because ucs2_general_mysql500_ci erroneously used my_collation_ucs2_general_ci_handler. 2. Cosmetic changes: Renaming: - plane00_mysql500 to my_unicase_mysql500_page00 - my_unicase_pages_mysql500 to my_unicase_mysql500_pages to use the same naming style with: - my_unicase_default_page00 - my_unicase_defaul_pages 3. Moving code fragments from - handler::check_collation_compatibility() in handler.cc - upgrade_collation() in table.cc into new methods in class Charset, to reuse the code easier. --- mysql-test/main/ctype_ucs.result | 17 ++++ mysql-test/main/ctype_ucs.test | 12 +++ mysql-test/main/ctype_upgrade.result | 53 ++++++++++++ mysql-test/main/ctype_upgrade.test | 35 ++++++++ .../mariadb100428_ucs2_general_ci.MYD | Bin 0 -> 60 bytes .../mariadb100428_ucs2_general_ci.MYI | Bin 0 -> 2048 bytes .../mariadb100428_ucs2_general_ci.frm | Bin 0 -> 982 bytes sql/handler.cc | 15 +--- sql/sql_string.h | 77 ++++++++++++++++++ sql/table.cc | 40 ++------- strings/ctype-ucs2.c | 39 ++++++++- strings/ctype-unidata.h | 3 + strings/ctype-utf8.c | 18 ++-- 13 files changed, 251 insertions(+), 58 deletions(-) create mode 100644 mysql-test/std_data/ctype_upgrade/mariadb100428_ucs2_general_ci.MYD create mode 100644 mysql-test/std_data/ctype_upgrade/mariadb100428_ucs2_general_ci.MYI create mode 100644 mysql-test/std_data/ctype_upgrade/mariadb100428_ucs2_general_ci.frm diff --git a/mysql-test/main/ctype_ucs.result b/mysql-test/main/ctype_ucs.result index 3e3115028ffbc..efd779900109c 100644 --- a/mysql-test/main/ctype_ucs.result +++ b/mysql-test/main/ctype_ucs.result @@ -6442,5 +6442,22 @@ IS_IPV4('10.0.0.1') 1 SET NAMES utf8; # +# MDEV-30746 Regression in ucs2_general_mysql500_ci +# +SET NAMES utf8mb3; +CREATE TABLE t1 (a VARCHAR(32) CHARACTER SET ucs2 COLLATE ucs2_general_mysql500_ci); +INSERT INTO t1 VALUES ('s'),('z'),(_latin1 0xDF); +SELECT GROUP_CONCAT(a) FROM t1 GROUP BY a ORDER BY a; +GROUP_CONCAT(a) +s +z +ß +SELECT a, HEX(a), HEX(WEIGHT_STRING(a)) FROM t1 ORDER BY a; +a HEX(a) HEX(WEIGHT_STRING(a)) +s 0073 0053 +z 007A 005A +ß 00DF 00DF +DROP TABLE t1; +# # End of 10.4 tests # diff --git a/mysql-test/main/ctype_ucs.test b/mysql-test/main/ctype_ucs.test index e0bcae3f13d5a..9bff79abe22ef 100644 --- a/mysql-test/main/ctype_ucs.test +++ b/mysql-test/main/ctype_ucs.test @@ -1136,6 +1136,18 @@ SELECT IS_IPV6('::'); SELECT IS_IPV4('10.0.0.1'); SET NAMES utf8; +--echo # +--echo # MDEV-30746 Regression in ucs2_general_mysql500_ci +--echo # + +SET NAMES utf8mb3; +CREATE TABLE t1 (a VARCHAR(32) CHARACTER SET ucs2 COLLATE ucs2_general_mysql500_ci); +INSERT INTO t1 VALUES ('s'),('z'),(_latin1 0xDF); +SELECT GROUP_CONCAT(a) FROM t1 GROUP BY a ORDER BY a; +SELECT a, HEX(a), HEX(WEIGHT_STRING(a)) FROM t1 ORDER BY a; +DROP TABLE t1; + + --echo # --echo # End of 10.4 tests --echo # diff --git a/mysql-test/main/ctype_upgrade.result b/mysql-test/main/ctype_upgrade.result index 960d44f5937bc..b995e9f626571 100644 --- a/mysql-test/main/ctype_upgrade.result +++ b/mysql-test/main/ctype_upgrade.result @@ -399,3 +399,56 @@ DROP TABLE maria050313_utf8_croatian_ci; DROP TABLE maria050533_xxx_croatian_ci; DROP TABLE maria100004_xxx_croatian_ci; DROP TABLE mysql050614_xxx_croatian_ci; +# +# Start of 10.4 tests +# +# +# MDEV-30746 Regression in ucs2_general_mysql500_ci +# +SET NAMES utf8mb3; +SHOW CREATE TABLE t1; +ERROR HY000: Table rebuild required. Please do "ALTER TABLE `test.t1` FORCE" or dump/reload to fix it! +SELECT * FROM t1; +ERROR HY000: Table rebuild required. Please do "ALTER TABLE `test.t1` FORCE" or dump/reload to fix it! +SELECT * FROM t1 IGNORE KEY(a); +ERROR HY000: Table rebuild required. Please do "ALTER TABLE `test.t1` FORCE" or dump/reload to fix it! +CHECK TABLE t1; +Table Op Msg_type Msg_text +test.t1 check error Upgrade required. Please do "REPAIR TABLE `t1`" or dump/reload to fix it! +REPAIR TABLE t1; +Table Op Msg_type Msg_text +test.t1 repair status OK +SELECT a, HEX(a), HEX(WEIGHT_STRING(a)) FROM t1 ORDER BY a; +a HEX(a) HEX(WEIGHT_STRING(a)) +s 0073 0053 +z 007A 005A +ß 00DF 00DF +SELECT a, HEX(a), HEX(WEIGHT_STRING(a)) FROM t1 FORCE KEY(a) ORDER BY a; +a HEX(a) HEX(WEIGHT_STRING(a)) +s 0073 0053 +z 007A 005A +ß 00DF 00DF +SELECT a, HEX(a), HEX(WEIGHT_STRING(a)) FROM t1 IGNORE KEY(a) ORDER BY a; +a HEX(a) HEX(WEIGHT_STRING(a)) +s 0073 0053 +z 007A 005A +ß 00DF 00DF +SELECT GROUP_CONCAT(a) FROM t1 GROUP BY a ORDER BY a; +GROUP_CONCAT(a) +s +z +ß +SELECT GROUP_CONCAT(a) FROM t1 IGNORE KEY(a) GROUP BY a ORDER BY a; +GROUP_CONCAT(a) +s +z +ß +SELECT GROUP_CONCAT(a) FROM t1 FORCE KEY(a) GROUP BY a ORDER BY a; +GROUP_CONCAT(a) +s +z +ß +DROP TABLE t1; +# +# End of 10.4 tests +# diff --git a/mysql-test/main/ctype_upgrade.test b/mysql-test/main/ctype_upgrade.test index fee962e7ceb57..7cb1ec9b69d60 100644 --- a/mysql-test/main/ctype_upgrade.test +++ b/mysql-test/main/ctype_upgrade.test @@ -203,3 +203,38 @@ DROP TABLE maria050313_utf8_croatian_ci; DROP TABLE maria050533_xxx_croatian_ci; DROP TABLE maria100004_xxx_croatian_ci; DROP TABLE mysql050614_xxx_croatian_ci; + + +--echo # +--echo # Start of 10.4 tests +--echo # + +--echo # +--echo # MDEV-30746 Regression in ucs2_general_mysql500_ci +--echo # + +SET NAMES utf8mb3; + +copy_file std_data/ctype_upgrade/mariadb100428_ucs2_general_ci.frm $MYSQLD_DATADIR/test/t1.frm; +copy_file std_data/ctype_upgrade/mariadb100428_ucs2_general_ci.MYD $MYSQLD_DATADIR/test/t1.MYD; +copy_file std_data/ctype_upgrade/mariadb100428_ucs2_general_ci.MYI $MYSQLD_DATADIR/test/t1.MYI; + +--error ER_TABLE_NEEDS_REBUILD +SHOW CREATE TABLE t1; +--error ER_TABLE_NEEDS_REBUILD +SELECT * FROM t1; +--error ER_TABLE_NEEDS_REBUILD +SELECT * FROM t1 IGNORE KEY(a); +CHECK TABLE t1; +REPAIR TABLE t1; +SELECT a, HEX(a), HEX(WEIGHT_STRING(a)) FROM t1 ORDER BY a; +SELECT a, HEX(a), HEX(WEIGHT_STRING(a)) FROM t1 FORCE KEY(a) ORDER BY a; +SELECT a, HEX(a), HEX(WEIGHT_STRING(a)) FROM t1 IGNORE KEY(a) ORDER BY a; +SELECT GROUP_CONCAT(a) FROM t1 GROUP BY a ORDER BY a; +SELECT GROUP_CONCAT(a) FROM t1 IGNORE KEY(a) GROUP BY a ORDER BY a; +SELECT GROUP_CONCAT(a) FROM t1 FORCE KEY(a) GROUP BY a ORDER BY a; +DROP TABLE t1; + +--echo # +--echo # End of 10.4 tests +--echo # diff --git a/mysql-test/std_data/ctype_upgrade/mariadb100428_ucs2_general_ci.MYD b/mysql-test/std_data/ctype_upgrade/mariadb100428_ucs2_general_ci.MYD new file mode 100644 index 0000000000000000000000000000000000000000..77a281667b55cc2362fbb0d7734cbc65665140c3 GIT binary patch literal 60 dcmZQ(VBz`4#8AwD1ehUWRY*b%P_g^SVgRRh1qJ{B literal 0 HcmV?d00001 diff --git a/mysql-test/std_data/ctype_upgrade/mariadb100428_ucs2_general_ci.MYI b/mysql-test/std_data/ctype_upgrade/mariadb100428_ucs2_general_ci.MYI new file mode 100644 index 0000000000000000000000000000000000000000..20fc1b97c00fd3e7270fab2b6ceb7444023b1a8c GIT binary patch literal 2048 zcmezOkDZZ$nK6W6149bK5e7yEAmRX$3=Ee4K_n0`Lnt`O{2vM+A{;OY8yEvO?RpI; zX91N5+rq%W!hmWX14HuPnX$-fkodTb2AV@8a003WVJ0AU24WE?n}LlD;v}F+0YEVn zz{tpu0Tg#<;9&6JpAY0QFi0>s07Xf|W4;fj VHJGcwG$>s->mysql_version; - if (mysql_version < 50124) + if (mysql_version < Charset::latest_mariadb_version_with_collation_change()) { KEY *key= table->key_info; KEY *key_end= key + table->s->keys; @@ -4124,18 +4124,7 @@ int handler::check_collation_compatibility() continue; Field *field= table->field[key_part->fieldnr - 1]; uint cs_number= field->charset()->number; - if ((mysql_version < 50048 && - (cs_number == 11 || /* ascii_general_ci - bug #29499, bug #27562 */ - cs_number == 41 || /* latin7_general_ci - bug #29461 */ - cs_number == 42 || /* latin7_general_cs - bug #29461 */ - cs_number == 20 || /* latin7_estonian_cs - bug #29461 */ - cs_number == 21 || /* latin2_hungarian_ci - bug #29461 */ - cs_number == 22 || /* koi8u_general_ci - bug #29461 */ - cs_number == 23 || /* cp1251_ukrainian_ci - bug #29461 */ - cs_number == 26)) || /* cp1250_general_ci - bug #29461 */ - (mysql_version < 50124 && - (cs_number == 33 || /* utf8_general_ci - bug #27877 */ - cs_number == 35))) /* ucs2_general_ci - bug #27877 */ + if (Charset::collation_changed_order(mysql_version, cs_number)) return HA_ADMIN_NEEDS_UPGRADE; } } diff --git a/sql/sql_string.h b/sql/sql_string.h index 33efd783d7369..491e27666439f 100644 --- a/sql/sql_string.h +++ b/sql/sql_string.h @@ -184,6 +184,83 @@ class Charset { return m_charset != &my_charset_bin; } + + /* + The MariaDB version when the last collation change happened, + e.g. due to a bug fix. See functions below. + */ + static ulong latest_mariadb_version_with_collation_change() + { + return 110002; + } + + /* + Check if the collation with the given ID changed its order + since the given MariaDB version. + */ + static bool collation_changed_order(ulong mysql_version, uint cs_number) + { + if ((mysql_version < 50048 && + (cs_number == 11 || /* ascii_general_ci - bug #29499, bug #27562 */ + cs_number == 41 || /* latin7_general_ci - bug #29461 */ + cs_number == 42 || /* latin7_general_cs - bug #29461 */ + cs_number == 20 || /* latin7_estonian_cs - bug #29461 */ + cs_number == 21 || /* latin2_hungarian_ci - bug #29461 */ + cs_number == 22 || /* koi8u_general_ci - bug #29461 */ + cs_number == 23 || /* cp1251_ukrainian_ci - bug #29461 */ + cs_number == 26)) || /* cp1250_general_ci - bug #29461 */ + (mysql_version < 50124 && + (cs_number == 33 || /* utf8_general_ci - bug #27877 */ + cs_number == 35))) /* ucs2_general_ci - bug #27877 */ + return true; + + if (cs_number == 159 && /* ucs2_general_mysql500_ci - MDEV-30746 */ + ((mysql_version >= 100400 && mysql_version < 100429) || + (mysql_version >= 100500 && mysql_version < 100520) || + (mysql_version >= 100600 && mysql_version < 100613) || + (mysql_version >= 100700 && mysql_version < 100708) || + (mysql_version >= 100800 && mysql_version < 100808) || + (mysql_version >= 100900 && mysql_version < 100906) || + (mysql_version >= 101000 && mysql_version < 101004) || + (mysql_version >= 101100 && mysql_version < 101103) || + (mysql_version >= 110000 && mysql_version < 110002))) + return true; + return false; + } + + /** + Check if a collation has changed ID since the given version. + Return the new ID. + + @param mysql_version + @param cs_number - collation ID + + @retval the new collation ID (or cs_number, if no change) + */ + + static uint upgrade_collation_id(ulong mysql_version, uint cs_number) + { + if (mysql_version >= 50300 && mysql_version <= 50399) + { + switch (cs_number) { + case 149: return MY_PAGE2_COLLATION_ID_UCS2; // ucs2_crotian_ci + case 213: return MY_PAGE2_COLLATION_ID_UTF8; // utf8_crotian_ci + } + } + if ((mysql_version >= 50500 && mysql_version <= 50599) || + (mysql_version >= 100000 && mysql_version <= 100005)) + { + switch (cs_number) { + case 149: return MY_PAGE2_COLLATION_ID_UCS2; // ucs2_crotian_ci + case 213: return MY_PAGE2_COLLATION_ID_UTF8; // utf8_crotian_ci + case 214: return MY_PAGE2_COLLATION_ID_UTF32; // utf32_croatian_ci + case 215: return MY_PAGE2_COLLATION_ID_UTF16; // utf16_croatian_ci + case 245: return MY_PAGE2_COLLATION_ID_UTF8MB4;// utf8mb4_croatian_ci + } + } + return cs_number; + } + }; diff --git a/sql/table.cc b/sql/table.cc index 141b2e4888042..20622d0e09fb9 100644 --- a/sql/table.cc +++ b/sql/table.cc @@ -929,39 +929,6 @@ static uint enum_value_with_check(THD *thd, TABLE_SHARE *share, } -/** - Check if a collation has changed number - - @param mysql_version - @param current collation number - - @retval new collation number (same as current collation number of no change) -*/ - -static uint upgrade_collation(ulong mysql_version, uint cs_number) -{ - if (mysql_version >= 50300 && mysql_version <= 50399) - { - switch (cs_number) { - case 149: return MY_PAGE2_COLLATION_ID_UCS2; // ucs2_crotian_ci - case 213: return MY_PAGE2_COLLATION_ID_UTF8; // utf8_crotian_ci - } - } - if ((mysql_version >= 50500 && mysql_version <= 50599) || - (mysql_version >= 100000 && mysql_version <= 100005)) - { - switch (cs_number) { - case 149: return MY_PAGE2_COLLATION_ID_UCS2; // ucs2_crotian_ci - case 213: return MY_PAGE2_COLLATION_ID_UTF8; // utf8_crotian_ci - case 214: return MY_PAGE2_COLLATION_ID_UTF32; // utf32_croatian_ci - case 215: return MY_PAGE2_COLLATION_ID_UTF16; // utf16_croatian_ci - case 245: return MY_PAGE2_COLLATION_ID_UTF8MB4;// utf8mb4_croatian_ci - } - } - return cs_number; -} - - void Column_definition_attributes::frm_pack_basic(uchar *buff) const { int2store(buff + 3, length); @@ -989,7 +956,7 @@ bool Column_definition_attributes::frm_unpack_charset(TABLE_SHARE *share, const uchar *buff) { uint cs_org= buff[14] + (((uint) buff[11]) << 8); - uint cs_new= upgrade_collation(share->mysql_version, cs_org); + uint cs_new= Charset::upgrade_collation_id(share->mysql_version, cs_org); if (cs_org != cs_new) share->incompatible_version|= HA_CREATE_USED_CHARSET; if (cs_new && !(charset= get_charset(cs_new, MYF(0)))) @@ -1735,7 +1702,7 @@ int TABLE_SHARE::init_from_binary_frm_image(THD *thd, bool write, if (!frm_image[32]) // New frm file in 3.23 { uint cs_org= (((uint) frm_image[41]) << 8) + (uint) frm_image[38]; - uint cs_new= upgrade_collation(share->mysql_version, cs_org); + uint cs_new= Charset::upgrade_collation_id(share->mysql_version, cs_org); if (cs_org != cs_new) share->incompatible_version|= HA_CREATE_USED_CHARSET; @@ -2760,6 +2727,9 @@ int TABLE_SHARE::init_from_binary_frm_image(THD *thd, bool write, goto err; field= key_part->field= share->field[key_part->fieldnr-1]; + if (Charset::collation_changed_order(share->mysql_version, + field->charset()->number)) + share->incompatible_version|= HA_CREATE_USED_CHARSET; key_part->type= field->key_type(); if (field->invisible > INVISIBLE_USER && !field->vers_sys_field()) diff --git a/strings/ctype-ucs2.c b/strings/ctype-ucs2.c index 2e6b1239c0a54..80a267dbf1d66 100644 --- a/strings/ctype-ucs2.c +++ b/strings/ctype-ucs2.c @@ -2987,6 +2987,14 @@ static inline int my_weight_mb2_ucs2_general_ci(uchar b0, uchar b1) } +static inline int my_weight_mb2_ucs2_general_mysql500_ci(uchar b0, uchar b1) +{ + my_wc_t wc= UCS2_CODE(b0, b1); + MY_UNICASE_CHARACTER *page= my_unicase_mysql500_pages[wc >> 8]; + return (int) (page ? page[wc & 0xFF].sort : wc); +} + + #define MY_FUNCTION_NAME(x) my_ ## x ## _ucs2_general_ci #define DEFINE_STRNXFRM_UNICODE #define DEFINE_STRNXFRM_UNICODE_NOPAD @@ -3000,6 +3008,18 @@ static inline int my_weight_mb2_ucs2_general_ci(uchar b0, uchar b1) #include "strcoll.inl" +#define MY_FUNCTION_NAME(x) my_ ## x ## _ucs2_general_mysql500_ci +#define DEFINE_STRNXFRM_UNICODE +#define MY_MB_WC(cs, pwc, s, e) my_mb_wc_ucs2_quick(pwc, s, e) +#define OPTIMIZE_ASCII 0 +#define UNICASE_MAXCHAR MY_UNICASE_INFO_DEFAULT_MAXCHAR +#define UNICASE_PAGE0 my_unicase_mysql500_page00 +#define UNICASE_PAGES my_unicase_mysql500_pages +#define WEIGHT_ILSEQ(x) (0xFF0000 + (uchar) (x)) +#define WEIGHT_MB2(b0,b1) my_weight_mb2_ucs2_general_mysql500_ci(b0,b1) +#include "strcoll.inl" + + #define MY_FUNCTION_NAME(x) my_ ## x ## _ucs2_bin #define DEFINE_STRNXFRM_UNICODE_BIN2 #define MY_MB_WC(cs, pwc, s, e) my_mb_wc_ucs2_quick(pwc, s, e) @@ -3285,6 +3305,23 @@ static MY_COLLATION_HANDLER my_collation_ucs2_general_ci_handler = }; +static MY_COLLATION_HANDLER my_collation_ucs2_general_mysql500_ci_handler = +{ + NULL, /* init */ + my_strnncoll_ucs2_general_mysql500_ci, + my_strnncollsp_ucs2_general_mysql500_ci, + my_strnncollsp_nchars_ucs2_general_mysql500_ci, + my_strnxfrm_ucs2_general_mysql500_ci, + my_strnxfrmlen_unicode, + my_like_range_generic, + my_wildcmp_ucs2_ci, + my_strcasecmp_mb2_or_mb4, + my_instr_mb, + my_hash_sort_ucs2, + my_propagate_simple +}; + + static MY_COLLATION_HANDLER my_collation_ucs2_bin_handler = { NULL, /* init */ @@ -3431,7 +3468,7 @@ struct charset_info_st my_charset_ucs2_general_mysql500_ci= 0, /* escape_with_backslash_is_dangerous */ 1, /* levels_for_order */ &my_charset_ucs2_handler, - &my_collation_ucs2_general_ci_handler + &my_collation_ucs2_general_mysql500_ci_handler }; diff --git a/strings/ctype-unidata.h b/strings/ctype-unidata.h index 6712f5e1d79a9..9900fd0ceddda 100644 --- a/strings/ctype-unidata.h +++ b/strings/ctype-unidata.h @@ -21,6 +21,9 @@ extern MY_UNICASE_CHARACTER my_unicase_default_page00[256]; extern MY_UNICASE_CHARACTER *my_unicase_default_pages[256]; +extern MY_UNICASE_CHARACTER my_unicase_mysql500_page00[256]; +extern MY_UNICASE_CHARACTER *my_unicase_mysql500_pages[256]; + size_t my_strxfrm_pad_nweights_unicode(uchar *str, uchar *strend, size_t nweights); size_t my_strxfrm_pad_unicode(uchar *str, uchar *strend); diff --git a/strings/ctype-utf8.c b/strings/ctype-utf8.c index 69ebb6b523ee7..cdac17be3c6c3 100644 --- a/strings/ctype-utf8.c +++ b/strings/ctype-utf8.c @@ -248,7 +248,7 @@ MY_UNICASE_CHARACTER my_unicase_default_page00[]={ Almost similar to my_unicase_default_page00, but maps sorting order for U+00DF to 0x00DF instead of 0x0053. */ -static MY_UNICASE_CHARACTER plane00_mysql500[]={ +MY_UNICASE_CHARACTER my_unicase_mysql500_page00[]={ {0x0000,0x0000,0x0000}, {0x0001,0x0001,0x0001}, {0x0002,0x0002,0x0002}, {0x0003,0x0003,0x0003}, {0x0004,0x0004,0x0004}, {0x0005,0x0005,0x0005}, @@ -1739,8 +1739,8 @@ MY_UNICASE_INFO my_unicase_default= /* Reproduce old utf8_general_ci behaviour before we fixed Bug#27877. */ -MY_UNICASE_CHARACTER *my_unicase_pages_mysql500[256]={ - plane00_mysql500, +MY_UNICASE_CHARACTER *my_unicase_mysql500_pages[256]={ + my_unicase_mysql500_page00, plane01, plane02, plane03, plane04, plane05, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, @@ -1780,7 +1780,7 @@ MY_UNICASE_CHARACTER *my_unicase_pages_mysql500[256]={ MY_UNICASE_INFO my_unicase_mysql500= { 0xFFFF, - my_unicase_pages_mysql500 + my_unicase_mysql500_pages }; @@ -5266,14 +5266,14 @@ static inline int my_weight_mb3_utf8_general_ci(uchar b0, uchar b1, uchar b2) static inline int my_weight_mb1_utf8_general_mysql500_ci(uchar b) { - return (int) plane00_mysql500[b & 0xFF].sort; + return (int) my_unicase_mysql500_page00[b & 0xFF].sort; } static inline int my_weight_mb2_utf8_general_mysql500_ci(uchar b0, uchar b1) { my_wc_t wc= UTF8MB2_CODE(b0, b1); - MY_UNICASE_CHARACTER *page= my_unicase_pages_mysql500[wc >> 8]; + MY_UNICASE_CHARACTER *page= my_unicase_mysql500_pages[wc >> 8]; return (int) (page ? page[wc & 0xFF].sort : wc); } @@ -5282,7 +5282,7 @@ static inline int my_weight_mb3_utf8_general_mysql500_ci(uchar b0, uchar b1, uchar b2) { my_wc_t wc= UTF8MB3_CODE(b0, b1, b2); - MY_UNICASE_CHARACTER *page= my_unicase_pages_mysql500[wc >> 8]; + MY_UNICASE_CHARACTER *page= my_unicase_mysql500_pages[wc >> 8]; return (int) (page ? page[wc & 0xFF].sort : wc); } @@ -5292,8 +5292,8 @@ my_weight_mb3_utf8_general_mysql500_ci(uchar b0, uchar b1, uchar b2) #define MY_MB_WC(cs, pwc, s, e) my_mb_wc_utf8mb3_quick(pwc, s, e) #define OPTIMIZE_ASCII 1 #define UNICASE_MAXCHAR MY_UNICASE_INFO_DEFAULT_MAXCHAR -#define UNICASE_PAGE0 plane00_mysql500 -#define UNICASE_PAGES my_unicase_pages_mysql500 +#define UNICASE_PAGE0 my_unicase_mysql500_page00 +#define UNICASE_PAGES my_unicase_mysql500_pages #define WEIGHT_ILSEQ(x) (0xFF0000 + (uchar) (x)) #define WEIGHT_MB1(x) my_weight_mb1_utf8_general_mysql500_ci(x) #define WEIGHT_MB2(x,y) my_weight_mb2_utf8_general_mysql500_ci(x,y) From acfb5dfd973e0b63090a32bbf90f380317192ab5 Mon Sep 17 00:00:00 2001 From: Lorna Luo Date: Wed, 1 Mar 2023 20:46:18 +0000 Subject: [PATCH 27/92] MDEV-22683: Ensure system tables are correctly upgraded in MariaDB 10.4 Running mysql_upgrade should end up with the exact same system tables as fresh installations have after running mysql_install_db. To ensure the upgrade is correct and complete: - Remove the redundant modification of thread_id`. On 5.5 version, the `general_log` table was created as `CREATE TABLE IF NOT EXISTS general_log (..., thread_id INTEGER NOT NULL, ...)`, and starting from 10.0+, the table is created as `CREATE TABLE IF NOT EXISTS general_log (..., thread_id BIGINT(21) UNSIGNED NOT NULL, ...)`, but mysql_upgrade is not properly upgrading the table. It modifies the `thread_id` twice in one query, which could leave the table not modified and lead to other potential error when upgrading from MariaDB 5.5 or older. - Update `servers` to ensure `Host` and `User` has correct data type if upgrading from 10.1 or older. On versions 10.0 and 10.1, the `servers` table was created as `CREATE TABLE IF NOT EXISTS servers (..., Host char(64) NOT NULL DEFAULT , ..., Owner char(64) NOT NULL DEFAULT , ...)`, and starting from 10.2, the table is created as `CREATE TABLE IF NOT EXISTS servers (..., Host varchar(2048) NOT NULL DEFAULT , ..., Owner varchar(512) NOT NULL DEFAULT , ...)`. All new code of the whole pull request, including one or several files that are either new files or modified ones, are contributed under the BSD-new license. I am contributing on behalf of my employer Amazon Web Services, Inc. --- .../main/system_mysql_db_fix50030.result | 4 +- .../main/system_mysql_db_fix50117.result | 4 +- .../main/system_mysql_db_fix50568.result | 297 ++++++++++++++++++ mysql-test/main/system_mysql_db_fix50568.test | 99 ++++++ scripts/mysql_system_tables_fix.sql | 6 +- 5 files changed, 405 insertions(+), 5 deletions(-) create mode 100644 mysql-test/main/system_mysql_db_fix50568.result create mode 100644 mysql-test/main/system_mysql_db_fix50568.test diff --git a/mysql-test/main/system_mysql_db_fix50030.result b/mysql-test/main/system_mysql_db_fix50030.result index f6edd82182204..b02a50a8d3dee 100644 --- a/mysql-test/main/system_mysql_db_fix50030.result +++ b/mysql-test/main/system_mysql_db_fix50030.result @@ -166,14 +166,14 @@ show create table servers; Table Create Table servers CREATE TABLE `servers` ( `Server_name` char(64) NOT NULL DEFAULT '', - `Host` char(64) NOT NULL DEFAULT '', + `Host` varchar(2048) NOT NULL DEFAULT '', `Db` char(64) NOT NULL DEFAULT '', `Username` char(80) NOT NULL DEFAULT '', `Password` char(64) NOT NULL DEFAULT '', `Port` int(4) NOT NULL DEFAULT 0, `Socket` char(64) NOT NULL DEFAULT '', `Wrapper` char(64) NOT NULL DEFAULT '', - `Owner` char(64) NOT NULL DEFAULT '', + `Owner` varchar(512) NOT NULL DEFAULT '', PRIMARY KEY (`Server_name`) ) ENGINE=Aria DEFAULT CHARSET=utf8 COLLATE=utf8_general_ci PAGE_CHECKSUM=1 TRANSACTIONAL=1 COMMENT='MySQL Foreign Servers table' show create table proc; diff --git a/mysql-test/main/system_mysql_db_fix50117.result b/mysql-test/main/system_mysql_db_fix50117.result index 84861744a7025..ca817b198c6a0 100644 --- a/mysql-test/main/system_mysql_db_fix50117.result +++ b/mysql-test/main/system_mysql_db_fix50117.result @@ -146,14 +146,14 @@ show create table servers; Table Create Table servers CREATE TABLE `servers` ( `Server_name` char(64) NOT NULL DEFAULT '', - `Host` char(64) NOT NULL DEFAULT '', + `Host` varchar(2048) NOT NULL DEFAULT '', `Db` char(64) NOT NULL DEFAULT '', `Username` char(80) NOT NULL DEFAULT '', `Password` char(64) NOT NULL DEFAULT '', `Port` int(4) NOT NULL DEFAULT 0, `Socket` char(64) NOT NULL DEFAULT '', `Wrapper` char(64) NOT NULL DEFAULT '', - `Owner` char(64) NOT NULL DEFAULT '', + `Owner` varchar(512) NOT NULL DEFAULT '', PRIMARY KEY (`Server_name`) ) ENGINE=Aria DEFAULT CHARSET=utf8 COLLATE=utf8_general_ci PAGE_CHECKSUM=1 TRANSACTIONAL=1 COMMENT='MySQL Foreign Servers table' show create table proc; diff --git a/mysql-test/main/system_mysql_db_fix50568.result b/mysql-test/main/system_mysql_db_fix50568.result new file mode 100644 index 0000000000000..898b11a6ce4b2 --- /dev/null +++ b/mysql-test/main/system_mysql_db_fix50568.result @@ -0,0 +1,297 @@ +use test; +CREATE TABLE IF NOT EXISTS db ( Host char(60) binary DEFAULT '' NOT NULL, Db char(64) binary DEFAULT '' NOT NULL, User char(16) binary DEFAULT '' NOT NULL, Select_priv enum('N','Y') COLLATE utf8_general_ci DEFAULT 'N' NOT NULL, Insert_priv enum('N','Y') COLLATE utf8_general_ci DEFAULT 'N' NOT NULL, Update_priv enum('N','Y') COLLATE utf8_general_ci DEFAULT 'N' NOT NULL, Delete_priv enum('N','Y') COLLATE utf8_general_ci DEFAULT 'N' NOT NULL, Create_priv enum('N','Y') COLLATE utf8_general_ci DEFAULT 'N' NOT NULL, Drop_priv enum('N','Y') COLLATE utf8_general_ci DEFAULT 'N' NOT NULL, Grant_priv enum('N','Y') COLLATE utf8_general_ci DEFAULT 'N' NOT NULL, References_priv enum('N','Y') COLLATE utf8_general_ci DEFAULT 'N' NOT NULL, Index_priv enum('N','Y') COLLATE utf8_general_ci DEFAULT 'N' NOT NULL, Alter_priv enum('N','Y') COLLATE utf8_general_ci DEFAULT 'N' NOT NULL, Create_tmp_table_priv enum('N','Y') COLLATE utf8_general_ci DEFAULT 'N' NOT NULL, Lock_tables_priv enum('N','Y') COLLATE utf8_general_ci DEFAULT 'N' NOT NULL, Create_view_priv enum('N','Y') COLLATE utf8_general_ci DEFAULT 'N' NOT NULL, Show_view_priv enum('N','Y') COLLATE utf8_general_ci DEFAULT 'N' NOT NULL, Create_routine_priv enum('N','Y') COLLATE utf8_general_ci DEFAULT 'N' NOT NULL, Alter_routine_priv enum('N','Y') COLLATE utf8_general_ci DEFAULT 'N' NOT NULL, Execute_priv enum('N','Y') COLLATE utf8_general_ci DEFAULT 'N' NOT NULL, Event_priv enum('N','Y') COLLATE utf8_general_ci DEFAULT 'N' NOT NULL, Trigger_priv enum('N','Y') COLLATE utf8_general_ci DEFAULT 'N' NOT NULL, PRIMARY KEY Host (Host,Db,User), KEY User (User) ) engine=MyISAM CHARACTER SET utf8 COLLATE utf8_bin comment='Database privileges'; +Warnings: +Warning 1280 Name 'Host' ignored for PRIMARY key. +CREATE TABLE IF NOT EXISTS host ( Host char(60) binary DEFAULT '' NOT NULL, Db char(64) binary DEFAULT '' NOT NULL, Select_priv enum('N','Y') COLLATE utf8_general_ci DEFAULT 'N' NOT NULL, Insert_priv enum('N','Y') COLLATE utf8_general_ci DEFAULT 'N' NOT NULL, Update_priv enum('N','Y') COLLATE utf8_general_ci DEFAULT 'N' NOT NULL, Delete_priv enum('N','Y') COLLATE utf8_general_ci DEFAULT 'N' NOT NULL, Create_priv enum('N','Y') COLLATE utf8_general_ci DEFAULT 'N' NOT NULL, Drop_priv enum('N','Y') COLLATE utf8_general_ci DEFAULT 'N' NOT NULL, Grant_priv enum('N','Y') COLLATE utf8_general_ci DEFAULT 'N' NOT NULL, References_priv enum('N','Y') COLLATE utf8_general_ci DEFAULT 'N' NOT NULL, Index_priv enum('N','Y') COLLATE utf8_general_ci DEFAULT 'N' NOT NULL, Alter_priv enum('N','Y') COLLATE utf8_general_ci DEFAULT 'N' NOT NULL, Create_tmp_table_priv enum('N','Y') COLLATE utf8_general_ci DEFAULT 'N' NOT NULL, Lock_tables_priv enum('N','Y') COLLATE utf8_general_ci DEFAULT 'N' NOT NULL, Create_view_priv enum('N','Y') COLLATE utf8_general_ci DEFAULT 'N' NOT NULL, Show_view_priv enum('N','Y') COLLATE utf8_general_ci DEFAULT 'N' NOT NULL, Create_routine_priv enum('N','Y') COLLATE utf8_general_ci DEFAULT 'N' NOT NULL, Alter_routine_priv enum('N','Y') COLLATE utf8_general_ci DEFAULT 'N' NOT NULL, Execute_priv enum('N','Y') COLLATE utf8_general_ci DEFAULT 'N' NOT NULL, Trigger_priv enum('N','Y') COLLATE utf8_general_ci DEFAULT 'N' NOT NULL, PRIMARY KEY Host (Host,Db) ) engine=MyISAM CHARACTER SET utf8 COLLATE utf8_bin comment='Host privileges; Merged with database privileges'; +Warnings: +Warning 1280 Name 'Host' ignored for PRIMARY key. +CREATE TABLE IF NOT EXISTS user ( Host char(60) binary DEFAULT '' NOT NULL, User char(16) binary DEFAULT '' NOT NULL, Password char(41) character set latin1 collate latin1_bin DEFAULT '' NOT NULL, Select_priv enum('N','Y') COLLATE utf8_general_ci DEFAULT 'N' NOT NULL, Insert_priv enum('N','Y') COLLATE utf8_general_ci DEFAULT 'N' NOT NULL, Update_priv enum('N','Y') COLLATE utf8_general_ci DEFAULT 'N' NOT NULL, Delete_priv enum('N','Y') COLLATE utf8_general_ci DEFAULT 'N' NOT NULL, Create_priv enum('N','Y') COLLATE utf8_general_ci DEFAULT 'N' NOT NULL, Drop_priv enum('N','Y') COLLATE utf8_general_ci DEFAULT 'N' NOT NULL, Reload_priv enum('N','Y') COLLATE utf8_general_ci DEFAULT 'N' NOT NULL, Shutdown_priv enum('N','Y') COLLATE utf8_general_ci DEFAULT 'N' NOT NULL, Process_priv enum('N','Y') COLLATE utf8_general_ci DEFAULT 'N' NOT NULL, File_priv enum('N','Y') COLLATE utf8_general_ci DEFAULT 'N' NOT NULL, Grant_priv enum('N','Y') COLLATE utf8_general_ci DEFAULT 'N' NOT NULL, References_priv enum('N','Y') COLLATE utf8_general_ci DEFAULT 'N' NOT NULL, Index_priv enum('N','Y') COLLATE utf8_general_ci DEFAULT 'N' NOT NULL, Alter_priv enum('N','Y') COLLATE utf8_general_ci DEFAULT 'N' NOT NULL, Show_db_priv enum('N','Y') COLLATE utf8_general_ci DEFAULT 'N' NOT NULL, Super_priv enum('N','Y') COLLATE utf8_general_ci DEFAULT 'N' NOT NULL, Create_tmp_table_priv enum('N','Y') COLLATE utf8_general_ci DEFAULT 'N' NOT NULL, Lock_tables_priv enum('N','Y') COLLATE utf8_general_ci DEFAULT 'N' NOT NULL, Execute_priv enum('N','Y') COLLATE utf8_general_ci DEFAULT 'N' NOT NULL, Repl_slave_priv enum('N','Y') COLLATE utf8_general_ci DEFAULT 'N' NOT NULL, Repl_client_priv enum('N','Y') COLLATE utf8_general_ci DEFAULT 'N' NOT NULL, Create_view_priv enum('N','Y') COLLATE utf8_general_ci DEFAULT 'N' NOT NULL, Show_view_priv enum('N','Y') COLLATE utf8_general_ci DEFAULT 'N' NOT NULL, Create_routine_priv enum('N','Y') COLLATE utf8_general_ci DEFAULT 'N' NOT NULL, Alter_routine_priv enum('N','Y') COLLATE utf8_general_ci DEFAULT 'N' NOT NULL, Create_user_priv enum('N','Y') COLLATE utf8_general_ci DEFAULT 'N' NOT NULL, Event_priv enum('N','Y') COLLATE utf8_general_ci DEFAULT 'N' NOT NULL, Trigger_priv enum('N','Y') COLLATE utf8_general_ci DEFAULT 'N' NOT NULL, Create_tablespace_priv enum('N','Y') COLLATE utf8_general_ci DEFAULT 'N' NOT NULL, ssl_type enum('','ANY','X509', 'SPECIFIED') COLLATE utf8_general_ci DEFAULT '' NOT NULL, ssl_cipher BLOB NOT NULL, x509_issuer BLOB NOT NULL, x509_subject BLOB NOT NULL, max_questions int(11) unsigned DEFAULT 0 NOT NULL, max_updates int(11) unsigned DEFAULT 0 NOT NULL, max_connections int(11) unsigned DEFAULT 0 NOT NULL, max_user_connections int(11) DEFAULT 0 NOT NULL, plugin char(64) CHARACTER SET latin1 DEFAULT '' NOT NULL, authentication_string TEXT NOT NULL, PRIMARY KEY Host (Host,User) ) engine=MyISAM CHARACTER SET utf8 COLLATE utf8_bin comment='Users and global privileges'; +Warnings: +Warning 1280 Name 'Host' ignored for PRIMARY key. +CREATE TABLE IF NOT EXISTS func ( name char(64) binary DEFAULT '' NOT NULL, ret tinyint(1) DEFAULT '0' NOT NULL, dl char(128) DEFAULT '' NOT NULL, type enum ('function','aggregate') COLLATE utf8_general_ci NOT NULL, PRIMARY KEY (name) ) engine=MyISAM CHARACTER SET utf8 COLLATE utf8_bin comment='User defined functions'; +CREATE TABLE IF NOT EXISTS plugin ( name varchar(64) DEFAULT '' NOT NULL, dl varchar(128) DEFAULT '' NOT NULL, PRIMARY KEY (name) ) engine=MyISAM CHARACTER SET utf8 COLLATE utf8_general_ci comment='MySQL plugins'; +CREATE TABLE IF NOT EXISTS servers ( Server_name char(64) NOT NULL DEFAULT '', Host char(64) NOT NULL DEFAULT '', Db char(64) NOT NULL DEFAULT '', Username char(64) NOT NULL DEFAULT '', Password char(64) NOT NULL DEFAULT '', Port INT(4) NOT NULL DEFAULT '0', Socket char(64) NOT NULL DEFAULT '', Wrapper char(64) NOT NULL DEFAULT '', Owner char(64) NOT NULL DEFAULT '', PRIMARY KEY (Server_name)) CHARACTER SET utf8 comment='MySQL Foreign Servers table'; +CREATE TABLE IF NOT EXISTS tables_priv ( Host char(60) binary DEFAULT '' NOT NULL, Db char(64) binary DEFAULT '' NOT NULL, User char(16) binary DEFAULT '' NOT NULL, Table_name char(64) binary DEFAULT '' NOT NULL, Grantor char(77) DEFAULT '' NOT NULL, Timestamp timestamp, Table_priv set('Select','Insert','Update','Delete','Create','Drop','Grant','References','Index','Alter','Create View','Show view','Trigger') COLLATE utf8_general_ci DEFAULT '' NOT NULL, Column_priv set('Select','Insert','Update','References') COLLATE utf8_general_ci DEFAULT '' NOT NULL, PRIMARY KEY (Host,Db,User,Table_name), KEY Grantor (Grantor) ) engine=MyISAM CHARACTER SET utf8 COLLATE utf8_bin comment='Table privileges'; +CREATE TABLE IF NOT EXISTS columns_priv ( Host char(60) binary DEFAULT '' NOT NULL, Db char(64) binary DEFAULT '' NOT NULL, User char(16) binary DEFAULT '' NOT NULL, Table_name char(64) binary DEFAULT '' NOT NULL, Column_name char(64) binary DEFAULT '' NOT NULL, Timestamp timestamp, Column_priv set('Select','Insert','Update','References') COLLATE utf8_general_ci DEFAULT '' NOT NULL, PRIMARY KEY (Host,Db,User,Table_name,Column_name) ) engine=MyISAM CHARACTER SET utf8 COLLATE utf8_bin comment='Column privileges'; +CREATE TABLE IF NOT EXISTS help_topic ( help_topic_id int unsigned not null, name char(64) not null, help_category_id smallint unsigned not null, description text not null, example text not null, url text not null, primary key (help_topic_id), unique index (name) ) engine=MyISAM CHARACTER SET utf8 comment='help topics'; +CREATE TABLE IF NOT EXISTS help_category ( help_category_id smallint unsigned not null, name char(64) not null, parent_category_id smallint unsigned null, url text not null, primary key (help_category_id), unique index (name) ) engine=MyISAM CHARACTER SET utf8 comment='help categories'; +CREATE TABLE IF NOT EXISTS help_relation ( help_topic_id int unsigned not null references help_topic, help_keyword_id int unsigned not null references help_keyword, primary key (help_keyword_id, help_topic_id) ) engine=MyISAM CHARACTER SET utf8 comment='keyword-topic relation'; +CREATE TABLE IF NOT EXISTS help_keyword ( help_keyword_id int unsigned not null, name char(64) not null, primary key (help_keyword_id), unique index (name) ) engine=MyISAM CHARACTER SET utf8 comment='help keywords'; +CREATE TABLE IF NOT EXISTS time_zone_name ( Name char(64) NOT NULL, Time_zone_id int unsigned NOT NULL, PRIMARY KEY Name (Name) ) engine=MyISAM CHARACTER SET utf8 comment='Time zone names'; +Warnings: +Warning 1280 Name 'Name' ignored for PRIMARY key. +CREATE TABLE IF NOT EXISTS time_zone ( Time_zone_id int unsigned NOT NULL auto_increment, Use_leap_seconds enum('Y','N') COLLATE utf8_general_ci DEFAULT 'N' NOT NULL, PRIMARY KEY TzId (Time_zone_id) ) engine=MyISAM CHARACTER SET utf8 comment='Time zones'; +Warnings: +Warning 1280 Name 'TzId' ignored for PRIMARY key. +CREATE TABLE IF NOT EXISTS time_zone_transition ( Time_zone_id int unsigned NOT NULL, Transition_time bigint signed NOT NULL, Transition_type_id int unsigned NOT NULL, PRIMARY KEY TzIdTranTime (Time_zone_id, Transition_time) ) engine=MyISAM CHARACTER SET utf8 comment='Time zone transitions'; +Warnings: +Warning 1280 Name 'TzIdTranTime' ignored for PRIMARY key. +CREATE TABLE IF NOT EXISTS time_zone_transition_type ( Time_zone_id int unsigned NOT NULL, Transition_type_id int unsigned NOT NULL, Offset int signed DEFAULT 0 NOT NULL, Is_DST tinyint unsigned DEFAULT 0 NOT NULL, Abbreviation char(8) DEFAULT '' NOT NULL, PRIMARY KEY TzIdTrTId (Time_zone_id, Transition_type_id) ) engine=MyISAM CHARACTER SET utf8 comment='Time zone transition types'; +Warnings: +Warning 1280 Name 'TzIdTrTId' ignored for PRIMARY key. +CREATE TABLE IF NOT EXISTS time_zone_leap_second ( Transition_time bigint signed NOT NULL, Correction int signed NOT NULL, PRIMARY KEY TranTime (Transition_time) ) engine=MyISAM CHARACTER SET utf8 comment='Leap seconds information for time zones'; +Warnings: +Warning 1280 Name 'TranTime' ignored for PRIMARY key. +CREATE TABLE IF NOT EXISTS proc (db char(64) collate utf8_bin DEFAULT '' NOT NULL, name char(64) DEFAULT '' NOT NULL, type enum('FUNCTION','PROCEDURE') NOT NULL, specific_name char(64) DEFAULT '' NOT NULL, language enum('SQL') DEFAULT 'SQL' NOT NULL, sql_data_access enum( 'CONTAINS_SQL', 'NO_SQL', 'READS_SQL_DATA', 'MODIFIES_SQL_DATA') DEFAULT 'CONTAINS_SQL' NOT NULL, is_deterministic enum('YES','NO') DEFAULT 'NO' NOT NULL, security_type enum('INVOKER','DEFINER') DEFAULT 'DEFINER' NOT NULL, param_list blob NOT NULL, returns longblob DEFAULT '' NOT NULL, body longblob NOT NULL, definer char(77) collate utf8_bin DEFAULT '' NOT NULL, created timestamp, modified timestamp, sql_mode set( 'REAL_AS_FLOAT', 'PIPES_AS_CONCAT', 'ANSI_QUOTES', 'IGNORE_SPACE', 'IGNORE_BAD_TABLE_OPTIONS', 'ONLY_FULL_GROUP_BY', 'NO_UNSIGNED_SUBTRACTION', 'NO_DIR_IN_CREATE', 'POSTGRESQL', 'ORACLE', 'MSSQL', 'DB2', 'MAXDB', 'NO_KEY_OPTIONS', 'NO_TABLE_OPTIONS', 'NO_FIELD_OPTIONS', 'MYSQL323', 'MYSQL40', 'ANSI', 'NO_AUTO_VALUE_ON_ZERO', 'NO_BACKSLASH_ESCAPES', 'STRICT_TRANS_TABLES', 'STRICT_ALL_TABLES', 'NO_ZERO_IN_DATE', 'NO_ZERO_DATE', 'INVALID_DATES', 'ERROR_FOR_DIVISION_BY_ZERO', 'TRADITIONAL', 'NO_AUTO_CREATE_USER', 'HIGH_NOT_PRECEDENCE', 'NO_ENGINE_SUBSTITUTION', 'PAD_CHAR_TO_FULL_LENGTH') DEFAULT '' NOT NULL, comment text collate utf8_bin NOT NULL, character_set_client char(32) collate utf8_bin, collation_connection char(32) collate utf8_bin, db_collation char(32) collate utf8_bin, body_utf8 longblob, PRIMARY KEY (db,name,type)) engine=MyISAM character set utf8 comment='Stored Procedures'; +CREATE TABLE IF NOT EXISTS procs_priv ( Host char(60) binary DEFAULT '' NOT NULL, Db char(64) binary DEFAULT '' NOT NULL, User char(16) binary DEFAULT '' NOT NULL, Routine_name char(64) COLLATE utf8_general_ci DEFAULT '' NOT NULL, Routine_type enum('FUNCTION','PROCEDURE') NOT NULL, Grantor char(77) DEFAULT '' NOT NULL, Proc_priv set('Execute','Alter Routine','Grant') COLLATE utf8_general_ci DEFAULT '' NOT NULL, Timestamp timestamp, PRIMARY KEY (Host,Db,User,Routine_name,Routine_type), KEY Grantor (Grantor) ) engine=MyISAM CHARACTER SET utf8 COLLATE utf8_bin comment='Procedure privileges'; +CREATE TABLE IF NOT EXISTS event ( db char(64) CHARACTER SET utf8 COLLATE utf8_bin NOT NULL default '', name char(64) CHARACTER SET utf8 NOT NULL default '', body longblob NOT NULL, definer char(77) CHARACTER SET utf8 COLLATE utf8_bin NOT NULL default '', execute_at DATETIME default NULL, interval_value int(11) default NULL, interval_field ENUM('YEAR','QUARTER','MONTH','DAY','HOUR','MINUTE','WEEK','SECOND','MICROSECOND','YEAR_MONTH','DAY_HOUR','DAY_MINUTE','DAY_SECOND','HOUR_MINUTE','HOUR_SECOND','MINUTE_SECOND','DAY_MICROSECOND','HOUR_MICROSECOND','MINUTE_MICROSECOND','SECOND_MICROSECOND') default NULL, created TIMESTAMP NOT NULL, modified TIMESTAMP NOT NULL, last_executed DATETIME default NULL, starts DATETIME default NULL, ends DATETIME default NULL, status ENUM('ENABLED','DISABLED','SLAVESIDE_DISABLED') NOT NULL default 'ENABLED', on_completion ENUM('DROP','PRESERVE') NOT NULL default 'DROP', sql_mode set('REAL_AS_FLOAT','PIPES_AS_CONCAT','ANSI_QUOTES','IGNORE_SPACE','IGNORE_BAD_TABLE_OPTIONS','ONLY_FULL_GROUP_BY','NO_UNSIGNED_SUBTRACTION','NO_DIR_IN_CREATE','POSTGRESQL','ORACLE','MSSQL','DB2','MAXDB','NO_KEY_OPTIONS','NO_TABLE_OPTIONS','NO_FIELD_OPTIONS','MYSQL323','MYSQL40','ANSI','NO_AUTO_VALUE_ON_ZERO','NO_BACKSLASH_ESCAPES','STRICT_TRANS_TABLES','STRICT_ALL_TABLES','NO_ZERO_IN_DATE','NO_ZERO_DATE','INVALID_DATES','ERROR_FOR_DIVISION_BY_ZERO','TRADITIONAL','NO_AUTO_CREATE_USER','HIGH_NOT_PRECEDENCE','NO_ENGINE_SUBSTITUTION','PAD_CHAR_TO_FULL_LENGTH') DEFAULT '' NOT NULL, comment char(64) CHARACTER SET utf8 COLLATE utf8_bin NOT NULL default '', originator INTEGER UNSIGNED NOT NULL, time_zone char(64) CHARACTER SET latin1 NOT NULL DEFAULT 'SYSTEM', character_set_client char(32) collate utf8_bin, collation_connection char(32) collate utf8_bin, db_collation char(32) collate utf8_bin, body_utf8 longblob, PRIMARY KEY (db, name) ) ENGINE=MyISAM DEFAULT CHARSET=utf8 COMMENT 'Events'; +CREATE TABLE IF NOT EXISTS ndb_binlog_index (Position BIGINT UNSIGNED NOT NULL, File VARCHAR(255) NOT NULL, epoch BIGINT UNSIGNED NOT NULL, inserts BIGINT UNSIGNED NOT NULL, updates BIGINT UNSIGNED NOT NULL, deletes BIGINT UNSIGNED NOT NULL, schemaops BIGINT UNSIGNED NOT NULL, PRIMARY KEY(epoch)) ENGINE=MYISAM; +CREATE TABLE IF NOT EXISTS proxies_priv (Host char(60) binary DEFAULT '' NOT NULL, User char(16) binary DEFAULT '' NOT NULL, Proxied_host char(60) binary DEFAULT '' NOT NULL, Proxied_user char(16) binary DEFAULT '' NOT NULL, With_grant BOOL DEFAULT 0 NOT NULL, Grantor char(77) DEFAULT '' NOT NULL, Timestamp timestamp, PRIMARY KEY Host (Host,User,Proxied_host,Proxied_user), KEY Grantor (Grantor) ) engine=MyISAM CHARACTER SET utf8 COLLATE utf8_bin comment='User proxy privileges'; +Warnings: +Warning 1280 Name 'Host' ignored for PRIMARY key. +show tables; +Tables_in_db +column_stats +columns_priv +db +event +func +general_log +global_priv +gtid_slave_pos +help_category +help_keyword +help_relation +help_topic +host +index_stats +innodb_index_stats +innodb_table_stats +ndb_binlog_index +plugin +proc +procs_priv +proxies_priv +roles_mapping +servers +slow_log +table_stats +tables_priv +time_zone +time_zone_leap_second +time_zone_name +time_zone_transition +time_zone_transition_type +transaction_registry +user +show create table db; +Table Create Table +db CREATE TABLE `db` ( + `Host` char(60) NOT NULL DEFAULT '', + `Db` char(64) NOT NULL DEFAULT '', + `User` char(80) NOT NULL DEFAULT '', + `Select_priv` enum('N','Y') CHARACTER SET utf8 COLLATE utf8_general_ci NOT NULL DEFAULT 'N', + `Insert_priv` enum('N','Y') CHARACTER SET utf8 COLLATE utf8_general_ci NOT NULL DEFAULT 'N', + `Update_priv` enum('N','Y') CHARACTER SET utf8 COLLATE utf8_general_ci NOT NULL DEFAULT 'N', + `Delete_priv` enum('N','Y') CHARACTER SET utf8 COLLATE utf8_general_ci NOT NULL DEFAULT 'N', + `Create_priv` enum('N','Y') CHARACTER SET utf8 COLLATE utf8_general_ci NOT NULL DEFAULT 'N', + `Drop_priv` enum('N','Y') CHARACTER SET utf8 COLLATE utf8_general_ci NOT NULL DEFAULT 'N', + `Grant_priv` enum('N','Y') CHARACTER SET utf8 COLLATE utf8_general_ci NOT NULL DEFAULT 'N', + `References_priv` enum('N','Y') CHARACTER SET utf8 COLLATE utf8_general_ci NOT NULL DEFAULT 'N', + `Index_priv` enum('N','Y') CHARACTER SET utf8 COLLATE utf8_general_ci NOT NULL DEFAULT 'N', + `Alter_priv` enum('N','Y') CHARACTER SET utf8 COLLATE utf8_general_ci NOT NULL DEFAULT 'N', + `Create_tmp_table_priv` enum('N','Y') CHARACTER SET utf8 COLLATE utf8_general_ci NOT NULL DEFAULT 'N', + `Lock_tables_priv` enum('N','Y') CHARACTER SET utf8 COLLATE utf8_general_ci NOT NULL DEFAULT 'N', + `Create_view_priv` enum('N','Y') CHARACTER SET utf8 COLLATE utf8_general_ci NOT NULL DEFAULT 'N', + `Show_view_priv` enum('N','Y') CHARACTER SET utf8 COLLATE utf8_general_ci NOT NULL DEFAULT 'N', + `Create_routine_priv` enum('N','Y') CHARACTER SET utf8 COLLATE utf8_general_ci NOT NULL DEFAULT 'N', + `Alter_routine_priv` enum('N','Y') CHARACTER SET utf8 COLLATE utf8_general_ci NOT NULL DEFAULT 'N', + `Execute_priv` enum('N','Y') CHARACTER SET utf8 COLLATE utf8_general_ci NOT NULL DEFAULT 'N', + `Event_priv` enum('N','Y') CHARACTER SET utf8 COLLATE utf8_general_ci NOT NULL DEFAULT 'N', + `Trigger_priv` enum('N','Y') CHARACTER SET utf8 COLLATE utf8_general_ci NOT NULL DEFAULT 'N', + `Delete_history_priv` enum('N','Y') CHARACTER SET utf8 COLLATE utf8_general_ci NOT NULL DEFAULT 'N', + PRIMARY KEY (`Host`,`Db`,`User`), + KEY `User` (`User`) +) ENGINE=Aria DEFAULT CHARSET=utf8 COLLATE=utf8_bin PAGE_CHECKSUM=1 TRANSACTIONAL=1 COMMENT='Database privileges' +show create table user; +View Create View character_set_client collation_connection +user CREATE ALGORITHM=UNDEFINED DEFINER=`mariadb.sys`@`localhost` SQL SECURITY DEFINER VIEW `user` AS select `global_priv`.`Host` AS `Host`,`global_priv`.`User` AS `User`,if(json_value(`global_priv`.`Priv`,'$.plugin') in ('mysql_native_password','mysql_old_password'),ifnull(json_value(`global_priv`.`Priv`,'$.authentication_string'),''),'') AS `Password`,if(json_value(`global_priv`.`Priv`,'$.access') & 1,'Y','N') AS `Select_priv`,if(json_value(`global_priv`.`Priv`,'$.access') & 2,'Y','N') AS `Insert_priv`,if(json_value(`global_priv`.`Priv`,'$.access') & 4,'Y','N') AS `Update_priv`,if(json_value(`global_priv`.`Priv`,'$.access') & 8,'Y','N') AS `Delete_priv`,if(json_value(`global_priv`.`Priv`,'$.access') & 16,'Y','N') AS `Create_priv`,if(json_value(`global_priv`.`Priv`,'$.access') & 32,'Y','N') AS `Drop_priv`,if(json_value(`global_priv`.`Priv`,'$.access') & 64,'Y','N') AS `Reload_priv`,if(json_value(`global_priv`.`Priv`,'$.access') & 128,'Y','N') AS `Shutdown_priv`,if(json_value(`global_priv`.`Priv`,'$.access') & 256,'Y','N') AS `Process_priv`,if(json_value(`global_priv`.`Priv`,'$.access') & 512,'Y','N') AS `File_priv`,if(json_value(`global_priv`.`Priv`,'$.access') & 1024,'Y','N') AS `Grant_priv`,if(json_value(`global_priv`.`Priv`,'$.access') & 2048,'Y','N') AS `References_priv`,if(json_value(`global_priv`.`Priv`,'$.access') & 4096,'Y','N') AS `Index_priv`,if(json_value(`global_priv`.`Priv`,'$.access') & 8192,'Y','N') AS `Alter_priv`,if(json_value(`global_priv`.`Priv`,'$.access') & 16384,'Y','N') AS `Show_db_priv`,if(json_value(`global_priv`.`Priv`,'$.access') & 32768,'Y','N') AS `Super_priv`,if(json_value(`global_priv`.`Priv`,'$.access') & 65536,'Y','N') AS `Create_tmp_table_priv`,if(json_value(`global_priv`.`Priv`,'$.access') & 131072,'Y','N') AS `Lock_tables_priv`,if(json_value(`global_priv`.`Priv`,'$.access') & 262144,'Y','N') AS `Execute_priv`,if(json_value(`global_priv`.`Priv`,'$.access') & 524288,'Y','N') AS `Repl_slave_priv`,if(json_value(`global_priv`.`Priv`,'$.access') & 1048576,'Y','N') AS `Repl_client_priv`,if(json_value(`global_priv`.`Priv`,'$.access') & 2097152,'Y','N') AS `Create_view_priv`,if(json_value(`global_priv`.`Priv`,'$.access') & 4194304,'Y','N') AS `Show_view_priv`,if(json_value(`global_priv`.`Priv`,'$.access') & 8388608,'Y','N') AS `Create_routine_priv`,if(json_value(`global_priv`.`Priv`,'$.access') & 16777216,'Y','N') AS `Alter_routine_priv`,if(json_value(`global_priv`.`Priv`,'$.access') & 33554432,'Y','N') AS `Create_user_priv`,if(json_value(`global_priv`.`Priv`,'$.access') & 67108864,'Y','N') AS `Event_priv`,if(json_value(`global_priv`.`Priv`,'$.access') & 134217728,'Y','N') AS `Trigger_priv`,if(json_value(`global_priv`.`Priv`,'$.access') & 268435456,'Y','N') AS `Create_tablespace_priv`,if(json_value(`global_priv`.`Priv`,'$.access') & 536870912,'Y','N') AS `Delete_history_priv`,elt(ifnull(json_value(`global_priv`.`Priv`,'$.ssl_type'),0) + 1,'','ANY','X509','SPECIFIED') AS `ssl_type`,ifnull(json_value(`global_priv`.`Priv`,'$.ssl_cipher'),'') AS `ssl_cipher`,ifnull(json_value(`global_priv`.`Priv`,'$.x509_issuer'),'') AS `x509_issuer`,ifnull(json_value(`global_priv`.`Priv`,'$.x509_subject'),'') AS `x509_subject`,cast(ifnull(json_value(`global_priv`.`Priv`,'$.max_questions'),0) as unsigned) AS `max_questions`,cast(ifnull(json_value(`global_priv`.`Priv`,'$.max_updates'),0) as unsigned) AS `max_updates`,cast(ifnull(json_value(`global_priv`.`Priv`,'$.max_connections'),0) as unsigned) AS `max_connections`,cast(ifnull(json_value(`global_priv`.`Priv`,'$.max_user_connections'),0) as signed) AS `max_user_connections`,ifnull(json_value(`global_priv`.`Priv`,'$.plugin'),'') AS `plugin`,ifnull(json_value(`global_priv`.`Priv`,'$.authentication_string'),'') AS `authentication_string`,if(ifnull(json_value(`global_priv`.`Priv`,'$.password_last_changed'),1) = 0,'Y','N') AS `password_expired`,elt(ifnull(json_value(`global_priv`.`Priv`,'$.is_role'),0) + 1,'N','Y') AS `is_role`,ifnull(json_value(`global_priv`.`Priv`,'$.default_role'),'') AS `default_role`,cast(ifnull(json_value(`global_priv`.`Priv`,'$.max_statement_time'),0.0) as decimal(12,6)) AS `max_statement_time` from `global_priv` latin1 latin1_swedish_ci +show create table func; +Table Create Table +func CREATE TABLE `func` ( + `name` char(64) NOT NULL DEFAULT '', + `ret` tinyint(1) NOT NULL DEFAULT 0, + `dl` char(128) NOT NULL DEFAULT '', + `type` enum('function','aggregate') CHARACTER SET utf8 COLLATE utf8_general_ci NOT NULL, + PRIMARY KEY (`name`) +) ENGINE=Aria DEFAULT CHARSET=utf8 COLLATE=utf8_bin PAGE_CHECKSUM=1 TRANSACTIONAL=1 COMMENT='User defined functions' +show create table global_priv; +Table Create Table +global_priv CREATE TABLE `global_priv` ( + `Host` char(60) NOT NULL DEFAULT '', + `User` char(80) NOT NULL DEFAULT '', + `Priv` longtext CHARACTER SET utf8mb4 COLLATE utf8mb4_bin NOT NULL DEFAULT '{}' CHECK (json_valid(`Priv`)), + PRIMARY KEY (`Host`,`User`) +) ENGINE=Aria DEFAULT CHARSET=utf8 COLLATE=utf8_bin PAGE_CHECKSUM=1 TRANSACTIONAL=1 COMMENT='Users and global privileges' +show create table tables_priv; +Table Create Table +tables_priv CREATE TABLE `tables_priv` ( + `Host` char(60) NOT NULL DEFAULT '', + `Db` char(64) NOT NULL DEFAULT '', + `User` char(80) NOT NULL DEFAULT '', + `Table_name` char(64) NOT NULL DEFAULT '', + `Grantor` char(141) NOT NULL DEFAULT '', + `Timestamp` timestamp NOT NULL DEFAULT current_timestamp() ON UPDATE current_timestamp(), + `Table_priv` set('Select','Insert','Update','Delete','Create','Drop','Grant','References','Index','Alter','Create View','Show view','Trigger','Delete versioning rows') CHARACTER SET utf8 COLLATE utf8_general_ci NOT NULL DEFAULT '', + `Column_priv` set('Select','Insert','Update','References') CHARACTER SET utf8 COLLATE utf8_general_ci NOT NULL DEFAULT '', + PRIMARY KEY (`Host`,`Db`,`User`,`Table_name`), + KEY `Grantor` (`Grantor`) +) ENGINE=Aria DEFAULT CHARSET=utf8 COLLATE=utf8_bin PAGE_CHECKSUM=1 TRANSACTIONAL=1 COMMENT='Table privileges' +show create table columns_priv; +Table Create Table +columns_priv CREATE TABLE `columns_priv` ( + `Host` char(60) NOT NULL DEFAULT '', + `Db` char(64) NOT NULL DEFAULT '', + `User` char(80) NOT NULL DEFAULT '', + `Table_name` char(64) NOT NULL DEFAULT '', + `Column_name` char(64) NOT NULL DEFAULT '', + `Timestamp` timestamp NOT NULL DEFAULT current_timestamp() ON UPDATE current_timestamp(), + `Column_priv` set('Select','Insert','Update','References') CHARACTER SET utf8 COLLATE utf8_general_ci NOT NULL DEFAULT '', + PRIMARY KEY (`Host`,`Db`,`User`,`Table_name`,`Column_name`) +) ENGINE=Aria DEFAULT CHARSET=utf8 COLLATE=utf8_bin PAGE_CHECKSUM=1 TRANSACTIONAL=1 COMMENT='Column privileges' +show create table procs_priv; +Table Create Table +procs_priv CREATE TABLE `procs_priv` ( + `Host` char(60) NOT NULL DEFAULT '', + `Db` char(64) NOT NULL DEFAULT '', + `User` char(80) NOT NULL DEFAULT '', + `Routine_name` char(64) CHARACTER SET utf8 COLLATE utf8_general_ci NOT NULL DEFAULT '', + `Routine_type` enum('FUNCTION','PROCEDURE','PACKAGE','PACKAGE BODY') NOT NULL, + `Grantor` char(141) NOT NULL DEFAULT '', + `Proc_priv` set('Execute','Alter Routine','Grant') CHARACTER SET utf8 COLLATE utf8_general_ci NOT NULL DEFAULT '', + `Timestamp` timestamp NOT NULL DEFAULT current_timestamp() ON UPDATE current_timestamp(), + PRIMARY KEY (`Host`,`Db`,`User`,`Routine_name`,`Routine_type`), + KEY `Grantor` (`Grantor`) +) ENGINE=Aria DEFAULT CHARSET=utf8 COLLATE=utf8_bin PAGE_CHECKSUM=1 TRANSACTIONAL=1 COMMENT='Procedure privileges' +show create table servers; +Table Create Table +servers CREATE TABLE `servers` ( + `Server_name` char(64) NOT NULL DEFAULT '', + `Host` varchar(2048) NOT NULL DEFAULT '', + `Db` char(64) NOT NULL DEFAULT '', + `Username` char(80) NOT NULL DEFAULT '', + `Password` char(64) NOT NULL DEFAULT '', + `Port` int(4) NOT NULL DEFAULT 0, + `Socket` char(64) NOT NULL DEFAULT '', + `Wrapper` char(64) NOT NULL DEFAULT '', + `Owner` varchar(512) NOT NULL DEFAULT '', + PRIMARY KEY (`Server_name`) +) ENGINE=Aria DEFAULT CHARSET=utf8 COLLATE=utf8_general_ci PAGE_CHECKSUM=1 TRANSACTIONAL=1 COMMENT='MySQL Foreign Servers table' +show create table proc; +Table Create Table +proc CREATE TABLE `proc` ( + `db` char(64) CHARACTER SET utf8 COLLATE utf8_bin NOT NULL DEFAULT '', + `name` char(64) NOT NULL DEFAULT '', + `type` enum('FUNCTION','PROCEDURE','PACKAGE','PACKAGE BODY') NOT NULL, + `specific_name` char(64) NOT NULL DEFAULT '', + `language` enum('SQL') NOT NULL DEFAULT 'SQL', + `sql_data_access` enum('CONTAINS_SQL','NO_SQL','READS_SQL_DATA','MODIFIES_SQL_DATA') NOT NULL DEFAULT 'CONTAINS_SQL', + `is_deterministic` enum('YES','NO') NOT NULL DEFAULT 'NO', + `security_type` enum('INVOKER','DEFINER') NOT NULL DEFAULT 'DEFINER', + `param_list` blob NOT NULL, + `returns` longblob NOT NULL, + `body` longblob NOT NULL, + `definer` char(141) CHARACTER SET utf8 COLLATE utf8_bin NOT NULL DEFAULT '', + `created` timestamp NOT NULL DEFAULT current_timestamp() ON UPDATE current_timestamp(), + `modified` timestamp NOT NULL DEFAULT '0000-00-00 00:00:00', + `sql_mode` set('REAL_AS_FLOAT','PIPES_AS_CONCAT','ANSI_QUOTES','IGNORE_SPACE','IGNORE_BAD_TABLE_OPTIONS','ONLY_FULL_GROUP_BY','NO_UNSIGNED_SUBTRACTION','NO_DIR_IN_CREATE','POSTGRESQL','ORACLE','MSSQL','DB2','MAXDB','NO_KEY_OPTIONS','NO_TABLE_OPTIONS','NO_FIELD_OPTIONS','MYSQL323','MYSQL40','ANSI','NO_AUTO_VALUE_ON_ZERO','NO_BACKSLASH_ESCAPES','STRICT_TRANS_TABLES','STRICT_ALL_TABLES','NO_ZERO_IN_DATE','NO_ZERO_DATE','INVALID_DATES','ERROR_FOR_DIVISION_BY_ZERO','TRADITIONAL','NO_AUTO_CREATE_USER','HIGH_NOT_PRECEDENCE','NO_ENGINE_SUBSTITUTION','PAD_CHAR_TO_FULL_LENGTH','EMPTY_STRING_IS_NULL','SIMULTANEOUS_ASSIGNMENT','TIME_ROUND_FRACTIONAL') NOT NULL DEFAULT '', + `comment` text CHARACTER SET utf8 COLLATE utf8_bin NOT NULL, + `character_set_client` char(32) CHARACTER SET utf8 COLLATE utf8_bin DEFAULT NULL, + `collation_connection` char(32) CHARACTER SET utf8 COLLATE utf8_bin DEFAULT NULL, + `db_collation` char(32) CHARACTER SET utf8 COLLATE utf8_bin DEFAULT NULL, + `body_utf8` longblob DEFAULT NULL, + `aggregate` enum('NONE','GROUP') NOT NULL DEFAULT 'NONE', + PRIMARY KEY (`db`,`name`,`type`) +) ENGINE=Aria DEFAULT CHARSET=utf8 COLLATE=utf8_general_ci PAGE_CHECKSUM=1 TRANSACTIONAL=1 COMMENT='Stored Procedures' +show create table event; +Table Create Table +event CREATE TABLE `event` ( + `db` char(64) CHARACTER SET utf8 COLLATE utf8_bin NOT NULL DEFAULT '', + `name` char(64) NOT NULL DEFAULT '', + `body` longblob NOT NULL, + `definer` char(141) CHARACTER SET utf8 COLLATE utf8_bin NOT NULL DEFAULT '', + `execute_at` datetime DEFAULT NULL, + `interval_value` int(11) DEFAULT NULL, + `interval_field` enum('YEAR','QUARTER','MONTH','DAY','HOUR','MINUTE','WEEK','SECOND','MICROSECOND','YEAR_MONTH','DAY_HOUR','DAY_MINUTE','DAY_SECOND','HOUR_MINUTE','HOUR_SECOND','MINUTE_SECOND','DAY_MICROSECOND','HOUR_MICROSECOND','MINUTE_MICROSECOND','SECOND_MICROSECOND') DEFAULT NULL, + `created` timestamp NOT NULL DEFAULT current_timestamp() ON UPDATE current_timestamp(), + `modified` timestamp NOT NULL DEFAULT '0000-00-00 00:00:00', + `last_executed` datetime DEFAULT NULL, + `starts` datetime DEFAULT NULL, + `ends` datetime DEFAULT NULL, + `status` enum('ENABLED','DISABLED','SLAVESIDE_DISABLED') NOT NULL DEFAULT 'ENABLED', + `on_completion` enum('DROP','PRESERVE') NOT NULL DEFAULT 'DROP', + `sql_mode` set('REAL_AS_FLOAT','PIPES_AS_CONCAT','ANSI_QUOTES','IGNORE_SPACE','IGNORE_BAD_TABLE_OPTIONS','ONLY_FULL_GROUP_BY','NO_UNSIGNED_SUBTRACTION','NO_DIR_IN_CREATE','POSTGRESQL','ORACLE','MSSQL','DB2','MAXDB','NO_KEY_OPTIONS','NO_TABLE_OPTIONS','NO_FIELD_OPTIONS','MYSQL323','MYSQL40','ANSI','NO_AUTO_VALUE_ON_ZERO','NO_BACKSLASH_ESCAPES','STRICT_TRANS_TABLES','STRICT_ALL_TABLES','NO_ZERO_IN_DATE','NO_ZERO_DATE','INVALID_DATES','ERROR_FOR_DIVISION_BY_ZERO','TRADITIONAL','NO_AUTO_CREATE_USER','HIGH_NOT_PRECEDENCE','NO_ENGINE_SUBSTITUTION','PAD_CHAR_TO_FULL_LENGTH','EMPTY_STRING_IS_NULL','SIMULTANEOUS_ASSIGNMENT','TIME_ROUND_FRACTIONAL') NOT NULL DEFAULT '', + `comment` char(64) CHARACTER SET utf8 COLLATE utf8_bin NOT NULL DEFAULT '', + `originator` int(10) unsigned NOT NULL, + `time_zone` char(64) CHARACTER SET latin1 COLLATE latin1_swedish_ci NOT NULL DEFAULT 'SYSTEM', + `character_set_client` char(32) CHARACTER SET utf8 COLLATE utf8_bin DEFAULT NULL, + `collation_connection` char(32) CHARACTER SET utf8 COLLATE utf8_bin DEFAULT NULL, + `db_collation` char(32) CHARACTER SET utf8 COLLATE utf8_bin DEFAULT NULL, + `body_utf8` longblob DEFAULT NULL, + PRIMARY KEY (`db`,`name`) +) ENGINE=Aria DEFAULT CHARSET=utf8 COLLATE=utf8_general_ci PAGE_CHECKSUM=1 TRANSACTIONAL=1 COMMENT='Events' +show create table general_log; +Table Create Table +general_log CREATE TABLE `general_log` ( + `event_time` timestamp(6) NOT NULL DEFAULT current_timestamp(6) ON UPDATE current_timestamp(6), + `user_host` mediumtext NOT NULL, + `thread_id` bigint(21) unsigned NOT NULL, + `server_id` int(10) unsigned NOT NULL, + `command_type` varchar(64) NOT NULL, + `argument` mediumtext NOT NULL +) ENGINE=CSV DEFAULT CHARSET=utf8 COLLATE=utf8_general_ci COMMENT='General log' +show create table slow_log; +Table Create Table +slow_log CREATE TABLE `slow_log` ( + `start_time` timestamp(6) NOT NULL DEFAULT current_timestamp(6) ON UPDATE current_timestamp(6), + `user_host` mediumtext NOT NULL, + `query_time` time(6) NOT NULL, + `lock_time` time(6) NOT NULL, + `rows_sent` int(11) NOT NULL, + `rows_examined` int(11) NOT NULL, + `db` varchar(512) NOT NULL, + `last_insert_id` int(11) NOT NULL, + `insert_id` int(11) NOT NULL, + `server_id` int(10) unsigned NOT NULL, + `sql_text` mediumtext NOT NULL, + `thread_id` bigint(21) unsigned NOT NULL, + `rows_affected` int(11) NOT NULL +) ENGINE=CSV DEFAULT CHARSET=utf8 COLLATE=utf8_general_ci COMMENT='Slow log' +show create table table_stats; +Table Create Table +table_stats CREATE TABLE `table_stats` ( + `db_name` varchar(64) NOT NULL, + `table_name` varchar(64) NOT NULL, + `cardinality` bigint(21) unsigned DEFAULT NULL, + PRIMARY KEY (`db_name`,`table_name`) +) ENGINE=Aria DEFAULT CHARSET=utf8 COLLATE=utf8_bin PAGE_CHECKSUM=1 TRANSACTIONAL=0 COMMENT='Statistics on Tables' +show create table column_stats; +Table Create Table +column_stats CREATE TABLE `column_stats` ( + `db_name` varchar(64) NOT NULL, + `table_name` varchar(64) NOT NULL, + `column_name` varchar(64) NOT NULL, + `min_value` varbinary(255) DEFAULT NULL, + `max_value` varbinary(255) DEFAULT NULL, + `nulls_ratio` decimal(12,4) DEFAULT NULL, + `avg_length` decimal(12,4) DEFAULT NULL, + `avg_frequency` decimal(12,4) DEFAULT NULL, + `hist_size` tinyint(3) unsigned DEFAULT NULL, + `hist_type` enum('SINGLE_PREC_HB','DOUBLE_PREC_HB') DEFAULT NULL, + `histogram` varbinary(255) DEFAULT NULL, + PRIMARY KEY (`db_name`,`table_name`,`column_name`) +) ENGINE=Aria DEFAULT CHARSET=utf8 COLLATE=utf8_bin PAGE_CHECKSUM=1 TRANSACTIONAL=0 COMMENT='Statistics on Columns' +show create table index_stats; +Table Create Table +index_stats CREATE TABLE `index_stats` ( + `db_name` varchar(64) NOT NULL, + `table_name` varchar(64) NOT NULL, + `index_name` varchar(64) NOT NULL, + `prefix_arity` int(11) unsigned NOT NULL, + `avg_frequency` decimal(12,4) DEFAULT NULL, + PRIMARY KEY (`db_name`,`table_name`,`index_name`,`prefix_arity`) +) ENGINE=Aria DEFAULT CHARSET=utf8 COLLATE=utf8_bin PAGE_CHECKSUM=1 TRANSACTIONAL=0 COMMENT='Statistics on Indexes' +DROP VIEW user; +DROP TABLE db, host, func, plugin, tables_priv, columns_priv, procs_priv, servers, help_category, help_keyword, help_relation, help_topic, proc, time_zone, time_zone_leap_second, time_zone_name, time_zone_transition, time_zone_transition_type, event, proxies_priv, general_log, slow_log, innodb_index_stats, innodb_table_stats, transaction_registry, table_stats, column_stats, index_stats, roles_mapping, gtid_slave_pos, global_priv, ndb_binlog_index; +show tables; +Tables_in_test diff --git a/mysql-test/main/system_mysql_db_fix50568.test b/mysql-test/main/system_mysql_db_fix50568.test new file mode 100644 index 0000000000000..9ecb2a23d5f77 --- /dev/null +++ b/mysql-test/main/system_mysql_db_fix50568.test @@ -0,0 +1,99 @@ +# Embedded server doesn't support external clients +--source include/not_embedded.inc +--source include/have_innodb.inc + +# Don't run this test if $MYSQL_FIX_PRIVILEGE_TABLES isn't set +# to the location of mysql_fix_privilege_tables.sql +if (!$MYSQL_FIX_PRIVILEGE_TABLES) +{ + skip Test needs MYSQL_FIX_PRIVILEGE_TABLES; +} + +# +# This is the test for mysql_fix_privilege_tables +# It checks that a system tables from mysql 5.5.68 +# can be upgraded to current system table format +# +# Note: If this test fails, don't be confused about the errors reported +# by mysql-test-run This shows warnings generated by +# mysql_fix_system_tables which should be ignored. +# Instead, concentrate on the errors in r/system_mysql_db.reject + +use test; + +# create system tables as in mysql-5.5.68 +CREATE TABLE IF NOT EXISTS db ( Host char(60) binary DEFAULT '' NOT NULL, Db char(64) binary DEFAULT '' NOT NULL, User char(16) binary DEFAULT '' NOT NULL, Select_priv enum('N','Y') COLLATE utf8_general_ci DEFAULT 'N' NOT NULL, Insert_priv enum('N','Y') COLLATE utf8_general_ci DEFAULT 'N' NOT NULL, Update_priv enum('N','Y') COLLATE utf8_general_ci DEFAULT 'N' NOT NULL, Delete_priv enum('N','Y') COLLATE utf8_general_ci DEFAULT 'N' NOT NULL, Create_priv enum('N','Y') COLLATE utf8_general_ci DEFAULT 'N' NOT NULL, Drop_priv enum('N','Y') COLLATE utf8_general_ci DEFAULT 'N' NOT NULL, Grant_priv enum('N','Y') COLLATE utf8_general_ci DEFAULT 'N' NOT NULL, References_priv enum('N','Y') COLLATE utf8_general_ci DEFAULT 'N' NOT NULL, Index_priv enum('N','Y') COLLATE utf8_general_ci DEFAULT 'N' NOT NULL, Alter_priv enum('N','Y') COLLATE utf8_general_ci DEFAULT 'N' NOT NULL, Create_tmp_table_priv enum('N','Y') COLLATE utf8_general_ci DEFAULT 'N' NOT NULL, Lock_tables_priv enum('N','Y') COLLATE utf8_general_ci DEFAULT 'N' NOT NULL, Create_view_priv enum('N','Y') COLLATE utf8_general_ci DEFAULT 'N' NOT NULL, Show_view_priv enum('N','Y') COLLATE utf8_general_ci DEFAULT 'N' NOT NULL, Create_routine_priv enum('N','Y') COLLATE utf8_general_ci DEFAULT 'N' NOT NULL, Alter_routine_priv enum('N','Y') COLLATE utf8_general_ci DEFAULT 'N' NOT NULL, Execute_priv enum('N','Y') COLLATE utf8_general_ci DEFAULT 'N' NOT NULL, Event_priv enum('N','Y') COLLATE utf8_general_ci DEFAULT 'N' NOT NULL, Trigger_priv enum('N','Y') COLLATE utf8_general_ci DEFAULT 'N' NOT NULL, PRIMARY KEY Host (Host,Db,User), KEY User (User) ) engine=MyISAM CHARACTER SET utf8 COLLATE utf8_bin comment='Database privileges'; + +CREATE TABLE IF NOT EXISTS host ( Host char(60) binary DEFAULT '' NOT NULL, Db char(64) binary DEFAULT '' NOT NULL, Select_priv enum('N','Y') COLLATE utf8_general_ci DEFAULT 'N' NOT NULL, Insert_priv enum('N','Y') COLLATE utf8_general_ci DEFAULT 'N' NOT NULL, Update_priv enum('N','Y') COLLATE utf8_general_ci DEFAULT 'N' NOT NULL, Delete_priv enum('N','Y') COLLATE utf8_general_ci DEFAULT 'N' NOT NULL, Create_priv enum('N','Y') COLLATE utf8_general_ci DEFAULT 'N' NOT NULL, Drop_priv enum('N','Y') COLLATE utf8_general_ci DEFAULT 'N' NOT NULL, Grant_priv enum('N','Y') COLLATE utf8_general_ci DEFAULT 'N' NOT NULL, References_priv enum('N','Y') COLLATE utf8_general_ci DEFAULT 'N' NOT NULL, Index_priv enum('N','Y') COLLATE utf8_general_ci DEFAULT 'N' NOT NULL, Alter_priv enum('N','Y') COLLATE utf8_general_ci DEFAULT 'N' NOT NULL, Create_tmp_table_priv enum('N','Y') COLLATE utf8_general_ci DEFAULT 'N' NOT NULL, Lock_tables_priv enum('N','Y') COLLATE utf8_general_ci DEFAULT 'N' NOT NULL, Create_view_priv enum('N','Y') COLLATE utf8_general_ci DEFAULT 'N' NOT NULL, Show_view_priv enum('N','Y') COLLATE utf8_general_ci DEFAULT 'N' NOT NULL, Create_routine_priv enum('N','Y') COLLATE utf8_general_ci DEFAULT 'N' NOT NULL, Alter_routine_priv enum('N','Y') COLLATE utf8_general_ci DEFAULT 'N' NOT NULL, Execute_priv enum('N','Y') COLLATE utf8_general_ci DEFAULT 'N' NOT NULL, Trigger_priv enum('N','Y') COLLATE utf8_general_ci DEFAULT 'N' NOT NULL, PRIMARY KEY Host (Host,Db) ) engine=MyISAM CHARACTER SET utf8 COLLATE utf8_bin comment='Host privileges; Merged with database privileges'; + +CREATE TABLE IF NOT EXISTS user ( Host char(60) binary DEFAULT '' NOT NULL, User char(16) binary DEFAULT '' NOT NULL, Password char(41) character set latin1 collate latin1_bin DEFAULT '' NOT NULL, Select_priv enum('N','Y') COLLATE utf8_general_ci DEFAULT 'N' NOT NULL, Insert_priv enum('N','Y') COLLATE utf8_general_ci DEFAULT 'N' NOT NULL, Update_priv enum('N','Y') COLLATE utf8_general_ci DEFAULT 'N' NOT NULL, Delete_priv enum('N','Y') COLLATE utf8_general_ci DEFAULT 'N' NOT NULL, Create_priv enum('N','Y') COLLATE utf8_general_ci DEFAULT 'N' NOT NULL, Drop_priv enum('N','Y') COLLATE utf8_general_ci DEFAULT 'N' NOT NULL, Reload_priv enum('N','Y') COLLATE utf8_general_ci DEFAULT 'N' NOT NULL, Shutdown_priv enum('N','Y') COLLATE utf8_general_ci DEFAULT 'N' NOT NULL, Process_priv enum('N','Y') COLLATE utf8_general_ci DEFAULT 'N' NOT NULL, File_priv enum('N','Y') COLLATE utf8_general_ci DEFAULT 'N' NOT NULL, Grant_priv enum('N','Y') COLLATE utf8_general_ci DEFAULT 'N' NOT NULL, References_priv enum('N','Y') COLLATE utf8_general_ci DEFAULT 'N' NOT NULL, Index_priv enum('N','Y') COLLATE utf8_general_ci DEFAULT 'N' NOT NULL, Alter_priv enum('N','Y') COLLATE utf8_general_ci DEFAULT 'N' NOT NULL, Show_db_priv enum('N','Y') COLLATE utf8_general_ci DEFAULT 'N' NOT NULL, Super_priv enum('N','Y') COLLATE utf8_general_ci DEFAULT 'N' NOT NULL, Create_tmp_table_priv enum('N','Y') COLLATE utf8_general_ci DEFAULT 'N' NOT NULL, Lock_tables_priv enum('N','Y') COLLATE utf8_general_ci DEFAULT 'N' NOT NULL, Execute_priv enum('N','Y') COLLATE utf8_general_ci DEFAULT 'N' NOT NULL, Repl_slave_priv enum('N','Y') COLLATE utf8_general_ci DEFAULT 'N' NOT NULL, Repl_client_priv enum('N','Y') COLLATE utf8_general_ci DEFAULT 'N' NOT NULL, Create_view_priv enum('N','Y') COLLATE utf8_general_ci DEFAULT 'N' NOT NULL, Show_view_priv enum('N','Y') COLLATE utf8_general_ci DEFAULT 'N' NOT NULL, Create_routine_priv enum('N','Y') COLLATE utf8_general_ci DEFAULT 'N' NOT NULL, Alter_routine_priv enum('N','Y') COLLATE utf8_general_ci DEFAULT 'N' NOT NULL, Create_user_priv enum('N','Y') COLLATE utf8_general_ci DEFAULT 'N' NOT NULL, Event_priv enum('N','Y') COLLATE utf8_general_ci DEFAULT 'N' NOT NULL, Trigger_priv enum('N','Y') COLLATE utf8_general_ci DEFAULT 'N' NOT NULL, Create_tablespace_priv enum('N','Y') COLLATE utf8_general_ci DEFAULT 'N' NOT NULL, ssl_type enum('','ANY','X509', 'SPECIFIED') COLLATE utf8_general_ci DEFAULT '' NOT NULL, ssl_cipher BLOB NOT NULL, x509_issuer BLOB NOT NULL, x509_subject BLOB NOT NULL, max_questions int(11) unsigned DEFAULT 0 NOT NULL, max_updates int(11) unsigned DEFAULT 0 NOT NULL, max_connections int(11) unsigned DEFAULT 0 NOT NULL, max_user_connections int(11) DEFAULT 0 NOT NULL, plugin char(64) CHARACTER SET latin1 DEFAULT '' NOT NULL, authentication_string TEXT NOT NULL, PRIMARY KEY Host (Host,User) ) engine=MyISAM CHARACTER SET utf8 COLLATE utf8_bin comment='Users and global privileges'; + +CREATE TABLE IF NOT EXISTS func ( name char(64) binary DEFAULT '' NOT NULL, ret tinyint(1) DEFAULT '0' NOT NULL, dl char(128) DEFAULT '' NOT NULL, type enum ('function','aggregate') COLLATE utf8_general_ci NOT NULL, PRIMARY KEY (name) ) engine=MyISAM CHARACTER SET utf8 COLLATE utf8_bin comment='User defined functions'; + + +CREATE TABLE IF NOT EXISTS plugin ( name varchar(64) DEFAULT '' NOT NULL, dl varchar(128) DEFAULT '' NOT NULL, PRIMARY KEY (name) ) engine=MyISAM CHARACTER SET utf8 COLLATE utf8_general_ci comment='MySQL plugins'; + + +CREATE TABLE IF NOT EXISTS servers ( Server_name char(64) NOT NULL DEFAULT '', Host char(64) NOT NULL DEFAULT '', Db char(64) NOT NULL DEFAULT '', Username char(64) NOT NULL DEFAULT '', Password char(64) NOT NULL DEFAULT '', Port INT(4) NOT NULL DEFAULT '0', Socket char(64) NOT NULL DEFAULT '', Wrapper char(64) NOT NULL DEFAULT '', Owner char(64) NOT NULL DEFAULT '', PRIMARY KEY (Server_name)) CHARACTER SET utf8 comment='MySQL Foreign Servers table'; + + +CREATE TABLE IF NOT EXISTS tables_priv ( Host char(60) binary DEFAULT '' NOT NULL, Db char(64) binary DEFAULT '' NOT NULL, User char(16) binary DEFAULT '' NOT NULL, Table_name char(64) binary DEFAULT '' NOT NULL, Grantor char(77) DEFAULT '' NOT NULL, Timestamp timestamp, Table_priv set('Select','Insert','Update','Delete','Create','Drop','Grant','References','Index','Alter','Create View','Show view','Trigger') COLLATE utf8_general_ci DEFAULT '' NOT NULL, Column_priv set('Select','Insert','Update','References') COLLATE utf8_general_ci DEFAULT '' NOT NULL, PRIMARY KEY (Host,Db,User,Table_name), KEY Grantor (Grantor) ) engine=MyISAM CHARACTER SET utf8 COLLATE utf8_bin comment='Table privileges'; + +CREATE TABLE IF NOT EXISTS columns_priv ( Host char(60) binary DEFAULT '' NOT NULL, Db char(64) binary DEFAULT '' NOT NULL, User char(16) binary DEFAULT '' NOT NULL, Table_name char(64) binary DEFAULT '' NOT NULL, Column_name char(64) binary DEFAULT '' NOT NULL, Timestamp timestamp, Column_priv set('Select','Insert','Update','References') COLLATE utf8_general_ci DEFAULT '' NOT NULL, PRIMARY KEY (Host,Db,User,Table_name,Column_name) ) engine=MyISAM CHARACTER SET utf8 COLLATE utf8_bin comment='Column privileges'; + + +CREATE TABLE IF NOT EXISTS help_topic ( help_topic_id int unsigned not null, name char(64) not null, help_category_id smallint unsigned not null, description text not null, example text not null, url text not null, primary key (help_topic_id), unique index (name) ) engine=MyISAM CHARACTER SET utf8 comment='help topics'; + + +CREATE TABLE IF NOT EXISTS help_category ( help_category_id smallint unsigned not null, name char(64) not null, parent_category_id smallint unsigned null, url text not null, primary key (help_category_id), unique index (name) ) engine=MyISAM CHARACTER SET utf8 comment='help categories'; + + +CREATE TABLE IF NOT EXISTS help_relation ( help_topic_id int unsigned not null references help_topic, help_keyword_id int unsigned not null references help_keyword, primary key (help_keyword_id, help_topic_id) ) engine=MyISAM CHARACTER SET utf8 comment='keyword-topic relation'; + + +CREATE TABLE IF NOT EXISTS help_keyword ( help_keyword_id int unsigned not null, name char(64) not null, primary key (help_keyword_id), unique index (name) ) engine=MyISAM CHARACTER SET utf8 comment='help keywords'; + + +CREATE TABLE IF NOT EXISTS time_zone_name ( Name char(64) NOT NULL, Time_zone_id int unsigned NOT NULL, PRIMARY KEY Name (Name) ) engine=MyISAM CHARACTER SET utf8 comment='Time zone names'; + + +CREATE TABLE IF NOT EXISTS time_zone ( Time_zone_id int unsigned NOT NULL auto_increment, Use_leap_seconds enum('Y','N') COLLATE utf8_general_ci DEFAULT 'N' NOT NULL, PRIMARY KEY TzId (Time_zone_id) ) engine=MyISAM CHARACTER SET utf8 comment='Time zones'; + + +CREATE TABLE IF NOT EXISTS time_zone_transition ( Time_zone_id int unsigned NOT NULL, Transition_time bigint signed NOT NULL, Transition_type_id int unsigned NOT NULL, PRIMARY KEY TzIdTranTime (Time_zone_id, Transition_time) ) engine=MyISAM CHARACTER SET utf8 comment='Time zone transitions'; + + +CREATE TABLE IF NOT EXISTS time_zone_transition_type ( Time_zone_id int unsigned NOT NULL, Transition_type_id int unsigned NOT NULL, Offset int signed DEFAULT 0 NOT NULL, Is_DST tinyint unsigned DEFAULT 0 NOT NULL, Abbreviation char(8) DEFAULT '' NOT NULL, PRIMARY KEY TzIdTrTId (Time_zone_id, Transition_type_id) ) engine=MyISAM CHARACTER SET utf8 comment='Time zone transition types'; + + +CREATE TABLE IF NOT EXISTS time_zone_leap_second ( Transition_time bigint signed NOT NULL, Correction int signed NOT NULL, PRIMARY KEY TranTime (Transition_time) ) engine=MyISAM CHARACTER SET utf8 comment='Leap seconds information for time zones'; + +CREATE TABLE IF NOT EXISTS proc (db char(64) collate utf8_bin DEFAULT '' NOT NULL, name char(64) DEFAULT '' NOT NULL, type enum('FUNCTION','PROCEDURE') NOT NULL, specific_name char(64) DEFAULT '' NOT NULL, language enum('SQL') DEFAULT 'SQL' NOT NULL, sql_data_access enum( 'CONTAINS_SQL', 'NO_SQL', 'READS_SQL_DATA', 'MODIFIES_SQL_DATA') DEFAULT 'CONTAINS_SQL' NOT NULL, is_deterministic enum('YES','NO') DEFAULT 'NO' NOT NULL, security_type enum('INVOKER','DEFINER') DEFAULT 'DEFINER' NOT NULL, param_list blob NOT NULL, returns longblob DEFAULT '' NOT NULL, body longblob NOT NULL, definer char(77) collate utf8_bin DEFAULT '' NOT NULL, created timestamp, modified timestamp, sql_mode set( 'REAL_AS_FLOAT', 'PIPES_AS_CONCAT', 'ANSI_QUOTES', 'IGNORE_SPACE', 'IGNORE_BAD_TABLE_OPTIONS', 'ONLY_FULL_GROUP_BY', 'NO_UNSIGNED_SUBTRACTION', 'NO_DIR_IN_CREATE', 'POSTGRESQL', 'ORACLE', 'MSSQL', 'DB2', 'MAXDB', 'NO_KEY_OPTIONS', 'NO_TABLE_OPTIONS', 'NO_FIELD_OPTIONS', 'MYSQL323', 'MYSQL40', 'ANSI', 'NO_AUTO_VALUE_ON_ZERO', 'NO_BACKSLASH_ESCAPES', 'STRICT_TRANS_TABLES', 'STRICT_ALL_TABLES', 'NO_ZERO_IN_DATE', 'NO_ZERO_DATE', 'INVALID_DATES', 'ERROR_FOR_DIVISION_BY_ZERO', 'TRADITIONAL', 'NO_AUTO_CREATE_USER', 'HIGH_NOT_PRECEDENCE', 'NO_ENGINE_SUBSTITUTION', 'PAD_CHAR_TO_FULL_LENGTH') DEFAULT '' NOT NULL, comment text collate utf8_bin NOT NULL, character_set_client char(32) collate utf8_bin, collation_connection char(32) collate utf8_bin, db_collation char(32) collate utf8_bin, body_utf8 longblob, PRIMARY KEY (db,name,type)) engine=MyISAM character set utf8 comment='Stored Procedures'; + +CREATE TABLE IF NOT EXISTS procs_priv ( Host char(60) binary DEFAULT '' NOT NULL, Db char(64) binary DEFAULT '' NOT NULL, User char(16) binary DEFAULT '' NOT NULL, Routine_name char(64) COLLATE utf8_general_ci DEFAULT '' NOT NULL, Routine_type enum('FUNCTION','PROCEDURE') NOT NULL, Grantor char(77) DEFAULT '' NOT NULL, Proc_priv set('Execute','Alter Routine','Grant') COLLATE utf8_general_ci DEFAULT '' NOT NULL, Timestamp timestamp, PRIMARY KEY (Host,Db,User,Routine_name,Routine_type), KEY Grantor (Grantor) ) engine=MyISAM CHARACTER SET utf8 COLLATE utf8_bin comment='Procedure privileges'; + + +CREATE TABLE IF NOT EXISTS event ( db char(64) CHARACTER SET utf8 COLLATE utf8_bin NOT NULL default '', name char(64) CHARACTER SET utf8 NOT NULL default '', body longblob NOT NULL, definer char(77) CHARACTER SET utf8 COLLATE utf8_bin NOT NULL default '', execute_at DATETIME default NULL, interval_value int(11) default NULL, interval_field ENUM('YEAR','QUARTER','MONTH','DAY','HOUR','MINUTE','WEEK','SECOND','MICROSECOND','YEAR_MONTH','DAY_HOUR','DAY_MINUTE','DAY_SECOND','HOUR_MINUTE','HOUR_SECOND','MINUTE_SECOND','DAY_MICROSECOND','HOUR_MICROSECOND','MINUTE_MICROSECOND','SECOND_MICROSECOND') default NULL, created TIMESTAMP NOT NULL, modified TIMESTAMP NOT NULL, last_executed DATETIME default NULL, starts DATETIME default NULL, ends DATETIME default NULL, status ENUM('ENABLED','DISABLED','SLAVESIDE_DISABLED') NOT NULL default 'ENABLED', on_completion ENUM('DROP','PRESERVE') NOT NULL default 'DROP', sql_mode set('REAL_AS_FLOAT','PIPES_AS_CONCAT','ANSI_QUOTES','IGNORE_SPACE','IGNORE_BAD_TABLE_OPTIONS','ONLY_FULL_GROUP_BY','NO_UNSIGNED_SUBTRACTION','NO_DIR_IN_CREATE','POSTGRESQL','ORACLE','MSSQL','DB2','MAXDB','NO_KEY_OPTIONS','NO_TABLE_OPTIONS','NO_FIELD_OPTIONS','MYSQL323','MYSQL40','ANSI','NO_AUTO_VALUE_ON_ZERO','NO_BACKSLASH_ESCAPES','STRICT_TRANS_TABLES','STRICT_ALL_TABLES','NO_ZERO_IN_DATE','NO_ZERO_DATE','INVALID_DATES','ERROR_FOR_DIVISION_BY_ZERO','TRADITIONAL','NO_AUTO_CREATE_USER','HIGH_NOT_PRECEDENCE','NO_ENGINE_SUBSTITUTION','PAD_CHAR_TO_FULL_LENGTH') DEFAULT '' NOT NULL, comment char(64) CHARACTER SET utf8 COLLATE utf8_bin NOT NULL default '', originator INTEGER UNSIGNED NOT NULL, time_zone char(64) CHARACTER SET latin1 NOT NULL DEFAULT 'SYSTEM', character_set_client char(32) collate utf8_bin, collation_connection char(32) collate utf8_bin, db_collation char(32) collate utf8_bin, body_utf8 longblob, PRIMARY KEY (db, name) ) ENGINE=MyISAM DEFAULT CHARSET=utf8 COMMENT 'Events'; + + +CREATE TABLE IF NOT EXISTS ndb_binlog_index (Position BIGINT UNSIGNED NOT NULL, File VARCHAR(255) NOT NULL, epoch BIGINT UNSIGNED NOT NULL, inserts BIGINT UNSIGNED NOT NULL, updates BIGINT UNSIGNED NOT NULL, deletes BIGINT UNSIGNED NOT NULL, schemaops BIGINT UNSIGNED NOT NULL, PRIMARY KEY(epoch)) ENGINE=MYISAM; + +CREATE TABLE IF NOT EXISTS proxies_priv (Host char(60) binary DEFAULT '' NOT NULL, User char(16) binary DEFAULT '' NOT NULL, Proxied_host char(60) binary DEFAULT '' NOT NULL, Proxied_user char(16) binary DEFAULT '' NOT NULL, With_grant BOOL DEFAULT 0 NOT NULL, Grantor char(77) DEFAULT '' NOT NULL, Timestamp timestamp, PRIMARY KEY Host (Host,User,Proxied_host,Proxied_user), KEY Grantor (Grantor) ) engine=MyISAM CHARACTER SET utf8 COLLATE utf8_bin comment='User proxy privileges'; + + +-- disable_result_log +# Run the mysql_fix_privilege_tables.sql using "mysql --force" +--exec $MYSQL --force test < $MYSQL_FIX_PRIVILEGE_TABLES +-- enable_result_log + +# Dump the tables that should be compared +-- source include/system_db_struct.inc + +# Drop all tables created by this test +DROP VIEW user; +DROP TABLE db, host, func, plugin, tables_priv, columns_priv, procs_priv, servers, help_category, help_keyword, help_relation, help_topic, proc, time_zone, time_zone_leap_second, time_zone_name, time_zone_transition, time_zone_transition_type, event, proxies_priv, general_log, slow_log, innodb_index_stats, innodb_table_stats, transaction_registry, table_stats, column_stats, index_stats, roles_mapping, gtid_slave_pos, global_priv, ndb_binlog_index; + +# check that we dropped all system tables +show tables; + +# End of 4.1 tests diff --git a/scripts/mysql_system_tables_fix.sql b/scripts/mysql_system_tables_fix.sql index 796bc90a2eeb9..c009a3de4a0b1 100644 --- a/scripts/mysql_system_tables_fix.sql +++ b/scripts/mysql_system_tables_fix.sql @@ -239,7 +239,6 @@ SET GLOBAL general_log = 'OFF'; ALTER TABLE general_log MODIFY event_time TIMESTAMP(6) NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP, MODIFY user_host MEDIUMTEXT NOT NULL, - MODIFY thread_id INTEGER NOT NULL, MODIFY server_id INTEGER UNSIGNED NOT NULL, MODIFY command_type VARCHAR(64) NOT NULL, MODIFY argument MEDIUMTEXT NOT NULL, @@ -841,3 +840,8 @@ IF 1 = (SELECT count(*) FROM information_schema.VIEWS WHERE TABLE_CATALOG = 'def END IF// DELIMITER ; + +# MDEV-22683 - upgrade Host and Owner of servers +ALTER TABLE servers + MODIFY Host varchar(2048) NOT NULL DEFAULT '', + MODIFY Owner varchar(512) NOT NULL DEFAULT ''; From 7bdd878ae40e19b69736ed01fd2bc861c83d1784 Mon Sep 17 00:00:00 2001 From: Hugo Wen Date: Thu, 23 Feb 2023 23:56:44 +0000 Subject: [PATCH 28/92] Fix few vulnerabilities found by Cppcheck While performing SAST scanning using Cppcheck against source code of commit 81196469, several code vulnerabilities were found. Fix following issues: 1. Parameters of `snprintf` function are incorrect. Cppcheck error: client/mysql_plugin.c:1228: error: snprintf format string requires 6 parameters but only 5 are given. It is due to commit 630d7229 introduced option `--lc-messages-dir` in the bootstrap command. However the parameter was not even given in the `snprintf` after changing the format string. Fix: Restructure the code logic and correct the function parameters for `snprintf`. 2. Null pointer is used in a `snprintf` which could cause a crash. Cppcheck error: extra/mariabackup/xbcloud.cc:2534: error: Null pointer dereference The code intended to print the swift_project name, if the opt_swift_project_id is NULL but opt_swift_project is not NULL. However the parameter of `snprintf` was mistakenly using `opt_swift_project_id`. Fix: Change to use the correct string from `opt_swift_project`. 3. Potential double release of a memory Cppcheck error: plugin/auth_pam/testing/pam_mariadb_mtr.c:69: error: Memory pointed to by 'resp' is freed twice. A pointer `resp` is reused and allocated new memory after it has been freed. However, `resp` was not set to NULL after freed. Potential double release of the same pointer if the call back function doesn't allocate new memory for `resp` pointer. Fix: Set the `resp` pointer to NULL after the first free() to make sure the same address is not freed twice. All new code of the whole pull request, including one or several files that are either new files or modified ones, are contributed under the BSD-new license. I am contributing on behalf of my employer Amazon Web Services, Inc. --- client/mysql_plugin.c | 112 ++++++++++------------ extra/mariabackup/xbcloud.cc | 2 +- plugin/auth_pam/testing/pam_mariadb_mtr.c | 1 + 3 files changed, 54 insertions(+), 61 deletions(-) diff --git a/client/mysql_plugin.c b/client/mysql_plugin.c index d87d4269f89a9..97dc48a1ff4d5 100644 --- a/client/mysql_plugin.c +++ b/client/mysql_plugin.c @@ -102,7 +102,7 @@ int main(int argc,char *argv[]) MY_INIT(argv[0]); sf_leaking_memory=1; /* don't report memory leaks on early exits */ plugin_data.name= 0; /* initialize name */ - + /* The following operations comprise the method for enabling or disabling a plugin. We begin by processing the command options then check the @@ -110,15 +110,15 @@ int main(int argc,char *argv[]) --plugin-ini (if specified). If the directories are Ok, we then look for the mysqld executable and the plugin soname. Finally, we build a bootstrap command file for use in bootstraping the server. - + If any step fails, the method issues an error message and the tool exits. - + 1) Parse, execute, and verify command options. 2) Check access to directories. 3) Look for mysqld executable. 4) Look for the plugin. 5) Build a bootstrap file with commands to enable or disable plugin. - + */ if ((error= process_options(argc, argv, operation)) || (error= check_access()) || @@ -126,11 +126,11 @@ int main(int argc,char *argv[]) (error= find_plugin(tp_path)) || (error= build_bootstrap_file(operation, bootstrap))) goto exit; - + /* Dump the bootstrap file if --verbose specified. */ if (opt_verbose && ((error= dump_bootstrap_file(bootstrap)))) goto exit; - + /* Start the server in bootstrap mode and execute bootstrap commands */ error= bootstrap_server(server_path, bootstrap); @@ -238,7 +238,7 @@ static int run_command(char* cmd, const char *mode) #ifdef __WIN__ /** Check to see if there are spaces in a path. - + @param[in] path The Windows path to examine. @retval int spaces found = 1, no spaces = 0 @@ -253,7 +253,7 @@ static int has_spaces(const char *path) /** Convert a Unix path to a Windows path. - + @param[in] path The Windows path to examine. @returns string containing path with / changed to \\ @@ -335,12 +335,12 @@ static int get_default_values() #ifdef __WIN__ { char *format_str= 0; - + if (has_spaces(tool_path) || has_spaces(defaults_file)) format_str = "\"%s --mysqld > %s\""; else format_str = "%s --mysqld > %s"; - + snprintf(defaults_cmd, sizeof(defaults_cmd), format_str, add_quotes(tool_path), add_quotes(defaults_file)); if (opt_verbose) @@ -675,7 +675,7 @@ static int load_plugin_data(char *plugin_name, char *config_file) { reason= "Bad format in plugin configuration file."; fclose(file_ptr); - goto error; + goto error; } break; } @@ -709,7 +709,7 @@ static int load_plugin_data(char *plugin_name, char *config_file) } } } - + fclose(file_ptr); return 0; @@ -740,7 +740,7 @@ static int check_options(int argc, char **argv, char *operation) int num_found= 0; /* number of options found (shortcut loop) */ char config_file[FN_REFLEN]; /* configuration file name */ char plugin_name[FN_REFLEN]; /* plugin name */ - + /* Form prefix strings for the options. */ const char *basedir_prefix = "--basedir="; size_t basedir_len= strlen(basedir_prefix); @@ -815,7 +815,7 @@ static int check_options(int argc, char **argv, char *operation) return 1; } /* If a plugin was specified, read the config file. */ - else if (strlen(plugin_name) > 0) + else if (strlen(plugin_name) > 0) { if (load_plugin_data(plugin_name, config_file)) { @@ -847,22 +847,22 @@ static int check_options(int argc, char **argv, char *operation) /** Parse, execute, and verify command options. - + This method handles all of the option processing including the optional features for displaying data (--print-defaults, --help ,etc.) that do not result in an attempt to ENABLE or DISABLE of a plugin. - + @param[in] arc Count of arguments @param[in] argv Array of arguments @param[out] operation Operation (ENABLE or DISABLE) - + @retval int error = 1, success = 0, exit program = -1 */ static int process_options(int argc, char *argv[], char *operation) { int error= 0; - + /* Parse and execute command-line options */ if ((error= handle_options(&argc, &argv, my_long_options, get_one_option))) return error; @@ -881,7 +881,7 @@ static int process_options(int argc, char *argv[], char *operation) char buff[FN_REFLEN]; if (basedir_len + 2 > FN_REFLEN) return -1; - + memcpy(buff, opt_basedir, basedir_len); buff[basedir_len]= '/'; buff[basedir_len + 1]= '\0'; @@ -890,7 +890,7 @@ static int process_options(int argc, char *argv[], char *operation) opt_basedir= my_strdup(buff, MYF(MY_FAE)); } } - + /* If the user did not specify the option to skip loading defaults from a config file and the required options are not present or there was an error @@ -925,18 +925,18 @@ static int process_options(int argc, char *argv[], char *operation) /** Check access - + This method checks to ensure all of the directories (opt_basedir, opt_plugin_dir, opt_datadir, and opt_plugin_ini) are accessible by the user. - + @retval int error = 1, success = 0 */ static int check_access() { int error= 0; - + if ((error= my_access(opt_basedir, F_OK))) { fprintf(stderr, "ERROR: Cannot access basedir at '%s'.\n", @@ -1048,13 +1048,13 @@ static int find_plugin(char *tp_path) /** Build the bootstrap file. - + Create a new file and populate it with SQL commands to ENABLE or DISABLE the plugin via REPLACE and DELETE operations on the mysql.plugin table. param[in] operation The type of operation (ENABLE or DISABLE) param[out] bootstrap A FILE* pointer - + @retval int error = 1, success = 0 */ @@ -1062,7 +1062,7 @@ static int build_bootstrap_file(char *operation, char *bootstrap) { int error= 0; FILE *file= 0; - + /* Perform plugin operation : ENABLE or DISABLE @@ -1073,10 +1073,10 @@ static int build_bootstrap_file(char *operation, char *bootstrap) .ini configuration file. Once the file is built, a call to mysqld is made in read only, bootstrap modes to read the SQL statements and execute them. - + Note: Replace was used so that if a user loads a newer version of a library with a different library name, the new library name is - used for symbols that match. + used for symbols that match. */ if ((error= make_tempfile(bootstrap, "sql"))) { @@ -1123,7 +1123,7 @@ static int build_bootstrap_file(char *operation, char *bootstrap) printf("# Disabling %s...\n", plugin_data.name); } } - + exit: fclose(file); return error; @@ -1132,11 +1132,11 @@ static int build_bootstrap_file(char *operation, char *bootstrap) /** Dump bootstrap file. - + Read the contents of the bootstrap file and print it out. - + @param[in] bootstrap_file Name of bootstrap file to read - + @retval int error = 1, success = 0 */ @@ -1173,7 +1173,7 @@ static int dump_bootstrap_file(char *bootstrap_file) /** Bootstrap the server - + Create a command line sequence to launch mysqld in bootstrap mode. This will allow mysqld to launch a minimal server instance to read and execute SQL commands from a file piped in (the bootstrap file). We use @@ -1194,47 +1194,39 @@ static int dump_bootstrap_file(char *bootstrap_file) static int bootstrap_server(char *server_path, char *bootstrap_file) { - char bootstrap_cmd[FN_REFLEN]; + char bootstrap_cmd[FN_REFLEN]= {0}; + char lc_messages_dir_str[FN_REFLEN]= {0}; int error= 0; #ifdef __WIN__ char *format_str= 0; const char *verbose_str= NULL; - - +#endif + + if (opt_lc_messages_dir != NULL) + snprintf(lc_messages_dir_str, sizeof(lc_messages_dir_str), "--lc-messages-dir=%s", + opt_lc_messages_dir); + +#ifdef __WIN__ if (opt_verbose) verbose_str= "--console"; else verbose_str= ""; + if (has_spaces(opt_datadir) || has_spaces(opt_basedir) || - has_spaces(bootstrap_file)) - { - if (opt_lc_messages_dir != NULL) - format_str= "\"%s %s --bootstrap --datadir=%s --basedir=%s --lc-messages-dir=%s <%s\""; - else - format_str= "\"%s %s --bootstrap --datadir=%s --basedir=%s <%s\""; - } + has_spaces(bootstrap_file) || has_spaces(lc_messages_dir_str)) + format_str= "\"%s %s --bootstrap --datadir=%s --basedir=%s %s <%s\""; else - { - if (opt_lc_messages_dir != NULL) - format_str= "\"%s %s --bootstrap --datadir=%s --basedir=%s --lc-messages-dir=%s <%s\""; - else - format_str= "%s %s --bootstrap --datadir=%s --basedir=%s <%s"; - } + format_str= "%s %s --bootstrap --datadir=%s --basedir=%s %s <%s"; + snprintf(bootstrap_cmd, sizeof(bootstrap_cmd), format_str, add_quotes(convert_path(server_path)), verbose_str, add_quotes(opt_datadir), add_quotes(opt_basedir), - add_quotes(bootstrap_file)); + add_quotes(lc_messages_dir_str), add_quotes(bootstrap_file)); #else - if (opt_lc_messages_dir != NULL) - snprintf(bootstrap_cmd, sizeof(bootstrap_cmd), - "%s --no-defaults --bootstrap --datadir=%s --basedir=%s --lc-messages-dir=%s" - " <%s", server_path, opt_datadir, opt_basedir, opt_lc_messages_dir, bootstrap_file); - else - snprintf(bootstrap_cmd, sizeof(bootstrap_cmd), - "%s --no-defaults --bootstrap --datadir=%s --basedir=%s" - " <%s", server_path, opt_datadir, opt_basedir, bootstrap_file); - + snprintf(bootstrap_cmd, sizeof(bootstrap_cmd), + "%s --no-defaults --bootstrap --datadir=%s --basedir=%s %s" + " <%s", server_path, opt_datadir, opt_basedir, lc_messages_dir_str, bootstrap_file); #endif /* Execute the command */ @@ -1247,6 +1239,6 @@ static int bootstrap_server(char *server_path, char *bootstrap_file) fprintf(stderr, "ERROR: Unexpected result from bootstrap. Error code: %d.\n", error); - + return error; } diff --git a/extra/mariabackup/xbcloud.cc b/extra/mariabackup/xbcloud.cc index cee76e5f3d7a7..588a15eb791dd 100644 --- a/extra/mariabackup/xbcloud.cc +++ b/extra/mariabackup/xbcloud.cc @@ -2534,7 +2534,7 @@ swift_keystone_auth_v3(const char *auth_url, swift_auth_info *info) } else if (opt_swift_project != NULL) { snprintf(scope, sizeof(scope), ",\"scope\":{\"project\":{\"name\":\"%s\"%s}}", - opt_swift_project_id, domain); + opt_swift_project, domain); } snprintf(payload, sizeof(payload), "{\"auth\":{\"identity\":" diff --git a/plugin/auth_pam/testing/pam_mariadb_mtr.c b/plugin/auth_pam/testing/pam_mariadb_mtr.c index 2075d5fdbf36b..d4c79f3133065 100644 --- a/plugin/auth_pam/testing/pam_mariadb_mtr.c +++ b/plugin/auth_pam/testing/pam_mariadb_mtr.c @@ -45,6 +45,7 @@ int pam_sm_authenticate(pam_handle_t *pamh, int flags __attribute__((unused)), else { free(resp); + resp= NULL; msg[0].msg_style = PAM_PROMPT_ECHO_ON; msg[0].msg = "PIN:"; pam_err = (*conv->conv)(1, msgp, &resp, conv->appdata_ptr); From a6a906d76697d5487418d51b251a3070ac6e8c80 Mon Sep 17 00:00:00 2001 From: Oleksandr Byelkin Date: Fri, 25 Nov 2022 12:54:24 +0100 Subject: [PATCH 29/92] MDEV-26831 fallout: fix problems of name resolution cache - Avoid passing real field cache as a parameter when we check for duplicates. - Correct cache cleanup (cached field number also have to be reset). - Name resolution cache simple test added. --- .../main/name_resolution_cache_debug.result | 25 +++++++++++++ .../main/name_resolution_cache_debug.test | 36 +++++++++++++++++++ sql/sql_base.cc | 30 +++++++++++++--- 3 files changed, 87 insertions(+), 4 deletions(-) create mode 100644 mysql-test/main/name_resolution_cache_debug.result create mode 100644 mysql-test/main/name_resolution_cache_debug.test diff --git a/mysql-test/main/name_resolution_cache_debug.result b/mysql-test/main/name_resolution_cache_debug.result new file mode 100644 index 0000000000000..7030176c5fe8e --- /dev/null +++ b/mysql-test/main/name_resolution_cache_debug.result @@ -0,0 +1,25 @@ +connect con1,localhost,root; +create table t1 (a int, b int); +create table t2 (c int, d int); +create view v1 as select c+1 as e, d+1 as f from t2; +SET DEBUG_SYNC= 'table_field_cached SIGNAL in_sync WAIT_FOR go'; +prepare stmt1 from "select a from t1"; +execute stmt1; +connection default; +SET DEBUG_SYNC= 'now WAIT_FOR in_sync'; +SET DEBUG_SYNC= 'now SIGNAL go'; +connection con1; +a +SET DEBUG_SYNC= 'table_field_cached SIGNAL in_sync WAIT_FOR go'; +prepare stmt1 from "select e from v1"; +execute stmt1; +connection default; +SET DEBUG_SYNC= 'now WAIT_FOR in_sync'; +SET DEBUG_SYNC= 'now SIGNAL go'; +connection con1; +e +connection default; +disconnect con1; +SET DEBUG_SYNC = 'RESET'; +drop view v1; +drop table t1,t2; diff --git a/mysql-test/main/name_resolution_cache_debug.test b/mysql-test/main/name_resolution_cache_debug.test new file mode 100644 index 0000000000000..362d883cbd1d7 --- /dev/null +++ b/mysql-test/main/name_resolution_cache_debug.test @@ -0,0 +1,36 @@ + +source include/have_debug_sync.inc; + +connect con1,localhost,root; +create table t1 (a int, b int); +create table t2 (c int, d int); +create view v1 as select c+1 as e, d+1 as f from t2; + +SET DEBUG_SYNC= 'table_field_cached SIGNAL in_sync WAIT_FOR go'; +prepare stmt1 from "select a from t1"; +--send execute stmt1 + +connection default; +SET DEBUG_SYNC= 'now WAIT_FOR in_sync'; +SET DEBUG_SYNC= 'now SIGNAL go'; + +connection con1; +--reap + +SET DEBUG_SYNC= 'table_field_cached SIGNAL in_sync WAIT_FOR go'; +prepare stmt1 from "select e from v1"; +--send execute stmt1 + +connection default; +SET DEBUG_SYNC= 'now WAIT_FOR in_sync'; +SET DEBUG_SYNC= 'now SIGNAL go'; + +connection con1; +--reap + +connection default; +disconnect con1; + +SET DEBUG_SYNC = 'RESET'; +drop view v1; +drop table t1,t2; diff --git a/sql/sql_base.cc b/sql/sql_base.cc index d1ee15fb0856d..dd633f0bb92ec 100644 --- a/sql/sql_base.cc +++ b/sql/sql_base.cc @@ -6037,7 +6037,10 @@ find_field_in_table(THD *thd, TABLE *table, const char *name, size_t length, if (cached_field_index < table->s->fields && !my_strcasecmp(system_charset_info, table->field[cached_field_index]->field_name.str, name)) + { field= table->field[cached_field_index]; + DEBUG_SYNC(thd, "table_field_cached"); + } else { LEX_CSTRING fname= {name, length}; @@ -6485,6 +6488,13 @@ find_field_in_tables(THD *thd, Item_ident *item, if (last_table) last_table= last_table->next_name_resolution_table; + uint fake_index_for_duplicate_search= NO_CACHED_FIELD_INDEX; + /* + For the field search it will point to field cache, but for duplicate + search it will point to fake_index_for_duplicate_search (no cache + present). + */ + uint *current_cache= &(item->cached_field_index); for (; cur_table != last_table ; cur_table= cur_table->next_name_resolution_table) { @@ -6494,7 +6504,7 @@ find_field_in_tables(THD *thd, Item_ident *item, SQLCOM_SHOW_FIELDS) ? false : check_privileges, allow_rowid, - &(item->cached_field_index), + current_cache, register_tree_change, &actual_table); if (cur_field) @@ -6509,7 +6519,7 @@ find_field_in_tables(THD *thd, Item_ident *item, item->name.str, db, table_name, ref, false, allow_rowid, - &(item->cached_field_index), + current_cache, register_tree_change, &actual_table); if (cur_field) @@ -6526,8 +6536,19 @@ find_field_in_tables(THD *thd, Item_ident *item, Store the original table of the field, which may be different from cur_table in the case of NATURAL/USING join. */ - item->cached_table= (!actual_table->cacheable_table || found) ? - 0 : actual_table; + if (actual_table->cacheable_table /*(1)*/ && !found /*(2)*/) + { + /* + We have just found a field allowed to cache (1) and + it is not dublicate search (2). + */ + item->cached_table= actual_table; + } + else + { + item->cached_table= NULL; + item->cached_field_index= NO_CACHED_FIELD_INDEX; + } DBUG_ASSERT(thd->where); /* @@ -6546,6 +6567,7 @@ find_field_in_tables(THD *thd, Item_ident *item, return (Field*) 0; } found= cur_field; + current_cache= &fake_index_for_duplicate_search; } } From ccec9b1de95a66b7597bc30e0a60bd61866f225d Mon Sep 17 00:00:00 2001 From: Igor Babaev Date: Wed, 1 Mar 2023 22:49:27 -0800 Subject: [PATCH 30/92] MDEV-30706 Different results of selects from view and CTE with same definition MDEV-30668 Set function aggregated in outer select used in view definition This patch fixes two bugs concerning views whose specifications contain subqueries with set functions aggregated in outer selects. Due to the first bug those such views that have implicit grouping were considered as mergeable. This led to wrong result sets for selects from these views. Due to the second bug the aggregation select was determined incorrectly and this led to bogus error messages. The patch added several test cases for these two bugs and for four other duplicate bugs. The patch also enables view-protocol for many other test cases. Approved by Oleksandr Byelkin --- mysql-test/main/derived_view.result | 482 ++++++++++++++++++ mysql-test/main/derived_view.test | 297 +++++++++++ mysql-test/main/func_group.result | 9 +- mysql-test/main/func_group.test | 11 +- mysql-test/main/group_by.result | 10 +- mysql-test/main/group_by.test | 23 +- mysql-test/main/opt_trace.result | 12 +- mysql-test/main/subselect.result | 262 ++++++---- mysql-test/main/subselect.test | 215 ++++---- mysql-test/main/subselect4.result | 4 +- .../main/subselect_no_exists_to_in.result | 262 ++++++---- mysql-test/main/subselect_no_mat.result | 262 ++++++---- mysql-test/main/subselect_no_opts.result | 262 ++++++---- mysql-test/main/subselect_no_scache.result | 262 ++++++---- mysql-test/main/subselect_no_semijoin.result | 262 ++++++---- sql/item.cc | 16 +- sql/item_sum.cc | 3 +- sql/sql_base.cc | 3 +- sql/sql_derived.cc | 18 - sql/sql_lex.cc | 43 +- sql/sql_lex.h | 2 + sql/table.cc | 16 +- sql/table.h | 7 +- 23 files changed, 2021 insertions(+), 722 deletions(-) diff --git a/mysql-test/main/derived_view.result b/mysql-test/main/derived_view.result index 3df1acc66e478..ab32e4778166d 100644 --- a/mysql-test/main/derived_view.result +++ b/mysql-test/main/derived_view.result @@ -3691,3 +3691,485 @@ drop procedure sp2; drop view v, v2; drop table t1,t2; # End of 10.2 tests +# +# MDEV-30706: view defined as select with implicit grouping and +# a set function used in a subquery +# +CREATE TABLE t1 (a INT PRIMARY KEY, b INT); +INSERT INTO t1 VALUES (1,1), (2,2); +CREATE TABLE t2 (a INT PRIMARY KEY, b INT); +INSERT INTO t2 VALUES (1,1), (3,3); +CREATE TABLE t3 (a INT PRIMARY KEY, b INT); +INSERT INTO t3 VALUES (2,2), (4,4), (7,7); +CREATE TABLE t4 (a INT PRIMARY KEY, b INT); +INSERT INTO t4 VALUES (2,2), (5,5), (7,7); +CREATE VIEW v AS SELECT +(SELECT SUM(t4.b) FROM t1, t2 WHERE t1.a = t2.b GROUP BY t1.a) AS m +FROM t3, t4 +WHERE t3.a = t4.b; +SELECT +(SELECT SUM(t4.b) FROM t1, t2 WHERE t1.a = t2.b GROUP BY t1.a) AS m +FROM t3, t4 +WHERE t3.a = t4.b; +m +9 +SELECT * FROM v; +m +9 +WITH cte AS ( SELECT +(SELECT SUM(t4.b) FROM t1, t2 WHERE t1.a = t2.b GROUP BY t1.a) AS m +FROM t3, t4 +WHERE t3.a = t4.b ) SELECT * FROM cte; +m +9 +EXPLAIN SELECT +(SELECT SUM(t4.b) FROM t1, t2 WHERE t1.a = t2.b GROUP BY t1.a) AS m +FROM t3, t4 +WHERE t3.a = t4.b; +id select_type table type possible_keys key key_len ref rows Extra +1 PRIMARY t4 ALL NULL NULL NULL NULL 3 Using where +1 PRIMARY t3 eq_ref PRIMARY PRIMARY 4 test.t4.b 1 Using index +2 DEPENDENT SUBQUERY t2 ALL NULL NULL NULL NULL 2 Using where; Using temporary; Using filesort +2 DEPENDENT SUBQUERY t1 eq_ref PRIMARY PRIMARY 4 test.t2.b 1 Using index +EXPLAIN SELECT * FROM v; +id select_type table type possible_keys key key_len ref rows Extra +1 PRIMARY ALL NULL NULL NULL NULL 3 +2 SUBQUERY t4 ALL NULL NULL NULL NULL 3 Using where +2 SUBQUERY t3 eq_ref PRIMARY PRIMARY 4 test.t4.b 1 Using index +3 DEPENDENT SUBQUERY t2 ALL NULL NULL NULL NULL 2 Using where; Using temporary; Using filesort +3 DEPENDENT SUBQUERY t1 eq_ref PRIMARY PRIMARY 4 test.t2.b 1 Using index +EXPLAIN WITH cte AS ( SELECT +(SELECT SUM(t4.b) FROM t1, t2 WHERE t1.a = t2.b GROUP BY t1.a) AS m +FROM t3, t4 +WHERE t3.a = t4.b ) SELECT * FROM cte; +id select_type table type possible_keys key key_len ref rows Extra +1 PRIMARY ALL NULL NULL NULL NULL 3 +2 DERIVED t4 ALL NULL NULL NULL NULL 3 Using where +2 DERIVED t3 eq_ref PRIMARY PRIMARY 4 test.t4.b 1 Using index +3 DEPENDENT SUBQUERY t2 ALL NULL NULL NULL NULL 2 Using where; Using temporary; Using filesort +3 DEPENDENT SUBQUERY t1 eq_ref PRIMARY PRIMARY 4 test.t2.b 1 Using index +PREPARE stmt FROM "SELECT +(SELECT SUM(t4.b) FROM t1, t2 WHERE t1.a = t2.b GROUP BY t1.a) AS m +FROM t3, t4 +WHERE t3.a = t4.b"; +execute stmt; +m +9 +execute stmt; +m +9 +DEALLOCATE PREPARE stmt; +PREPARE stmt FROM "SELECT * FROM v"; +execute stmt; +m +9 +execute stmt; +m +9 +DEALLOCATE PREPARE stmt; +PREPARE stmt FROM "WITH cte AS ( SELECT +(SELECT SUM(t4.b) FROM t1, t2 WHERE t1.a = t2.b GROUP BY t1.a) AS m +FROM t3, t4 +WHERE t3.a = t4.b ) SELECT * FROM cte"; +execute stmt; +m +9 +execute stmt; +m +9 +DEALLOCATE PREPARE stmt; +DROP VIEW v; +DROP TABLE t1,t2,t3,t4; +# +# MDEV-29224: view defined as select with implicit grouping and +# a set function used in a subquery +# +CREATE TABLE t1 (f1 INT); +INSERT INTO t1 VALUES (1),(2); +CREATE TABLE t2 (f2 int); +INSERT INTO t2 VALUES (3); +CREATE VIEW v AS SELECT ( SELECT MAX(f1) FROM t2 ) FROM t1; +SELECT ( SELECT MAX(f1) FROM t2 ) FROM t1; +( SELECT MAX(f1) FROM t2 ) +2 +SELECT * FROM v; +( SELECT MAX(f1) FROM t2 ) +2 +WITH cte AS ( SELECT ( SELECT MAX(f1) FROM t2 ) FROM t1 ) SELECT * FROM cte; +( SELECT MAX(f1) FROM t2 ) +2 +EXPLAIN SELECT ( SELECT MAX(f1) FROM t2 ) FROM t1; +id select_type table type possible_keys key key_len ref rows Extra +1 PRIMARY t1 ALL NULL NULL NULL NULL 2 +2 DEPENDENT SUBQUERY t2 system NULL NULL NULL NULL 1 +EXPLAIN SELECT * FROM v; +id select_type table type possible_keys key key_len ref rows Extra +1 PRIMARY ALL NULL NULL NULL NULL 2 +2 SUBQUERY t1 ALL NULL NULL NULL NULL 2 +3 DEPENDENT SUBQUERY t2 system NULL NULL NULL NULL 1 +EXPLAIN WITH cte AS ( SELECT ( SELECT MAX(f1) FROM t2 ) FROM t1 ) SELECT * FROM cte; +id select_type table type possible_keys key key_len ref rows Extra +1 PRIMARY ALL NULL NULL NULL NULL 2 +2 DERIVED t1 ALL NULL NULL NULL NULL 2 +3 DEPENDENT SUBQUERY t2 system NULL NULL NULL NULL 1 +PREPARE stmt FROM "SELECT ( SELECT MAX(f1) FROM t2 ) FROM t1"; +execute stmt; +( SELECT MAX(f1) FROM t2 ) +2 +execute stmt; +( SELECT MAX(f1) FROM t2 ) +2 +DEALLOCATE PREPARE stmt; +PREPARE stmt FROM "SELECT * FROM v"; +execute stmt; +( SELECT MAX(f1) FROM t2 ) +2 +execute stmt; +( SELECT MAX(f1) FROM t2 ) +2 +DEALLOCATE PREPARE stmt; +PREPARE stmt FROM "WITH cte AS ( SELECT ( SELECT MAX(f1) FROM t2 ) FROM t1 ) SELECT * FROM cte"; +execute stmt; +( SELECT MAX(f1) FROM t2 ) +2 +execute stmt; +( SELECT MAX(f1) FROM t2 ) +2 +DEALLOCATE PREPARE stmt; +DROP VIEW v; +DROP TABLE t1,t2; +# +# MDEV-28573: view defined as select with implicit grouping and +# a set function used in a subquery +# +CREATE TABLE t1 (a INTEGER, b INTEGER); +CREATE TABLE t2 (c INTEGER); +INSERT INTO t1 VALUES (1,11), (2,22), (2,22); +INSERT INTO t2 VALUES (1), (2); +CREATE VIEW v1 AS SELECT (SELECT COUNT(b) FROM t2) FROM t1; +CREATE VIEW v2 AS SELECT (SELECT COUNT(b) FROM t2 WHERE c > 1) FROM t1; +SELECT (SELECT COUNT(b) FROM t2) FROM t1; +ERROR 21000: Subquery returns more than 1 row +SELECT * FROM v1; +ERROR 21000: Subquery returns more than 1 row +WITH cte AS ( SELECT (SELECT COUNT(b) FROM t2) FROM t1 ) SELECT * FROM cte; +ERROR 21000: Subquery returns more than 1 row +SELECT (SELECT COUNT(b) FROM t2 WHERE c > 1) FROM t1; +(SELECT COUNT(b) FROM t2 WHERE c > 1) +3 +SELECT * FROM v2; +(SELECT COUNT(b) FROM t2 WHERE c > 1) +3 +WITH cte AS ( SELECT (SELECT COUNT(b) FROM t2 WHERE c > 1) FROM t1 ) SELECT * FROM cte; +(SELECT COUNT(b) FROM t2 WHERE c > 1) +3 +EXPLAIN SELECT (SELECT COUNT(b) FROM t2) FROM t1; +id select_type table type possible_keys key key_len ref rows Extra +1 PRIMARY t1 ALL NULL NULL NULL NULL 3 +2 DEPENDENT SUBQUERY t2 ALL NULL NULL NULL NULL 2 +EXPLAIN SELECT * FROM v1; +id select_type table type possible_keys key key_len ref rows Extra +1 PRIMARY ALL NULL NULL NULL NULL 3 +2 SUBQUERY t1 ALL NULL NULL NULL NULL 3 +3 DEPENDENT SUBQUERY t2 ALL NULL NULL NULL NULL 2 +EXPLAIN WITH cte AS ( SELECT (SELECT COUNT(b) FROM t2) FROM t1 ) SELECT * FROM cte; +id select_type table type possible_keys key key_len ref rows Extra +1 PRIMARY ALL NULL NULL NULL NULL 3 +2 DERIVED t1 ALL NULL NULL NULL NULL 3 +3 DEPENDENT SUBQUERY t2 ALL NULL NULL NULL NULL 2 +PREPARE stmt FROM "SELECT (SELECT COUNT(b) FROM t2) FROM t1"; +execute stmt; +ERROR 21000: Subquery returns more than 1 row +execute stmt; +ERROR 21000: Subquery returns more than 1 row +DEALLOCATE PREPARE stmt; +PREPARE stmt FROM "SELECT * FROM v1"; +execute stmt; +ERROR 21000: Subquery returns more than 1 row +execute stmt; +ERROR 21000: Subquery returns more than 1 row +DEALLOCATE PREPARE stmt; +PREPARE stmt FROM "WITH cte AS ( SELECT (SELECT COUNT(b) FROM t2) FROM t1 ) SELECT * FROM cte"; +execute stmt; +ERROR 21000: Subquery returns more than 1 row +execute stmt; +ERROR 21000: Subquery returns more than 1 row +DEALLOCATE PREPARE stmt; +PREPARE stmt FROM "SELECT (SELECT COUNT(b) FROM t2 WHERE c > 1) FROM t1"; +execute stmt; +(SELECT COUNT(b) FROM t2 WHERE c > 1) +3 +execute stmt; +(SELECT COUNT(b) FROM t2 WHERE c > 1) +3 +DEALLOCATE PREPARE stmt; +PREPARE stmt FROM "SELECT * FROM v2"; +execute stmt; +(SELECT COUNT(b) FROM t2 WHERE c > 1) +3 +execute stmt; +(SELECT COUNT(b) FROM t2 WHERE c > 1) +3 +DEALLOCATE PREPARE stmt; +PREPARE stmt FROM "WITH cte AS ( SELECT (SELECT COUNT(b) FROM t2 WHERE c > 1) FROM t1 ) SELECT * FROM cte"; +execute stmt; +(SELECT COUNT(b) FROM t2 WHERE c > 1) +3 +execute stmt; +(SELECT COUNT(b) FROM t2 WHERE c > 1) +3 +DEALLOCATE PREPARE stmt; +DROP VIEW v1,v2; +DROP TABLE t1,t2; +# +# MDEV-28570: VIEW with WHERE containing subquery +# with set function aggregated in query +# +CREATE TABLE t1 (a int, b int); +CREATE TABLE t2 (c int, d int); +INSERT INTO t1 VALUES +(1,10), (2,10), (1,20), (2,20), (3,20), (2,30), (4,40); +INSERT INTO t2 VALUES +(2,10), (2,20), (4,10), (5,10), (3,20), (2,40); +CREATE VIEW v AS SELECT a FROM t1 GROUP BY a +HAVING a IN (SELECT c FROM t2 WHERE MAX(b)>20); +SELECT a FROM t1 GROUP BY a +HAVING a IN (SELECT c FROM t2 WHERE MAX(b)>20); +a +2 +4 +SELECT * FROM v; +a +2 +4 +WITH cte AS ( SELECT a FROM t1 GROUP BY a +HAVING a IN (SELECT c FROM t2 WHERE MAX(b)>20) ) SELECT * FROM cte; +a +2 +4 +EXPLAIN SELECT a FROM t1 GROUP BY a +HAVING a IN (SELECT c FROM t2 WHERE MAX(b)>20); +id select_type table type possible_keys key key_len ref rows Extra +1 PRIMARY t1 ALL NULL NULL NULL NULL 7 Using temporary; Using filesort +2 DEPENDENT SUBQUERY t2 ALL NULL NULL NULL NULL 6 +EXPLAIN SELECT * FROM v; +id select_type table type possible_keys key key_len ref rows Extra +1 PRIMARY ALL NULL NULL NULL NULL 7 +2 DERIVED t1 ALL NULL NULL NULL NULL 7 Using temporary; Using filesort +3 DEPENDENT SUBQUERY t2 ALL NULL NULL NULL NULL 6 +EXPLAIN WITH cte AS ( SELECT a FROM t1 GROUP BY a +HAVING a IN (SELECT c FROM t2 WHERE MAX(b)>20) ) SELECT * FROM cte; +id select_type table type possible_keys key key_len ref rows Extra +1 PRIMARY ALL NULL NULL NULL NULL 7 +2 DERIVED t1 ALL NULL NULL NULL NULL 7 Using temporary; Using filesort +3 DEPENDENT SUBQUERY t2 ALL NULL NULL NULL NULL 6 +PREPARE stmt FROM "SELECT a FROM t1 GROUP BY a +HAVING a IN (SELECT c FROM t2 WHERE MAX(b)>20)"; +execute stmt; +a +2 +4 +execute stmt; +a +2 +4 +DEALLOCATE PREPARE stmt; +PREPARE stmt FROM "SELECT * FROM v"; +execute stmt; +a +2 +4 +execute stmt; +a +2 +4 +DEALLOCATE PREPARE stmt; +PREPARE stmt FROM "WITH cte AS ( SELECT a FROM t1 GROUP BY a +HAVING a IN (SELECT c FROM t2 WHERE MAX(b)>20) ) SELECT * FROM cte"; +execute stmt; +a +2 +4 +execute stmt; +a +2 +4 +DEALLOCATE PREPARE stmt; +DROP VIEW v; +DROP TABLE t1,t2; +# +# MDEV-28571: VIEW with select list containing subquery +# with set function aggregated in query +# +CREATE TABLE t1 (a int, b int); +CREATE TABLE t2 (m int, n int); +INSERT INTO t1 VALUES (2,2), (2,2), (3,3), (3,3), (3,3), (4,4); +INSERT INTO t2 VALUES (1,11), (2,22), (3,32), (4,44), (4,44); +CREATE VIEW v AS SELECT (SELECT GROUP_CONCAT(COUNT(a)) FROM t2 WHERE m = a) AS c +FROM t1 +GROUP BY a; +SELECT (SELECT GROUP_CONCAT(COUNT(a)) FROM t2 WHERE m = a) AS c +FROM t1 +GROUP BY a; +c +2 +3 +1,1 +SELECT * FROM v; +c +2 +3 +1,1 +WITH cte AS ( SELECT (SELECT GROUP_CONCAT(COUNT(a)) FROM t2 WHERE m = a) AS c +FROM t1 +GROUP BY a ) SELECT * FROM cte; +c +2 +3 +1,1 +EXPLAIN SELECT (SELECT GROUP_CONCAT(COUNT(a)) FROM t2 WHERE m = a) AS c +FROM t1 +GROUP BY a; +id select_type table type possible_keys key key_len ref rows Extra +1 PRIMARY t1 ALL NULL NULL NULL NULL 6 Using temporary; Using filesort +2 DEPENDENT SUBQUERY t2 ALL NULL NULL NULL NULL 5 Using where +EXPLAIN SELECT * FROM v; +id select_type table type possible_keys key key_len ref rows Extra +1 PRIMARY ALL NULL NULL NULL NULL 6 +2 DERIVED t1 ALL NULL NULL NULL NULL 6 Using temporary; Using filesort +3 DEPENDENT SUBQUERY t2 ALL NULL NULL NULL NULL 5 Using where +EXPLAIN WITH cte AS ( SELECT (SELECT GROUP_CONCAT(COUNT(a)) FROM t2 WHERE m = a) AS c +FROM t1 +GROUP BY a ) SELECT * FROM cte; +id select_type table type possible_keys key key_len ref rows Extra +1 PRIMARY ALL NULL NULL NULL NULL 6 +2 DERIVED t1 ALL NULL NULL NULL NULL 6 Using temporary; Using filesort +3 DEPENDENT SUBQUERY t2 ALL NULL NULL NULL NULL 5 Using where +PREPARE stmt FROM "SELECT (SELECT GROUP_CONCAT(COUNT(a)) FROM t2 WHERE m = a) AS c +FROM t1 +GROUP BY a"; +execute stmt; +c +2 +3 +1,1 +execute stmt; +c +2 +3 +1,1 +DEALLOCATE PREPARE stmt; +PREPARE stmt FROM "SELECT * FROM v"; +execute stmt; +c +2 +3 +1,1 +execute stmt; +c +2 +3 +1,1 +DEALLOCATE PREPARE stmt; +PREPARE stmt FROM "WITH cte AS ( SELECT (SELECT GROUP_CONCAT(COUNT(a)) FROM t2 WHERE m = a) AS c +FROM t1 +GROUP BY a ) SELECT * FROM cte"; +execute stmt; +c +2 +3 +1,1 +execute stmt; +c +2 +3 +1,1 +DEALLOCATE PREPARE stmt; +DROP VIEW v; +DROP TABLE t1,t2; +# +# MDEV-30668: VIEW with WHERE containing nested subquery +# with set function aggregated in outer subquery +# +create table t1 (a int); +insert into t1 values (3), (7), (1); +create table t2 (b int); +insert into t2 values (2), (1), (4), (7); +create table t3 (a int, b int); +insert into t3 values (2,10), (7,30), (2,30), (1,10), (7,40); +create view v as select * from t1 +where t1.a in (select t3.a from t3 group by t3.a +having t3.a > any (select t2.b from t2 +where t2.b*10 < sum(t3.b))); +select * from t1 +where t1.a in (select t3.a from t3 group by t3.a +having t3.a > any (select t2.b from t2 +where t2.b*10 < sum(t3.b))); +a +7 +select * from v; +a +7 +with cte as ( select * from t1 +where t1.a in (select t3.a from t3 group by t3.a +having t3.a > any (select t2.b from t2 +where t2.b*10 < sum(t3.b))) ) select * from cte; +a +7 +explain select * from t1 +where t1.a in (select t3.a from t3 group by t3.a +having t3.a > any (select t2.b from t2 +where t2.b*10 < sum(t3.b))); +id select_type table type possible_keys key key_len ref rows Extra +1 PRIMARY t1 ALL NULL NULL NULL NULL 3 Using where +1 PRIMARY eq_ref distinct_key distinct_key 4 test.t1.a 1 +2 MATERIALIZED t3 ALL NULL NULL NULL NULL 5 Using temporary +3 DEPENDENT SUBQUERY t2 ALL NULL NULL NULL NULL 4 Using where +explain select * from v; +id select_type table type possible_keys key key_len ref rows Extra +1 PRIMARY t1 ALL NULL NULL NULL NULL 3 Using where +1 PRIMARY eq_ref distinct_key distinct_key 4 test.t1.a 1 +3 MATERIALIZED t3 ALL NULL NULL NULL NULL 5 Using temporary +4 DEPENDENT SUBQUERY t2 ALL NULL NULL NULL NULL 4 Using where +explain with cte as ( select * from t1 +where t1.a in (select t3.a from t3 group by t3.a +having t3.a > any (select t2.b from t2 +where t2.b*10 < sum(t3.b))) ) select * from cte; +id select_type table type possible_keys key key_len ref rows Extra +1 PRIMARY t1 ALL NULL NULL NULL NULL 3 Using where +1 PRIMARY eq_ref distinct_key distinct_key 4 test.t1.a 1 +3 MATERIALIZED t3 ALL NULL NULL NULL NULL 5 Using temporary +4 DEPENDENT SUBQUERY t2 ALL NULL NULL NULL NULL 4 Using where +prepare stmt from "select * from t1 +where t1.a in (select t3.a from t3 group by t3.a +having t3.a > any (select t2.b from t2 +where t2.b*10 < sum(t3.b)))"; +execute stmt; +a +7 +execute stmt; +a +7 +deallocate prepare stmt; +prepare stmt from "select * from v"; +execute stmt; +a +7 +execute stmt; +a +7 +deallocate prepare stmt; +prepare stmt from "with cte as ( select * from t1 +where t1.a in (select t3.a from t3 group by t3.a +having t3.a > any (select t2.b from t2 +where t2.b*10 < sum(t3.b))) ) select * from cte"; +execute stmt; +a +7 +execute stmt; +a +7 +deallocate prepare stmt; +drop view v; +drop table t1,t2,t3; +# End of 10.4 tests diff --git a/mysql-test/main/derived_view.test b/mysql-test/main/derived_view.test index caccc7dafa166..5422fbcfd1d65 100644 --- a/mysql-test/main/derived_view.test +++ b/mysql-test/main/derived_view.test @@ -2455,3 +2455,300 @@ drop view v, v2; drop table t1,t2; --echo # End of 10.2 tests + +--echo # +--echo # MDEV-30706: view defined as select with implicit grouping and +--echo # a set function used in a subquery +--echo # + +CREATE TABLE t1 (a INT PRIMARY KEY, b INT); +INSERT INTO t1 VALUES (1,1), (2,2); +CREATE TABLE t2 (a INT PRIMARY KEY, b INT); +INSERT INTO t2 VALUES (1,1), (3,3); +CREATE TABLE t3 (a INT PRIMARY KEY, b INT); +INSERT INTO t3 VALUES (2,2), (4,4), (7,7); +CREATE TABLE t4 (a INT PRIMARY KEY, b INT); +INSERT INTO t4 VALUES (2,2), (5,5), (7,7); + +let $q= +SELECT + (SELECT SUM(t4.b) FROM t1, t2 WHERE t1.a = t2.b GROUP BY t1.a) AS m +FROM t3, t4 + WHERE t3.a = t4.b; + +eval CREATE VIEW v AS $q; + +eval $q; +SELECT * FROM v; +eval WITH cte AS ( $q ) SELECT * FROM cte; + +eval EXPLAIN $q; +EXPLAIN SELECT * FROM v; +eval EXPLAIN WITH cte AS ( $q ) SELECT * FROM cte; + +eval PREPARE stmt FROM "$q"; +execute stmt; +execute stmt; +DEALLOCATE PREPARE stmt; + +eval PREPARE stmt FROM "SELECT * FROM v"; +execute stmt; +execute stmt; +DEALLOCATE PREPARE stmt; + +eval PREPARE stmt FROM "WITH cte AS ( $q ) SELECT * FROM cte"; +execute stmt; +execute stmt; +DEALLOCATE PREPARE stmt; + +DROP VIEW v; +DROP TABLE t1,t2,t3,t4; + +--echo # +--echo # MDEV-29224: view defined as select with implicit grouping and +--echo # a set function used in a subquery +--echo # + +CREATE TABLE t1 (f1 INT); +INSERT INTO t1 VALUES (1),(2); +CREATE TABLE t2 (f2 int); +INSERT INTO t2 VALUES (3); + +let $q= +SELECT ( SELECT MAX(f1) FROM t2 ) FROM t1; + +eval CREATE VIEW v AS $q; + +eval $q; +SELECT * FROM v; +eval WITH cte AS ( $q ) SELECT * FROM cte; + +eval EXPLAIN $q; +EXPLAIN SELECT * FROM v; +eval EXPLAIN WITH cte AS ( $q ) SELECT * FROM cte; + +eval PREPARE stmt FROM "$q"; +execute stmt; +execute stmt; +DEALLOCATE PREPARE stmt; + +eval PREPARE stmt FROM "SELECT * FROM v"; +execute stmt; +execute stmt; +DEALLOCATE PREPARE stmt; + +eval PREPARE stmt FROM "WITH cte AS ( $q ) SELECT * FROM cte"; +execute stmt; +execute stmt; +DEALLOCATE PREPARE stmt; + +DROP VIEW v; +DROP TABLE t1,t2; + +--echo # +--echo # MDEV-28573: view defined as select with implicit grouping and +--echo # a set function used in a subquery +--echo # + +CREATE TABLE t1 (a INTEGER, b INTEGER); +CREATE TABLE t2 (c INTEGER); +INSERT INTO t1 VALUES (1,11), (2,22), (2,22); +INSERT INTO t2 VALUES (1), (2); + +let $q1= +SELECT (SELECT COUNT(b) FROM t2) FROM t1; +let $q2= +SELECT (SELECT COUNT(b) FROM t2 WHERE c > 1) FROM t1; + +eval CREATE VIEW v1 AS $q1; +eval CREATE VIEW v2 AS $q2; + +--error ER_SUBQUERY_NO_1_ROW +eval $q1; +--error ER_SUBQUERY_NO_1_ROW +SELECT * FROM v1; +--error ER_SUBQUERY_NO_1_ROW +eval WITH cte AS ( $q1 ) SELECT * FROM cte; +eval $q2; +SELECT * FROM v2; +eval WITH cte AS ( $q2 ) SELECT * FROM cte; + +eval EXPLAIN $q1; +EXPLAIN SELECT * FROM v1; +eval EXPLAIN WITH cte AS ( $q1 ) SELECT * FROM cte; + +eval PREPARE stmt FROM "$q1"; +--error ER_SUBQUERY_NO_1_ROW +execute stmt; +--error ER_SUBQUERY_NO_1_ROW +execute stmt; +DEALLOCATE PREPARE stmt; + +eval PREPARE stmt FROM "SELECT * FROM v1"; +--error ER_SUBQUERY_NO_1_ROW +execute stmt; +--error ER_SUBQUERY_NO_1_ROW +execute stmt; +DEALLOCATE PREPARE stmt; + +eval PREPARE stmt FROM "WITH cte AS ( $q1 ) SELECT * FROM cte"; +--error ER_SUBQUERY_NO_1_ROW +execute stmt; +--error ER_SUBQUERY_NO_1_ROW +execute stmt; +DEALLOCATE PREPARE stmt; + +eval PREPARE stmt FROM "$q2"; +execute stmt; +execute stmt; +DEALLOCATE PREPARE stmt; + +eval PREPARE stmt FROM "SELECT * FROM v2"; +execute stmt; +execute stmt; +DEALLOCATE PREPARE stmt; + +eval PREPARE stmt FROM "WITH cte AS ( $q2 ) SELECT * FROM cte"; +execute stmt; +execute stmt; +DEALLOCATE PREPARE stmt; + +DROP VIEW v1,v2; +DROP TABLE t1,t2; + +--echo # +--echo # MDEV-28570: VIEW with WHERE containing subquery +--echo # with set function aggregated in query +--echo # + +CREATE TABLE t1 (a int, b int); +CREATE TABLE t2 (c int, d int); + +INSERT INTO t1 VALUES + (1,10), (2,10), (1,20), (2,20), (3,20), (2,30), (4,40); +INSERT INTO t2 VALUES + (2,10), (2,20), (4,10), (5,10), (3,20), (2,40); + +let $q= +SELECT a FROM t1 GROUP BY a + HAVING a IN (SELECT c FROM t2 WHERE MAX(b)>20); + +eval CREATE VIEW v AS $q; + +eval $q; +SELECT * FROM v; +eval WITH cte AS ( $q ) SELECT * FROM cte; + +eval EXPLAIN $q; +EXPLAIN SELECT * FROM v; +eval EXPLAIN WITH cte AS ( $q ) SELECT * FROM cte; + +eval PREPARE stmt FROM "$q"; +execute stmt; +execute stmt; +DEALLOCATE PREPARE stmt; + +eval PREPARE stmt FROM "SELECT * FROM v"; +execute stmt; +execute stmt; +DEALLOCATE PREPARE stmt; + +eval PREPARE stmt FROM "WITH cte AS ( $q ) SELECT * FROM cte"; +execute stmt; +execute stmt; +DEALLOCATE PREPARE stmt; + +DROP VIEW v; +DROP TABLE t1,t2; + +--echo # +--echo # MDEV-28571: VIEW with select list containing subquery +--echo # with set function aggregated in query +--echo # + +CREATE TABLE t1 (a int, b int); +CREATE TABLE t2 (m int, n int); +INSERT INTO t1 VALUES (2,2), (2,2), (3,3), (3,3), (3,3), (4,4); +INSERT INTO t2 VALUES (1,11), (2,22), (3,32), (4,44), (4,44); + +let $q= +SELECT (SELECT GROUP_CONCAT(COUNT(a)) FROM t2 WHERE m = a) AS c +FROM t1 +GROUP BY a; + +eval CREATE VIEW v AS $q; + +eval $q; +SELECT * FROM v; +eval WITH cte AS ( $q ) SELECT * FROM cte; + +eval EXPLAIN $q; +EXPLAIN SELECT * FROM v; +eval EXPLAIN WITH cte AS ( $q ) SELECT * FROM cte; + +eval PREPARE stmt FROM "$q"; +execute stmt; +execute stmt; +DEALLOCATE PREPARE stmt; + +eval PREPARE stmt FROM "SELECT * FROM v"; +execute stmt; +execute stmt; +DEALLOCATE PREPARE stmt; + +eval PREPARE stmt FROM "WITH cte AS ( $q ) SELECT * FROM cte"; +execute stmt; +execute stmt; +DEALLOCATE PREPARE stmt; + +DROP VIEW v; +DROP TABLE t1,t2; + +--echo # +--echo # MDEV-30668: VIEW with WHERE containing nested subquery +--echo # with set function aggregated in outer subquery +--echo # + +create table t1 (a int); +insert into t1 values (3), (7), (1); + +create table t2 (b int); +insert into t2 values (2), (1), (4), (7); + +create table t3 (a int, b int); +insert into t3 values (2,10), (7,30), (2,30), (1,10), (7,40); + +let $q= +select * from t1 + where t1.a in (select t3.a from t3 group by t3.a + having t3.a > any (select t2.b from t2 + where t2.b*10 < sum(t3.b))); +eval create view v as $q; + +eval $q; +eval select * from v; +eval with cte as ( $q ) select * from cte; + +eval explain $q; +eval explain select * from v; +eval explain with cte as ( $q ) select * from cte; + +eval prepare stmt from "$q"; +execute stmt; +execute stmt; +deallocate prepare stmt; + +eval prepare stmt from "select * from v"; +execute stmt; +execute stmt; +deallocate prepare stmt; + +eval prepare stmt from "with cte as ( $q ) select * from cte"; +execute stmt; +execute stmt; +deallocate prepare stmt; + +drop view v; +drop table t1,t2,t3; + +--echo # End of 10.4 tests diff --git a/mysql-test/main/func_group.result b/mysql-test/main/func_group.result index a0ee121df0622..f6fcc61dcfe00 100644 --- a/mysql-test/main/func_group.result +++ b/mysql-test/main/func_group.result @@ -1443,16 +1443,11 @@ FROM derived1 AS X WHERE X.int_nokey < 61 GROUP BY pk -LIMIT 1) +LIMIT 1) AS m FROM D AS X WHERE X.int_key < 13 GROUP BY int_nokey LIMIT 1; -(SELECT COUNT( int_nokey ) -FROM derived1 AS X -WHERE -X.int_nokey < 61 -GROUP BY pk -LIMIT 1) +m 1 DROP TABLE derived1; DROP TABLE D; diff --git a/mysql-test/main/func_group.test b/mysql-test/main/func_group.test index e5ae33f720844..446154e517b92 100644 --- a/mysql-test/main/func_group.test +++ b/mysql-test/main/func_group.test @@ -579,8 +579,6 @@ DROP TABLE t1; # # Bug #16792 query with subselect, join, and group not returning proper values # -#enable after fix MDEV-28573 ---disable_view_protocol CREATE TABLE t1 (a INT, b INT); INSERT INTO t1 VALUES (1,1),(1,2),(2,3); @@ -591,7 +589,6 @@ SELECT AVG(2), BIT_AND(2), BIT_OR(2), BIT_XOR(2), COUNT(*), COUNT(12), COUNT(DISTINCT 12), MIN(2),MAX(2),STD(2), VARIANCE(2),SUM(2), GROUP_CONCAT(2),GROUP_CONCAT(DISTINCT 2); DROP TABLE t1; ---enable_view_protocol # End of 4.1 tests @@ -623,13 +620,10 @@ drop table t1, t2, t3; # # BUG#3190, WL#1639: Standard Deviation STDDEV - 2 different calculations # -#enable after fix MDEV-28573 ---disable_view_protocol CREATE TABLE t1 (id int(11),value1 float(10,2)); INSERT INTO t1 VALUES (1,0.00),(1,1.00), (1,2.00), (2,10.00), (2,11.00), (2,12.00), (2,13.00); select id, stddev_pop(value1), var_pop(value1), stddev_samp(value1), var_samp(value1) from t1 group by id; DROP TABLE t1; ---enable_view_protocol # # BUG#8464 decimal AVG returns incorrect result @@ -966,22 +960,19 @@ INSERT INTO D VALUES (83,45,4,repeat(' X', 42)), (105,53,12,NULL); -#enable after fix MDEV-27871 ---disable_view_protocol SELECT (SELECT COUNT( int_nokey ) FROM derived1 AS X WHERE X.int_nokey < 61 GROUP BY pk - LIMIT 1) + LIMIT 1) AS m FROM D AS X WHERE X.int_key < 13 GROUP BY int_nokey LIMIT 1; DROP TABLE derived1; DROP TABLE D; ---enable_view_protocol # # Bug #39656: Behaviour different for agg functions with & without where - diff --git a/mysql-test/main/group_by.result b/mysql-test/main/group_by.result index 06138b3030c23..07629a2bcf2c3 100644 --- a/mysql-test/main/group_by.result +++ b/mysql-test/main/group_by.result @@ -1027,8 +1027,9 @@ FROM t1 AS t1_outer GROUP BY t1_outer.b; 21 21 SELECT (SELECT SUM(t1_inner.a) FROM t1 AS t1_inner GROUP BY t1_inner.b LIMIT 1) +AS m FROM t1 AS t1_outer; -(SELECT SUM(t1_inner.a) FROM t1 AS t1_inner GROUP BY t1_inner.b LIMIT 1) +m 3 3 3 @@ -1268,12 +1269,9 @@ a select avg ( (select (select sum(outr.a + innr.a) from t1 as innr limit 1) as tt -from t1 as outr order by outr.a limit 1)) +from t1 as outr order by outr.a limit 1)) as m from t1 as most_outer; -avg ( -(select -(select sum(outr.a + innr.a) from t1 as innr limit 1) as tt -from t1 as outr order by outr.a limit 1)) +m 29.0000 select avg ( (select ( diff --git a/mysql-test/main/group_by.test b/mysql-test/main/group_by.test index 95518c3716010..9bbe1e0bf2b54 100644 --- a/mysql-test/main/group_by.test +++ b/mysql-test/main/group_by.test @@ -774,11 +774,9 @@ SELECT 1 FROM t1 as t1_outer GROUP BY a SELECT (SELECT SUM(t1_inner.a) FROM t1 AS t1_inner LIMIT 1) FROM t1 AS t1_outer GROUP BY t1_outer.b; -#enable after fix MDEV-27871 ---disable_view_protocol SELECT (SELECT SUM(t1_inner.a) FROM t1 AS t1_inner GROUP BY t1_inner.b LIMIT 1) +AS m FROM t1 AS t1_outer; ---enable_view_protocol --error ER_WRONG_FIELD_WITH_GROUP SELECT (SELECT SUM(t1_outer.a) FROM t1 AS t1_inner LIMIT 1) @@ -854,6 +852,7 @@ DROP TABLE t1; --echo # --echo # Bug#27219: Aggregate functions in ORDER BY. --echo # + SET @save_sql_mode=@@sql_mode; SET @@sql_mode='ONLY_FULL_GROUP_BY'; @@ -875,6 +874,8 @@ SELECT 1 FROM t1 ORDER BY SUM(a) + 1; --error 1140 SELECT 1 FROM t1 ORDER BY SUM(a), b; +--disable_service_connection + --error 1140 SELECT a FROM t1 ORDER BY COUNT(b); @@ -887,9 +888,6 @@ SELECT t1.a FROM t1 ORDER BY (SELECT SUM(t2.a) FROM t2 ORDER BY t2.a); --error 1140 SELECT t1.a FROM t1 ORDER BY (SELECT t2.a FROM t2 ORDER BY SUM(t2.b) LIMIT 1); -#enable after fix MDEV-28570 ---disable_view_protocol - --error 1140 SELECT t1.a FROM t1 WHERE t1.a = (SELECT t2.a FROM t2 ORDER BY SUM(t2.b) LIMIT 1); @@ -927,7 +925,7 @@ SELECT 1 FROM t1 GROUP BY t1.a SELECT 1 FROM t1 GROUP BY t1.a HAVING (SELECT AVG(t1.b + t2.b) FROM t2 ORDER BY t2.a LIMIT 1); ---enable_view_protocol +--enable_service_connection # Both SUMs are aggregated in the subquery, no mixture: SELECT t1.a FROM t1 @@ -952,18 +950,17 @@ SELECT t1.a, SUM(t1.b) FROM t1 ORDER BY SUM(t2.b + t1.a) LIMIT 1) GROUP BY t1.a; -#enable after fix MDEV-28570, MDEV-28571 ---disable_view_protocol - SELECT t1.a FROM t1 GROUP BY t1.a HAVING (1, 1) = (SELECT SUM(t1.a), t1.a FROM t2 LIMIT 1); select avg ( (select (select sum(outr.a + innr.a) from t1 as innr limit 1) as tt - from t1 as outr order by outr.a limit 1)) + from t1 as outr order by outr.a limit 1)) as m from t1 as most_outer; +--disable_service_connection + --error 1140 select avg ( (select ( @@ -971,7 +968,7 @@ select avg ( from t1 as outr order by count(outr.a) limit 1)) as tt from t1 as most_outer; ---enable_view_protocol +--enable_service_connection select (select sum(outr.a + t1.a) from t1 limit 1) as tt from t1 as outr order by outr.a; @@ -1369,7 +1366,7 @@ DROP TABLE t1; --echo # Bug#11765254 (58200): Assertion failed: param.sort_length when grouping --echo # by functions --echo # -#createing view adds one new warning +#creating view adds one new warning --disable_view_protocol SET BIG_TABLES=1; diff --git a/mysql-test/main/opt_trace.result b/mysql-test/main/opt_trace.result index a97d0074d241a..a343d5941f189 100644 --- a/mysql-test/main/opt_trace.result +++ b/mysql-test/main/opt_trace.result @@ -4130,7 +4130,7 @@ explain select * from (select rand() from t1)q { "derived": { "table": "q", "select_id": 2, - "algorithm": "merged" + "algorithm": "materialized" } }, { @@ -4144,7 +4144,7 @@ explain select * from (select rand() from t1)q { } }, { - "expanded_query": "/* select#1 */ select rand() AS `rand()` from (/* select#2 */ select rand() AS `rand()` from t1) q" + "expanded_query": "/* select#1 */ select q.`rand()` AS `rand()` from (/* select#2 */ select rand() AS `rand()` from t1) q" } ] } @@ -4153,14 +4153,6 @@ explain select * from (select rand() from t1)q { "join_optimization": { "select_id": 1, "steps": [ - { - "derived": { - "table": "q", - "select_id": 2, - "algorithm": "materialized", - "cause": "Random function in the select" - } - }, { "join_optimization": { "select_id": 2, diff --git a/mysql-test/main/subselect.result b/mysql-test/main/subselect.result index c57cae70965cb..d2ae34029beaa 100644 --- a/mysql-test/main/subselect.result +++ b/mysql-test/main/subselect.result @@ -118,27 +118,27 @@ ROW(1,2,3) > (SELECT 1,2,1) SELECT ROW(1,2,3) = (SELECT 1,2,NULL); ROW(1,2,3) = (SELECT 1,2,NULL) NULL -SELECT (SELECT 1.5,2,'a') = ROW(1.5,2,'a'); -(SELECT 1.5,2,'a') = ROW(1.5,2,'a') +SELECT (SELECT 1.5,2,'a') = ROW(1.5,2,'a') AS m; +m 1 -SELECT (SELECT 1.5,2,'a') = ROW(1.5,2,'b'); -(SELECT 1.5,2,'a') = ROW(1.5,2,'b') +SELECT (SELECT 1.5,2,'a') = ROW(1.5,2,'b') AS m; +m 0 -SELECT (SELECT 1.5,2,'a') = ROW('1.5b',2,'b'); -(SELECT 1.5,2,'a') = ROW('1.5b',2,'b') +SELECT (SELECT 1.5,2,'a') = ROW('1.5b',2,'b') AS m; +m 0 Warnings: Warning 1292 Truncated incorrect DOUBLE value: '1.5b' -SELECT (SELECT 'b',2,'a') = ROW(1.5,2,'a'); -(SELECT 'b',2,'a') = ROW(1.5,2,'a') +SELECT (SELECT 'b',2,'a') = ROW(1.5,2,'a') AS m; +m 0 Warnings: Warning 1292 Truncated incorrect DOUBLE value: 'b' -SELECT (SELECT 1.5,2,'a') = ROW(1.5,'2','a'); -(SELECT 1.5,2,'a') = ROW(1.5,'2','a') +SELECT (SELECT 1.5,2,'a') = ROW(1.5,'2','a') AS m; +m 1 -SELECT (SELECT 1.5,'c','a') = ROW(1.5,2,'a'); -(SELECT 1.5,'c','a') = ROW(1.5,2,'a') +SELECT (SELECT 1.5,'c','a') = ROW(1.5,2,'a') AS m; +m 0 Warnings: Warning 1292 Truncated incorrect DECIMAL value: 'c' @@ -228,19 +228,26 @@ a 2 select * from t1 where t1.a=(select t2.a from t2 where t2.b=(select max(a) from t3 where t3.a < t1.a) order by 1 desc limit 1); a -select b,(select avg(t2.a+(select min(t3.a) from t3 where t3.a >= t4.a)) from t2) from t4; -b (select avg(t2.a+(select min(t3.a) from t3 where t3.a >= t4.a)) from t2) +select +b, +(select avg(t2.a+(select min(t3.a) from t3 where t3.a >= t4.a)) from t2) as m +from t4; +b m 8 7.5000 8 4.5000 9 7.5000 -explain extended select b,(select avg(t2.a+(select min(t3.a) from t3 where t3.a >= t4.a)) from t2) from t4; +explain extended +select +b, +(select avg(t2.a+(select min(t3.a) from t3 where t3.a >= t4.a)) from t2) as m +from t4; id select_type table type possible_keys key key_len ref rows filtered Extra 1 PRIMARY t4 ALL NULL NULL NULL NULL 3 100.00 2 DEPENDENT SUBQUERY t2 ALL NULL NULL NULL NULL 2 100.00 3 DEPENDENT SUBQUERY t3 ALL NULL NULL NULL NULL 3 100.00 Using where Warnings: Note 1276 Field or reference 'test.t4.a' of SELECT #3 was resolved in SELECT #1 -Note 1003 /* select#1 */ select `test`.`t4`.`b` AS `b`,<`test`.`t4`.`a`>((/* select#2 */ select avg(`test`.`t2`.`a` + (/* select#3 */ select min(`test`.`t3`.`a`) from `test`.`t3` where `test`.`t3`.`a` >= `test`.`t4`.`a`)) from `test`.`t2`)) AS `(select avg(t2.a+(select min(t3.a) from t3 where t3.a >= t4.a)) from t2)` from `test`.`t4` +Note 1003 /* select#1 */ select `test`.`t4`.`b` AS `b`,<`test`.`t4`.`a`>((/* select#2 */ select avg(`test`.`t2`.`a` + (/* select#3 */ select min(`test`.`t3`.`a`) from `test`.`t3` where `test`.`t3`.`a` >= `test`.`t4`.`a`)) from `test`.`t2`)) AS `m` from `test`.`t4` select * from t3 where exists (select * from t2 where t2.b=t3.a); a 7 @@ -307,21 +314,34 @@ select b,max(a) as ma from t4 group by b having b >= (select max(t2.a) from t2 w b ma 7 12 create table t5 (a int); -select (select a from t1 where t1.a=t2.a union select a from t5 where t5.a=t2.a), a from t2; -(select a from t1 where t1.a=t2.a union select a from t5 where t5.a=t2.a) a +select +(select a from t1 where t1.a=t2.a union select a from t5 where t5.a=t2.a) as m, +a +from t2; +m a NULL 1 2 2 insert into t5 values (5); -select (select a from t1 where t1.a=t2.a union select a from t5 where t5.a=t2.a), a from t2; -(select a from t1 where t1.a=t2.a union select a from t5 where t5.a=t2.a) a +select +(select a from t1 where t1.a=t2.a union select a from t5 where t5.a=t2.a) as m, +a +from t2; +m a NULL 1 2 2 insert into t5 values (2); -select (select a from t1 where t1.a=t2.a union select a from t5 where t5.a=t2.a), a from t2; -(select a from t1 where t1.a=t2.a union select a from t5 where t5.a=t2.a) a +select +(select a from t1 where t1.a=t2.a union select a from t5 where t5.a=t2.a) as m, +a +from t2; +m a NULL 1 2 2 -explain extended select (select a from t1 where t1.a=t2.a union select a from t5 where t5.a=t2.a), a from t2; +explain extended +select +(select a from t1 where t1.a=t2.a union select a from t5 where t5.a=t2.a) as m, +a +from t2; id select_type table type possible_keys key key_len ref rows filtered Extra 1 PRIMARY t2 ALL NULL NULL NULL NULL 2 100.00 2 DEPENDENT SUBQUERY t1 system NULL NULL NULL NULL 1 100.00 @@ -330,7 +350,7 @@ NULL UNION RESULT ALL NULL NULL NULL NULL NULL NULL Warnings: Note 1276 Field or reference 'test.t2.a' of SELECT #2 was resolved in SELECT #1 Note 1276 Field or reference 'test.t2.a' of SELECT #3 was resolved in SELECT #1 -Note 1003 /* select#1 */ select <`test`.`t2`.`a`>((/* select#2 */ select 2 from dual where 2 = `test`.`t2`.`a` union /* select#3 */ select `test`.`t5`.`a` from `test`.`t5` where `test`.`t5`.`a` = `test`.`t2`.`a`)) AS `(select a from t1 where t1.a=t2.a union select a from t5 where t5.a=t2.a)`,`test`.`t2`.`a` AS `a` from `test`.`t2` +Note 1003 /* select#1 */ select <`test`.`t2`.`a`>((/* select#2 */ select 2 from dual where 2 = `test`.`t2`.`a` union /* select#3 */ select `test`.`t5`.`a` from `test`.`t5` where `test`.`t5`.`a` = `test`.`t2`.`a`)) AS `m`,`test`.`t2`.`a` AS `a` from `test`.`t2` select (select a from t1 where t1.a=t2.a union all select a from t5 where t5.a=t2.a), a from t2; ERROR 21000: Subquery returns more than 1 row create table t6 (patient_uq int, clinic_uq int, index i1 (clinic_uq)); @@ -486,8 +506,11 @@ SELECT * from t2 where topic = all (SELECT topic FROM t2 GROUP BY topic HAVING t mot topic date pseudo joce 40143 2002-10-22 joce joce 43506 2002-10-22 joce -SELECT *, topic = all (SELECT topic FROM t2 GROUP BY topic HAVING topic < 4100) from t2; -mot topic date pseudo topic = all (SELECT topic FROM t2 GROUP BY topic HAVING topic < 4100) +SELECT +*, +topic = all (SELECT topic FROM t2 GROUP BY topic HAVING topic < 4100) AS m +FROM t2; +mot topic date pseudo m joce 40143 2002-10-22 joce 1 joce 43506 2002-10-22 joce 1 SELECT * from t2 where topic = all (SELECT SUM(topic) FROM t2); @@ -505,8 +528,11 @@ joce 40143 2002-10-22 joce SELECT * from t2 where topic = all (SELECT topic FROM t2 GROUP BY topic HAVING topic < 41000); mot topic date pseudo joce 40143 2002-10-22 joce -SELECT *, topic = all (SELECT topic FROM t2 GROUP BY topic HAVING topic < 41000) from t2; -mot topic date pseudo topic = all (SELECT topic FROM t2 GROUP BY topic HAVING topic < 41000) +SELECT +*, +topic = all (SELECT topic FROM t2 GROUP BY topic HAVING topic < 41000) AS m +FROM t2; +mot topic date pseudo m joce 40143 2002-10-22 joce 1 joce 43506 2002-10-22 joce 0 drop table t1,t2; @@ -881,6 +907,25 @@ NULL select 1.5 > ANY (SELECT * from t1); 1.5 > ANY (SELECT * from t1) NULL +update t1 set a=NULL where a=2.5; +select 1.5 IN (SELECT * from t1); +1.5 IN (SELECT * from t1) +1 +select 3.5 IN (SELECT * from t1); +3.5 IN (SELECT * from t1) +1 +select 10.5 IN (SELECT * from t1); +10.5 IN (SELECT * from t1) +NULL +select 1.5 > ALL (SELECT * from t1); +1.5 > ALL (SELECT * from t1) +0 +select 10.5 > ALL (SELECT * from t1); +10.5 > ALL (SELECT * from t1) +NULL +select 1.5 > ANY (SELECT * from t1); +1.5 > ANY (SELECT * from t1) +NULL select 10.5 > ANY (SELECT * from t1); 10.5 > ANY (SELECT * from t1) 1 @@ -891,6 +936,20 @@ Warnings: Note 1276 Field or reference 'test.t1.a' of SELECT #2 was resolved in SELECT #1 Note 1249 Select 2 was reduced during optimization Note 1003 select `test`.`t1`.`a` + 1 AS `(select a+1)` from `test`.`t1` +explain extended select (select a+1) from t1; +id select_type table type possible_keys key key_len ref rows filtered Extra +1 SIMPLE t1 ALL NULL NULL NULL NULL 3 100.00 +Warnings: +Note 1276 Field or reference 'test.t1.a' of SELECT #2 was resolved in SELECT #1 +Note 1249 Select 2 was reduced during optimization +Note 1003 select `test`.`t1`.`a` + 1 AS `(select a+1)` from `test`.`t1` +explain extended select (select a+1) from t1; +id select_type table type possible_keys key key_len ref rows filtered Extra +1 SIMPLE t1 ALL NULL NULL NULL NULL 3 100.00 +Warnings: +Note 1276 Field or reference 'test.t1.a' of SELECT #2 was resolved in SELECT #1 +Note 1249 Select 2 was reduced during optimization +Note 1003 select `test`.`t1`.`a` + 1 AS `(select a+1)` from `test`.`t1` select (select a+1) from t1; (select a+1) 2.5 @@ -1532,8 +1591,8 @@ create table t3 (a int, b int); insert into t1 values (0,100),(1,2), (1,3), (2,2), (2,7), (2,-1), (3,10); insert into t2 values (0,0), (1,1), (2,1), (3,1), (4,1); insert into t3 values (3,3), (2,2), (1,1); -select a,(select count(distinct t1.b) as sum from t1,t2 where t1.a=t2.a and t2.b > 0 and t1.a <= t3.b group by t1.a order by sum limit 1) from t3; -a (select count(distinct t1.b) as sum from t1,t2 where t1.a=t2.a and t2.b > 0 and t1.a <= t3.b group by t1.a order by sum limit 1) +select a,(select count(distinct t1.b) as sum from t1,t2 where t1.a=t2.a and t2.b > 0 and t1.a <= t3.b group by t1.a order by sum limit 1) as m from t3; +a m 3 1 2 2 1 2 @@ -1728,8 +1787,8 @@ CREATE TABLE `t3` (`taskgenid` mediumint(9) NOT NULL auto_increment,`dbid` int(1 INSERT INTO `t3` (`taskgenid`, `dbid`, `taskid`, `mon`, `tues`,`wed`, `thur`, `fri`, `sat`, `sun`, `how_often`, `userid`, `active`) VALUES (1,-1, 1, 1, 1, 1, 1, 1, 0, 0, 1, 0, 1); CREATE TABLE `t4` (`task_id` smallint(6) NOT NULL default '0',`description` varchar(200) NOT NULL default '') ENGINE=MyISAM CHARSET=latin1; INSERT INTO `t4` (`task_id`, `description`) VALUES (1, 'Daily Check List'),(2, 'Weekly Status'); -select dbid, name, (date_format(now() , '%Y-%m-%d') - INTERVAL how_often DAY) >= ifnull((SELECT date_format(max(create_date),'%Y-%m-%d') FROM t1 WHERE dbid = b.db_id AND taskid = a.taskgenid), '1950-01-01') from t3 a, t2 b, t4 WHERE dbid = - 1 AND primary_uid = '1' AND t4.task_id = taskid; -dbid name (date_format(now() , '%Y-%m-%d') - INTERVAL how_often DAY) >= ifnull((SELECT date_format(max(create_date),'%Y-%m-%d') FROM t1 WHERE dbid = b.db_id AND taskid = a.taskgenid), '1950-01-01') +select dbid, name, (date_format(now() , '%Y-%m-%d') - INTERVAL how_often DAY) >= ifnull((SELECT date_format(max(create_date),'%Y-%m-%d') as m FROM t1 WHERE dbid = b.db_id AND taskid = a.taskgenid), '1950-01-01') as m from t3 a, t2 b, t4 WHERE dbid = - 1 AND primary_uid = '1' AND t4.task_id = taskid; +dbid name m -1 Valid 1 -1 Valid 2 1 -1 Should Not Return 0 @@ -3784,9 +3843,10 @@ SELECT (SELECT COUNT(DISTINCT t1.b) from t2) FROM t1 GROUP BY t1.a; 2 1 1 -SELECT (SELECT COUNT(DISTINCT t1.b) from t2 union select 1 from t2 where 12 < 3) +SELECT +(SELECT COUNT(DISTINCT t1.b) from t2 union select 1 from t2 where 12 < 3) AS m FROM t1 GROUP BY t1.a; -(SELECT COUNT(DISTINCT t1.b) from t2 union select 1 from t2 where 12 < 3) +m 2 1 1 @@ -3796,9 +3856,9 @@ COUNT(DISTINCT t1.b) (SELECT COUNT(DISTINCT t1.b)) 1 1 1 1 SELECT COUNT(DISTINCT t1.b), -(SELECT COUNT(DISTINCT t1.b) union select 1 from DUAL where 12 < 3) +(SELECT COUNT(DISTINCT t1.b) union select 1 from DUAL where 12 < 3) AS m FROM t1 GROUP BY t1.a; -COUNT(DISTINCT t1.b) (SELECT COUNT(DISTINCT t1.b) union select 1 from DUAL where 12 < 3) +COUNT(DISTINCT t1.b) m 2 2 1 1 1 1 @@ -3822,16 +3882,10 @@ SELECT ( SELECT COUNT(DISTINCT t1.b) ) ) -FROM t1 GROUP BY t1.a LIMIT 1) +FROM t1 GROUP BY t1.a LIMIT 1) AS m FROM t1 t2 GROUP BY t2.a; -( -SELECT ( -SELECT ( -SELECT COUNT(DISTINCT t1.b) -) -) -FROM t1 GROUP BY t1.a LIMIT 1) +m 2 2 2 @@ -6425,11 +6479,10 @@ CREATE TABLE t3 (a int, b int); INSERT INTO t3 VALUES (10,7), (0,7); SELECT SUM(DISTINCT b), (SELECT t2.a FROM t1 JOIN t2 ON t2.c != 0 -WHERE t.a != 0 AND t2.a != 0) +WHERE t.a != 0 AND t2.a != 0) AS m FROM (SELECT * FROM t3) AS t GROUP BY 2; -SUM(DISTINCT b) (SELECT t2.a FROM t1 JOIN t2 ON t2.c != 0 -WHERE t.a != 0 AND t2.a != 0) +SUM(DISTINCT b) m 7 NULL SELECT SUM(DISTINCT b), (SELECT t2.a FROM t1,t2 WHERE t.a != 0 or 1=2 LIMIT 1) @@ -6562,66 +6615,93 @@ CREATE TABLE t3 (f3a int default 1, f3b int default 2); INSERT INTO t3 VALUES (1,1),(2,2); set @old_optimizer_switch = @@session.optimizer_switch; set @@optimizer_switch='materialization=on,partial_match_rowid_merge=on,partial_match_table_scan=off,subquery_cache=off,semijoin=off'; -SELECT (SELECT f3a FROM t3 where f3a > 3) NOT IN (SELECT f1a FROM t1) FROM t2; -(SELECT f3a FROM t3 where f3a > 3) NOT IN (SELECT f1a FROM t1) +SELECT +(SELECT f3a FROM t3 where f3a > 3) NOT IN (SELECT f1a FROM t1) AS m +FROM t2; +m NULL NULL -SELECT (SELECT f3a,f3a FROM t3 where f3a > 3) NOT IN (SELECT f1a,f1a FROM t1) FROM t2; -(SELECT f3a,f3a FROM t3 where f3a > 3) NOT IN (SELECT f1a,f1a FROM t1) +SELECT +(SELECT f3a,f3a FROM t3 where f3a > 3) NOT IN (SELECT f1a,f1a FROM t1) AS m +FROM t2; +m NULL NULL -SELECT (SELECT f3a, f3b FROM t3 where f3a > 3) NOT IN (SELECT f1a, f1b FROM t1) FROM t2; -(SELECT f3a, f3b FROM t3 where f3a > 3) NOT IN (SELECT f1a, f1b FROM t1) +SELECT +(SELECT f3a, f3b FROM t3 where f3a > 3) NOT IN (SELECT f1a, f1b FROM t1) AS m +FROM t2; +m NULL NULL -SELECT (SELECT f3a, f3b FROM t3 where f3a > 3) NOT IN (SELECT f1a, f1b FROM t1); -(SELECT f3a, f3b FROM t3 where f3a > 3) NOT IN (SELECT f1a, f1b FROM t1) +SELECT +(SELECT f3a, f3b FROM t3 where f3a > 3) NOT IN (SELECT f1a, f1b FROM t1) AS m; +m NULL -SELECT (SELECT f3a FROM t3 where f3a > 3) IN (SELECT f1a FROM t1) FROM t2; -(SELECT f3a FROM t3 where f3a > 3) IN (SELECT f1a FROM t1) +SELECT +(SELECT f3a FROM t3 where f3a > 3) IN (SELECT f1a FROM t1) AS m +FROM t2; +m NULL NULL -SELECT (SELECT f3a,f3a FROM t3 where f3a > 3) IN (SELECT f1a,f1a FROM t1) FROM t2; -(SELECT f3a,f3a FROM t3 where f3a > 3) IN (SELECT f1a,f1a FROM t1) +SELECT +(SELECT f3a,f3a FROM t3 where f3a > 3) IN (SELECT f1a,f1a FROM t1) AS m +FROM t2; +m NULL NULL -SELECT (SELECT f3a, f3b FROM t3 where f3a > 3) IN (SELECT f1a, f1b FROM t1) FROM t2; -(SELECT f3a, f3b FROM t3 where f3a > 3) IN (SELECT f1a, f1b FROM t1) +SELECT +(SELECT f3a, f3b FROM t3 where f3a > 3) IN (SELECT f1a, f1b FROM t1) AS m +FROM t2; +m NULL NULL -SELECT (SELECT f3a, f3b FROM t3 where f3a > 3) IN (SELECT f1a, f1b FROM t1); -(SELECT f3a, f3b FROM t3 where f3a > 3) IN (SELECT f1a, f1b FROM t1) +SELECT +(SELECT f3a, f3b FROM t3 where f3a > 3) IN (SELECT f1a, f1b FROM t1) AS m; +m NULL set @@session.optimizer_switch=@old_optimizer_switch; -SELECT (SELECT f3a FROM t3 where f3a > 3) NOT IN (SELECT f1a FROM t1) FROM t2; -(SELECT f3a FROM t3 where f3a > 3) NOT IN (SELECT f1a FROM t1) +SELECT +(SELECT f3a FROM t3 where f3a > 3) NOT IN (SELECT f1a FROM t1) AS m +FROM t2; +m NULL NULL -SELECT (SELECT f3a,f3a FROM t3 where f3a > 3) NOT IN (SELECT f1a,f1a FROM t1) FROM t2; -(SELECT f3a,f3a FROM t3 where f3a > 3) NOT IN (SELECT f1a,f1a FROM t1) +SELECT +(SELECT f3a,f3a FROM t3 where f3a > 3) NOT IN (SELECT f1a,f1a FROM t1) AS m +FROM t2; +m NULL NULL -SELECT (SELECT f3a, f3b FROM t3 where f3a > 3) NOT IN (SELECT f1a, f1b FROM t1) FROM t2; -(SELECT f3a, f3b FROM t3 where f3a > 3) NOT IN (SELECT f1a, f1b FROM t1) +SELECT +(SELECT f3a, f3b FROM t3 where f3a > 3) NOT IN (SELECT f1a, f1b FROM t1) AS m +FROM t2; +m NULL NULL -SELECT (SELECT f3a, f3b FROM t3 where f3a > 3) NOT IN (SELECT f1a, f1b FROM t1); -(SELECT f3a, f3b FROM t3 where f3a > 3) NOT IN (SELECT f1a, f1b FROM t1) +SELECT +(SELECT f3a, f3b FROM t3 where f3a > 3) NOT IN (SELECT f1a, f1b FROM t1) AS m; +m NULL -SELECT (SELECT f3a FROM t3 where f3a > 3) IN (SELECT f1a FROM t1) FROM t2; +SELECT +(SELECT f3a FROM t3 where f3a > 3) IN (SELECT f1a FROM t1) FROM t2 AS m; (SELECT f3a FROM t3 where f3a > 3) IN (SELECT f1a FROM t1) NULL NULL -SELECT (SELECT f3a,f3a FROM t3 where f3a > 3) IN (SELECT f1a,f1a FROM t1) FROM t2; -(SELECT f3a,f3a FROM t3 where f3a > 3) IN (SELECT f1a,f1a FROM t1) +SELECT +(SELECT f3a,f3a FROM t3 where f3a > 3) IN (SELECT f1a,f1a FROM t1) AS m +FROM t2; +m NULL NULL -SELECT (SELECT f3a, f3b FROM t3 where f3a > 3) IN (SELECT f1a, f1b FROM t1) FROM t2; -(SELECT f3a, f3b FROM t3 where f3a > 3) IN (SELECT f1a, f1b FROM t1) +SELECT +(SELECT f3a, f3b FROM t3 where f3a > 3) IN (SELECT f1a, f1b FROM t1) AS m +FROM t2; +m NULL NULL -SELECT (SELECT f3a, f3b FROM t3 where f3a > 3) IN (SELECT f1a, f1b FROM t1); -(SELECT f3a, f3b FROM t3 where f3a > 3) IN (SELECT f1a, f1b FROM t1) +SELECT +(SELECT f3a, f3b FROM t3 where f3a > 3) IN (SELECT f1a, f1b FROM t1) AS m; +m NULL select (null, null) = (null, null); (null, null) = (null, null) @@ -6667,8 +6747,10 @@ INSERT INTO t2 VALUES (1); CREATE TABLE t3 ( c INT ); INSERT INTO t3 VALUES (4),(5); SET optimizer_switch='subquery_cache=off'; -SELECT ( SELECT b FROM t2 WHERE b = a OR EXISTS ( SELECT c FROM t3 WHERE c = b ) ) FROM t1; -( SELECT b FROM t2 WHERE b = a OR EXISTS ( SELECT c FROM t3 WHERE c = b ) ) +SELECT +( SELECT b FROM t2 WHERE b = a OR EXISTS ( SELECT c FROM t3 WHERE c = b ) ) AS m +FROM t1; +m 1 NULL SELECT ( SELECT b FROM t2 WHERE b = a OR b * 0) FROM t1; @@ -6885,7 +6967,9 @@ CREATE TABLE t3 (c INT); INSERT INTO t3 VALUES (8),(3); set @@expensive_subquery_limit= 0; EXPLAIN -SELECT (SELECT MIN(b) FROM t1, t2 WHERE b = a AND (b = alias1.b OR EXISTS (SELECT * FROM t3))) +SELECT +(SELECT MIN(b) FROM t1, t2 +WHERE b = a AND (b = alias1.b OR EXISTS (SELECT * FROM t3))) AS m FROM t2 alias1, t1 alias2, t1 alias3; id select_type table type possible_keys key key_len ref rows Extra 1 PRIMARY alias1 ALL NULL NULL NULL NULL 2 @@ -6895,9 +6979,11 @@ id select_type table type possible_keys key key_len ref rows Extra 2 DEPENDENT SUBQUERY t2 ALL NULL NULL NULL NULL 2 Using where; Using join buffer (flat, BNL join) 3 SUBQUERY t3 ALL NULL NULL NULL NULL 2 flush status; -SELECT (SELECT MIN(b) FROM t1, t2 WHERE b = a AND (b = alias1.b OR EXISTS (SELECT * FROM t3))) +SELECT +(SELECT MIN(b) FROM t1, t2 +WHERE b = a AND (b = alias1.b OR EXISTS (SELECT * FROM t3))) AS m FROM t2 alias1, t1 alias2, t1 alias3; -(SELECT MIN(b) FROM t1, t2 WHERE b = a AND (b = alias1.b OR EXISTS (SELECT * FROM t3))) +m NULL NULL NULL @@ -6923,7 +7009,9 @@ Handler_read_rnd_deleted 0 Handler_read_rnd_next 22 set @@expensive_subquery_limit= default; EXPLAIN -SELECT (SELECT MIN(b) FROM t1, t2 WHERE b = a AND (b = alias1.b OR EXISTS (SELECT * FROM t3))) +SELECT +(SELECT MIN(b) FROM t1, t2 +WHERE b = a AND (b = alias1.b OR EXISTS (SELECT * FROM t3))) AS m FROM t2 alias1, t1 alias2, t1 alias3; id select_type table type possible_keys key key_len ref rows Extra 1 PRIMARY alias1 ALL NULL NULL NULL NULL 2 @@ -6933,9 +7021,11 @@ id select_type table type possible_keys key key_len ref rows Extra 2 SUBQUERY t2 ALL NULL NULL NULL NULL 2 Using where; Using join buffer (flat, BNL join) 3 SUBQUERY t3 ALL NULL NULL NULL NULL 2 flush status; -SELECT (SELECT MIN(b) FROM t1, t2 WHERE b = a AND (b = alias1.b OR EXISTS (SELECT * FROM t3))) +SELECT +(SELECT MIN(b) FROM t1, t2 +WHERE b = a AND (b = alias1.b OR EXISTS (SELECT * FROM t3))) AS m FROM t2 alias1, t1 alias2, t1 alias3; -(SELECT MIN(b) FROM t1, t2 WHERE b = a AND (b = alias1.b OR EXISTS (SELECT * FROM t3))) +m NULL NULL NULL diff --git a/mysql-test/main/subselect.test b/mysql-test/main/subselect.test index 187dc80b4b4d0..77da710a53552 100644 --- a/mysql-test/main/subselect.test +++ b/mysql-test/main/subselect.test @@ -74,13 +74,13 @@ SELECT ROW(1,2,3) > (SELECT 1,2,1); #enable after fix MDEV-28585 --disable_view_protocol SELECT ROW(1,2,3) = (SELECT 1,2,NULL); -SELECT (SELECT 1.5,2,'a') = ROW(1.5,2,'a'); -SELECT (SELECT 1.5,2,'a') = ROW(1.5,2,'b'); -SELECT (SELECT 1.5,2,'a') = ROW('1.5b',2,'b'); -SELECT (SELECT 'b',2,'a') = ROW(1.5,2,'a'); -SELECT (SELECT 1.5,2,'a') = ROW(1.5,'2','a'); -SELECT (SELECT 1.5,'c','a') = ROW(1.5,2,'a'); --enable_view_protocol +SELECT (SELECT 1.5,2,'a') = ROW(1.5,2,'a') AS m; +SELECT (SELECT 1.5,2,'a') = ROW(1.5,2,'b') AS m; +SELECT (SELECT 1.5,2,'a') = ROW('1.5b',2,'b') AS m; +SELECT (SELECT 'b',2,'a') = ROW(1.5,2,'a') AS m; +SELECT (SELECT 1.5,2,'a') = ROW(1.5,'2','a') AS m; +SELECT (SELECT 1.5,'c','a') = ROW(1.5,2,'a') AS m; -- error ER_OPERAND_COLUMNS SELECT (SELECT * FROM (SELECT 'test' a,'test' b) a); @@ -118,11 +118,15 @@ set optimizer_switch=@tmp_optimizer_switch; select * from t1 where t1.a=(select t2.a from t2 where t2.b=(select max(a) from t3) order by 1 desc limit 1); select * from t1 where t1.a=(select t2.a from t2 where t2.b=(select max(a) from t3 where t3.a > t1.a) order by 1 desc limit 1); select * from t1 where t1.a=(select t2.a from t2 where t2.b=(select max(a) from t3 where t3.a < t1.a) order by 1 desc limit 1); -#enable afte fix MDEV-27871 ---disable_view_protocol -select b,(select avg(t2.a+(select min(t3.a) from t3 where t3.a >= t4.a)) from t2) from t4; -explain extended select b,(select avg(t2.a+(select min(t3.a) from t3 where t3.a >= t4.a)) from t2) from t4; ---enable_view_protocol +select + b, + (select avg(t2.a+(select min(t3.a) from t3 where t3.a >= t4.a)) from t2) as m +from t4; +explain extended +select + b, + (select avg(t2.a+(select min(t3.a) from t3 where t3.a >= t4.a)) from t2) as m +from t4; select * from t3 where exists (select * from t2 where t2.b=t3.a); select * from t3 where not exists (select * from t2 where t2.b=t3.a); select * from t3 where a in (select b from t2); @@ -155,16 +159,25 @@ delete from t2 where a=2 and b=10; select b,max(a) as ma from t4 group by b having b >= (select max(t2.a) from t2 where t2.b=t4.b); create table t5 (a int); -#enable afte fix MDEV-27871 ---disable_view_protocol - -select (select a from t1 where t1.a=t2.a union select a from t5 where t5.a=t2.a), a from t2; +select + (select a from t1 where t1.a=t2.a union select a from t5 where t5.a=t2.a) as m, + a +from t2; insert into t5 values (5); -select (select a from t1 where t1.a=t2.a union select a from t5 where t5.a=t2.a), a from t2; +select + (select a from t1 where t1.a=t2.a union select a from t5 where t5.a=t2.a) as m, + a +from t2; insert into t5 values (2); -select (select a from t1 where t1.a=t2.a union select a from t5 where t5.a=t2.a), a from t2; -explain extended select (select a from t1 where t1.a=t2.a union select a from t5 where t5.a=t2.a), a from t2; ---enable_view_protocol +select + (select a from t1 where t1.a=t2.a union select a from t5 where t5.a=t2.a) as m, + a +from t2; +explain extended +select + (select a from t1 where t1.a=t2.a union select a from t5 where t5.a=t2.a) as m, + a +from t2; -- error ER_SUBQUERY_NO_1_ROW select (select a from t1 where t1.a=t2.a union all select a from t5 where t5.a=t2.a), a from t2; @@ -269,19 +282,19 @@ SELECT * from t2 where topic = any (SELECT topic FROM t2 GROUP BY topic HAVING t SELECT * from t2 where topic = any (SELECT SUM(topic) FROM t1); SELECT * from t2 where topic = all (SELECT topic FROM t2 GROUP BY topic); SELECT * from t2 where topic = all (SELECT topic FROM t2 GROUP BY topic HAVING topic < 4100); -#enable after fix MDEV-27871 ---disable_view_protocol -SELECT *, topic = all (SELECT topic FROM t2 GROUP BY topic HAVING topic < 4100) from t2; ---enable_view_protocol +SELECT + *, + topic = all (SELECT topic FROM t2 GROUP BY topic HAVING topic < 4100) AS m +FROM t2; SELECT * from t2 where topic = all (SELECT SUM(topic) FROM t2); SELECT * from t2 where topic <> any (SELECT SUM(topic) FROM t2); SELECT * from t2 where topic IN (SELECT topic FROM t2 GROUP BY topic HAVING topic < 41000); SELECT * from t2 where topic = any (SELECT topic FROM t2 GROUP BY topic HAVING topic < 41000); SELECT * from t2 where topic = all (SELECT topic FROM t2 GROUP BY topic HAVING topic < 41000); -#enable after fix MDEV-27871 ---disable_view_protocol -SELECT *, topic = all (SELECT topic FROM t2 GROUP BY topic HAVING topic < 41000) from t2; ---enable_view_protocol +SELECT + *, + topic = all (SELECT topic FROM t2 GROUP BY topic HAVING topic < 41000) AS m +FROM t2; drop table t1,t2; #forumconthardwarefr7 @@ -523,11 +536,20 @@ select 10.5 IN (SELECT * from t1); select 1.5 > ALL (SELECT * from t1); select 10.5 > ALL (SELECT * from t1); select 1.5 > ANY (SELECT * from t1); +update t1 set a=NULL where a=2.5; +select 1.5 IN (SELECT * from t1); +select 3.5 IN (SELECT * from t1); +select 10.5 IN (SELECT * from t1); +select 1.5 > ALL (SELECT * from t1); +select 10.5 > ALL (SELECT * from t1); +select 1.5 > ANY (SELECT * from t1); select 10.5 > ANY (SELECT * from t1); +--enable_view_protocol +explain extended select (select a+1) from t1; +explain extended select (select a+1) from t1; explain extended select (select a+1) from t1; select (select a+1) from t1; drop table t1; ---enable_view_protocol # # Null with keys @@ -947,10 +969,7 @@ create table t3 (a int, b int); insert into t1 values (0,100),(1,2), (1,3), (2,2), (2,7), (2,-1), (3,10); insert into t2 values (0,0), (1,1), (2,1), (3,1), (4,1); insert into t3 values (3,3), (2,2), (1,1); -#enable after fix MDEV-27871 ---disable_view_protocol -select a,(select count(distinct t1.b) as sum from t1,t2 where t1.a=t2.a and t2.b > 0 and t1.a <= t3.b group by t1.a order by sum limit 1) from t3; ---enable_view_protocol +select a,(select count(distinct t1.b) as sum from t1,t2 where t1.a=t2.a and t2.b > 0 and t1.a <= t3.b group by t1.a order by sum limit 1) as m from t3; drop table t1,t2,t3; # @@ -1068,10 +1087,7 @@ CREATE TABLE `t3` (`taskgenid` mediumint(9) NOT NULL auto_increment,`dbid` int(1 INSERT INTO `t3` (`taskgenid`, `dbid`, `taskid`, `mon`, `tues`,`wed`, `thur`, `fri`, `sat`, `sun`, `how_often`, `userid`, `active`) VALUES (1,-1, 1, 1, 1, 1, 1, 1, 0, 0, 1, 0, 1); CREATE TABLE `t4` (`task_id` smallint(6) NOT NULL default '0',`description` varchar(200) NOT NULL default '') ENGINE=MyISAM CHARSET=latin1; INSERT INTO `t4` (`task_id`, `description`) VALUES (1, 'Daily Check List'),(2, 'Weekly Status'); -#enable after fix MDEV-27871 ---disable_view_protocol -select dbid, name, (date_format(now() , '%Y-%m-%d') - INTERVAL how_often DAY) >= ifnull((SELECT date_format(max(create_date),'%Y-%m-%d') FROM t1 WHERE dbid = b.db_id AND taskid = a.taskgenid), '1950-01-01') from t3 a, t2 b, t4 WHERE dbid = - 1 AND primary_uid = '1' AND t4.task_id = taskid; ---enable_view_protocol +select dbid, name, (date_format(now() , '%Y-%m-%d') - INTERVAL how_often DAY) >= ifnull((SELECT date_format(max(create_date),'%Y-%m-%d') as m FROM t1 WHERE dbid = b.db_id AND taskid = a.taskgenid), '1950-01-01') as m from t3 a, t2 b, t4 WHERE dbid = - 1 AND primary_uid = '1' AND t4.task_id = taskid; SELECT dbid, name FROM t3 a, t2 b, t4 WHERE dbid = - 1 AND primary_uid = '1' AND ((date_format(now() , '%Y-%m-%d') - INTERVAL how_often DAY) >= ifnull((SELECT date_format(max(create_date),'%Y-%m-%d') FROM t1 WHERE dbid = b.db_id AND taskid = a.taskgenid), '1950-01-01')) AND t4.task_id = taskid; drop table t1,t2,t3,t4; @@ -2390,9 +2406,6 @@ SELECT a, MAX(b), MIN(b) FROM t1 GROUP BY a; SELECT * FROM t2; SELECT * FROM t3; -#enable after fix MDEV-28570 ---disable_view_protocol - SELECT a FROM t1 GROUP BY a HAVING a IN (SELECT c FROM t2 WHERE MAX(b)>20); SELECT a FROM t1 GROUP BY a @@ -2457,8 +2470,6 @@ SELECT t1.a, SUM(b) AS sum FROM t1 GROUP BY t1.a HAVING t1.a IN (SELECT t2.c FROM t2 GROUP BY t2.c HAVING t2.c+sum > 20); ---enable_view_protocol - DROP TABLE t1,t2,t3; @@ -2689,19 +2700,17 @@ DROP TABLE t1; # Bug#21540 Subqueries with no from and aggregate functions return # wrong results -#enable after fix MDEV-27871, MDEV-28573 ---disable_view_protocol - CREATE TABLE t1 (a INT, b INT); CREATE TABLE t2 (a INT); INSERT INTO t2 values (1); INSERT INTO t1 VALUES (1,1),(1,2),(2,3),(3,4); SELECT (SELECT COUNT(DISTINCT t1.b) from t2) FROM t1 GROUP BY t1.a; -SELECT (SELECT COUNT(DISTINCT t1.b) from t2 union select 1 from t2 where 12 < 3) +SELECT + (SELECT COUNT(DISTINCT t1.b) from t2 union select 1 from t2 where 12 < 3) AS m FROM t1 GROUP BY t1.a; SELECT COUNT(DISTINCT t1.b), (SELECT COUNT(DISTINCT t1.b)) FROM t1 GROUP BY t1.a; SELECT COUNT(DISTINCT t1.b), - (SELECT COUNT(DISTINCT t1.b) union select 1 from DUAL where 12 < 3) + (SELECT COUNT(DISTINCT t1.b) union select 1 from DUAL where 12 < 3) AS m FROM t1 GROUP BY t1.a; SELECT ( SELECT ( @@ -2715,11 +2724,10 @@ SELECT ( SELECT COUNT(DISTINCT t1.b) ) ) - FROM t1 GROUP BY t1.a LIMIT 1) + FROM t1 GROUP BY t1.a LIMIT 1) AS m FROM t1 t2 GROUP BY t2.a; DROP TABLE t1,t2; ---enable_view_protocol # # Bug#21727 Correlated subquery that requires filesort: @@ -2954,8 +2962,6 @@ DROP TABLE t1,t2; # Bug#27229 GROUP_CONCAT in subselect with COUNT() as an argument # -#enable after fix MDEV-28571 ---disable_view_protocol CREATE TABLE t1 (a int, b int); CREATE TABLE t2 (m int, n int); INSERT INTO t1 VALUES (2,2), (2,2), (3,3), (3,3), (3,3), (4,4); @@ -2970,7 +2976,6 @@ SELECT COUNT(*) c, a, FROM t1 GROUP BY a; DROP table t1,t2; ---enable_view_protocol # # Bug#27321 Wrong subquery result in a grouping select @@ -3001,14 +3006,11 @@ SELECT tt.a, FROM t1 WHERE t1.a=tt.a GROUP BY a LIMIT 1) as test FROM t1 as tt GROUP BY tt.a; -#enable after fix MDEV-28571 ---disable_view_protocol SELECT tt.a, MAX( (SELECT (SELECT t.c FROM t1 AS t WHERE t1.a=t.a AND t.d=MAX(t1.b + tt.a) LIMIT 1) FROM t1 WHERE t1.a=tt.a GROUP BY a LIMIT 1)) as test FROM t1 as tt GROUP BY tt.a; ---enable_view_protocol DROP TABLE t1; @@ -3163,8 +3165,6 @@ CREATE TABLE t2 (x INTEGER); INSERT INTO t1 VALUES (1,11), (2,22), (2,22); INSERT INTO t2 VALUES (1), (2); -#enable after fix MDEV-28573 ---disable_view_protocol # wasn't failing, but should --error ER_SUBQUERY_NO_1_ROW SELECT a, COUNT(b), (SELECT COUNT(b) FROM t2) FROM t1 GROUP BY a; @@ -3174,7 +3174,6 @@ SELECT a, COUNT(b), (SELECT COUNT(b) FROM t2) FROM t1 GROUP BY a; SELECT a, COUNT(b), (SELECT COUNT(b)+0 FROM t2) FROM t1 GROUP BY a; SELECT (SELECT SUM(t1.a)/AVG(t2.x) FROM t2) FROM t1; ---enable_view_protocol DROP TABLE t1,t2; @@ -3189,8 +3188,6 @@ GROUP BY a1.a; DROP TABLE t1; #test cases from 29297 -#enable after fix MDEV-28573 ---disable_view_protocol CREATE TABLE t1 (a INT); CREATE TABLE t2 (a INT); INSERT INTO t1 VALUES (1),(2); @@ -3200,7 +3197,6 @@ SELECT (SELECT SUM(t1.a) FROM t2 WHERE a=0) FROM t1; SELECT (SELECT SUM(t1.a) FROM t2 WHERE a!=0) FROM t1; SELECT (SELECT SUM(t1.a) FROM t2 WHERE a=1) FROM t1; DROP TABLE t1,t2; ---enable_view_protocol # # Bug#31884 Assertion + crash in subquery in the SELECT clause. @@ -5402,14 +5398,11 @@ INSERT INTO t2 VALUES (10,7,0), (0,7,0); CREATE TABLE t3 (a int, b int); INSERT INTO t3 VALUES (10,7), (0,7); -#enable after fix MDEV-27871 ---disable_view_protocol SELECT SUM(DISTINCT b), (SELECT t2.a FROM t1 JOIN t2 ON t2.c != 0 - WHERE t.a != 0 AND t2.a != 0) + WHERE t.a != 0 AND t2.a != 0) AS m FROM (SELECT * FROM t3) AS t GROUP BY 2; ---enable_view_protocol SELECT SUM(DISTINCT b), (SELECT t2.a FROM t1,t2 WHERE t.a != 0 or 1=2 LIMIT 1) @@ -5567,29 +5560,53 @@ INSERT INTO t3 VALUES (1,1),(2,2); set @old_optimizer_switch = @@session.optimizer_switch; set @@optimizer_switch='materialization=on,partial_match_rowid_merge=on,partial_match_table_scan=off,subquery_cache=off,semijoin=off'; -#enable after fix MDEV-27871 ---disable_view_protocol -SELECT (SELECT f3a FROM t3 where f3a > 3) NOT IN (SELECT f1a FROM t1) FROM t2; -SELECT (SELECT f3a,f3a FROM t3 where f3a > 3) NOT IN (SELECT f1a,f1a FROM t1) FROM t2; -SELECT (SELECT f3a, f3b FROM t3 where f3a > 3) NOT IN (SELECT f1a, f1b FROM t1) FROM t2; -SELECT (SELECT f3a, f3b FROM t3 where f3a > 3) NOT IN (SELECT f1a, f1b FROM t1); -SELECT (SELECT f3a FROM t3 where f3a > 3) IN (SELECT f1a FROM t1) FROM t2; -SELECT (SELECT f3a,f3a FROM t3 where f3a > 3) IN (SELECT f1a,f1a FROM t1) FROM t2; -SELECT (SELECT f3a, f3b FROM t3 where f3a > 3) IN (SELECT f1a, f1b FROM t1) FROM t2; -SELECT (SELECT f3a, f3b FROM t3 where f3a > 3) IN (SELECT f1a, f1b FROM t1); +SELECT + (SELECT f3a FROM t3 where f3a > 3) NOT IN (SELECT f1a FROM t1) AS m +FROM t2; +SELECT + (SELECT f3a,f3a FROM t3 where f3a > 3) NOT IN (SELECT f1a,f1a FROM t1) AS m + FROM t2; +SELECT + (SELECT f3a, f3b FROM t3 where f3a > 3) NOT IN (SELECT f1a, f1b FROM t1) AS m +FROM t2; +SELECT + (SELECT f3a, f3b FROM t3 where f3a > 3) NOT IN (SELECT f1a, f1b FROM t1) AS m; +SELECT + (SELECT f3a FROM t3 where f3a > 3) IN (SELECT f1a FROM t1) AS m +FROM t2; +SELECT + (SELECT f3a,f3a FROM t3 where f3a > 3) IN (SELECT f1a,f1a FROM t1) AS m +FROM t2; +SELECT + (SELECT f3a, f3b FROM t3 where f3a > 3) IN (SELECT f1a, f1b FROM t1) AS m +FROM t2; +SELECT + (SELECT f3a, f3b FROM t3 where f3a > 3) IN (SELECT f1a, f1b FROM t1) AS m; set @@session.optimizer_switch=@old_optimizer_switch; # check different IN with default switches -SELECT (SELECT f3a FROM t3 where f3a > 3) NOT IN (SELECT f1a FROM t1) FROM t2; -SELECT (SELECT f3a,f3a FROM t3 where f3a > 3) NOT IN (SELECT f1a,f1a FROM t1) FROM t2; -SELECT (SELECT f3a, f3b FROM t3 where f3a > 3) NOT IN (SELECT f1a, f1b FROM t1) FROM t2; -SELECT (SELECT f3a, f3b FROM t3 where f3a > 3) NOT IN (SELECT f1a, f1b FROM t1); -SELECT (SELECT f3a FROM t3 where f3a > 3) IN (SELECT f1a FROM t1) FROM t2; -SELECT (SELECT f3a,f3a FROM t3 where f3a > 3) IN (SELECT f1a,f1a FROM t1) FROM t2; -SELECT (SELECT f3a, f3b FROM t3 where f3a > 3) IN (SELECT f1a, f1b FROM t1) FROM t2; -SELECT (SELECT f3a, f3b FROM t3 where f3a > 3) IN (SELECT f1a, f1b FROM t1); ---enable_view_protocol +SELECT + (SELECT f3a FROM t3 where f3a > 3) NOT IN (SELECT f1a FROM t1) AS m +FROM t2; +SELECT + (SELECT f3a,f3a FROM t3 where f3a > 3) NOT IN (SELECT f1a,f1a FROM t1) AS m +FROM t2; +SELECT + (SELECT f3a, f3b FROM t3 where f3a > 3) NOT IN (SELECT f1a, f1b FROM t1) AS m +FROM t2; +SELECT + (SELECT f3a, f3b FROM t3 where f3a > 3) NOT IN (SELECT f1a, f1b FROM t1) AS m; +SELECT + (SELECT f3a FROM t3 where f3a > 3) IN (SELECT f1a FROM t1) FROM t2 AS m; +SELECT + (SELECT f3a,f3a FROM t3 where f3a > 3) IN (SELECT f1a,f1a FROM t1) AS m +FROM t2; +SELECT + (SELECT f3a, f3b FROM t3 where f3a > 3) IN (SELECT f1a, f1b FROM t1) AS m +FROM t2; +SELECT + (SELECT f3a, f3b FROM t3 where f3a > 3) IN (SELECT f1a, f1b FROM t1) AS m; # other row operation with NULL single row subquery also should work select (null, null) = (null, null); @@ -5629,10 +5646,9 @@ INSERT INTO t3 VALUES (4),(5); SET optimizer_switch='subquery_cache=off'; -#enable after fix MDEV-27871 ---disable_view_protocol -SELECT ( SELECT b FROM t2 WHERE b = a OR EXISTS ( SELECT c FROM t3 WHERE c = b ) ) FROM t1; ---enable_view_protocol +SELECT + ( SELECT b FROM t2 WHERE b = a OR EXISTS ( SELECT c FROM t3 WHERE c = b ) ) AS m +FROM t1; # This query just for example, it should return the same as above (1 and NULL) SELECT ( SELECT b FROM t2 WHERE b = a OR b * 0) FROM t1; @@ -5821,15 +5837,17 @@ INSERT INTO t3 VALUES (8),(3); set @@expensive_subquery_limit= 0; -#enable after fix MDEV-27871 ---disable_view_protocol EXPLAIN -SELECT (SELECT MIN(b) FROM t1, t2 WHERE b = a AND (b = alias1.b OR EXISTS (SELECT * FROM t3))) +SELECT + (SELECT MIN(b) FROM t1, t2 + WHERE b = a AND (b = alias1.b OR EXISTS (SELECT * FROM t3))) AS m FROM t2 alias1, t1 alias2, t1 alias3; flush status; -SELECT (SELECT MIN(b) FROM t1, t2 WHERE b = a AND (b = alias1.b OR EXISTS (SELECT * FROM t3))) +SELECT + (SELECT MIN(b) FROM t1, t2 + WHERE b = a AND (b = alias1.b OR EXISTS (SELECT * FROM t3))) AS m FROM t2 alias1, t1 alias2, t1 alias3; show status like "subquery_cache%"; @@ -5838,17 +5856,20 @@ show status like '%Handler_read%'; set @@expensive_subquery_limit= default; EXPLAIN -SELECT (SELECT MIN(b) FROM t1, t2 WHERE b = a AND (b = alias1.b OR EXISTS (SELECT * FROM t3))) +SELECT + (SELECT MIN(b) FROM t1, t2 + WHERE b = a AND (b = alias1.b OR EXISTS (SELECT * FROM t3))) AS m FROM t2 alias1, t1 alias2, t1 alias3; flush status; -SELECT (SELECT MIN(b) FROM t1, t2 WHERE b = a AND (b = alias1.b OR EXISTS (SELECT * FROM t3))) +SELECT + (SELECT MIN(b) FROM t1, t2 + WHERE b = a AND (b = alias1.b OR EXISTS (SELECT * FROM t3))) AS m FROM t2 alias1, t1 alias2, t1 alias3; show status like "subquery_cache%"; show status like '%Handler_read%'; ---enable_view_protocol drop table t1, t2, t3; @@ -6102,22 +6123,16 @@ INSERT INTO t1 VALUES (1),(2); CREATE TABLE t2 (f2 int); INSERT INTO t2 VALUES (3); -#enable after fix MDEV-29224 ---disable_view_protocol SELECT ( SELECT MAX(f1) FROM t2 ) FROM t1; SELECT ( SELECT MAX(f1) FROM t2 ) FROM v1; ---enable_view_protocol INSERT INTO t2 VALUES (4); -#enable after fix MDEV-28573 ---disable_view_protocol --error ER_SUBQUERY_NO_1_ROW SELECT ( SELECT MAX(f1) FROM t2 ) FROM v1; --error ER_SUBQUERY_NO_1_ROW SELECT ( SELECT MAX(f1) FROM t2 ) FROM t1; ---enable_view_protocol drop view v1; drop table t1,t2; diff --git a/mysql-test/main/subselect4.result b/mysql-test/main/subselect4.result index 262adc51d3ac2..259337cf646de 100644 --- a/mysql-test/main/subselect4.result +++ b/mysql-test/main/subselect4.result @@ -20,8 +20,8 @@ WHERE NOT EXISTS (SELECT 1 FROM t2 WHERE 1 = (SELECT MIN(t2.b) FROM t3)) ORDER BY count(*); id select_type table type possible_keys key key_len ref rows Extra 1 PRIMARY t1 index NULL a 5 NULL 2 Using index -2 DEPENDENT SUBQUERY t2 ALL NULL NULL NULL NULL 2 Using where -3 DEPENDENT SUBQUERY t3 system NULL NULL NULL NULL 0 Const row not found +2 SUBQUERY t2 ALL NULL NULL NULL NULL 2 Using where +3 DEPENDENT SUBQUERY NULL NULL NULL NULL NULL NULL NULL no matching row in const table # should not crash the next statement SELECT 1 FROM t1 WHERE NOT EXISTS (SELECT 1 FROM t2 WHERE 1 = (SELECT MIN(t2.b) FROM t3)) diff --git a/mysql-test/main/subselect_no_exists_to_in.result b/mysql-test/main/subselect_no_exists_to_in.result index 8746f7278c3e7..f508cb259bbb9 100644 --- a/mysql-test/main/subselect_no_exists_to_in.result +++ b/mysql-test/main/subselect_no_exists_to_in.result @@ -122,27 +122,27 @@ ROW(1,2,3) > (SELECT 1,2,1) SELECT ROW(1,2,3) = (SELECT 1,2,NULL); ROW(1,2,3) = (SELECT 1,2,NULL) NULL -SELECT (SELECT 1.5,2,'a') = ROW(1.5,2,'a'); -(SELECT 1.5,2,'a') = ROW(1.5,2,'a') +SELECT (SELECT 1.5,2,'a') = ROW(1.5,2,'a') AS m; +m 1 -SELECT (SELECT 1.5,2,'a') = ROW(1.5,2,'b'); -(SELECT 1.5,2,'a') = ROW(1.5,2,'b') +SELECT (SELECT 1.5,2,'a') = ROW(1.5,2,'b') AS m; +m 0 -SELECT (SELECT 1.5,2,'a') = ROW('1.5b',2,'b'); -(SELECT 1.5,2,'a') = ROW('1.5b',2,'b') +SELECT (SELECT 1.5,2,'a') = ROW('1.5b',2,'b') AS m; +m 0 Warnings: Warning 1292 Truncated incorrect DOUBLE value: '1.5b' -SELECT (SELECT 'b',2,'a') = ROW(1.5,2,'a'); -(SELECT 'b',2,'a') = ROW(1.5,2,'a') +SELECT (SELECT 'b',2,'a') = ROW(1.5,2,'a') AS m; +m 0 Warnings: Warning 1292 Truncated incorrect DOUBLE value: 'b' -SELECT (SELECT 1.5,2,'a') = ROW(1.5,'2','a'); -(SELECT 1.5,2,'a') = ROW(1.5,'2','a') +SELECT (SELECT 1.5,2,'a') = ROW(1.5,'2','a') AS m; +m 1 -SELECT (SELECT 1.5,'c','a') = ROW(1.5,2,'a'); -(SELECT 1.5,'c','a') = ROW(1.5,2,'a') +SELECT (SELECT 1.5,'c','a') = ROW(1.5,2,'a') AS m; +m 0 Warnings: Warning 1292 Truncated incorrect DECIMAL value: 'c' @@ -232,19 +232,26 @@ a 2 select * from t1 where t1.a=(select t2.a from t2 where t2.b=(select max(a) from t3 where t3.a < t1.a) order by 1 desc limit 1); a -select b,(select avg(t2.a+(select min(t3.a) from t3 where t3.a >= t4.a)) from t2) from t4; -b (select avg(t2.a+(select min(t3.a) from t3 where t3.a >= t4.a)) from t2) +select +b, +(select avg(t2.a+(select min(t3.a) from t3 where t3.a >= t4.a)) from t2) as m +from t4; +b m 8 7.5000 8 4.5000 9 7.5000 -explain extended select b,(select avg(t2.a+(select min(t3.a) from t3 where t3.a >= t4.a)) from t2) from t4; +explain extended +select +b, +(select avg(t2.a+(select min(t3.a) from t3 where t3.a >= t4.a)) from t2) as m +from t4; id select_type table type possible_keys key key_len ref rows filtered Extra 1 PRIMARY t4 ALL NULL NULL NULL NULL 3 100.00 2 DEPENDENT SUBQUERY t2 ALL NULL NULL NULL NULL 2 100.00 3 DEPENDENT SUBQUERY t3 ALL NULL NULL NULL NULL 3 100.00 Using where Warnings: Note 1276 Field or reference 'test.t4.a' of SELECT #3 was resolved in SELECT #1 -Note 1003 /* select#1 */ select `test`.`t4`.`b` AS `b`,<`test`.`t4`.`a`>((/* select#2 */ select avg(`test`.`t2`.`a` + (/* select#3 */ select min(`test`.`t3`.`a`) from `test`.`t3` where `test`.`t3`.`a` >= `test`.`t4`.`a`)) from `test`.`t2`)) AS `(select avg(t2.a+(select min(t3.a) from t3 where t3.a >= t4.a)) from t2)` from `test`.`t4` +Note 1003 /* select#1 */ select `test`.`t4`.`b` AS `b`,<`test`.`t4`.`a`>((/* select#2 */ select avg(`test`.`t2`.`a` + (/* select#3 */ select min(`test`.`t3`.`a`) from `test`.`t3` where `test`.`t3`.`a` >= `test`.`t4`.`a`)) from `test`.`t2`)) AS `m` from `test`.`t4` select * from t3 where exists (select * from t2 where t2.b=t3.a); a 7 @@ -311,21 +318,34 @@ select b,max(a) as ma from t4 group by b having b >= (select max(t2.a) from t2 w b ma 7 12 create table t5 (a int); -select (select a from t1 where t1.a=t2.a union select a from t5 where t5.a=t2.a), a from t2; -(select a from t1 where t1.a=t2.a union select a from t5 where t5.a=t2.a) a +select +(select a from t1 where t1.a=t2.a union select a from t5 where t5.a=t2.a) as m, +a +from t2; +m a NULL 1 2 2 insert into t5 values (5); -select (select a from t1 where t1.a=t2.a union select a from t5 where t5.a=t2.a), a from t2; -(select a from t1 where t1.a=t2.a union select a from t5 where t5.a=t2.a) a +select +(select a from t1 where t1.a=t2.a union select a from t5 where t5.a=t2.a) as m, +a +from t2; +m a NULL 1 2 2 insert into t5 values (2); -select (select a from t1 where t1.a=t2.a union select a from t5 where t5.a=t2.a), a from t2; -(select a from t1 where t1.a=t2.a union select a from t5 where t5.a=t2.a) a +select +(select a from t1 where t1.a=t2.a union select a from t5 where t5.a=t2.a) as m, +a +from t2; +m a NULL 1 2 2 -explain extended select (select a from t1 where t1.a=t2.a union select a from t5 where t5.a=t2.a), a from t2; +explain extended +select +(select a from t1 where t1.a=t2.a union select a from t5 where t5.a=t2.a) as m, +a +from t2; id select_type table type possible_keys key key_len ref rows filtered Extra 1 PRIMARY t2 ALL NULL NULL NULL NULL 2 100.00 2 DEPENDENT SUBQUERY t1 system NULL NULL NULL NULL 1 100.00 @@ -334,7 +354,7 @@ NULL UNION RESULT ALL NULL NULL NULL NULL NULL NULL Warnings: Note 1276 Field or reference 'test.t2.a' of SELECT #2 was resolved in SELECT #1 Note 1276 Field or reference 'test.t2.a' of SELECT #3 was resolved in SELECT #1 -Note 1003 /* select#1 */ select <`test`.`t2`.`a`>((/* select#2 */ select 2 from dual where 2 = `test`.`t2`.`a` union /* select#3 */ select `test`.`t5`.`a` from `test`.`t5` where `test`.`t5`.`a` = `test`.`t2`.`a`)) AS `(select a from t1 where t1.a=t2.a union select a from t5 where t5.a=t2.a)`,`test`.`t2`.`a` AS `a` from `test`.`t2` +Note 1003 /* select#1 */ select <`test`.`t2`.`a`>((/* select#2 */ select 2 from dual where 2 = `test`.`t2`.`a` union /* select#3 */ select `test`.`t5`.`a` from `test`.`t5` where `test`.`t5`.`a` = `test`.`t2`.`a`)) AS `m`,`test`.`t2`.`a` AS `a` from `test`.`t2` select (select a from t1 where t1.a=t2.a union all select a from t5 where t5.a=t2.a), a from t2; ERROR 21000: Subquery returns more than 1 row create table t6 (patient_uq int, clinic_uq int, index i1 (clinic_uq)); @@ -490,8 +510,11 @@ SELECT * from t2 where topic = all (SELECT topic FROM t2 GROUP BY topic HAVING t mot topic date pseudo joce 40143 2002-10-22 joce joce 43506 2002-10-22 joce -SELECT *, topic = all (SELECT topic FROM t2 GROUP BY topic HAVING topic < 4100) from t2; -mot topic date pseudo topic = all (SELECT topic FROM t2 GROUP BY topic HAVING topic < 4100) +SELECT +*, +topic = all (SELECT topic FROM t2 GROUP BY topic HAVING topic < 4100) AS m +FROM t2; +mot topic date pseudo m joce 40143 2002-10-22 joce 1 joce 43506 2002-10-22 joce 1 SELECT * from t2 where topic = all (SELECT SUM(topic) FROM t2); @@ -509,8 +532,11 @@ joce 40143 2002-10-22 joce SELECT * from t2 where topic = all (SELECT topic FROM t2 GROUP BY topic HAVING topic < 41000); mot topic date pseudo joce 40143 2002-10-22 joce -SELECT *, topic = all (SELECT topic FROM t2 GROUP BY topic HAVING topic < 41000) from t2; -mot topic date pseudo topic = all (SELECT topic FROM t2 GROUP BY topic HAVING topic < 41000) +SELECT +*, +topic = all (SELECT topic FROM t2 GROUP BY topic HAVING topic < 41000) AS m +FROM t2; +mot topic date pseudo m joce 40143 2002-10-22 joce 1 joce 43506 2002-10-22 joce 0 drop table t1,t2; @@ -885,6 +911,25 @@ NULL select 1.5 > ANY (SELECT * from t1); 1.5 > ANY (SELECT * from t1) NULL +update t1 set a=NULL where a=2.5; +select 1.5 IN (SELECT * from t1); +1.5 IN (SELECT * from t1) +1 +select 3.5 IN (SELECT * from t1); +3.5 IN (SELECT * from t1) +1 +select 10.5 IN (SELECT * from t1); +10.5 IN (SELECT * from t1) +NULL +select 1.5 > ALL (SELECT * from t1); +1.5 > ALL (SELECT * from t1) +0 +select 10.5 > ALL (SELECT * from t1); +10.5 > ALL (SELECT * from t1) +NULL +select 1.5 > ANY (SELECT * from t1); +1.5 > ANY (SELECT * from t1) +NULL select 10.5 > ANY (SELECT * from t1); 10.5 > ANY (SELECT * from t1) 1 @@ -895,6 +940,20 @@ Warnings: Note 1276 Field or reference 'test.t1.a' of SELECT #2 was resolved in SELECT #1 Note 1249 Select 2 was reduced during optimization Note 1003 select `test`.`t1`.`a` + 1 AS `(select a+1)` from `test`.`t1` +explain extended select (select a+1) from t1; +id select_type table type possible_keys key key_len ref rows filtered Extra +1 SIMPLE t1 ALL NULL NULL NULL NULL 3 100.00 +Warnings: +Note 1276 Field or reference 'test.t1.a' of SELECT #2 was resolved in SELECT #1 +Note 1249 Select 2 was reduced during optimization +Note 1003 select `test`.`t1`.`a` + 1 AS `(select a+1)` from `test`.`t1` +explain extended select (select a+1) from t1; +id select_type table type possible_keys key key_len ref rows filtered Extra +1 SIMPLE t1 ALL NULL NULL NULL NULL 3 100.00 +Warnings: +Note 1276 Field or reference 'test.t1.a' of SELECT #2 was resolved in SELECT #1 +Note 1249 Select 2 was reduced during optimization +Note 1003 select `test`.`t1`.`a` + 1 AS `(select a+1)` from `test`.`t1` select (select a+1) from t1; (select a+1) 2.5 @@ -1536,8 +1595,8 @@ create table t3 (a int, b int); insert into t1 values (0,100),(1,2), (1,3), (2,2), (2,7), (2,-1), (3,10); insert into t2 values (0,0), (1,1), (2,1), (3,1), (4,1); insert into t3 values (3,3), (2,2), (1,1); -select a,(select count(distinct t1.b) as sum from t1,t2 where t1.a=t2.a and t2.b > 0 and t1.a <= t3.b group by t1.a order by sum limit 1) from t3; -a (select count(distinct t1.b) as sum from t1,t2 where t1.a=t2.a and t2.b > 0 and t1.a <= t3.b group by t1.a order by sum limit 1) +select a,(select count(distinct t1.b) as sum from t1,t2 where t1.a=t2.a and t2.b > 0 and t1.a <= t3.b group by t1.a order by sum limit 1) as m from t3; +a m 3 1 2 2 1 2 @@ -1732,8 +1791,8 @@ CREATE TABLE `t3` (`taskgenid` mediumint(9) NOT NULL auto_increment,`dbid` int(1 INSERT INTO `t3` (`taskgenid`, `dbid`, `taskid`, `mon`, `tues`,`wed`, `thur`, `fri`, `sat`, `sun`, `how_often`, `userid`, `active`) VALUES (1,-1, 1, 1, 1, 1, 1, 1, 0, 0, 1, 0, 1); CREATE TABLE `t4` (`task_id` smallint(6) NOT NULL default '0',`description` varchar(200) NOT NULL default '') ENGINE=MyISAM CHARSET=latin1; INSERT INTO `t4` (`task_id`, `description`) VALUES (1, 'Daily Check List'),(2, 'Weekly Status'); -select dbid, name, (date_format(now() , '%Y-%m-%d') - INTERVAL how_often DAY) >= ifnull((SELECT date_format(max(create_date),'%Y-%m-%d') FROM t1 WHERE dbid = b.db_id AND taskid = a.taskgenid), '1950-01-01') from t3 a, t2 b, t4 WHERE dbid = - 1 AND primary_uid = '1' AND t4.task_id = taskid; -dbid name (date_format(now() , '%Y-%m-%d') - INTERVAL how_often DAY) >= ifnull((SELECT date_format(max(create_date),'%Y-%m-%d') FROM t1 WHERE dbid = b.db_id AND taskid = a.taskgenid), '1950-01-01') +select dbid, name, (date_format(now() , '%Y-%m-%d') - INTERVAL how_often DAY) >= ifnull((SELECT date_format(max(create_date),'%Y-%m-%d') as m FROM t1 WHERE dbid = b.db_id AND taskid = a.taskgenid), '1950-01-01') as m from t3 a, t2 b, t4 WHERE dbid = - 1 AND primary_uid = '1' AND t4.task_id = taskid; +dbid name m -1 Valid 1 -1 Valid 2 1 -1 Should Not Return 0 @@ -3787,9 +3846,10 @@ SELECT (SELECT COUNT(DISTINCT t1.b) from t2) FROM t1 GROUP BY t1.a; 2 1 1 -SELECT (SELECT COUNT(DISTINCT t1.b) from t2 union select 1 from t2 where 12 < 3) +SELECT +(SELECT COUNT(DISTINCT t1.b) from t2 union select 1 from t2 where 12 < 3) AS m FROM t1 GROUP BY t1.a; -(SELECT COUNT(DISTINCT t1.b) from t2 union select 1 from t2 where 12 < 3) +m 2 1 1 @@ -3799,9 +3859,9 @@ COUNT(DISTINCT t1.b) (SELECT COUNT(DISTINCT t1.b)) 1 1 1 1 SELECT COUNT(DISTINCT t1.b), -(SELECT COUNT(DISTINCT t1.b) union select 1 from DUAL where 12 < 3) +(SELECT COUNT(DISTINCT t1.b) union select 1 from DUAL where 12 < 3) AS m FROM t1 GROUP BY t1.a; -COUNT(DISTINCT t1.b) (SELECT COUNT(DISTINCT t1.b) union select 1 from DUAL where 12 < 3) +COUNT(DISTINCT t1.b) m 2 2 1 1 1 1 @@ -3825,16 +3885,10 @@ SELECT ( SELECT COUNT(DISTINCT t1.b) ) ) -FROM t1 GROUP BY t1.a LIMIT 1) +FROM t1 GROUP BY t1.a LIMIT 1) AS m FROM t1 t2 GROUP BY t2.a; -( -SELECT ( -SELECT ( -SELECT COUNT(DISTINCT t1.b) -) -) -FROM t1 GROUP BY t1.a LIMIT 1) +m 2 2 2 @@ -6425,11 +6479,10 @@ CREATE TABLE t3 (a int, b int); INSERT INTO t3 VALUES (10,7), (0,7); SELECT SUM(DISTINCT b), (SELECT t2.a FROM t1 JOIN t2 ON t2.c != 0 -WHERE t.a != 0 AND t2.a != 0) +WHERE t.a != 0 AND t2.a != 0) AS m FROM (SELECT * FROM t3) AS t GROUP BY 2; -SUM(DISTINCT b) (SELECT t2.a FROM t1 JOIN t2 ON t2.c != 0 -WHERE t.a != 0 AND t2.a != 0) +SUM(DISTINCT b) m 7 NULL SELECT SUM(DISTINCT b), (SELECT t2.a FROM t1,t2 WHERE t.a != 0 or 1=2 LIMIT 1) @@ -6562,66 +6615,93 @@ CREATE TABLE t3 (f3a int default 1, f3b int default 2); INSERT INTO t3 VALUES (1,1),(2,2); set @old_optimizer_switch = @@session.optimizer_switch; set @@optimizer_switch='materialization=on,partial_match_rowid_merge=on,partial_match_table_scan=off,subquery_cache=off,semijoin=off'; -SELECT (SELECT f3a FROM t3 where f3a > 3) NOT IN (SELECT f1a FROM t1) FROM t2; -(SELECT f3a FROM t3 where f3a > 3) NOT IN (SELECT f1a FROM t1) +SELECT +(SELECT f3a FROM t3 where f3a > 3) NOT IN (SELECT f1a FROM t1) AS m +FROM t2; +m NULL NULL -SELECT (SELECT f3a,f3a FROM t3 where f3a > 3) NOT IN (SELECT f1a,f1a FROM t1) FROM t2; -(SELECT f3a,f3a FROM t3 where f3a > 3) NOT IN (SELECT f1a,f1a FROM t1) +SELECT +(SELECT f3a,f3a FROM t3 where f3a > 3) NOT IN (SELECT f1a,f1a FROM t1) AS m +FROM t2; +m NULL NULL -SELECT (SELECT f3a, f3b FROM t3 where f3a > 3) NOT IN (SELECT f1a, f1b FROM t1) FROM t2; -(SELECT f3a, f3b FROM t3 where f3a > 3) NOT IN (SELECT f1a, f1b FROM t1) +SELECT +(SELECT f3a, f3b FROM t3 where f3a > 3) NOT IN (SELECT f1a, f1b FROM t1) AS m +FROM t2; +m NULL NULL -SELECT (SELECT f3a, f3b FROM t3 where f3a > 3) NOT IN (SELECT f1a, f1b FROM t1); -(SELECT f3a, f3b FROM t3 where f3a > 3) NOT IN (SELECT f1a, f1b FROM t1) +SELECT +(SELECT f3a, f3b FROM t3 where f3a > 3) NOT IN (SELECT f1a, f1b FROM t1) AS m; +m NULL -SELECT (SELECT f3a FROM t3 where f3a > 3) IN (SELECT f1a FROM t1) FROM t2; -(SELECT f3a FROM t3 where f3a > 3) IN (SELECT f1a FROM t1) +SELECT +(SELECT f3a FROM t3 where f3a > 3) IN (SELECT f1a FROM t1) AS m +FROM t2; +m NULL NULL -SELECT (SELECT f3a,f3a FROM t3 where f3a > 3) IN (SELECT f1a,f1a FROM t1) FROM t2; -(SELECT f3a,f3a FROM t3 where f3a > 3) IN (SELECT f1a,f1a FROM t1) +SELECT +(SELECT f3a,f3a FROM t3 where f3a > 3) IN (SELECT f1a,f1a FROM t1) AS m +FROM t2; +m NULL NULL -SELECT (SELECT f3a, f3b FROM t3 where f3a > 3) IN (SELECT f1a, f1b FROM t1) FROM t2; -(SELECT f3a, f3b FROM t3 where f3a > 3) IN (SELECT f1a, f1b FROM t1) +SELECT +(SELECT f3a, f3b FROM t3 where f3a > 3) IN (SELECT f1a, f1b FROM t1) AS m +FROM t2; +m NULL NULL -SELECT (SELECT f3a, f3b FROM t3 where f3a > 3) IN (SELECT f1a, f1b FROM t1); -(SELECT f3a, f3b FROM t3 where f3a > 3) IN (SELECT f1a, f1b FROM t1) +SELECT +(SELECT f3a, f3b FROM t3 where f3a > 3) IN (SELECT f1a, f1b FROM t1) AS m; +m NULL set @@session.optimizer_switch=@old_optimizer_switch; -SELECT (SELECT f3a FROM t3 where f3a > 3) NOT IN (SELECT f1a FROM t1) FROM t2; -(SELECT f3a FROM t3 where f3a > 3) NOT IN (SELECT f1a FROM t1) +SELECT +(SELECT f3a FROM t3 where f3a > 3) NOT IN (SELECT f1a FROM t1) AS m +FROM t2; +m NULL NULL -SELECT (SELECT f3a,f3a FROM t3 where f3a > 3) NOT IN (SELECT f1a,f1a FROM t1) FROM t2; -(SELECT f3a,f3a FROM t3 where f3a > 3) NOT IN (SELECT f1a,f1a FROM t1) +SELECT +(SELECT f3a,f3a FROM t3 where f3a > 3) NOT IN (SELECT f1a,f1a FROM t1) AS m +FROM t2; +m NULL NULL -SELECT (SELECT f3a, f3b FROM t3 where f3a > 3) NOT IN (SELECT f1a, f1b FROM t1) FROM t2; -(SELECT f3a, f3b FROM t3 where f3a > 3) NOT IN (SELECT f1a, f1b FROM t1) +SELECT +(SELECT f3a, f3b FROM t3 where f3a > 3) NOT IN (SELECT f1a, f1b FROM t1) AS m +FROM t2; +m NULL NULL -SELECT (SELECT f3a, f3b FROM t3 where f3a > 3) NOT IN (SELECT f1a, f1b FROM t1); -(SELECT f3a, f3b FROM t3 where f3a > 3) NOT IN (SELECT f1a, f1b FROM t1) +SELECT +(SELECT f3a, f3b FROM t3 where f3a > 3) NOT IN (SELECT f1a, f1b FROM t1) AS m; +m NULL -SELECT (SELECT f3a FROM t3 where f3a > 3) IN (SELECT f1a FROM t1) FROM t2; +SELECT +(SELECT f3a FROM t3 where f3a > 3) IN (SELECT f1a FROM t1) FROM t2 AS m; (SELECT f3a FROM t3 where f3a > 3) IN (SELECT f1a FROM t1) NULL NULL -SELECT (SELECT f3a,f3a FROM t3 where f3a > 3) IN (SELECT f1a,f1a FROM t1) FROM t2; -(SELECT f3a,f3a FROM t3 where f3a > 3) IN (SELECT f1a,f1a FROM t1) +SELECT +(SELECT f3a,f3a FROM t3 where f3a > 3) IN (SELECT f1a,f1a FROM t1) AS m +FROM t2; +m NULL NULL -SELECT (SELECT f3a, f3b FROM t3 where f3a > 3) IN (SELECT f1a, f1b FROM t1) FROM t2; -(SELECT f3a, f3b FROM t3 where f3a > 3) IN (SELECT f1a, f1b FROM t1) +SELECT +(SELECT f3a, f3b FROM t3 where f3a > 3) IN (SELECT f1a, f1b FROM t1) AS m +FROM t2; +m NULL NULL -SELECT (SELECT f3a, f3b FROM t3 where f3a > 3) IN (SELECT f1a, f1b FROM t1); -(SELECT f3a, f3b FROM t3 where f3a > 3) IN (SELECT f1a, f1b FROM t1) +SELECT +(SELECT f3a, f3b FROM t3 where f3a > 3) IN (SELECT f1a, f1b FROM t1) AS m; +m NULL select (null, null) = (null, null); (null, null) = (null, null) @@ -6667,8 +6747,10 @@ INSERT INTO t2 VALUES (1); CREATE TABLE t3 ( c INT ); INSERT INTO t3 VALUES (4),(5); SET optimizer_switch='subquery_cache=off'; -SELECT ( SELECT b FROM t2 WHERE b = a OR EXISTS ( SELECT c FROM t3 WHERE c = b ) ) FROM t1; -( SELECT b FROM t2 WHERE b = a OR EXISTS ( SELECT c FROM t3 WHERE c = b ) ) +SELECT +( SELECT b FROM t2 WHERE b = a OR EXISTS ( SELECT c FROM t3 WHERE c = b ) ) AS m +FROM t1; +m 1 NULL SELECT ( SELECT b FROM t2 WHERE b = a OR b * 0) FROM t1; @@ -6885,7 +6967,9 @@ CREATE TABLE t3 (c INT); INSERT INTO t3 VALUES (8),(3); set @@expensive_subquery_limit= 0; EXPLAIN -SELECT (SELECT MIN(b) FROM t1, t2 WHERE b = a AND (b = alias1.b OR EXISTS (SELECT * FROM t3))) +SELECT +(SELECT MIN(b) FROM t1, t2 +WHERE b = a AND (b = alias1.b OR EXISTS (SELECT * FROM t3))) AS m FROM t2 alias1, t1 alias2, t1 alias3; id select_type table type possible_keys key key_len ref rows Extra 1 PRIMARY alias1 ALL NULL NULL NULL NULL 2 @@ -6895,9 +6979,11 @@ id select_type table type possible_keys key key_len ref rows Extra 2 DEPENDENT SUBQUERY t2 ALL NULL NULL NULL NULL 2 Using where; Using join buffer (flat, BNL join) 3 SUBQUERY t3 ALL NULL NULL NULL NULL 2 flush status; -SELECT (SELECT MIN(b) FROM t1, t2 WHERE b = a AND (b = alias1.b OR EXISTS (SELECT * FROM t3))) +SELECT +(SELECT MIN(b) FROM t1, t2 +WHERE b = a AND (b = alias1.b OR EXISTS (SELECT * FROM t3))) AS m FROM t2 alias1, t1 alias2, t1 alias3; -(SELECT MIN(b) FROM t1, t2 WHERE b = a AND (b = alias1.b OR EXISTS (SELECT * FROM t3))) +m NULL NULL NULL @@ -6923,7 +7009,9 @@ Handler_read_rnd_deleted 0 Handler_read_rnd_next 22 set @@expensive_subquery_limit= default; EXPLAIN -SELECT (SELECT MIN(b) FROM t1, t2 WHERE b = a AND (b = alias1.b OR EXISTS (SELECT * FROM t3))) +SELECT +(SELECT MIN(b) FROM t1, t2 +WHERE b = a AND (b = alias1.b OR EXISTS (SELECT * FROM t3))) AS m FROM t2 alias1, t1 alias2, t1 alias3; id select_type table type possible_keys key key_len ref rows Extra 1 PRIMARY alias1 ALL NULL NULL NULL NULL 2 @@ -6933,9 +7021,11 @@ id select_type table type possible_keys key key_len ref rows Extra 2 SUBQUERY t2 ALL NULL NULL NULL NULL 2 Using where; Using join buffer (flat, BNL join) 3 SUBQUERY t3 ALL NULL NULL NULL NULL 2 flush status; -SELECT (SELECT MIN(b) FROM t1, t2 WHERE b = a AND (b = alias1.b OR EXISTS (SELECT * FROM t3))) +SELECT +(SELECT MIN(b) FROM t1, t2 +WHERE b = a AND (b = alias1.b OR EXISTS (SELECT * FROM t3))) AS m FROM t2 alias1, t1 alias2, t1 alias3; -(SELECT MIN(b) FROM t1, t2 WHERE b = a AND (b = alias1.b OR EXISTS (SELECT * FROM t3))) +m NULL NULL NULL diff --git a/mysql-test/main/subselect_no_mat.result b/mysql-test/main/subselect_no_mat.result index f0d788d6b4a31..02cb92fde0861 100644 --- a/mysql-test/main/subselect_no_mat.result +++ b/mysql-test/main/subselect_no_mat.result @@ -125,27 +125,27 @@ ROW(1,2,3) > (SELECT 1,2,1) SELECT ROW(1,2,3) = (SELECT 1,2,NULL); ROW(1,2,3) = (SELECT 1,2,NULL) NULL -SELECT (SELECT 1.5,2,'a') = ROW(1.5,2,'a'); -(SELECT 1.5,2,'a') = ROW(1.5,2,'a') +SELECT (SELECT 1.5,2,'a') = ROW(1.5,2,'a') AS m; +m 1 -SELECT (SELECT 1.5,2,'a') = ROW(1.5,2,'b'); -(SELECT 1.5,2,'a') = ROW(1.5,2,'b') +SELECT (SELECT 1.5,2,'a') = ROW(1.5,2,'b') AS m; +m 0 -SELECT (SELECT 1.5,2,'a') = ROW('1.5b',2,'b'); -(SELECT 1.5,2,'a') = ROW('1.5b',2,'b') +SELECT (SELECT 1.5,2,'a') = ROW('1.5b',2,'b') AS m; +m 0 Warnings: Warning 1292 Truncated incorrect DOUBLE value: '1.5b' -SELECT (SELECT 'b',2,'a') = ROW(1.5,2,'a'); -(SELECT 'b',2,'a') = ROW(1.5,2,'a') +SELECT (SELECT 'b',2,'a') = ROW(1.5,2,'a') AS m; +m 0 Warnings: Warning 1292 Truncated incorrect DOUBLE value: 'b' -SELECT (SELECT 1.5,2,'a') = ROW(1.5,'2','a'); -(SELECT 1.5,2,'a') = ROW(1.5,'2','a') +SELECT (SELECT 1.5,2,'a') = ROW(1.5,'2','a') AS m; +m 1 -SELECT (SELECT 1.5,'c','a') = ROW(1.5,2,'a'); -(SELECT 1.5,'c','a') = ROW(1.5,2,'a') +SELECT (SELECT 1.5,'c','a') = ROW(1.5,2,'a') AS m; +m 0 Warnings: Warning 1292 Truncated incorrect DECIMAL value: 'c' @@ -235,19 +235,26 @@ a 2 select * from t1 where t1.a=(select t2.a from t2 where t2.b=(select max(a) from t3 where t3.a < t1.a) order by 1 desc limit 1); a -select b,(select avg(t2.a+(select min(t3.a) from t3 where t3.a >= t4.a)) from t2) from t4; -b (select avg(t2.a+(select min(t3.a) from t3 where t3.a >= t4.a)) from t2) +select +b, +(select avg(t2.a+(select min(t3.a) from t3 where t3.a >= t4.a)) from t2) as m +from t4; +b m 8 7.5000 8 4.5000 9 7.5000 -explain extended select b,(select avg(t2.a+(select min(t3.a) from t3 where t3.a >= t4.a)) from t2) from t4; +explain extended +select +b, +(select avg(t2.a+(select min(t3.a) from t3 where t3.a >= t4.a)) from t2) as m +from t4; id select_type table type possible_keys key key_len ref rows filtered Extra 1 PRIMARY t4 ALL NULL NULL NULL NULL 3 100.00 2 DEPENDENT SUBQUERY t2 ALL NULL NULL NULL NULL 2 100.00 3 DEPENDENT SUBQUERY t3 ALL NULL NULL NULL NULL 3 100.00 Using where Warnings: Note 1276 Field or reference 'test.t4.a' of SELECT #3 was resolved in SELECT #1 -Note 1003 /* select#1 */ select `test`.`t4`.`b` AS `b`,<`test`.`t4`.`a`>((/* select#2 */ select avg(`test`.`t2`.`a` + (/* select#3 */ select min(`test`.`t3`.`a`) from `test`.`t3` where `test`.`t3`.`a` >= `test`.`t4`.`a`)) from `test`.`t2`)) AS `(select avg(t2.a+(select min(t3.a) from t3 where t3.a >= t4.a)) from t2)` from `test`.`t4` +Note 1003 /* select#1 */ select `test`.`t4`.`b` AS `b`,<`test`.`t4`.`a`>((/* select#2 */ select avg(`test`.`t2`.`a` + (/* select#3 */ select min(`test`.`t3`.`a`) from `test`.`t3` where `test`.`t3`.`a` >= `test`.`t4`.`a`)) from `test`.`t2`)) AS `m` from `test`.`t4` select * from t3 where exists (select * from t2 where t2.b=t3.a); a 7 @@ -314,21 +321,34 @@ select b,max(a) as ma from t4 group by b having b >= (select max(t2.a) from t2 w b ma 7 12 create table t5 (a int); -select (select a from t1 where t1.a=t2.a union select a from t5 where t5.a=t2.a), a from t2; -(select a from t1 where t1.a=t2.a union select a from t5 where t5.a=t2.a) a +select +(select a from t1 where t1.a=t2.a union select a from t5 where t5.a=t2.a) as m, +a +from t2; +m a NULL 1 2 2 insert into t5 values (5); -select (select a from t1 where t1.a=t2.a union select a from t5 where t5.a=t2.a), a from t2; -(select a from t1 where t1.a=t2.a union select a from t5 where t5.a=t2.a) a +select +(select a from t1 where t1.a=t2.a union select a from t5 where t5.a=t2.a) as m, +a +from t2; +m a NULL 1 2 2 insert into t5 values (2); -select (select a from t1 where t1.a=t2.a union select a from t5 where t5.a=t2.a), a from t2; -(select a from t1 where t1.a=t2.a union select a from t5 where t5.a=t2.a) a +select +(select a from t1 where t1.a=t2.a union select a from t5 where t5.a=t2.a) as m, +a +from t2; +m a NULL 1 2 2 -explain extended select (select a from t1 where t1.a=t2.a union select a from t5 where t5.a=t2.a), a from t2; +explain extended +select +(select a from t1 where t1.a=t2.a union select a from t5 where t5.a=t2.a) as m, +a +from t2; id select_type table type possible_keys key key_len ref rows filtered Extra 1 PRIMARY t2 ALL NULL NULL NULL NULL 2 100.00 2 DEPENDENT SUBQUERY t1 system NULL NULL NULL NULL 1 100.00 @@ -337,7 +357,7 @@ NULL UNION RESULT ALL NULL NULL NULL NULL NULL NULL Warnings: Note 1276 Field or reference 'test.t2.a' of SELECT #2 was resolved in SELECT #1 Note 1276 Field or reference 'test.t2.a' of SELECT #3 was resolved in SELECT #1 -Note 1003 /* select#1 */ select <`test`.`t2`.`a`>((/* select#2 */ select 2 from dual where 2 = `test`.`t2`.`a` union /* select#3 */ select `test`.`t5`.`a` from `test`.`t5` where `test`.`t5`.`a` = `test`.`t2`.`a`)) AS `(select a from t1 where t1.a=t2.a union select a from t5 where t5.a=t2.a)`,`test`.`t2`.`a` AS `a` from `test`.`t2` +Note 1003 /* select#1 */ select <`test`.`t2`.`a`>((/* select#2 */ select 2 from dual where 2 = `test`.`t2`.`a` union /* select#3 */ select `test`.`t5`.`a` from `test`.`t5` where `test`.`t5`.`a` = `test`.`t2`.`a`)) AS `m`,`test`.`t2`.`a` AS `a` from `test`.`t2` select (select a from t1 where t1.a=t2.a union all select a from t5 where t5.a=t2.a), a from t2; ERROR 21000: Subquery returns more than 1 row create table t6 (patient_uq int, clinic_uq int, index i1 (clinic_uq)); @@ -493,8 +513,11 @@ SELECT * from t2 where topic = all (SELECT topic FROM t2 GROUP BY topic HAVING t mot topic date pseudo joce 40143 2002-10-22 joce joce 43506 2002-10-22 joce -SELECT *, topic = all (SELECT topic FROM t2 GROUP BY topic HAVING topic < 4100) from t2; -mot topic date pseudo topic = all (SELECT topic FROM t2 GROUP BY topic HAVING topic < 4100) +SELECT +*, +topic = all (SELECT topic FROM t2 GROUP BY topic HAVING topic < 4100) AS m +FROM t2; +mot topic date pseudo m joce 40143 2002-10-22 joce 1 joce 43506 2002-10-22 joce 1 SELECT * from t2 where topic = all (SELECT SUM(topic) FROM t2); @@ -512,8 +535,11 @@ joce 40143 2002-10-22 joce SELECT * from t2 where topic = all (SELECT topic FROM t2 GROUP BY topic HAVING topic < 41000); mot topic date pseudo joce 40143 2002-10-22 joce -SELECT *, topic = all (SELECT topic FROM t2 GROUP BY topic HAVING topic < 41000) from t2; -mot topic date pseudo topic = all (SELECT topic FROM t2 GROUP BY topic HAVING topic < 41000) +SELECT +*, +topic = all (SELECT topic FROM t2 GROUP BY topic HAVING topic < 41000) AS m +FROM t2; +mot topic date pseudo m joce 40143 2002-10-22 joce 1 joce 43506 2002-10-22 joce 0 drop table t1,t2; @@ -888,6 +914,25 @@ NULL select 1.5 > ANY (SELECT * from t1); 1.5 > ANY (SELECT * from t1) NULL +update t1 set a=NULL where a=2.5; +select 1.5 IN (SELECT * from t1); +1.5 IN (SELECT * from t1) +1 +select 3.5 IN (SELECT * from t1); +3.5 IN (SELECT * from t1) +1 +select 10.5 IN (SELECT * from t1); +10.5 IN (SELECT * from t1) +NULL +select 1.5 > ALL (SELECT * from t1); +1.5 > ALL (SELECT * from t1) +0 +select 10.5 > ALL (SELECT * from t1); +10.5 > ALL (SELECT * from t1) +NULL +select 1.5 > ANY (SELECT * from t1); +1.5 > ANY (SELECT * from t1) +NULL select 10.5 > ANY (SELECT * from t1); 10.5 > ANY (SELECT * from t1) 1 @@ -898,6 +943,20 @@ Warnings: Note 1276 Field or reference 'test.t1.a' of SELECT #2 was resolved in SELECT #1 Note 1249 Select 2 was reduced during optimization Note 1003 select `test`.`t1`.`a` + 1 AS `(select a+1)` from `test`.`t1` +explain extended select (select a+1) from t1; +id select_type table type possible_keys key key_len ref rows filtered Extra +1 SIMPLE t1 ALL NULL NULL NULL NULL 3 100.00 +Warnings: +Note 1276 Field or reference 'test.t1.a' of SELECT #2 was resolved in SELECT #1 +Note 1249 Select 2 was reduced during optimization +Note 1003 select `test`.`t1`.`a` + 1 AS `(select a+1)` from `test`.`t1` +explain extended select (select a+1) from t1; +id select_type table type possible_keys key key_len ref rows filtered Extra +1 SIMPLE t1 ALL NULL NULL NULL NULL 3 100.00 +Warnings: +Note 1276 Field or reference 'test.t1.a' of SELECT #2 was resolved in SELECT #1 +Note 1249 Select 2 was reduced during optimization +Note 1003 select `test`.`t1`.`a` + 1 AS `(select a+1)` from `test`.`t1` select (select a+1) from t1; (select a+1) 2.5 @@ -1539,8 +1598,8 @@ create table t3 (a int, b int); insert into t1 values (0,100),(1,2), (1,3), (2,2), (2,7), (2,-1), (3,10); insert into t2 values (0,0), (1,1), (2,1), (3,1), (4,1); insert into t3 values (3,3), (2,2), (1,1); -select a,(select count(distinct t1.b) as sum from t1,t2 where t1.a=t2.a and t2.b > 0 and t1.a <= t3.b group by t1.a order by sum limit 1) from t3; -a (select count(distinct t1.b) as sum from t1,t2 where t1.a=t2.a and t2.b > 0 and t1.a <= t3.b group by t1.a order by sum limit 1) +select a,(select count(distinct t1.b) as sum from t1,t2 where t1.a=t2.a and t2.b > 0 and t1.a <= t3.b group by t1.a order by sum limit 1) as m from t3; +a m 3 1 2 2 1 2 @@ -1735,8 +1794,8 @@ CREATE TABLE `t3` (`taskgenid` mediumint(9) NOT NULL auto_increment,`dbid` int(1 INSERT INTO `t3` (`taskgenid`, `dbid`, `taskid`, `mon`, `tues`,`wed`, `thur`, `fri`, `sat`, `sun`, `how_often`, `userid`, `active`) VALUES (1,-1, 1, 1, 1, 1, 1, 1, 0, 0, 1, 0, 1); CREATE TABLE `t4` (`task_id` smallint(6) NOT NULL default '0',`description` varchar(200) NOT NULL default '') ENGINE=MyISAM CHARSET=latin1; INSERT INTO `t4` (`task_id`, `description`) VALUES (1, 'Daily Check List'),(2, 'Weekly Status'); -select dbid, name, (date_format(now() , '%Y-%m-%d') - INTERVAL how_often DAY) >= ifnull((SELECT date_format(max(create_date),'%Y-%m-%d') FROM t1 WHERE dbid = b.db_id AND taskid = a.taskgenid), '1950-01-01') from t3 a, t2 b, t4 WHERE dbid = - 1 AND primary_uid = '1' AND t4.task_id = taskid; -dbid name (date_format(now() , '%Y-%m-%d') - INTERVAL how_often DAY) >= ifnull((SELECT date_format(max(create_date),'%Y-%m-%d') FROM t1 WHERE dbid = b.db_id AND taskid = a.taskgenid), '1950-01-01') +select dbid, name, (date_format(now() , '%Y-%m-%d') - INTERVAL how_often DAY) >= ifnull((SELECT date_format(max(create_date),'%Y-%m-%d') as m FROM t1 WHERE dbid = b.db_id AND taskid = a.taskgenid), '1950-01-01') as m from t3 a, t2 b, t4 WHERE dbid = - 1 AND primary_uid = '1' AND t4.task_id = taskid; +dbid name m -1 Valid 1 -1 Valid 2 1 -1 Should Not Return 0 @@ -3787,9 +3846,10 @@ SELECT (SELECT COUNT(DISTINCT t1.b) from t2) FROM t1 GROUP BY t1.a; 2 1 1 -SELECT (SELECT COUNT(DISTINCT t1.b) from t2 union select 1 from t2 where 12 < 3) +SELECT +(SELECT COUNT(DISTINCT t1.b) from t2 union select 1 from t2 where 12 < 3) AS m FROM t1 GROUP BY t1.a; -(SELECT COUNT(DISTINCT t1.b) from t2 union select 1 from t2 where 12 < 3) +m 2 1 1 @@ -3799,9 +3859,9 @@ COUNT(DISTINCT t1.b) (SELECT COUNT(DISTINCT t1.b)) 1 1 1 1 SELECT COUNT(DISTINCT t1.b), -(SELECT COUNT(DISTINCT t1.b) union select 1 from DUAL where 12 < 3) +(SELECT COUNT(DISTINCT t1.b) union select 1 from DUAL where 12 < 3) AS m FROM t1 GROUP BY t1.a; -COUNT(DISTINCT t1.b) (SELECT COUNT(DISTINCT t1.b) union select 1 from DUAL where 12 < 3) +COUNT(DISTINCT t1.b) m 2 2 1 1 1 1 @@ -3825,16 +3885,10 @@ SELECT ( SELECT COUNT(DISTINCT t1.b) ) ) -FROM t1 GROUP BY t1.a LIMIT 1) +FROM t1 GROUP BY t1.a LIMIT 1) AS m FROM t1 t2 GROUP BY t2.a; -( -SELECT ( -SELECT ( -SELECT COUNT(DISTINCT t1.b) -) -) -FROM t1 GROUP BY t1.a LIMIT 1) +m 2 2 2 @@ -6420,11 +6474,10 @@ CREATE TABLE t3 (a int, b int); INSERT INTO t3 VALUES (10,7), (0,7); SELECT SUM(DISTINCT b), (SELECT t2.a FROM t1 JOIN t2 ON t2.c != 0 -WHERE t.a != 0 AND t2.a != 0) +WHERE t.a != 0 AND t2.a != 0) AS m FROM (SELECT * FROM t3) AS t GROUP BY 2; -SUM(DISTINCT b) (SELECT t2.a FROM t1 JOIN t2 ON t2.c != 0 -WHERE t.a != 0 AND t2.a != 0) +SUM(DISTINCT b) m 7 NULL SELECT SUM(DISTINCT b), (SELECT t2.a FROM t1,t2 WHERE t.a != 0 or 1=2 LIMIT 1) @@ -6557,66 +6610,93 @@ CREATE TABLE t3 (f3a int default 1, f3b int default 2); INSERT INTO t3 VALUES (1,1),(2,2); set @old_optimizer_switch = @@session.optimizer_switch; set @@optimizer_switch='materialization=on,partial_match_rowid_merge=on,partial_match_table_scan=off,subquery_cache=off,semijoin=off'; -SELECT (SELECT f3a FROM t3 where f3a > 3) NOT IN (SELECT f1a FROM t1) FROM t2; -(SELECT f3a FROM t3 where f3a > 3) NOT IN (SELECT f1a FROM t1) +SELECT +(SELECT f3a FROM t3 where f3a > 3) NOT IN (SELECT f1a FROM t1) AS m +FROM t2; +m NULL NULL -SELECT (SELECT f3a,f3a FROM t3 where f3a > 3) NOT IN (SELECT f1a,f1a FROM t1) FROM t2; -(SELECT f3a,f3a FROM t3 where f3a > 3) NOT IN (SELECT f1a,f1a FROM t1) +SELECT +(SELECT f3a,f3a FROM t3 where f3a > 3) NOT IN (SELECT f1a,f1a FROM t1) AS m +FROM t2; +m NULL NULL -SELECT (SELECT f3a, f3b FROM t3 where f3a > 3) NOT IN (SELECT f1a, f1b FROM t1) FROM t2; -(SELECT f3a, f3b FROM t3 where f3a > 3) NOT IN (SELECT f1a, f1b FROM t1) +SELECT +(SELECT f3a, f3b FROM t3 where f3a > 3) NOT IN (SELECT f1a, f1b FROM t1) AS m +FROM t2; +m NULL NULL -SELECT (SELECT f3a, f3b FROM t3 where f3a > 3) NOT IN (SELECT f1a, f1b FROM t1); -(SELECT f3a, f3b FROM t3 where f3a > 3) NOT IN (SELECT f1a, f1b FROM t1) +SELECT +(SELECT f3a, f3b FROM t3 where f3a > 3) NOT IN (SELECT f1a, f1b FROM t1) AS m; +m NULL -SELECT (SELECT f3a FROM t3 where f3a > 3) IN (SELECT f1a FROM t1) FROM t2; -(SELECT f3a FROM t3 where f3a > 3) IN (SELECT f1a FROM t1) +SELECT +(SELECT f3a FROM t3 where f3a > 3) IN (SELECT f1a FROM t1) AS m +FROM t2; +m NULL NULL -SELECT (SELECT f3a,f3a FROM t3 where f3a > 3) IN (SELECT f1a,f1a FROM t1) FROM t2; -(SELECT f3a,f3a FROM t3 where f3a > 3) IN (SELECT f1a,f1a FROM t1) +SELECT +(SELECT f3a,f3a FROM t3 where f3a > 3) IN (SELECT f1a,f1a FROM t1) AS m +FROM t2; +m NULL NULL -SELECT (SELECT f3a, f3b FROM t3 where f3a > 3) IN (SELECT f1a, f1b FROM t1) FROM t2; -(SELECT f3a, f3b FROM t3 where f3a > 3) IN (SELECT f1a, f1b FROM t1) +SELECT +(SELECT f3a, f3b FROM t3 where f3a > 3) IN (SELECT f1a, f1b FROM t1) AS m +FROM t2; +m NULL NULL -SELECT (SELECT f3a, f3b FROM t3 where f3a > 3) IN (SELECT f1a, f1b FROM t1); -(SELECT f3a, f3b FROM t3 where f3a > 3) IN (SELECT f1a, f1b FROM t1) +SELECT +(SELECT f3a, f3b FROM t3 where f3a > 3) IN (SELECT f1a, f1b FROM t1) AS m; +m NULL set @@session.optimizer_switch=@old_optimizer_switch; -SELECT (SELECT f3a FROM t3 where f3a > 3) NOT IN (SELECT f1a FROM t1) FROM t2; -(SELECT f3a FROM t3 where f3a > 3) NOT IN (SELECT f1a FROM t1) +SELECT +(SELECT f3a FROM t3 where f3a > 3) NOT IN (SELECT f1a FROM t1) AS m +FROM t2; +m NULL NULL -SELECT (SELECT f3a,f3a FROM t3 where f3a > 3) NOT IN (SELECT f1a,f1a FROM t1) FROM t2; -(SELECT f3a,f3a FROM t3 where f3a > 3) NOT IN (SELECT f1a,f1a FROM t1) +SELECT +(SELECT f3a,f3a FROM t3 where f3a > 3) NOT IN (SELECT f1a,f1a FROM t1) AS m +FROM t2; +m NULL NULL -SELECT (SELECT f3a, f3b FROM t3 where f3a > 3) NOT IN (SELECT f1a, f1b FROM t1) FROM t2; -(SELECT f3a, f3b FROM t3 where f3a > 3) NOT IN (SELECT f1a, f1b FROM t1) +SELECT +(SELECT f3a, f3b FROM t3 where f3a > 3) NOT IN (SELECT f1a, f1b FROM t1) AS m +FROM t2; +m NULL NULL -SELECT (SELECT f3a, f3b FROM t3 where f3a > 3) NOT IN (SELECT f1a, f1b FROM t1); -(SELECT f3a, f3b FROM t3 where f3a > 3) NOT IN (SELECT f1a, f1b FROM t1) +SELECT +(SELECT f3a, f3b FROM t3 where f3a > 3) NOT IN (SELECT f1a, f1b FROM t1) AS m; +m NULL -SELECT (SELECT f3a FROM t3 where f3a > 3) IN (SELECT f1a FROM t1) FROM t2; +SELECT +(SELECT f3a FROM t3 where f3a > 3) IN (SELECT f1a FROM t1) FROM t2 AS m; (SELECT f3a FROM t3 where f3a > 3) IN (SELECT f1a FROM t1) NULL NULL -SELECT (SELECT f3a,f3a FROM t3 where f3a > 3) IN (SELECT f1a,f1a FROM t1) FROM t2; -(SELECT f3a,f3a FROM t3 where f3a > 3) IN (SELECT f1a,f1a FROM t1) +SELECT +(SELECT f3a,f3a FROM t3 where f3a > 3) IN (SELECT f1a,f1a FROM t1) AS m +FROM t2; +m NULL NULL -SELECT (SELECT f3a, f3b FROM t3 where f3a > 3) IN (SELECT f1a, f1b FROM t1) FROM t2; -(SELECT f3a, f3b FROM t3 where f3a > 3) IN (SELECT f1a, f1b FROM t1) +SELECT +(SELECT f3a, f3b FROM t3 where f3a > 3) IN (SELECT f1a, f1b FROM t1) AS m +FROM t2; +m NULL NULL -SELECT (SELECT f3a, f3b FROM t3 where f3a > 3) IN (SELECT f1a, f1b FROM t1); -(SELECT f3a, f3b FROM t3 where f3a > 3) IN (SELECT f1a, f1b FROM t1) +SELECT +(SELECT f3a, f3b FROM t3 where f3a > 3) IN (SELECT f1a, f1b FROM t1) AS m; +m NULL select (null, null) = (null, null); (null, null) = (null, null) @@ -6662,8 +6742,10 @@ INSERT INTO t2 VALUES (1); CREATE TABLE t3 ( c INT ); INSERT INTO t3 VALUES (4),(5); SET optimizer_switch='subquery_cache=off'; -SELECT ( SELECT b FROM t2 WHERE b = a OR EXISTS ( SELECT c FROM t3 WHERE c = b ) ) FROM t1; -( SELECT b FROM t2 WHERE b = a OR EXISTS ( SELECT c FROM t3 WHERE c = b ) ) +SELECT +( SELECT b FROM t2 WHERE b = a OR EXISTS ( SELECT c FROM t3 WHERE c = b ) ) AS m +FROM t1; +m 1 NULL SELECT ( SELECT b FROM t2 WHERE b = a OR b * 0) FROM t1; @@ -6879,7 +6961,9 @@ CREATE TABLE t3 (c INT); INSERT INTO t3 VALUES (8),(3); set @@expensive_subquery_limit= 0; EXPLAIN -SELECT (SELECT MIN(b) FROM t1, t2 WHERE b = a AND (b = alias1.b OR EXISTS (SELECT * FROM t3))) +SELECT +(SELECT MIN(b) FROM t1, t2 +WHERE b = a AND (b = alias1.b OR EXISTS (SELECT * FROM t3))) AS m FROM t2 alias1, t1 alias2, t1 alias3; id select_type table type possible_keys key key_len ref rows Extra 1 PRIMARY alias1 ALL NULL NULL NULL NULL 2 @@ -6889,9 +6973,11 @@ id select_type table type possible_keys key key_len ref rows Extra 2 DEPENDENT SUBQUERY t2 ALL NULL NULL NULL NULL 2 Using where; Using join buffer (flat, BNL join) 3 SUBQUERY t3 ALL NULL NULL NULL NULL 2 flush status; -SELECT (SELECT MIN(b) FROM t1, t2 WHERE b = a AND (b = alias1.b OR EXISTS (SELECT * FROM t3))) +SELECT +(SELECT MIN(b) FROM t1, t2 +WHERE b = a AND (b = alias1.b OR EXISTS (SELECT * FROM t3))) AS m FROM t2 alias1, t1 alias2, t1 alias3; -(SELECT MIN(b) FROM t1, t2 WHERE b = a AND (b = alias1.b OR EXISTS (SELECT * FROM t3))) +m NULL NULL NULL @@ -6917,7 +7003,9 @@ Handler_read_rnd_deleted 0 Handler_read_rnd_next 22 set @@expensive_subquery_limit= default; EXPLAIN -SELECT (SELECT MIN(b) FROM t1, t2 WHERE b = a AND (b = alias1.b OR EXISTS (SELECT * FROM t3))) +SELECT +(SELECT MIN(b) FROM t1, t2 +WHERE b = a AND (b = alias1.b OR EXISTS (SELECT * FROM t3))) AS m FROM t2 alias1, t1 alias2, t1 alias3; id select_type table type possible_keys key key_len ref rows Extra 1 PRIMARY alias1 ALL NULL NULL NULL NULL 2 @@ -6927,9 +7015,11 @@ id select_type table type possible_keys key key_len ref rows Extra 2 SUBQUERY t2 ALL NULL NULL NULL NULL 2 Using where; Using join buffer (flat, BNL join) 3 SUBQUERY t3 ALL NULL NULL NULL NULL 2 flush status; -SELECT (SELECT MIN(b) FROM t1, t2 WHERE b = a AND (b = alias1.b OR EXISTS (SELECT * FROM t3))) +SELECT +(SELECT MIN(b) FROM t1, t2 +WHERE b = a AND (b = alias1.b OR EXISTS (SELECT * FROM t3))) AS m FROM t2 alias1, t1 alias2, t1 alias3; -(SELECT MIN(b) FROM t1, t2 WHERE b = a AND (b = alias1.b OR EXISTS (SELECT * FROM t3))) +m NULL NULL NULL diff --git a/mysql-test/main/subselect_no_opts.result b/mysql-test/main/subselect_no_opts.result index 91e82ca838fab..72b148b59d4db 100644 --- a/mysql-test/main/subselect_no_opts.result +++ b/mysql-test/main/subselect_no_opts.result @@ -121,27 +121,27 @@ ROW(1,2,3) > (SELECT 1,2,1) SELECT ROW(1,2,3) = (SELECT 1,2,NULL); ROW(1,2,3) = (SELECT 1,2,NULL) NULL -SELECT (SELECT 1.5,2,'a') = ROW(1.5,2,'a'); -(SELECT 1.5,2,'a') = ROW(1.5,2,'a') +SELECT (SELECT 1.5,2,'a') = ROW(1.5,2,'a') AS m; +m 1 -SELECT (SELECT 1.5,2,'a') = ROW(1.5,2,'b'); -(SELECT 1.5,2,'a') = ROW(1.5,2,'b') +SELECT (SELECT 1.5,2,'a') = ROW(1.5,2,'b') AS m; +m 0 -SELECT (SELECT 1.5,2,'a') = ROW('1.5b',2,'b'); -(SELECT 1.5,2,'a') = ROW('1.5b',2,'b') +SELECT (SELECT 1.5,2,'a') = ROW('1.5b',2,'b') AS m; +m 0 Warnings: Warning 1292 Truncated incorrect DOUBLE value: '1.5b' -SELECT (SELECT 'b',2,'a') = ROW(1.5,2,'a'); -(SELECT 'b',2,'a') = ROW(1.5,2,'a') +SELECT (SELECT 'b',2,'a') = ROW(1.5,2,'a') AS m; +m 0 Warnings: Warning 1292 Truncated incorrect DOUBLE value: 'b' -SELECT (SELECT 1.5,2,'a') = ROW(1.5,'2','a'); -(SELECT 1.5,2,'a') = ROW(1.5,'2','a') +SELECT (SELECT 1.5,2,'a') = ROW(1.5,'2','a') AS m; +m 1 -SELECT (SELECT 1.5,'c','a') = ROW(1.5,2,'a'); -(SELECT 1.5,'c','a') = ROW(1.5,2,'a') +SELECT (SELECT 1.5,'c','a') = ROW(1.5,2,'a') AS m; +m 0 Warnings: Warning 1292 Truncated incorrect DECIMAL value: 'c' @@ -231,19 +231,26 @@ a 2 select * from t1 where t1.a=(select t2.a from t2 where t2.b=(select max(a) from t3 where t3.a < t1.a) order by 1 desc limit 1); a -select b,(select avg(t2.a+(select min(t3.a) from t3 where t3.a >= t4.a)) from t2) from t4; -b (select avg(t2.a+(select min(t3.a) from t3 where t3.a >= t4.a)) from t2) +select +b, +(select avg(t2.a+(select min(t3.a) from t3 where t3.a >= t4.a)) from t2) as m +from t4; +b m 8 7.5000 8 4.5000 9 7.5000 -explain extended select b,(select avg(t2.a+(select min(t3.a) from t3 where t3.a >= t4.a)) from t2) from t4; +explain extended +select +b, +(select avg(t2.a+(select min(t3.a) from t3 where t3.a >= t4.a)) from t2) as m +from t4; id select_type table type possible_keys key key_len ref rows filtered Extra 1 PRIMARY t4 ALL NULL NULL NULL NULL 3 100.00 2 DEPENDENT SUBQUERY t2 ALL NULL NULL NULL NULL 2 100.00 3 DEPENDENT SUBQUERY t3 ALL NULL NULL NULL NULL 3 100.00 Using where Warnings: Note 1276 Field or reference 'test.t4.a' of SELECT #3 was resolved in SELECT #1 -Note 1003 /* select#1 */ select `test`.`t4`.`b` AS `b`,(/* select#2 */ select avg(`test`.`t2`.`a` + (/* select#3 */ select min(`test`.`t3`.`a`) from `test`.`t3` where `test`.`t3`.`a` >= `test`.`t4`.`a`)) from `test`.`t2`) AS `(select avg(t2.a+(select min(t3.a) from t3 where t3.a >= t4.a)) from t2)` from `test`.`t4` +Note 1003 /* select#1 */ select `test`.`t4`.`b` AS `b`,(/* select#2 */ select avg(`test`.`t2`.`a` + (/* select#3 */ select min(`test`.`t3`.`a`) from `test`.`t3` where `test`.`t3`.`a` >= `test`.`t4`.`a`)) from `test`.`t2`) AS `m` from `test`.`t4` select * from t3 where exists (select * from t2 where t2.b=t3.a); a 7 @@ -310,21 +317,34 @@ select b,max(a) as ma from t4 group by b having b >= (select max(t2.a) from t2 w b ma 7 12 create table t5 (a int); -select (select a from t1 where t1.a=t2.a union select a from t5 where t5.a=t2.a), a from t2; -(select a from t1 where t1.a=t2.a union select a from t5 where t5.a=t2.a) a +select +(select a from t1 where t1.a=t2.a union select a from t5 where t5.a=t2.a) as m, +a +from t2; +m a NULL 1 2 2 insert into t5 values (5); -select (select a from t1 where t1.a=t2.a union select a from t5 where t5.a=t2.a), a from t2; -(select a from t1 where t1.a=t2.a union select a from t5 where t5.a=t2.a) a +select +(select a from t1 where t1.a=t2.a union select a from t5 where t5.a=t2.a) as m, +a +from t2; +m a NULL 1 2 2 insert into t5 values (2); -select (select a from t1 where t1.a=t2.a union select a from t5 where t5.a=t2.a), a from t2; -(select a from t1 where t1.a=t2.a union select a from t5 where t5.a=t2.a) a +select +(select a from t1 where t1.a=t2.a union select a from t5 where t5.a=t2.a) as m, +a +from t2; +m a NULL 1 2 2 -explain extended select (select a from t1 where t1.a=t2.a union select a from t5 where t5.a=t2.a), a from t2; +explain extended +select +(select a from t1 where t1.a=t2.a union select a from t5 where t5.a=t2.a) as m, +a +from t2; id select_type table type possible_keys key key_len ref rows filtered Extra 1 PRIMARY t2 ALL NULL NULL NULL NULL 2 100.00 2 DEPENDENT SUBQUERY t1 system NULL NULL NULL NULL 1 100.00 @@ -333,7 +353,7 @@ NULL UNION RESULT ALL NULL NULL NULL NULL NULL NULL Warnings: Note 1276 Field or reference 'test.t2.a' of SELECT #2 was resolved in SELECT #1 Note 1276 Field or reference 'test.t2.a' of SELECT #3 was resolved in SELECT #1 -Note 1003 /* select#1 */ select (/* select#2 */ select 2 from dual where 2 = `test`.`t2`.`a` union /* select#3 */ select `test`.`t5`.`a` from `test`.`t5` where `test`.`t5`.`a` = `test`.`t2`.`a`) AS `(select a from t1 where t1.a=t2.a union select a from t5 where t5.a=t2.a)`,`test`.`t2`.`a` AS `a` from `test`.`t2` +Note 1003 /* select#1 */ select (/* select#2 */ select 2 from dual where 2 = `test`.`t2`.`a` union /* select#3 */ select `test`.`t5`.`a` from `test`.`t5` where `test`.`t5`.`a` = `test`.`t2`.`a`) AS `m`,`test`.`t2`.`a` AS `a` from `test`.`t2` select (select a from t1 where t1.a=t2.a union all select a from t5 where t5.a=t2.a), a from t2; ERROR 21000: Subquery returns more than 1 row create table t6 (patient_uq int, clinic_uq int, index i1 (clinic_uq)); @@ -489,8 +509,11 @@ SELECT * from t2 where topic = all (SELECT topic FROM t2 GROUP BY topic HAVING t mot topic date pseudo joce 40143 2002-10-22 joce joce 43506 2002-10-22 joce -SELECT *, topic = all (SELECT topic FROM t2 GROUP BY topic HAVING topic < 4100) from t2; -mot topic date pseudo topic = all (SELECT topic FROM t2 GROUP BY topic HAVING topic < 4100) +SELECT +*, +topic = all (SELECT topic FROM t2 GROUP BY topic HAVING topic < 4100) AS m +FROM t2; +mot topic date pseudo m joce 40143 2002-10-22 joce 1 joce 43506 2002-10-22 joce 1 SELECT * from t2 where topic = all (SELECT SUM(topic) FROM t2); @@ -508,8 +531,11 @@ joce 40143 2002-10-22 joce SELECT * from t2 where topic = all (SELECT topic FROM t2 GROUP BY topic HAVING topic < 41000); mot topic date pseudo joce 40143 2002-10-22 joce -SELECT *, topic = all (SELECT topic FROM t2 GROUP BY topic HAVING topic < 41000) from t2; -mot topic date pseudo topic = all (SELECT topic FROM t2 GROUP BY topic HAVING topic < 41000) +SELECT +*, +topic = all (SELECT topic FROM t2 GROUP BY topic HAVING topic < 41000) AS m +FROM t2; +mot topic date pseudo m joce 40143 2002-10-22 joce 1 joce 43506 2002-10-22 joce 0 drop table t1,t2; @@ -884,6 +910,25 @@ NULL select 1.5 > ANY (SELECT * from t1); 1.5 > ANY (SELECT * from t1) NULL +update t1 set a=NULL where a=2.5; +select 1.5 IN (SELECT * from t1); +1.5 IN (SELECT * from t1) +1 +select 3.5 IN (SELECT * from t1); +3.5 IN (SELECT * from t1) +1 +select 10.5 IN (SELECT * from t1); +10.5 IN (SELECT * from t1) +NULL +select 1.5 > ALL (SELECT * from t1); +1.5 > ALL (SELECT * from t1) +0 +select 10.5 > ALL (SELECT * from t1); +10.5 > ALL (SELECT * from t1) +NULL +select 1.5 > ANY (SELECT * from t1); +1.5 > ANY (SELECT * from t1) +NULL select 10.5 > ANY (SELECT * from t1); 10.5 > ANY (SELECT * from t1) 1 @@ -894,6 +939,20 @@ Warnings: Note 1276 Field or reference 'test.t1.a' of SELECT #2 was resolved in SELECT #1 Note 1249 Select 2 was reduced during optimization Note 1003 select `test`.`t1`.`a` + 1 AS `(select a+1)` from `test`.`t1` +explain extended select (select a+1) from t1; +id select_type table type possible_keys key key_len ref rows filtered Extra +1 SIMPLE t1 ALL NULL NULL NULL NULL 3 100.00 +Warnings: +Note 1276 Field or reference 'test.t1.a' of SELECT #2 was resolved in SELECT #1 +Note 1249 Select 2 was reduced during optimization +Note 1003 select `test`.`t1`.`a` + 1 AS `(select a+1)` from `test`.`t1` +explain extended select (select a+1) from t1; +id select_type table type possible_keys key key_len ref rows filtered Extra +1 SIMPLE t1 ALL NULL NULL NULL NULL 3 100.00 +Warnings: +Note 1276 Field or reference 'test.t1.a' of SELECT #2 was resolved in SELECT #1 +Note 1249 Select 2 was reduced during optimization +Note 1003 select `test`.`t1`.`a` + 1 AS `(select a+1)` from `test`.`t1` select (select a+1) from t1; (select a+1) 2.5 @@ -1535,8 +1594,8 @@ create table t3 (a int, b int); insert into t1 values (0,100),(1,2), (1,3), (2,2), (2,7), (2,-1), (3,10); insert into t2 values (0,0), (1,1), (2,1), (3,1), (4,1); insert into t3 values (3,3), (2,2), (1,1); -select a,(select count(distinct t1.b) as sum from t1,t2 where t1.a=t2.a and t2.b > 0 and t1.a <= t3.b group by t1.a order by sum limit 1) from t3; -a (select count(distinct t1.b) as sum from t1,t2 where t1.a=t2.a and t2.b > 0 and t1.a <= t3.b group by t1.a order by sum limit 1) +select a,(select count(distinct t1.b) as sum from t1,t2 where t1.a=t2.a and t2.b > 0 and t1.a <= t3.b group by t1.a order by sum limit 1) as m from t3; +a m 3 1 2 2 1 2 @@ -1731,8 +1790,8 @@ CREATE TABLE `t3` (`taskgenid` mediumint(9) NOT NULL auto_increment,`dbid` int(1 INSERT INTO `t3` (`taskgenid`, `dbid`, `taskid`, `mon`, `tues`,`wed`, `thur`, `fri`, `sat`, `sun`, `how_often`, `userid`, `active`) VALUES (1,-1, 1, 1, 1, 1, 1, 1, 0, 0, 1, 0, 1); CREATE TABLE `t4` (`task_id` smallint(6) NOT NULL default '0',`description` varchar(200) NOT NULL default '') ENGINE=MyISAM CHARSET=latin1; INSERT INTO `t4` (`task_id`, `description`) VALUES (1, 'Daily Check List'),(2, 'Weekly Status'); -select dbid, name, (date_format(now() , '%Y-%m-%d') - INTERVAL how_often DAY) >= ifnull((SELECT date_format(max(create_date),'%Y-%m-%d') FROM t1 WHERE dbid = b.db_id AND taskid = a.taskgenid), '1950-01-01') from t3 a, t2 b, t4 WHERE dbid = - 1 AND primary_uid = '1' AND t4.task_id = taskid; -dbid name (date_format(now() , '%Y-%m-%d') - INTERVAL how_often DAY) >= ifnull((SELECT date_format(max(create_date),'%Y-%m-%d') FROM t1 WHERE dbid = b.db_id AND taskid = a.taskgenid), '1950-01-01') +select dbid, name, (date_format(now() , '%Y-%m-%d') - INTERVAL how_often DAY) >= ifnull((SELECT date_format(max(create_date),'%Y-%m-%d') as m FROM t1 WHERE dbid = b.db_id AND taskid = a.taskgenid), '1950-01-01') as m from t3 a, t2 b, t4 WHERE dbid = - 1 AND primary_uid = '1' AND t4.task_id = taskid; +dbid name m -1 Valid 1 -1 Valid 2 1 -1 Should Not Return 0 @@ -3783,9 +3842,10 @@ SELECT (SELECT COUNT(DISTINCT t1.b) from t2) FROM t1 GROUP BY t1.a; 2 1 1 -SELECT (SELECT COUNT(DISTINCT t1.b) from t2 union select 1 from t2 where 12 < 3) +SELECT +(SELECT COUNT(DISTINCT t1.b) from t2 union select 1 from t2 where 12 < 3) AS m FROM t1 GROUP BY t1.a; -(SELECT COUNT(DISTINCT t1.b) from t2 union select 1 from t2 where 12 < 3) +m 2 1 1 @@ -3795,9 +3855,9 @@ COUNT(DISTINCT t1.b) (SELECT COUNT(DISTINCT t1.b)) 1 1 1 1 SELECT COUNT(DISTINCT t1.b), -(SELECT COUNT(DISTINCT t1.b) union select 1 from DUAL where 12 < 3) +(SELECT COUNT(DISTINCT t1.b) union select 1 from DUAL where 12 < 3) AS m FROM t1 GROUP BY t1.a; -COUNT(DISTINCT t1.b) (SELECT COUNT(DISTINCT t1.b) union select 1 from DUAL where 12 < 3) +COUNT(DISTINCT t1.b) m 2 2 1 1 1 1 @@ -3821,16 +3881,10 @@ SELECT ( SELECT COUNT(DISTINCT t1.b) ) ) -FROM t1 GROUP BY t1.a LIMIT 1) +FROM t1 GROUP BY t1.a LIMIT 1) AS m FROM t1 t2 GROUP BY t2.a; -( -SELECT ( -SELECT ( -SELECT COUNT(DISTINCT t1.b) -) -) -FROM t1 GROUP BY t1.a LIMIT 1) +m 2 2 2 @@ -6416,11 +6470,10 @@ CREATE TABLE t3 (a int, b int); INSERT INTO t3 VALUES (10,7), (0,7); SELECT SUM(DISTINCT b), (SELECT t2.a FROM t1 JOIN t2 ON t2.c != 0 -WHERE t.a != 0 AND t2.a != 0) +WHERE t.a != 0 AND t2.a != 0) AS m FROM (SELECT * FROM t3) AS t GROUP BY 2; -SUM(DISTINCT b) (SELECT t2.a FROM t1 JOIN t2 ON t2.c != 0 -WHERE t.a != 0 AND t2.a != 0) +SUM(DISTINCT b) m 7 NULL SELECT SUM(DISTINCT b), (SELECT t2.a FROM t1,t2 WHERE t.a != 0 or 1=2 LIMIT 1) @@ -6553,66 +6606,93 @@ CREATE TABLE t3 (f3a int default 1, f3b int default 2); INSERT INTO t3 VALUES (1,1),(2,2); set @old_optimizer_switch = @@session.optimizer_switch; set @@optimizer_switch='materialization=on,partial_match_rowid_merge=on,partial_match_table_scan=off,subquery_cache=off,semijoin=off'; -SELECT (SELECT f3a FROM t3 where f3a > 3) NOT IN (SELECT f1a FROM t1) FROM t2; -(SELECT f3a FROM t3 where f3a > 3) NOT IN (SELECT f1a FROM t1) +SELECT +(SELECT f3a FROM t3 where f3a > 3) NOT IN (SELECT f1a FROM t1) AS m +FROM t2; +m NULL NULL -SELECT (SELECT f3a,f3a FROM t3 where f3a > 3) NOT IN (SELECT f1a,f1a FROM t1) FROM t2; -(SELECT f3a,f3a FROM t3 where f3a > 3) NOT IN (SELECT f1a,f1a FROM t1) +SELECT +(SELECT f3a,f3a FROM t3 where f3a > 3) NOT IN (SELECT f1a,f1a FROM t1) AS m +FROM t2; +m NULL NULL -SELECT (SELECT f3a, f3b FROM t3 where f3a > 3) NOT IN (SELECT f1a, f1b FROM t1) FROM t2; -(SELECT f3a, f3b FROM t3 where f3a > 3) NOT IN (SELECT f1a, f1b FROM t1) +SELECT +(SELECT f3a, f3b FROM t3 where f3a > 3) NOT IN (SELECT f1a, f1b FROM t1) AS m +FROM t2; +m NULL NULL -SELECT (SELECT f3a, f3b FROM t3 where f3a > 3) NOT IN (SELECT f1a, f1b FROM t1); -(SELECT f3a, f3b FROM t3 where f3a > 3) NOT IN (SELECT f1a, f1b FROM t1) +SELECT +(SELECT f3a, f3b FROM t3 where f3a > 3) NOT IN (SELECT f1a, f1b FROM t1) AS m; +m NULL -SELECT (SELECT f3a FROM t3 where f3a > 3) IN (SELECT f1a FROM t1) FROM t2; -(SELECT f3a FROM t3 where f3a > 3) IN (SELECT f1a FROM t1) +SELECT +(SELECT f3a FROM t3 where f3a > 3) IN (SELECT f1a FROM t1) AS m +FROM t2; +m NULL NULL -SELECT (SELECT f3a,f3a FROM t3 where f3a > 3) IN (SELECT f1a,f1a FROM t1) FROM t2; -(SELECT f3a,f3a FROM t3 where f3a > 3) IN (SELECT f1a,f1a FROM t1) +SELECT +(SELECT f3a,f3a FROM t3 where f3a > 3) IN (SELECT f1a,f1a FROM t1) AS m +FROM t2; +m NULL NULL -SELECT (SELECT f3a, f3b FROM t3 where f3a > 3) IN (SELECT f1a, f1b FROM t1) FROM t2; -(SELECT f3a, f3b FROM t3 where f3a > 3) IN (SELECT f1a, f1b FROM t1) +SELECT +(SELECT f3a, f3b FROM t3 where f3a > 3) IN (SELECT f1a, f1b FROM t1) AS m +FROM t2; +m NULL NULL -SELECT (SELECT f3a, f3b FROM t3 where f3a > 3) IN (SELECT f1a, f1b FROM t1); -(SELECT f3a, f3b FROM t3 where f3a > 3) IN (SELECT f1a, f1b FROM t1) +SELECT +(SELECT f3a, f3b FROM t3 where f3a > 3) IN (SELECT f1a, f1b FROM t1) AS m; +m NULL set @@session.optimizer_switch=@old_optimizer_switch; -SELECT (SELECT f3a FROM t3 where f3a > 3) NOT IN (SELECT f1a FROM t1) FROM t2; -(SELECT f3a FROM t3 where f3a > 3) NOT IN (SELECT f1a FROM t1) +SELECT +(SELECT f3a FROM t3 where f3a > 3) NOT IN (SELECT f1a FROM t1) AS m +FROM t2; +m NULL NULL -SELECT (SELECT f3a,f3a FROM t3 where f3a > 3) NOT IN (SELECT f1a,f1a FROM t1) FROM t2; -(SELECT f3a,f3a FROM t3 where f3a > 3) NOT IN (SELECT f1a,f1a FROM t1) +SELECT +(SELECT f3a,f3a FROM t3 where f3a > 3) NOT IN (SELECT f1a,f1a FROM t1) AS m +FROM t2; +m NULL NULL -SELECT (SELECT f3a, f3b FROM t3 where f3a > 3) NOT IN (SELECT f1a, f1b FROM t1) FROM t2; -(SELECT f3a, f3b FROM t3 where f3a > 3) NOT IN (SELECT f1a, f1b FROM t1) +SELECT +(SELECT f3a, f3b FROM t3 where f3a > 3) NOT IN (SELECT f1a, f1b FROM t1) AS m +FROM t2; +m NULL NULL -SELECT (SELECT f3a, f3b FROM t3 where f3a > 3) NOT IN (SELECT f1a, f1b FROM t1); -(SELECT f3a, f3b FROM t3 where f3a > 3) NOT IN (SELECT f1a, f1b FROM t1) +SELECT +(SELECT f3a, f3b FROM t3 where f3a > 3) NOT IN (SELECT f1a, f1b FROM t1) AS m; +m NULL -SELECT (SELECT f3a FROM t3 where f3a > 3) IN (SELECT f1a FROM t1) FROM t2; +SELECT +(SELECT f3a FROM t3 where f3a > 3) IN (SELECT f1a FROM t1) FROM t2 AS m; (SELECT f3a FROM t3 where f3a > 3) IN (SELECT f1a FROM t1) NULL NULL -SELECT (SELECT f3a,f3a FROM t3 where f3a > 3) IN (SELECT f1a,f1a FROM t1) FROM t2; -(SELECT f3a,f3a FROM t3 where f3a > 3) IN (SELECT f1a,f1a FROM t1) +SELECT +(SELECT f3a,f3a FROM t3 where f3a > 3) IN (SELECT f1a,f1a FROM t1) AS m +FROM t2; +m NULL NULL -SELECT (SELECT f3a, f3b FROM t3 where f3a > 3) IN (SELECT f1a, f1b FROM t1) FROM t2; -(SELECT f3a, f3b FROM t3 where f3a > 3) IN (SELECT f1a, f1b FROM t1) +SELECT +(SELECT f3a, f3b FROM t3 where f3a > 3) IN (SELECT f1a, f1b FROM t1) AS m +FROM t2; +m NULL NULL -SELECT (SELECT f3a, f3b FROM t3 where f3a > 3) IN (SELECT f1a, f1b FROM t1); -(SELECT f3a, f3b FROM t3 where f3a > 3) IN (SELECT f1a, f1b FROM t1) +SELECT +(SELECT f3a, f3b FROM t3 where f3a > 3) IN (SELECT f1a, f1b FROM t1) AS m; +m NULL select (null, null) = (null, null); (null, null) = (null, null) @@ -6658,8 +6738,10 @@ INSERT INTO t2 VALUES (1); CREATE TABLE t3 ( c INT ); INSERT INTO t3 VALUES (4),(5); SET optimizer_switch='subquery_cache=off'; -SELECT ( SELECT b FROM t2 WHERE b = a OR EXISTS ( SELECT c FROM t3 WHERE c = b ) ) FROM t1; -( SELECT b FROM t2 WHERE b = a OR EXISTS ( SELECT c FROM t3 WHERE c = b ) ) +SELECT +( SELECT b FROM t2 WHERE b = a OR EXISTS ( SELECT c FROM t3 WHERE c = b ) ) AS m +FROM t1; +m 1 NULL SELECT ( SELECT b FROM t2 WHERE b = a OR b * 0) FROM t1; @@ -6876,7 +6958,9 @@ CREATE TABLE t3 (c INT); INSERT INTO t3 VALUES (8),(3); set @@expensive_subquery_limit= 0; EXPLAIN -SELECT (SELECT MIN(b) FROM t1, t2 WHERE b = a AND (b = alias1.b OR EXISTS (SELECT * FROM t3))) +SELECT +(SELECT MIN(b) FROM t1, t2 +WHERE b = a AND (b = alias1.b OR EXISTS (SELECT * FROM t3))) AS m FROM t2 alias1, t1 alias2, t1 alias3; id select_type table type possible_keys key key_len ref rows Extra 1 PRIMARY alias1 ALL NULL NULL NULL NULL 2 @@ -6886,9 +6970,11 @@ id select_type table type possible_keys key key_len ref rows Extra 2 DEPENDENT SUBQUERY t2 ALL NULL NULL NULL NULL 2 Using where; Using join buffer (flat, BNL join) 3 SUBQUERY t3 ALL NULL NULL NULL NULL 2 flush status; -SELECT (SELECT MIN(b) FROM t1, t2 WHERE b = a AND (b = alias1.b OR EXISTS (SELECT * FROM t3))) +SELECT +(SELECT MIN(b) FROM t1, t2 +WHERE b = a AND (b = alias1.b OR EXISTS (SELECT * FROM t3))) AS m FROM t2 alias1, t1 alias2, t1 alias3; -(SELECT MIN(b) FROM t1, t2 WHERE b = a AND (b = alias1.b OR EXISTS (SELECT * FROM t3))) +m NULL NULL NULL @@ -6914,7 +7000,9 @@ Handler_read_rnd_deleted 0 Handler_read_rnd_next 22 set @@expensive_subquery_limit= default; EXPLAIN -SELECT (SELECT MIN(b) FROM t1, t2 WHERE b = a AND (b = alias1.b OR EXISTS (SELECT * FROM t3))) +SELECT +(SELECT MIN(b) FROM t1, t2 +WHERE b = a AND (b = alias1.b OR EXISTS (SELECT * FROM t3))) AS m FROM t2 alias1, t1 alias2, t1 alias3; id select_type table type possible_keys key key_len ref rows Extra 1 PRIMARY alias1 ALL NULL NULL NULL NULL 2 @@ -6924,9 +7012,11 @@ id select_type table type possible_keys key key_len ref rows Extra 2 SUBQUERY t2 ALL NULL NULL NULL NULL 2 Using where; Using join buffer (flat, BNL join) 3 SUBQUERY t3 ALL NULL NULL NULL NULL 2 flush status; -SELECT (SELECT MIN(b) FROM t1, t2 WHERE b = a AND (b = alias1.b OR EXISTS (SELECT * FROM t3))) +SELECT +(SELECT MIN(b) FROM t1, t2 +WHERE b = a AND (b = alias1.b OR EXISTS (SELECT * FROM t3))) AS m FROM t2 alias1, t1 alias2, t1 alias3; -(SELECT MIN(b) FROM t1, t2 WHERE b = a AND (b = alias1.b OR EXISTS (SELECT * FROM t3))) +m NULL NULL NULL diff --git a/mysql-test/main/subselect_no_scache.result b/mysql-test/main/subselect_no_scache.result index 1cc69ef4e8549..4717eb9bd157a 100644 --- a/mysql-test/main/subselect_no_scache.result +++ b/mysql-test/main/subselect_no_scache.result @@ -124,27 +124,27 @@ ROW(1,2,3) > (SELECT 1,2,1) SELECT ROW(1,2,3) = (SELECT 1,2,NULL); ROW(1,2,3) = (SELECT 1,2,NULL) NULL -SELECT (SELECT 1.5,2,'a') = ROW(1.5,2,'a'); -(SELECT 1.5,2,'a') = ROW(1.5,2,'a') +SELECT (SELECT 1.5,2,'a') = ROW(1.5,2,'a') AS m; +m 1 -SELECT (SELECT 1.5,2,'a') = ROW(1.5,2,'b'); -(SELECT 1.5,2,'a') = ROW(1.5,2,'b') +SELECT (SELECT 1.5,2,'a') = ROW(1.5,2,'b') AS m; +m 0 -SELECT (SELECT 1.5,2,'a') = ROW('1.5b',2,'b'); -(SELECT 1.5,2,'a') = ROW('1.5b',2,'b') +SELECT (SELECT 1.5,2,'a') = ROW('1.5b',2,'b') AS m; +m 0 Warnings: Warning 1292 Truncated incorrect DOUBLE value: '1.5b' -SELECT (SELECT 'b',2,'a') = ROW(1.5,2,'a'); -(SELECT 'b',2,'a') = ROW(1.5,2,'a') +SELECT (SELECT 'b',2,'a') = ROW(1.5,2,'a') AS m; +m 0 Warnings: Warning 1292 Truncated incorrect DOUBLE value: 'b' -SELECT (SELECT 1.5,2,'a') = ROW(1.5,'2','a'); -(SELECT 1.5,2,'a') = ROW(1.5,'2','a') +SELECT (SELECT 1.5,2,'a') = ROW(1.5,'2','a') AS m; +m 1 -SELECT (SELECT 1.5,'c','a') = ROW(1.5,2,'a'); -(SELECT 1.5,'c','a') = ROW(1.5,2,'a') +SELECT (SELECT 1.5,'c','a') = ROW(1.5,2,'a') AS m; +m 0 Warnings: Warning 1292 Truncated incorrect DECIMAL value: 'c' @@ -234,19 +234,26 @@ a 2 select * from t1 where t1.a=(select t2.a from t2 where t2.b=(select max(a) from t3 where t3.a < t1.a) order by 1 desc limit 1); a -select b,(select avg(t2.a+(select min(t3.a) from t3 where t3.a >= t4.a)) from t2) from t4; -b (select avg(t2.a+(select min(t3.a) from t3 where t3.a >= t4.a)) from t2) +select +b, +(select avg(t2.a+(select min(t3.a) from t3 where t3.a >= t4.a)) from t2) as m +from t4; +b m 8 7.5000 8 4.5000 9 7.5000 -explain extended select b,(select avg(t2.a+(select min(t3.a) from t3 where t3.a >= t4.a)) from t2) from t4; +explain extended +select +b, +(select avg(t2.a+(select min(t3.a) from t3 where t3.a >= t4.a)) from t2) as m +from t4; id select_type table type possible_keys key key_len ref rows filtered Extra 1 PRIMARY t4 ALL NULL NULL NULL NULL 3 100.00 2 DEPENDENT SUBQUERY t2 ALL NULL NULL NULL NULL 2 100.00 3 DEPENDENT SUBQUERY t3 ALL NULL NULL NULL NULL 3 100.00 Using where Warnings: Note 1276 Field or reference 'test.t4.a' of SELECT #3 was resolved in SELECT #1 -Note 1003 /* select#1 */ select `test`.`t4`.`b` AS `b`,(/* select#2 */ select avg(`test`.`t2`.`a` + (/* select#3 */ select min(`test`.`t3`.`a`) from `test`.`t3` where `test`.`t3`.`a` >= `test`.`t4`.`a`)) from `test`.`t2`) AS `(select avg(t2.a+(select min(t3.a) from t3 where t3.a >= t4.a)) from t2)` from `test`.`t4` +Note 1003 /* select#1 */ select `test`.`t4`.`b` AS `b`,(/* select#2 */ select avg(`test`.`t2`.`a` + (/* select#3 */ select min(`test`.`t3`.`a`) from `test`.`t3` where `test`.`t3`.`a` >= `test`.`t4`.`a`)) from `test`.`t2`) AS `m` from `test`.`t4` select * from t3 where exists (select * from t2 where t2.b=t3.a); a 7 @@ -313,21 +320,34 @@ select b,max(a) as ma from t4 group by b having b >= (select max(t2.a) from t2 w b ma 7 12 create table t5 (a int); -select (select a from t1 where t1.a=t2.a union select a from t5 where t5.a=t2.a), a from t2; -(select a from t1 where t1.a=t2.a union select a from t5 where t5.a=t2.a) a +select +(select a from t1 where t1.a=t2.a union select a from t5 where t5.a=t2.a) as m, +a +from t2; +m a NULL 1 2 2 insert into t5 values (5); -select (select a from t1 where t1.a=t2.a union select a from t5 where t5.a=t2.a), a from t2; -(select a from t1 where t1.a=t2.a union select a from t5 where t5.a=t2.a) a +select +(select a from t1 where t1.a=t2.a union select a from t5 where t5.a=t2.a) as m, +a +from t2; +m a NULL 1 2 2 insert into t5 values (2); -select (select a from t1 where t1.a=t2.a union select a from t5 where t5.a=t2.a), a from t2; -(select a from t1 where t1.a=t2.a union select a from t5 where t5.a=t2.a) a +select +(select a from t1 where t1.a=t2.a union select a from t5 where t5.a=t2.a) as m, +a +from t2; +m a NULL 1 2 2 -explain extended select (select a from t1 where t1.a=t2.a union select a from t5 where t5.a=t2.a), a from t2; +explain extended +select +(select a from t1 where t1.a=t2.a union select a from t5 where t5.a=t2.a) as m, +a +from t2; id select_type table type possible_keys key key_len ref rows filtered Extra 1 PRIMARY t2 ALL NULL NULL NULL NULL 2 100.00 2 DEPENDENT SUBQUERY t1 system NULL NULL NULL NULL 1 100.00 @@ -336,7 +356,7 @@ NULL UNION RESULT ALL NULL NULL NULL NULL NULL NULL Warnings: Note 1276 Field or reference 'test.t2.a' of SELECT #2 was resolved in SELECT #1 Note 1276 Field or reference 'test.t2.a' of SELECT #3 was resolved in SELECT #1 -Note 1003 /* select#1 */ select (/* select#2 */ select 2 from dual where 2 = `test`.`t2`.`a` union /* select#3 */ select `test`.`t5`.`a` from `test`.`t5` where `test`.`t5`.`a` = `test`.`t2`.`a`) AS `(select a from t1 where t1.a=t2.a union select a from t5 where t5.a=t2.a)`,`test`.`t2`.`a` AS `a` from `test`.`t2` +Note 1003 /* select#1 */ select (/* select#2 */ select 2 from dual where 2 = `test`.`t2`.`a` union /* select#3 */ select `test`.`t5`.`a` from `test`.`t5` where `test`.`t5`.`a` = `test`.`t2`.`a`) AS `m`,`test`.`t2`.`a` AS `a` from `test`.`t2` select (select a from t1 where t1.a=t2.a union all select a from t5 where t5.a=t2.a), a from t2; ERROR 21000: Subquery returns more than 1 row create table t6 (patient_uq int, clinic_uq int, index i1 (clinic_uq)); @@ -492,8 +512,11 @@ SELECT * from t2 where topic = all (SELECT topic FROM t2 GROUP BY topic HAVING t mot topic date pseudo joce 40143 2002-10-22 joce joce 43506 2002-10-22 joce -SELECT *, topic = all (SELECT topic FROM t2 GROUP BY topic HAVING topic < 4100) from t2; -mot topic date pseudo topic = all (SELECT topic FROM t2 GROUP BY topic HAVING topic < 4100) +SELECT +*, +topic = all (SELECT topic FROM t2 GROUP BY topic HAVING topic < 4100) AS m +FROM t2; +mot topic date pseudo m joce 40143 2002-10-22 joce 1 joce 43506 2002-10-22 joce 1 SELECT * from t2 where topic = all (SELECT SUM(topic) FROM t2); @@ -511,8 +534,11 @@ joce 40143 2002-10-22 joce SELECT * from t2 where topic = all (SELECT topic FROM t2 GROUP BY topic HAVING topic < 41000); mot topic date pseudo joce 40143 2002-10-22 joce -SELECT *, topic = all (SELECT topic FROM t2 GROUP BY topic HAVING topic < 41000) from t2; -mot topic date pseudo topic = all (SELECT topic FROM t2 GROUP BY topic HAVING topic < 41000) +SELECT +*, +topic = all (SELECT topic FROM t2 GROUP BY topic HAVING topic < 41000) AS m +FROM t2; +mot topic date pseudo m joce 40143 2002-10-22 joce 1 joce 43506 2002-10-22 joce 0 drop table t1,t2; @@ -887,6 +913,25 @@ NULL select 1.5 > ANY (SELECT * from t1); 1.5 > ANY (SELECT * from t1) NULL +update t1 set a=NULL where a=2.5; +select 1.5 IN (SELECT * from t1); +1.5 IN (SELECT * from t1) +1 +select 3.5 IN (SELECT * from t1); +3.5 IN (SELECT * from t1) +1 +select 10.5 IN (SELECT * from t1); +10.5 IN (SELECT * from t1) +NULL +select 1.5 > ALL (SELECT * from t1); +1.5 > ALL (SELECT * from t1) +0 +select 10.5 > ALL (SELECT * from t1); +10.5 > ALL (SELECT * from t1) +NULL +select 1.5 > ANY (SELECT * from t1); +1.5 > ANY (SELECT * from t1) +NULL select 10.5 > ANY (SELECT * from t1); 10.5 > ANY (SELECT * from t1) 1 @@ -897,6 +942,20 @@ Warnings: Note 1276 Field or reference 'test.t1.a' of SELECT #2 was resolved in SELECT #1 Note 1249 Select 2 was reduced during optimization Note 1003 select `test`.`t1`.`a` + 1 AS `(select a+1)` from `test`.`t1` +explain extended select (select a+1) from t1; +id select_type table type possible_keys key key_len ref rows filtered Extra +1 SIMPLE t1 ALL NULL NULL NULL NULL 3 100.00 +Warnings: +Note 1276 Field or reference 'test.t1.a' of SELECT #2 was resolved in SELECT #1 +Note 1249 Select 2 was reduced during optimization +Note 1003 select `test`.`t1`.`a` + 1 AS `(select a+1)` from `test`.`t1` +explain extended select (select a+1) from t1; +id select_type table type possible_keys key key_len ref rows filtered Extra +1 SIMPLE t1 ALL NULL NULL NULL NULL 3 100.00 +Warnings: +Note 1276 Field or reference 'test.t1.a' of SELECT #2 was resolved in SELECT #1 +Note 1249 Select 2 was reduced during optimization +Note 1003 select `test`.`t1`.`a` + 1 AS `(select a+1)` from `test`.`t1` select (select a+1) from t1; (select a+1) 2.5 @@ -1538,8 +1597,8 @@ create table t3 (a int, b int); insert into t1 values (0,100),(1,2), (1,3), (2,2), (2,7), (2,-1), (3,10); insert into t2 values (0,0), (1,1), (2,1), (3,1), (4,1); insert into t3 values (3,3), (2,2), (1,1); -select a,(select count(distinct t1.b) as sum from t1,t2 where t1.a=t2.a and t2.b > 0 and t1.a <= t3.b group by t1.a order by sum limit 1) from t3; -a (select count(distinct t1.b) as sum from t1,t2 where t1.a=t2.a and t2.b > 0 and t1.a <= t3.b group by t1.a order by sum limit 1) +select a,(select count(distinct t1.b) as sum from t1,t2 where t1.a=t2.a and t2.b > 0 and t1.a <= t3.b group by t1.a order by sum limit 1) as m from t3; +a m 3 1 2 2 1 2 @@ -1734,8 +1793,8 @@ CREATE TABLE `t3` (`taskgenid` mediumint(9) NOT NULL auto_increment,`dbid` int(1 INSERT INTO `t3` (`taskgenid`, `dbid`, `taskid`, `mon`, `tues`,`wed`, `thur`, `fri`, `sat`, `sun`, `how_often`, `userid`, `active`) VALUES (1,-1, 1, 1, 1, 1, 1, 1, 0, 0, 1, 0, 1); CREATE TABLE `t4` (`task_id` smallint(6) NOT NULL default '0',`description` varchar(200) NOT NULL default '') ENGINE=MyISAM CHARSET=latin1; INSERT INTO `t4` (`task_id`, `description`) VALUES (1, 'Daily Check List'),(2, 'Weekly Status'); -select dbid, name, (date_format(now() , '%Y-%m-%d') - INTERVAL how_often DAY) >= ifnull((SELECT date_format(max(create_date),'%Y-%m-%d') FROM t1 WHERE dbid = b.db_id AND taskid = a.taskgenid), '1950-01-01') from t3 a, t2 b, t4 WHERE dbid = - 1 AND primary_uid = '1' AND t4.task_id = taskid; -dbid name (date_format(now() , '%Y-%m-%d') - INTERVAL how_often DAY) >= ifnull((SELECT date_format(max(create_date),'%Y-%m-%d') FROM t1 WHERE dbid = b.db_id AND taskid = a.taskgenid), '1950-01-01') +select dbid, name, (date_format(now() , '%Y-%m-%d') - INTERVAL how_often DAY) >= ifnull((SELECT date_format(max(create_date),'%Y-%m-%d') as m FROM t1 WHERE dbid = b.db_id AND taskid = a.taskgenid), '1950-01-01') as m from t3 a, t2 b, t4 WHERE dbid = - 1 AND primary_uid = '1' AND t4.task_id = taskid; +dbid name m -1 Valid 1 -1 Valid 2 1 -1 Should Not Return 0 @@ -3790,9 +3849,10 @@ SELECT (SELECT COUNT(DISTINCT t1.b) from t2) FROM t1 GROUP BY t1.a; 2 1 1 -SELECT (SELECT COUNT(DISTINCT t1.b) from t2 union select 1 from t2 where 12 < 3) +SELECT +(SELECT COUNT(DISTINCT t1.b) from t2 union select 1 from t2 where 12 < 3) AS m FROM t1 GROUP BY t1.a; -(SELECT COUNT(DISTINCT t1.b) from t2 union select 1 from t2 where 12 < 3) +m 2 1 1 @@ -3802,9 +3862,9 @@ COUNT(DISTINCT t1.b) (SELECT COUNT(DISTINCT t1.b)) 1 1 1 1 SELECT COUNT(DISTINCT t1.b), -(SELECT COUNT(DISTINCT t1.b) union select 1 from DUAL where 12 < 3) +(SELECT COUNT(DISTINCT t1.b) union select 1 from DUAL where 12 < 3) AS m FROM t1 GROUP BY t1.a; -COUNT(DISTINCT t1.b) (SELECT COUNT(DISTINCT t1.b) union select 1 from DUAL where 12 < 3) +COUNT(DISTINCT t1.b) m 2 2 1 1 1 1 @@ -3828,16 +3888,10 @@ SELECT ( SELECT COUNT(DISTINCT t1.b) ) ) -FROM t1 GROUP BY t1.a LIMIT 1) +FROM t1 GROUP BY t1.a LIMIT 1) AS m FROM t1 t2 GROUP BY t2.a; -( -SELECT ( -SELECT ( -SELECT COUNT(DISTINCT t1.b) -) -) -FROM t1 GROUP BY t1.a LIMIT 1) +m 2 2 2 @@ -6431,11 +6485,10 @@ CREATE TABLE t3 (a int, b int); INSERT INTO t3 VALUES (10,7), (0,7); SELECT SUM(DISTINCT b), (SELECT t2.a FROM t1 JOIN t2 ON t2.c != 0 -WHERE t.a != 0 AND t2.a != 0) +WHERE t.a != 0 AND t2.a != 0) AS m FROM (SELECT * FROM t3) AS t GROUP BY 2; -SUM(DISTINCT b) (SELECT t2.a FROM t1 JOIN t2 ON t2.c != 0 -WHERE t.a != 0 AND t2.a != 0) +SUM(DISTINCT b) m 7 NULL SELECT SUM(DISTINCT b), (SELECT t2.a FROM t1,t2 WHERE t.a != 0 or 1=2 LIMIT 1) @@ -6568,66 +6621,93 @@ CREATE TABLE t3 (f3a int default 1, f3b int default 2); INSERT INTO t3 VALUES (1,1),(2,2); set @old_optimizer_switch = @@session.optimizer_switch; set @@optimizer_switch='materialization=on,partial_match_rowid_merge=on,partial_match_table_scan=off,subquery_cache=off,semijoin=off'; -SELECT (SELECT f3a FROM t3 where f3a > 3) NOT IN (SELECT f1a FROM t1) FROM t2; -(SELECT f3a FROM t3 where f3a > 3) NOT IN (SELECT f1a FROM t1) +SELECT +(SELECT f3a FROM t3 where f3a > 3) NOT IN (SELECT f1a FROM t1) AS m +FROM t2; +m NULL NULL -SELECT (SELECT f3a,f3a FROM t3 where f3a > 3) NOT IN (SELECT f1a,f1a FROM t1) FROM t2; -(SELECT f3a,f3a FROM t3 where f3a > 3) NOT IN (SELECT f1a,f1a FROM t1) +SELECT +(SELECT f3a,f3a FROM t3 where f3a > 3) NOT IN (SELECT f1a,f1a FROM t1) AS m +FROM t2; +m NULL NULL -SELECT (SELECT f3a, f3b FROM t3 where f3a > 3) NOT IN (SELECT f1a, f1b FROM t1) FROM t2; -(SELECT f3a, f3b FROM t3 where f3a > 3) NOT IN (SELECT f1a, f1b FROM t1) +SELECT +(SELECT f3a, f3b FROM t3 where f3a > 3) NOT IN (SELECT f1a, f1b FROM t1) AS m +FROM t2; +m NULL NULL -SELECT (SELECT f3a, f3b FROM t3 where f3a > 3) NOT IN (SELECT f1a, f1b FROM t1); -(SELECT f3a, f3b FROM t3 where f3a > 3) NOT IN (SELECT f1a, f1b FROM t1) +SELECT +(SELECT f3a, f3b FROM t3 where f3a > 3) NOT IN (SELECT f1a, f1b FROM t1) AS m; +m NULL -SELECT (SELECT f3a FROM t3 where f3a > 3) IN (SELECT f1a FROM t1) FROM t2; -(SELECT f3a FROM t3 where f3a > 3) IN (SELECT f1a FROM t1) +SELECT +(SELECT f3a FROM t3 where f3a > 3) IN (SELECT f1a FROM t1) AS m +FROM t2; +m NULL NULL -SELECT (SELECT f3a,f3a FROM t3 where f3a > 3) IN (SELECT f1a,f1a FROM t1) FROM t2; -(SELECT f3a,f3a FROM t3 where f3a > 3) IN (SELECT f1a,f1a FROM t1) +SELECT +(SELECT f3a,f3a FROM t3 where f3a > 3) IN (SELECT f1a,f1a FROM t1) AS m +FROM t2; +m NULL NULL -SELECT (SELECT f3a, f3b FROM t3 where f3a > 3) IN (SELECT f1a, f1b FROM t1) FROM t2; -(SELECT f3a, f3b FROM t3 where f3a > 3) IN (SELECT f1a, f1b FROM t1) +SELECT +(SELECT f3a, f3b FROM t3 where f3a > 3) IN (SELECT f1a, f1b FROM t1) AS m +FROM t2; +m NULL NULL -SELECT (SELECT f3a, f3b FROM t3 where f3a > 3) IN (SELECT f1a, f1b FROM t1); -(SELECT f3a, f3b FROM t3 where f3a > 3) IN (SELECT f1a, f1b FROM t1) +SELECT +(SELECT f3a, f3b FROM t3 where f3a > 3) IN (SELECT f1a, f1b FROM t1) AS m; +m NULL set @@session.optimizer_switch=@old_optimizer_switch; -SELECT (SELECT f3a FROM t3 where f3a > 3) NOT IN (SELECT f1a FROM t1) FROM t2; -(SELECT f3a FROM t3 where f3a > 3) NOT IN (SELECT f1a FROM t1) +SELECT +(SELECT f3a FROM t3 where f3a > 3) NOT IN (SELECT f1a FROM t1) AS m +FROM t2; +m NULL NULL -SELECT (SELECT f3a,f3a FROM t3 where f3a > 3) NOT IN (SELECT f1a,f1a FROM t1) FROM t2; -(SELECT f3a,f3a FROM t3 where f3a > 3) NOT IN (SELECT f1a,f1a FROM t1) +SELECT +(SELECT f3a,f3a FROM t3 where f3a > 3) NOT IN (SELECT f1a,f1a FROM t1) AS m +FROM t2; +m NULL NULL -SELECT (SELECT f3a, f3b FROM t3 where f3a > 3) NOT IN (SELECT f1a, f1b FROM t1) FROM t2; -(SELECT f3a, f3b FROM t3 where f3a > 3) NOT IN (SELECT f1a, f1b FROM t1) +SELECT +(SELECT f3a, f3b FROM t3 where f3a > 3) NOT IN (SELECT f1a, f1b FROM t1) AS m +FROM t2; +m NULL NULL -SELECT (SELECT f3a, f3b FROM t3 where f3a > 3) NOT IN (SELECT f1a, f1b FROM t1); -(SELECT f3a, f3b FROM t3 where f3a > 3) NOT IN (SELECT f1a, f1b FROM t1) +SELECT +(SELECT f3a, f3b FROM t3 where f3a > 3) NOT IN (SELECT f1a, f1b FROM t1) AS m; +m NULL -SELECT (SELECT f3a FROM t3 where f3a > 3) IN (SELECT f1a FROM t1) FROM t2; +SELECT +(SELECT f3a FROM t3 where f3a > 3) IN (SELECT f1a FROM t1) FROM t2 AS m; (SELECT f3a FROM t3 where f3a > 3) IN (SELECT f1a FROM t1) NULL NULL -SELECT (SELECT f3a,f3a FROM t3 where f3a > 3) IN (SELECT f1a,f1a FROM t1) FROM t2; -(SELECT f3a,f3a FROM t3 where f3a > 3) IN (SELECT f1a,f1a FROM t1) +SELECT +(SELECT f3a,f3a FROM t3 where f3a > 3) IN (SELECT f1a,f1a FROM t1) AS m +FROM t2; +m NULL NULL -SELECT (SELECT f3a, f3b FROM t3 where f3a > 3) IN (SELECT f1a, f1b FROM t1) FROM t2; -(SELECT f3a, f3b FROM t3 where f3a > 3) IN (SELECT f1a, f1b FROM t1) +SELECT +(SELECT f3a, f3b FROM t3 where f3a > 3) IN (SELECT f1a, f1b FROM t1) AS m +FROM t2; +m NULL NULL -SELECT (SELECT f3a, f3b FROM t3 where f3a > 3) IN (SELECT f1a, f1b FROM t1); -(SELECT f3a, f3b FROM t3 where f3a > 3) IN (SELECT f1a, f1b FROM t1) +SELECT +(SELECT f3a, f3b FROM t3 where f3a > 3) IN (SELECT f1a, f1b FROM t1) AS m; +m NULL select (null, null) = (null, null); (null, null) = (null, null) @@ -6673,8 +6753,10 @@ INSERT INTO t2 VALUES (1); CREATE TABLE t3 ( c INT ); INSERT INTO t3 VALUES (4),(5); SET optimizer_switch='subquery_cache=off'; -SELECT ( SELECT b FROM t2 WHERE b = a OR EXISTS ( SELECT c FROM t3 WHERE c = b ) ) FROM t1; -( SELECT b FROM t2 WHERE b = a OR EXISTS ( SELECT c FROM t3 WHERE c = b ) ) +SELECT +( SELECT b FROM t2 WHERE b = a OR EXISTS ( SELECT c FROM t3 WHERE c = b ) ) AS m +FROM t1; +m 1 NULL SELECT ( SELECT b FROM t2 WHERE b = a OR b * 0) FROM t1; @@ -6891,7 +6973,9 @@ CREATE TABLE t3 (c INT); INSERT INTO t3 VALUES (8),(3); set @@expensive_subquery_limit= 0; EXPLAIN -SELECT (SELECT MIN(b) FROM t1, t2 WHERE b = a AND (b = alias1.b OR EXISTS (SELECT * FROM t3))) +SELECT +(SELECT MIN(b) FROM t1, t2 +WHERE b = a AND (b = alias1.b OR EXISTS (SELECT * FROM t3))) AS m FROM t2 alias1, t1 alias2, t1 alias3; id select_type table type possible_keys key key_len ref rows Extra 1 PRIMARY alias1 ALL NULL NULL NULL NULL 2 @@ -6901,9 +6985,11 @@ id select_type table type possible_keys key key_len ref rows Extra 2 DEPENDENT SUBQUERY t2 ALL NULL NULL NULL NULL 2 Using where; Using join buffer (flat, BNL join) 3 SUBQUERY t3 ALL NULL NULL NULL NULL 2 flush status; -SELECT (SELECT MIN(b) FROM t1, t2 WHERE b = a AND (b = alias1.b OR EXISTS (SELECT * FROM t3))) +SELECT +(SELECT MIN(b) FROM t1, t2 +WHERE b = a AND (b = alias1.b OR EXISTS (SELECT * FROM t3))) AS m FROM t2 alias1, t1 alias2, t1 alias3; -(SELECT MIN(b) FROM t1, t2 WHERE b = a AND (b = alias1.b OR EXISTS (SELECT * FROM t3))) +m NULL NULL NULL @@ -6929,7 +7015,9 @@ Handler_read_rnd_deleted 0 Handler_read_rnd_next 58 set @@expensive_subquery_limit= default; EXPLAIN -SELECT (SELECT MIN(b) FROM t1, t2 WHERE b = a AND (b = alias1.b OR EXISTS (SELECT * FROM t3))) +SELECT +(SELECT MIN(b) FROM t1, t2 +WHERE b = a AND (b = alias1.b OR EXISTS (SELECT * FROM t3))) AS m FROM t2 alias1, t1 alias2, t1 alias3; id select_type table type possible_keys key key_len ref rows Extra 1 PRIMARY alias1 ALL NULL NULL NULL NULL 2 @@ -6939,9 +7027,11 @@ id select_type table type possible_keys key key_len ref rows Extra 2 SUBQUERY t2 ALL NULL NULL NULL NULL 2 Using where; Using join buffer (flat, BNL join) 3 SUBQUERY t3 ALL NULL NULL NULL NULL 2 flush status; -SELECT (SELECT MIN(b) FROM t1, t2 WHERE b = a AND (b = alias1.b OR EXISTS (SELECT * FROM t3))) +SELECT +(SELECT MIN(b) FROM t1, t2 +WHERE b = a AND (b = alias1.b OR EXISTS (SELECT * FROM t3))) AS m FROM t2 alias1, t1 alias2, t1 alias3; -(SELECT MIN(b) FROM t1, t2 WHERE b = a AND (b = alias1.b OR EXISTS (SELECT * FROM t3))) +m NULL NULL NULL diff --git a/mysql-test/main/subselect_no_semijoin.result b/mysql-test/main/subselect_no_semijoin.result index 7dbee3ff88225..9450cf4fe9cde 100644 --- a/mysql-test/main/subselect_no_semijoin.result +++ b/mysql-test/main/subselect_no_semijoin.result @@ -121,27 +121,27 @@ ROW(1,2,3) > (SELECT 1,2,1) SELECT ROW(1,2,3) = (SELECT 1,2,NULL); ROW(1,2,3) = (SELECT 1,2,NULL) NULL -SELECT (SELECT 1.5,2,'a') = ROW(1.5,2,'a'); -(SELECT 1.5,2,'a') = ROW(1.5,2,'a') +SELECT (SELECT 1.5,2,'a') = ROW(1.5,2,'a') AS m; +m 1 -SELECT (SELECT 1.5,2,'a') = ROW(1.5,2,'b'); -(SELECT 1.5,2,'a') = ROW(1.5,2,'b') +SELECT (SELECT 1.5,2,'a') = ROW(1.5,2,'b') AS m; +m 0 -SELECT (SELECT 1.5,2,'a') = ROW('1.5b',2,'b'); -(SELECT 1.5,2,'a') = ROW('1.5b',2,'b') +SELECT (SELECT 1.5,2,'a') = ROW('1.5b',2,'b') AS m; +m 0 Warnings: Warning 1292 Truncated incorrect DOUBLE value: '1.5b' -SELECT (SELECT 'b',2,'a') = ROW(1.5,2,'a'); -(SELECT 'b',2,'a') = ROW(1.5,2,'a') +SELECT (SELECT 'b',2,'a') = ROW(1.5,2,'a') AS m; +m 0 Warnings: Warning 1292 Truncated incorrect DOUBLE value: 'b' -SELECT (SELECT 1.5,2,'a') = ROW(1.5,'2','a'); -(SELECT 1.5,2,'a') = ROW(1.5,'2','a') +SELECT (SELECT 1.5,2,'a') = ROW(1.5,'2','a') AS m; +m 1 -SELECT (SELECT 1.5,'c','a') = ROW(1.5,2,'a'); -(SELECT 1.5,'c','a') = ROW(1.5,2,'a') +SELECT (SELECT 1.5,'c','a') = ROW(1.5,2,'a') AS m; +m 0 Warnings: Warning 1292 Truncated incorrect DECIMAL value: 'c' @@ -231,19 +231,26 @@ a 2 select * from t1 where t1.a=(select t2.a from t2 where t2.b=(select max(a) from t3 where t3.a < t1.a) order by 1 desc limit 1); a -select b,(select avg(t2.a+(select min(t3.a) from t3 where t3.a >= t4.a)) from t2) from t4; -b (select avg(t2.a+(select min(t3.a) from t3 where t3.a >= t4.a)) from t2) +select +b, +(select avg(t2.a+(select min(t3.a) from t3 where t3.a >= t4.a)) from t2) as m +from t4; +b m 8 7.5000 8 4.5000 9 7.5000 -explain extended select b,(select avg(t2.a+(select min(t3.a) from t3 where t3.a >= t4.a)) from t2) from t4; +explain extended +select +b, +(select avg(t2.a+(select min(t3.a) from t3 where t3.a >= t4.a)) from t2) as m +from t4; id select_type table type possible_keys key key_len ref rows filtered Extra 1 PRIMARY t4 ALL NULL NULL NULL NULL 3 100.00 2 DEPENDENT SUBQUERY t2 ALL NULL NULL NULL NULL 2 100.00 3 DEPENDENT SUBQUERY t3 ALL NULL NULL NULL NULL 3 100.00 Using where Warnings: Note 1276 Field or reference 'test.t4.a' of SELECT #3 was resolved in SELECT #1 -Note 1003 /* select#1 */ select `test`.`t4`.`b` AS `b`,<`test`.`t4`.`a`>((/* select#2 */ select avg(`test`.`t2`.`a` + (/* select#3 */ select min(`test`.`t3`.`a`) from `test`.`t3` where `test`.`t3`.`a` >= `test`.`t4`.`a`)) from `test`.`t2`)) AS `(select avg(t2.a+(select min(t3.a) from t3 where t3.a >= t4.a)) from t2)` from `test`.`t4` +Note 1003 /* select#1 */ select `test`.`t4`.`b` AS `b`,<`test`.`t4`.`a`>((/* select#2 */ select avg(`test`.`t2`.`a` + (/* select#3 */ select min(`test`.`t3`.`a`) from `test`.`t3` where `test`.`t3`.`a` >= `test`.`t4`.`a`)) from `test`.`t2`)) AS `m` from `test`.`t4` select * from t3 where exists (select * from t2 where t2.b=t3.a); a 7 @@ -310,21 +317,34 @@ select b,max(a) as ma from t4 group by b having b >= (select max(t2.a) from t2 w b ma 7 12 create table t5 (a int); -select (select a from t1 where t1.a=t2.a union select a from t5 where t5.a=t2.a), a from t2; -(select a from t1 where t1.a=t2.a union select a from t5 where t5.a=t2.a) a +select +(select a from t1 where t1.a=t2.a union select a from t5 where t5.a=t2.a) as m, +a +from t2; +m a NULL 1 2 2 insert into t5 values (5); -select (select a from t1 where t1.a=t2.a union select a from t5 where t5.a=t2.a), a from t2; -(select a from t1 where t1.a=t2.a union select a from t5 where t5.a=t2.a) a +select +(select a from t1 where t1.a=t2.a union select a from t5 where t5.a=t2.a) as m, +a +from t2; +m a NULL 1 2 2 insert into t5 values (2); -select (select a from t1 where t1.a=t2.a union select a from t5 where t5.a=t2.a), a from t2; -(select a from t1 where t1.a=t2.a union select a from t5 where t5.a=t2.a) a +select +(select a from t1 where t1.a=t2.a union select a from t5 where t5.a=t2.a) as m, +a +from t2; +m a NULL 1 2 2 -explain extended select (select a from t1 where t1.a=t2.a union select a from t5 where t5.a=t2.a), a from t2; +explain extended +select +(select a from t1 where t1.a=t2.a union select a from t5 where t5.a=t2.a) as m, +a +from t2; id select_type table type possible_keys key key_len ref rows filtered Extra 1 PRIMARY t2 ALL NULL NULL NULL NULL 2 100.00 2 DEPENDENT SUBQUERY t1 system NULL NULL NULL NULL 1 100.00 @@ -333,7 +353,7 @@ NULL UNION RESULT ALL NULL NULL NULL NULL NULL NULL Warnings: Note 1276 Field or reference 'test.t2.a' of SELECT #2 was resolved in SELECT #1 Note 1276 Field or reference 'test.t2.a' of SELECT #3 was resolved in SELECT #1 -Note 1003 /* select#1 */ select <`test`.`t2`.`a`>((/* select#2 */ select 2 from dual where 2 = `test`.`t2`.`a` union /* select#3 */ select `test`.`t5`.`a` from `test`.`t5` where `test`.`t5`.`a` = `test`.`t2`.`a`)) AS `(select a from t1 where t1.a=t2.a union select a from t5 where t5.a=t2.a)`,`test`.`t2`.`a` AS `a` from `test`.`t2` +Note 1003 /* select#1 */ select <`test`.`t2`.`a`>((/* select#2 */ select 2 from dual where 2 = `test`.`t2`.`a` union /* select#3 */ select `test`.`t5`.`a` from `test`.`t5` where `test`.`t5`.`a` = `test`.`t2`.`a`)) AS `m`,`test`.`t2`.`a` AS `a` from `test`.`t2` select (select a from t1 where t1.a=t2.a union all select a from t5 where t5.a=t2.a), a from t2; ERROR 21000: Subquery returns more than 1 row create table t6 (patient_uq int, clinic_uq int, index i1 (clinic_uq)); @@ -489,8 +509,11 @@ SELECT * from t2 where topic = all (SELECT topic FROM t2 GROUP BY topic HAVING t mot topic date pseudo joce 40143 2002-10-22 joce joce 43506 2002-10-22 joce -SELECT *, topic = all (SELECT topic FROM t2 GROUP BY topic HAVING topic < 4100) from t2; -mot topic date pseudo topic = all (SELECT topic FROM t2 GROUP BY topic HAVING topic < 4100) +SELECT +*, +topic = all (SELECT topic FROM t2 GROUP BY topic HAVING topic < 4100) AS m +FROM t2; +mot topic date pseudo m joce 40143 2002-10-22 joce 1 joce 43506 2002-10-22 joce 1 SELECT * from t2 where topic = all (SELECT SUM(topic) FROM t2); @@ -508,8 +531,11 @@ joce 40143 2002-10-22 joce SELECT * from t2 where topic = all (SELECT topic FROM t2 GROUP BY topic HAVING topic < 41000); mot topic date pseudo joce 40143 2002-10-22 joce -SELECT *, topic = all (SELECT topic FROM t2 GROUP BY topic HAVING topic < 41000) from t2; -mot topic date pseudo topic = all (SELECT topic FROM t2 GROUP BY topic HAVING topic < 41000) +SELECT +*, +topic = all (SELECT topic FROM t2 GROUP BY topic HAVING topic < 41000) AS m +FROM t2; +mot topic date pseudo m joce 40143 2002-10-22 joce 1 joce 43506 2002-10-22 joce 0 drop table t1,t2; @@ -884,6 +910,25 @@ NULL select 1.5 > ANY (SELECT * from t1); 1.5 > ANY (SELECT * from t1) NULL +update t1 set a=NULL where a=2.5; +select 1.5 IN (SELECT * from t1); +1.5 IN (SELECT * from t1) +1 +select 3.5 IN (SELECT * from t1); +3.5 IN (SELECT * from t1) +1 +select 10.5 IN (SELECT * from t1); +10.5 IN (SELECT * from t1) +NULL +select 1.5 > ALL (SELECT * from t1); +1.5 > ALL (SELECT * from t1) +0 +select 10.5 > ALL (SELECT * from t1); +10.5 > ALL (SELECT * from t1) +NULL +select 1.5 > ANY (SELECT * from t1); +1.5 > ANY (SELECT * from t1) +NULL select 10.5 > ANY (SELECT * from t1); 10.5 > ANY (SELECT * from t1) 1 @@ -894,6 +939,20 @@ Warnings: Note 1276 Field or reference 'test.t1.a' of SELECT #2 was resolved in SELECT #1 Note 1249 Select 2 was reduced during optimization Note 1003 select `test`.`t1`.`a` + 1 AS `(select a+1)` from `test`.`t1` +explain extended select (select a+1) from t1; +id select_type table type possible_keys key key_len ref rows filtered Extra +1 SIMPLE t1 ALL NULL NULL NULL NULL 3 100.00 +Warnings: +Note 1276 Field or reference 'test.t1.a' of SELECT #2 was resolved in SELECT #1 +Note 1249 Select 2 was reduced during optimization +Note 1003 select `test`.`t1`.`a` + 1 AS `(select a+1)` from `test`.`t1` +explain extended select (select a+1) from t1; +id select_type table type possible_keys key key_len ref rows filtered Extra +1 SIMPLE t1 ALL NULL NULL NULL NULL 3 100.00 +Warnings: +Note 1276 Field or reference 'test.t1.a' of SELECT #2 was resolved in SELECT #1 +Note 1249 Select 2 was reduced during optimization +Note 1003 select `test`.`t1`.`a` + 1 AS `(select a+1)` from `test`.`t1` select (select a+1) from t1; (select a+1) 2.5 @@ -1535,8 +1594,8 @@ create table t3 (a int, b int); insert into t1 values (0,100),(1,2), (1,3), (2,2), (2,7), (2,-1), (3,10); insert into t2 values (0,0), (1,1), (2,1), (3,1), (4,1); insert into t3 values (3,3), (2,2), (1,1); -select a,(select count(distinct t1.b) as sum from t1,t2 where t1.a=t2.a and t2.b > 0 and t1.a <= t3.b group by t1.a order by sum limit 1) from t3; -a (select count(distinct t1.b) as sum from t1,t2 where t1.a=t2.a and t2.b > 0 and t1.a <= t3.b group by t1.a order by sum limit 1) +select a,(select count(distinct t1.b) as sum from t1,t2 where t1.a=t2.a and t2.b > 0 and t1.a <= t3.b group by t1.a order by sum limit 1) as m from t3; +a m 3 1 2 2 1 2 @@ -1731,8 +1790,8 @@ CREATE TABLE `t3` (`taskgenid` mediumint(9) NOT NULL auto_increment,`dbid` int(1 INSERT INTO `t3` (`taskgenid`, `dbid`, `taskid`, `mon`, `tues`,`wed`, `thur`, `fri`, `sat`, `sun`, `how_often`, `userid`, `active`) VALUES (1,-1, 1, 1, 1, 1, 1, 1, 0, 0, 1, 0, 1); CREATE TABLE `t4` (`task_id` smallint(6) NOT NULL default '0',`description` varchar(200) NOT NULL default '') ENGINE=MyISAM CHARSET=latin1; INSERT INTO `t4` (`task_id`, `description`) VALUES (1, 'Daily Check List'),(2, 'Weekly Status'); -select dbid, name, (date_format(now() , '%Y-%m-%d') - INTERVAL how_often DAY) >= ifnull((SELECT date_format(max(create_date),'%Y-%m-%d') FROM t1 WHERE dbid = b.db_id AND taskid = a.taskgenid), '1950-01-01') from t3 a, t2 b, t4 WHERE dbid = - 1 AND primary_uid = '1' AND t4.task_id = taskid; -dbid name (date_format(now() , '%Y-%m-%d') - INTERVAL how_often DAY) >= ifnull((SELECT date_format(max(create_date),'%Y-%m-%d') FROM t1 WHERE dbid = b.db_id AND taskid = a.taskgenid), '1950-01-01') +select dbid, name, (date_format(now() , '%Y-%m-%d') - INTERVAL how_often DAY) >= ifnull((SELECT date_format(max(create_date),'%Y-%m-%d') as m FROM t1 WHERE dbid = b.db_id AND taskid = a.taskgenid), '1950-01-01') as m from t3 a, t2 b, t4 WHERE dbid = - 1 AND primary_uid = '1' AND t4.task_id = taskid; +dbid name m -1 Valid 1 -1 Valid 2 1 -1 Should Not Return 0 @@ -3783,9 +3842,10 @@ SELECT (SELECT COUNT(DISTINCT t1.b) from t2) FROM t1 GROUP BY t1.a; 2 1 1 -SELECT (SELECT COUNT(DISTINCT t1.b) from t2 union select 1 from t2 where 12 < 3) +SELECT +(SELECT COUNT(DISTINCT t1.b) from t2 union select 1 from t2 where 12 < 3) AS m FROM t1 GROUP BY t1.a; -(SELECT COUNT(DISTINCT t1.b) from t2 union select 1 from t2 where 12 < 3) +m 2 1 1 @@ -3795,9 +3855,9 @@ COUNT(DISTINCT t1.b) (SELECT COUNT(DISTINCT t1.b)) 1 1 1 1 SELECT COUNT(DISTINCT t1.b), -(SELECT COUNT(DISTINCT t1.b) union select 1 from DUAL where 12 < 3) +(SELECT COUNT(DISTINCT t1.b) union select 1 from DUAL where 12 < 3) AS m FROM t1 GROUP BY t1.a; -COUNT(DISTINCT t1.b) (SELECT COUNT(DISTINCT t1.b) union select 1 from DUAL where 12 < 3) +COUNT(DISTINCT t1.b) m 2 2 1 1 1 1 @@ -3821,16 +3881,10 @@ SELECT ( SELECT COUNT(DISTINCT t1.b) ) ) -FROM t1 GROUP BY t1.a LIMIT 1) +FROM t1 GROUP BY t1.a LIMIT 1) AS m FROM t1 t2 GROUP BY t2.a; -( -SELECT ( -SELECT ( -SELECT COUNT(DISTINCT t1.b) -) -) -FROM t1 GROUP BY t1.a LIMIT 1) +m 2 2 2 @@ -6416,11 +6470,10 @@ CREATE TABLE t3 (a int, b int); INSERT INTO t3 VALUES (10,7), (0,7); SELECT SUM(DISTINCT b), (SELECT t2.a FROM t1 JOIN t2 ON t2.c != 0 -WHERE t.a != 0 AND t2.a != 0) +WHERE t.a != 0 AND t2.a != 0) AS m FROM (SELECT * FROM t3) AS t GROUP BY 2; -SUM(DISTINCT b) (SELECT t2.a FROM t1 JOIN t2 ON t2.c != 0 -WHERE t.a != 0 AND t2.a != 0) +SUM(DISTINCT b) m 7 NULL SELECT SUM(DISTINCT b), (SELECT t2.a FROM t1,t2 WHERE t.a != 0 or 1=2 LIMIT 1) @@ -6553,66 +6606,93 @@ CREATE TABLE t3 (f3a int default 1, f3b int default 2); INSERT INTO t3 VALUES (1,1),(2,2); set @old_optimizer_switch = @@session.optimizer_switch; set @@optimizer_switch='materialization=on,partial_match_rowid_merge=on,partial_match_table_scan=off,subquery_cache=off,semijoin=off'; -SELECT (SELECT f3a FROM t3 where f3a > 3) NOT IN (SELECT f1a FROM t1) FROM t2; -(SELECT f3a FROM t3 where f3a > 3) NOT IN (SELECT f1a FROM t1) +SELECT +(SELECT f3a FROM t3 where f3a > 3) NOT IN (SELECT f1a FROM t1) AS m +FROM t2; +m NULL NULL -SELECT (SELECT f3a,f3a FROM t3 where f3a > 3) NOT IN (SELECT f1a,f1a FROM t1) FROM t2; -(SELECT f3a,f3a FROM t3 where f3a > 3) NOT IN (SELECT f1a,f1a FROM t1) +SELECT +(SELECT f3a,f3a FROM t3 where f3a > 3) NOT IN (SELECT f1a,f1a FROM t1) AS m +FROM t2; +m NULL NULL -SELECT (SELECT f3a, f3b FROM t3 where f3a > 3) NOT IN (SELECT f1a, f1b FROM t1) FROM t2; -(SELECT f3a, f3b FROM t3 where f3a > 3) NOT IN (SELECT f1a, f1b FROM t1) +SELECT +(SELECT f3a, f3b FROM t3 where f3a > 3) NOT IN (SELECT f1a, f1b FROM t1) AS m +FROM t2; +m NULL NULL -SELECT (SELECT f3a, f3b FROM t3 where f3a > 3) NOT IN (SELECT f1a, f1b FROM t1); -(SELECT f3a, f3b FROM t3 where f3a > 3) NOT IN (SELECT f1a, f1b FROM t1) +SELECT +(SELECT f3a, f3b FROM t3 where f3a > 3) NOT IN (SELECT f1a, f1b FROM t1) AS m; +m NULL -SELECT (SELECT f3a FROM t3 where f3a > 3) IN (SELECT f1a FROM t1) FROM t2; -(SELECT f3a FROM t3 where f3a > 3) IN (SELECT f1a FROM t1) +SELECT +(SELECT f3a FROM t3 where f3a > 3) IN (SELECT f1a FROM t1) AS m +FROM t2; +m NULL NULL -SELECT (SELECT f3a,f3a FROM t3 where f3a > 3) IN (SELECT f1a,f1a FROM t1) FROM t2; -(SELECT f3a,f3a FROM t3 where f3a > 3) IN (SELECT f1a,f1a FROM t1) +SELECT +(SELECT f3a,f3a FROM t3 where f3a > 3) IN (SELECT f1a,f1a FROM t1) AS m +FROM t2; +m NULL NULL -SELECT (SELECT f3a, f3b FROM t3 where f3a > 3) IN (SELECT f1a, f1b FROM t1) FROM t2; -(SELECT f3a, f3b FROM t3 where f3a > 3) IN (SELECT f1a, f1b FROM t1) +SELECT +(SELECT f3a, f3b FROM t3 where f3a > 3) IN (SELECT f1a, f1b FROM t1) AS m +FROM t2; +m NULL NULL -SELECT (SELECT f3a, f3b FROM t3 where f3a > 3) IN (SELECT f1a, f1b FROM t1); -(SELECT f3a, f3b FROM t3 where f3a > 3) IN (SELECT f1a, f1b FROM t1) +SELECT +(SELECT f3a, f3b FROM t3 where f3a > 3) IN (SELECT f1a, f1b FROM t1) AS m; +m NULL set @@session.optimizer_switch=@old_optimizer_switch; -SELECT (SELECT f3a FROM t3 where f3a > 3) NOT IN (SELECT f1a FROM t1) FROM t2; -(SELECT f3a FROM t3 where f3a > 3) NOT IN (SELECT f1a FROM t1) +SELECT +(SELECT f3a FROM t3 where f3a > 3) NOT IN (SELECT f1a FROM t1) AS m +FROM t2; +m NULL NULL -SELECT (SELECT f3a,f3a FROM t3 where f3a > 3) NOT IN (SELECT f1a,f1a FROM t1) FROM t2; -(SELECT f3a,f3a FROM t3 where f3a > 3) NOT IN (SELECT f1a,f1a FROM t1) +SELECT +(SELECT f3a,f3a FROM t3 where f3a > 3) NOT IN (SELECT f1a,f1a FROM t1) AS m +FROM t2; +m NULL NULL -SELECT (SELECT f3a, f3b FROM t3 where f3a > 3) NOT IN (SELECT f1a, f1b FROM t1) FROM t2; -(SELECT f3a, f3b FROM t3 where f3a > 3) NOT IN (SELECT f1a, f1b FROM t1) +SELECT +(SELECT f3a, f3b FROM t3 where f3a > 3) NOT IN (SELECT f1a, f1b FROM t1) AS m +FROM t2; +m NULL NULL -SELECT (SELECT f3a, f3b FROM t3 where f3a > 3) NOT IN (SELECT f1a, f1b FROM t1); -(SELECT f3a, f3b FROM t3 where f3a > 3) NOT IN (SELECT f1a, f1b FROM t1) +SELECT +(SELECT f3a, f3b FROM t3 where f3a > 3) NOT IN (SELECT f1a, f1b FROM t1) AS m; +m NULL -SELECT (SELECT f3a FROM t3 where f3a > 3) IN (SELECT f1a FROM t1) FROM t2; +SELECT +(SELECT f3a FROM t3 where f3a > 3) IN (SELECT f1a FROM t1) FROM t2 AS m; (SELECT f3a FROM t3 where f3a > 3) IN (SELECT f1a FROM t1) NULL NULL -SELECT (SELECT f3a,f3a FROM t3 where f3a > 3) IN (SELECT f1a,f1a FROM t1) FROM t2; -(SELECT f3a,f3a FROM t3 where f3a > 3) IN (SELECT f1a,f1a FROM t1) +SELECT +(SELECT f3a,f3a FROM t3 where f3a > 3) IN (SELECT f1a,f1a FROM t1) AS m +FROM t2; +m NULL NULL -SELECT (SELECT f3a, f3b FROM t3 where f3a > 3) IN (SELECT f1a, f1b FROM t1) FROM t2; -(SELECT f3a, f3b FROM t3 where f3a > 3) IN (SELECT f1a, f1b FROM t1) +SELECT +(SELECT f3a, f3b FROM t3 where f3a > 3) IN (SELECT f1a, f1b FROM t1) AS m +FROM t2; +m NULL NULL -SELECT (SELECT f3a, f3b FROM t3 where f3a > 3) IN (SELECT f1a, f1b FROM t1); -(SELECT f3a, f3b FROM t3 where f3a > 3) IN (SELECT f1a, f1b FROM t1) +SELECT +(SELECT f3a, f3b FROM t3 where f3a > 3) IN (SELECT f1a, f1b FROM t1) AS m; +m NULL select (null, null) = (null, null); (null, null) = (null, null) @@ -6658,8 +6738,10 @@ INSERT INTO t2 VALUES (1); CREATE TABLE t3 ( c INT ); INSERT INTO t3 VALUES (4),(5); SET optimizer_switch='subquery_cache=off'; -SELECT ( SELECT b FROM t2 WHERE b = a OR EXISTS ( SELECT c FROM t3 WHERE c = b ) ) FROM t1; -( SELECT b FROM t2 WHERE b = a OR EXISTS ( SELECT c FROM t3 WHERE c = b ) ) +SELECT +( SELECT b FROM t2 WHERE b = a OR EXISTS ( SELECT c FROM t3 WHERE c = b ) ) AS m +FROM t1; +m 1 NULL SELECT ( SELECT b FROM t2 WHERE b = a OR b * 0) FROM t1; @@ -6876,7 +6958,9 @@ CREATE TABLE t3 (c INT); INSERT INTO t3 VALUES (8),(3); set @@expensive_subquery_limit= 0; EXPLAIN -SELECT (SELECT MIN(b) FROM t1, t2 WHERE b = a AND (b = alias1.b OR EXISTS (SELECT * FROM t3))) +SELECT +(SELECT MIN(b) FROM t1, t2 +WHERE b = a AND (b = alias1.b OR EXISTS (SELECT * FROM t3))) AS m FROM t2 alias1, t1 alias2, t1 alias3; id select_type table type possible_keys key key_len ref rows Extra 1 PRIMARY alias1 ALL NULL NULL NULL NULL 2 @@ -6886,9 +6970,11 @@ id select_type table type possible_keys key key_len ref rows Extra 2 DEPENDENT SUBQUERY t2 ALL NULL NULL NULL NULL 2 Using where; Using join buffer (flat, BNL join) 3 SUBQUERY t3 ALL NULL NULL NULL NULL 2 flush status; -SELECT (SELECT MIN(b) FROM t1, t2 WHERE b = a AND (b = alias1.b OR EXISTS (SELECT * FROM t3))) +SELECT +(SELECT MIN(b) FROM t1, t2 +WHERE b = a AND (b = alias1.b OR EXISTS (SELECT * FROM t3))) AS m FROM t2 alias1, t1 alias2, t1 alias3; -(SELECT MIN(b) FROM t1, t2 WHERE b = a AND (b = alias1.b OR EXISTS (SELECT * FROM t3))) +m NULL NULL NULL @@ -6914,7 +7000,9 @@ Handler_read_rnd_deleted 0 Handler_read_rnd_next 22 set @@expensive_subquery_limit= default; EXPLAIN -SELECT (SELECT MIN(b) FROM t1, t2 WHERE b = a AND (b = alias1.b OR EXISTS (SELECT * FROM t3))) +SELECT +(SELECT MIN(b) FROM t1, t2 +WHERE b = a AND (b = alias1.b OR EXISTS (SELECT * FROM t3))) AS m FROM t2 alias1, t1 alias2, t1 alias3; id select_type table type possible_keys key key_len ref rows Extra 1 PRIMARY alias1 ALL NULL NULL NULL NULL 2 @@ -6924,9 +7012,11 @@ id select_type table type possible_keys key key_len ref rows Extra 2 SUBQUERY t2 ALL NULL NULL NULL NULL 2 Using where; Using join buffer (flat, BNL join) 3 SUBQUERY t3 ALL NULL NULL NULL NULL 2 flush status; -SELECT (SELECT MIN(b) FROM t1, t2 WHERE b = a AND (b = alias1.b OR EXISTS (SELECT * FROM t3))) +SELECT +(SELECT MIN(b) FROM t1, t2 +WHERE b = a AND (b = alias1.b OR EXISTS (SELECT * FROM t3))) AS m FROM t2 alias1, t1 alias2, t1 alias3; -(SELECT MIN(b) FROM t1, t2 WHERE b = a AND (b = alias1.b OR EXISTS (SELECT * FROM t3))) +m NULL NULL NULL diff --git a/sql/item.cc b/sql/item.cc index ca6697422cc72..be7780cb0159f 100644 --- a/sql/item.cc +++ b/sql/item.cc @@ -5655,7 +5655,8 @@ Item_field::fix_outer_field(THD *thd, Field **from_field, Item **reference) max_arg_level for the function if it's needed. */ if (thd->lex->in_sum_func && - thd->lex == context->select_lex->parent_lex && + last_checked_context->select_lex->parent_lex == + context->select_lex->parent_lex && thd->lex->in_sum_func->nest_level >= select->nest_level) { Item::Type ref_type= (*reference)->type(); @@ -5681,7 +5682,8 @@ Item_field::fix_outer_field(THD *thd, Field **from_field, Item **reference) (Item_ident*) (*reference) : 0), false); if (thd->lex->in_sum_func && - thd->lex == context->select_lex->parent_lex && + last_checked_context->select_lex->parent_lex == + context->select_lex->parent_lex && thd->lex->in_sum_func->nest_level >= select->nest_level) { set_if_bigger(thd->lex->in_sum_func->max_arg_level, @@ -6017,7 +6019,6 @@ bool Item_field::fix_fields(THD *thd, Item **reference) if (!thd->lex->current_select->no_wrap_view_item && thd->lex->in_sum_func && - thd->lex == select->parent_lex && thd->lex->in_sum_func->nest_level == select->nest_level) set_if_bigger(thd->lex->in_sum_func->max_arg_level, @@ -8051,7 +8052,8 @@ bool Item_ref::fix_fields(THD *thd, Item **reference) max_arg_level for the function if it's needed. */ if (thd->lex->in_sum_func && - thd->lex == context->select_lex->parent_lex && + last_checked_context->select_lex->parent_lex == + context->select_lex->parent_lex && thd->lex->in_sum_func->nest_level >= last_checked_context->select_lex->nest_level) set_if_bigger(thd->lex->in_sum_func->max_arg_level, @@ -8075,7 +8077,8 @@ bool Item_ref::fix_fields(THD *thd, Item **reference) max_arg_level for the function if it's needed. */ if (thd->lex->in_sum_func && - thd->lex == context->select_lex->parent_lex && + last_checked_context->select_lex->parent_lex == + context->select_lex->parent_lex && thd->lex->in_sum_func->nest_level >= last_checked_context->select_lex->nest_level) set_if_bigger(thd->lex->in_sum_func->max_arg_level, @@ -8090,7 +8093,8 @@ bool Item_ref::fix_fields(THD *thd, Item **reference) 1. outer reference (will be fixed later by the fix_inner_refs function); 2. an unnamed reference inside an aggregate function. */ - if (!((*ref)->type() == REF_ITEM && + if (!set_properties_only && + !((*ref)->type() == REF_ITEM && ((Item_ref *)(*ref))->ref_type() == OUTER_REF) && (((*ref)->with_sum_func() && name.str && !(current_sel->get_linkage() != GLOBAL_OPTIONS_TYPE && diff --git a/sql/item_sum.cc b/sql/item_sum.cc index f80b89bc82841..9a0f08e2a181a 100644 --- a/sql/item_sum.cc +++ b/sql/item_sum.cc @@ -408,7 +408,8 @@ bool Item_sum::register_sum_func(THD *thd, Item **ref) sl= sl->master_unit()->outer_select() ) sl->master_unit()->item->get_with_sum_func_cache()->set_with_sum_func(); } - thd->lex->current_select->mark_as_dependent(thd, aggr_sel, NULL); + if (aggr_sel) + thd->lex->current_select->mark_as_dependent(thd, aggr_sel, NULL); if ((thd->lex->describe & DESCRIBE_EXTENDED) && aggr_sel) { diff --git a/sql/sql_base.cc b/sql/sql_base.cc index dd633f0bb92ec..37336a83bfb30 100644 --- a/sql/sql_base.cc +++ b/sql/sql_base.cc @@ -8016,9 +8016,8 @@ bool setup_tables(THD *thd, Name_resolution_context *context, table_list; table_list= table_list->next_local) { - if (table_list->merge_underlying_list) + if (table_list->is_merged_derived() && table_list->merge_underlying_list) { - DBUG_ASSERT(table_list->is_merged_derived()); Query_arena *arena, backup; arena= thd->activate_stmt_arena_if_needed(&backup); bool res; diff --git a/sql/sql_derived.cc b/sql/sql_derived.cc index 4dcc8a6198519..2e2327307991d 100644 --- a/sql/sql_derived.cc +++ b/sql/sql_derived.cc @@ -351,24 +351,6 @@ bool mysql_derived_merge(THD *thd, LEX *lex, TABLE_LIST *derived) DBUG_RETURN(FALSE); } - if (dt_select->uncacheable & UNCACHEABLE_RAND) - { - /* There is random function => fall back to materialization. */ - cause= "Random function in the select"; - if (unlikely(thd->trace_started())) - { - OPT_TRACE_VIEWS_TRANSFORM(thd, trace_wrapper, trace_derived, - derived->is_derived() ? "derived" : "view", - derived->alias.str ? derived->alias.str : "", - derived->get_unit()->first_select()->select_number, - "materialized"); - trace_derived.add("cause", cause); - } - derived->change_refs_to_fields(); - derived->set_materialized_derived(); - DBUG_RETURN(FALSE); - } - if (derived->dt_handler) { derived->change_refs_to_fields(); diff --git a/sql/sql_lex.cc b/sql/sql_lex.cc index 62c7556dcd642..e14d9f7a7406f 100644 --- a/sql/sql_lex.cc +++ b/sql/sql_lex.cc @@ -3284,40 +3284,45 @@ LEX::LEX() } +bool LEX::can_be_merged() +{ + return unit.can_be_merged(); +} + + /* - Check whether the merging algorithm can be used on this VIEW + Check whether the merging algorithm can be used for this unit SYNOPSIS - LEX::can_be_merged() + st_select_lex_unit::can_be_merged() DESCRIPTION - We can apply merge algorithm if it is single SELECT view with - subqueries only in WHERE clause (we do not count SELECTs of underlying - views, and second level subqueries) and we have not grpouping, ordering, - HAVING clause, aggregate functions, DISTINCT clause, LIMIT clause and - several underlying tables. + We can apply merge algorithm for a unit if it is single SELECT with + subqueries only in WHERE clauses or in ON conditions or in select list + (we do not count SELECTs of underlying views/derived tables/CTEs and + second level subqueries) and we have no grouping, ordering, HAVING + clause, aggregate functions, DISTINCT clause, LIMIT clause. RETURN FALSE - only temporary table algorithm can be used TRUE - merge algorithm can be used */ -bool LEX::can_be_merged() +bool st_select_lex_unit::can_be_merged() { // TODO: do not forget implement case when select_lex.table_list.elements==0 /* find non VIEW subqueries/unions */ - bool selects_allow_merge= (first_select_lex()->next_select() == 0 && - !(first_select_lex()->uncacheable & + bool selects_allow_merge= (first_select()->next_select() == 0 && + !(first_select()->uncacheable & UNCACHEABLE_RAND)); if (selects_allow_merge) { - for (SELECT_LEX_UNIT *tmp_unit= first_select_lex()->first_inner_unit(); + for (SELECT_LEX_UNIT *tmp_unit= first_select()->first_inner_unit(); tmp_unit; tmp_unit= tmp_unit->next_unit()) { - if (tmp_unit->first_select()->parent_lex == this && - (tmp_unit->item != 0 && + if ((tmp_unit->item != 0 && (tmp_unit->item->place() != IN_WHERE && tmp_unit->item->place() != IN_ON && tmp_unit->item->place() != SELECT_LIST))) @@ -3329,12 +3334,12 @@ bool LEX::can_be_merged() } return (selects_allow_merge && - first_select_lex()->group_list.elements == 0 && - first_select_lex()->having == 0 && - first_select_lex()->with_sum_func == 0 && - first_select_lex()->table_list.elements >= 1 && - !(first_select_lex()->options & SELECT_DISTINCT) && - first_select_lex()->select_limit == 0); + first_select()->group_list.elements == 0 && + first_select()->having == 0 && + first_select()->with_sum_func == 0 && + first_select()->table_list.elements >= 1 && + !(first_select()->options & SELECT_DISTINCT) && + first_select()->select_limit == 0); } diff --git a/sql/sql_lex.h b/sql/sql_lex.h index 8f25426a09c7b..769b17508cf64 100644 --- a/sql/sql_lex.h +++ b/sql/sql_lex.h @@ -1003,6 +1003,8 @@ class st_select_lex_unit: public st_select_lex_node { bool set_lock_to_the_last_select(Lex_select_lock l); + bool can_be_merged(); + friend class st_select_lex; }; diff --git a/sql/table.cc b/sql/table.cc index 20622d0e09fb9..d96e9248cd13d 100644 --- a/sql/table.cc +++ b/sql/table.cc @@ -6454,6 +6454,9 @@ bool TABLE_LIST::prepare_security(THD *thd) #ifndef DBUG_OFF void TABLE_LIST::set_check_merged() { + if (is_view()) + return; + DBUG_ASSERT(derived); /* It is not simple to check all, but at least this should be checked: @@ -6781,9 +6784,8 @@ void Field_iterator_table_ref::set_field_iterator() table_ref->alias.str)); } /* This is a merge view, so use field_translation. */ - else if (table_ref->field_translation) + else if (table_ref->is_merged_derived() && table_ref->field_translation) { - DBUG_ASSERT(table_ref->is_merged_derived()); field_it= &view_field_it; DBUG_PRINT("info", ("field_it for '%s' is Field_iterator_view", table_ref->alias.str)); @@ -9233,15 +9235,15 @@ bool TABLE_LIST::init_derived(THD *thd, bool init_view) set_derived(); } - if (!is_view() && + if (is_view() || !derived_table_optimization_done(this)) { /* A subquery might be forced to be materialized due to a side-effect. */ - if (!is_materialized_derived() && first_select->is_mergeable() && - optimizer_flag(thd, OPTIMIZER_SWITCH_DERIVED_MERGE) && + if (!is_materialized_derived() && unit->can_be_merged() && + (optimizer_flag(thd, OPTIMIZER_SWITCH_DERIVED_MERGE) || is_view()) && !thd->lex->can_not_use_merged() && - !(thd->lex->sql_command == SQLCOM_UPDATE_MULTI || - thd->lex->sql_command == SQLCOM_DELETE_MULTI) && + !((thd->lex->sql_command == SQLCOM_UPDATE_MULTI || + thd->lex->sql_command == SQLCOM_DELETE_MULTI) && !is_view()) && !is_recursive_with_table()) set_merged_derived(); else diff --git a/sql/table.h b/sql/table.h index 3adcc887a2c77..c4b0d78959d65 100644 --- a/sql/table.h +++ b/sql/table.h @@ -2863,8 +2863,7 @@ struct TABLE_LIST DBUG_PRINT("enter", ("Alias: '%s' Unit: %p", (alias.str ? alias.str : ""), get_unit())); - derived_type= ((derived_type & DTYPE_MASK) | - DTYPE_TABLE | DTYPE_MERGE); + derived_type= (derived_type & DTYPE_MASK) | DTYPE_MERGE; set_check_merged(); DBUG_VOID_RETURN; } @@ -2878,9 +2877,7 @@ struct TABLE_LIST DBUG_PRINT("enter", ("Alias: '%s' Unit: %p", (alias.str ? alias.str : ""), get_unit())); - derived= get_unit(); - derived_type= ((derived_type & (derived ? DTYPE_MASK : DTYPE_VIEW)) | - DTYPE_TABLE | DTYPE_MATERIALIZE); + derived_type= (derived_type & DTYPE_MASK) | DTYPE_MATERIALIZE; set_check_materialized(); DBUG_VOID_RETURN; } From 99ee200b8bc8d76469249a828b642f3a1efee2de Mon Sep 17 00:00:00 2001 From: Debjyoti Date: Thu, 2 Mar 2023 23:37:17 +0530 Subject: [PATCH 31/92] MDEV-24005 Updated the --use-memory option usage message in Mariabackup help command --- extra/mariabackup/xtrabackup.cc | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/extra/mariabackup/xtrabackup.cc b/extra/mariabackup/xtrabackup.cc index f7a5d00b92cf5..c674b3e16e1fd 100644 --- a/extra/mariabackup/xtrabackup.cc +++ b/extra/mariabackup/xtrabackup.cc @@ -1088,7 +1088,8 @@ struct my_option xb_client_options[]= { (G_PTR *) &xtrabackup_print_param, (G_PTR *) &xtrabackup_print_param, 0, GET_BOOL, NO_ARG, 0, 0, 0, 0, 0, 0}, {"use-memory", OPT_XTRA_USE_MEMORY, - "The value is used instead of buffer_pool_size", + "The value is used in place of innodb_buffer_pool_size. " + "This option is only relevant when the --prepare option is specified.", (G_PTR *) &xtrabackup_use_memory, (G_PTR *) &xtrabackup_use_memory, 0, GET_LL, REQUIRED_ARG, 100 * 1024 * 1024L, 1024 * 1024L, LONGLONG_MAX, 0, 1024 * 1024L, 0}, From 66b21ed5403aa4ef18a4c797af353ec3379b152d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marko=20M=C3=A4kel=C3=A4?= Date: Mon, 6 Mar 2023 15:32:25 +0200 Subject: [PATCH 32/92] MDEV-30567 rec_get_offsets() is not optimal rec_init_offsets_comp_ordinary(), rec_init_offsets(), rec_get_offsets_reverse(), rec_get_nth_field_offs_old(): Simplify some bitwise arithmetics to avoid conditional jumps, and add branch prediction hints with the assumption that most variable-length columns are short. Tested by: Matthias Leich --- storage/innobase/rem/rem0rec.cc | 137 ++++++++++++++------------------ 1 file changed, 60 insertions(+), 77 deletions(-) diff --git a/storage/innobase/rem/rem0rec.cc b/storage/innobase/rem/rem0rec.cc index 0868230441062..de300bf799a60 100644 --- a/storage/innobase/rem/rem0rec.cc +++ b/storage/innobase/rem/rem0rec.cc @@ -217,14 +217,12 @@ rec_get_n_extern_new( stored in one byte for 0..127. The length will be encoded in two bytes when it is 128 or more, or when the field is stored externally. */ - if (DATA_BIG_COL(col)) { - if (len & 0x80) { - /* 1exxxxxxx xxxxxxxx */ - if (len & 0x40) { - n_extern++; - } - lens--; + if (UNIV_UNLIKELY(len & 0x80) && DATA_BIG_COL(col)) { + /* 1exxxxxxx xxxxxxxx */ + if (len & 0x40) { + n_extern++; } + lens--; } } } while (++i < n); @@ -432,24 +430,21 @@ rec_init_offsets_comp_ordinary( stored in one byte for 0..127. The length will be encoded in two bytes when it is 128 or more, or when the field is stored externally. */ - if ((len & 0x80) && DATA_BIG_COL(col)) { + if (UNIV_UNLIKELY(len & 0x80) && DATA_BIG_COL(col)) { /* 1exxxxxxx xxxxxxxx */ len <<= 8; len |= *lens--; - + static_assert(STORED_OFFPAGE == 0x4000, ""); + static_assert(REC_OFFS_EXTERNAL == 0x4000, ""); + const rec_offs ext = len & REC_OFFS_EXTERNAL; offs += get_value(len); - if (UNIV_UNLIKELY(len & 0x4000)) { - ut_ad(dict_index_is_clust(index)); - any |= REC_OFFS_EXTERNAL; - len = combine(offs, STORED_OFFPAGE); - } else { - len = offs; - } - + len = offs | ext; + any |= ext; + ut_ad(!ext || index->is_primary()); continue; } - len = offs += len; + len = offs += static_cast(len); } else { len = offs += field->fixed_len; } @@ -714,23 +709,20 @@ rec_init_offsets( encoded in two bytes when it is 128 or more, or when the field is stored externally. */ - if (DATA_BIG_COL(col)) { - if (len & 0x80) { - /* 1exxxxxxx xxxxxxxx */ - - len <<= 8; - len |= *lens--; - - /* B-tree node pointers - must not contain externally - stored columns. Thus - the "e" flag must be 0. */ - ut_a(!(len & 0x4000)); - offs += get_value(len); - len = offs; - - goto resolved; - } + if (UNIV_UNLIKELY(len & 0x80) + && DATA_BIG_COL(col)) { + /* 1exxxxxxx xxxxxxxx */ + len <<= 8; + len |= *lens--; + + /* B-tree node pointers + must not contain externally + stored columns. Thus + the "e" flag must be 0. */ + ut_a(!(len & 0x4000)); + offs += len & 0x3fff; + len = offs; + goto resolved; } len = offs += len; @@ -758,26 +750,24 @@ rec_init_offsets( do { offs = rec_1_get_field_end_info(rec, i); if (offs & REC_1BYTE_SQL_NULL_MASK) { - offs &= ~REC_1BYTE_SQL_NULL_MASK; - set_type(offs, SQL_NULL); + offs ^= REC_1BYTE_SQL_NULL_MASK + | SQL_NULL; } rec_offs_base(offsets)[1 + i] = offs; } while (++i < n); } else { - offs += 2 * static_cast(n_fields); + offs += static_cast(2 * n_fields); any = offs; /* Determine offsets to fields */ do { offs = rec_2_get_field_end_info(rec, i); - if (offs & REC_2BYTE_SQL_NULL_MASK) { - offs &= ~REC_2BYTE_SQL_NULL_MASK; - set_type(offs, SQL_NULL); - } - if (offs & REC_2BYTE_EXTERN_MASK) { - offs &= ~REC_2BYTE_EXTERN_MASK; - set_type(offs, STORED_OFFPAGE); - any |= REC_OFFS_EXTERNAL; - } + static_assert(REC_2BYTE_SQL_NULL_MASK + == SQL_NULL, ""); + static_assert(REC_2BYTE_EXTERN_MASK + == STORED_OFFPAGE, ""); + static_assert(REC_OFFS_EXTERNAL + == STORED_OFFPAGE, ""); + any |= (offs & REC_OFFS_EXTERNAL); rec_offs_base(offsets)[1 + i] = offs; } while (++i < n); } @@ -1028,23 +1018,18 @@ rec_get_offsets_reverse( stored in one byte for 0..127. The length will be encoded in two bytes when it is 128 or more, or when the field is stored externally. */ - if (DATA_BIG_COL(col)) { - if (len & 0x80) { - /* 1exxxxxxx xxxxxxxx */ - len <<= 8; - len |= *lens++; - - offs += get_value(len); - if (UNIV_UNLIKELY(len & 0x4000)) { - any_ext = REC_OFFS_EXTERNAL; - len = combine(offs, - STORED_OFFPAGE); - } else { - len = offs; - } - - goto resolved; - } + if (UNIV_UNLIKELY(len & 0x80) && DATA_BIG_COL(col)) { + /* 1exxxxxxx xxxxxxxx */ + len &= 0x7f; + len <<= 8; + len |= *lens++; + static_assert(STORED_OFFPAGE == 0x4000, ""); + static_assert(REC_OFFS_EXTERNAL == 0x4000, ""); + rec_offs ext = len & REC_OFFS_EXTERNAL; + offs += get_value(len); + len = offs | ext; + any_ext |= ext; + goto resolved; } len = offs += len; @@ -1089,7 +1074,7 @@ rec_get_nth_field_offs_old( return(os); } - next_os = next_os & ~REC_1BYTE_SQL_NULL_MASK; + next_os &= ~REC_1BYTE_SQL_NULL_MASK; } else { os = rec_2_get_field_start_offs(rec, n); @@ -1101,8 +1086,7 @@ rec_get_nth_field_offs_old( return(os); } - next_os = next_os & ~(REC_2BYTE_SQL_NULL_MASK - | REC_2BYTE_EXTERN_MASK); + next_os &= ~(REC_2BYTE_SQL_NULL_MASK | REC_2BYTE_EXTERN_MASK); } *len = next_os - os; @@ -1255,7 +1239,8 @@ rec_get_converted_size_comp_prefix_low( } else if (dfield_is_ext(dfield)) { ut_ad(DATA_BIG_COL(field->col)); extra_size += 2; - } else if (len < 128 || !DATA_BIG_COL(field->col)) { + } else if (UNIV_LIKELY(len < 128) + || !DATA_BIG_COL(field->col)) { extra_size++; } else { /* For variable-length columns, we look up the @@ -1652,7 +1637,7 @@ rec_convert_dtuple_to_rec_comp( /* set the null flag if necessary */ if (dfield_is_null(field)) { - *nulls |= null_mask; + *nulls |= static_cast(null_mask); null_mask <<= 1; continue; } @@ -2122,14 +2107,12 @@ rec_copy_prefix_to_buf( stored in one byte for 0..127. The length will be encoded in two bytes when it is 128 or more, or when the column is stored externally. */ - if (DATA_BIG_COL(col)) { - if (len & 0x80) { - /* 1exxxxxx */ - len &= 0x3f; - len <<= 8; - len |= *lens--; - UNIV_PREFETCH_R(lens); - } + if (UNIV_UNLIKELY(len & 0x80) && DATA_BIG_COL(col)) { + /* 1exxxxxx */ + len &= 0x3f; + len <<= 8; + len |= *lens--; + UNIV_PREFETCH_R(lens); } prefix_len += len; } From 46a7e96339d166fee60f80f03a8cf9281b42aa32 Mon Sep 17 00:00:00 2001 From: Julius Goryavsky Date: Thu, 2 Mar 2023 14:21:59 +0100 Subject: [PATCH 33/92] move alloca() definition from all *.h files to one new header file --- include/CMakeLists.txt | 2 + include/my_alloca.h | 45 +++++++++++++++++++ include/my_global.h | 8 +--- include/my_sys.h | 14 +----- include/mysql/service_encryption.h | 11 ++--- .../cracklib_password_check.c | 2 +- .../handlersocket/hstcpsvr_worker.cpp | 5 +-- .../handler_socket/libhsclient/allocator.hpp | 1 + 8 files changed, 56 insertions(+), 32 deletions(-) create mode 100644 include/my_alloca.h diff --git a/include/CMakeLists.txt b/include/CMakeLists.txt index 9a3f820e62f12..fe02098621e82 100644 --- a/include/CMakeLists.txt +++ b/include/CMakeLists.txt @@ -37,6 +37,7 @@ SET(HEADERS ma_dyncol.h my_list.h my_alloc.h + my_alloca.h typelib.h my_dbug.h m_string.h @@ -105,6 +106,7 @@ ENDMACRO() INSTALL_COMPAT_HEADER(my_global.h "") INSTALL_COMPAT_HEADER(my_config.h "") +INSTALL_COMPAT_HEADER(my_alloca.h "") INSTALL_COMPAT_HEADER(my_sys.h "") INSTALL_COMPAT_HEADER(mysql_version.h " #include diff --git a/include/my_alloca.h b/include/my_alloca.h new file mode 100644 index 0000000000000..761c2adb89046 --- /dev/null +++ b/include/my_alloca.h @@ -0,0 +1,45 @@ +/* Copyright (c) 2023, 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 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 Street, Fifth Floor, Boston, MA 02110-1335 USA */ + +#ifndef MY_ALLOCA_INCLUDED +#define MY_ALLOCA_INCLUDED + +#ifdef _WIN32 +#include /*for alloca*/ +/* + MSVC may define "alloca" when compiling in /Ze mode + (with extensions from Microsoft), but otherwise only + the _alloca function is defined: +*/ +#ifndef alloca +#define alloca _alloca +#endif +#else +#ifdef HAVE_ALLOCA_H +#include +#endif +#endif + +#if defined(HAVE_ALLOCA) +/* + If the GCC/LLVM compiler from the MinGW is used, + alloca may not be defined when using the MSVC CRT: +*/ +#if defined(__GNUC__) && !defined(HAVE_ALLOCA_H) && !defined(alloca) +#define alloca __builtin_alloca +#endif /* GNUC */ +#endif + +#endif /* MY_ALLOCA_INCLUDED */ diff --git a/include/my_global.h b/include/my_global.h index 1e1821e2f2589..8cf06ddcb1e24 100644 --- a/include/my_global.h +++ b/include/my_global.h @@ -358,13 +358,6 @@ C_MODE_END #ifdef HAVE_UNISTD_H #include #endif -#if defined(__cplusplus) && defined(NO_CPLUSPLUS_ALLOCA) -#undef HAVE_ALLOCA -#undef HAVE_ALLOCA_H -#endif -#ifdef HAVE_ALLOCA_H -#include -#endif #include /* Recommended by debian */ /* We need the following to go around a problem with openssl on solaris */ @@ -521,6 +514,7 @@ typedef unsigned short ushort; #endif #include +#include /* Wen using the embedded library, users might run into link problems, diff --git a/include/my_sys.h b/include/my_sys.h index 91610f15a5001..87df04c60873f 100644 --- a/include/my_sys.h +++ b/include/my_sys.h @@ -36,9 +36,7 @@ typedef struct my_aio_result { #include /* for CHARSET_INFO */ #include #include -#ifdef _WIN32 -#include /*for alloca*/ -#endif +#include #include #include @@ -196,16 +194,6 @@ my_bool my_test_if_atomic_write(File handle, int pagesize); extern my_bool my_may_have_atomic_write; #if defined(HAVE_ALLOCA) && !defined(HAVE_valgrind) -#if defined(_AIX) && !defined(__GNUC__) && !defined(_AIX43) -#pragma alloca -#endif /* _AIX */ -#if defined(__MWERKS__) -#undef alloca -#define alloca _alloca -#endif /* __MWERKS__ */ -#if defined(__GNUC__) && !defined(HAVE_ALLOCA_H) && ! defined(alloca) -#define alloca __builtin_alloca -#endif /* GNUC */ #define my_alloca(SZ) alloca((size_t) (SZ)) #define my_afree(PTR) ((void)0) #define MAX_ALLOCA_SZ 4096 diff --git a/include/mysql/service_encryption.h b/include/mysql/service_encryption.h index 69d205a27e8e8..280b9c69e3562 100644 --- a/include/mysql/service_encryption.h +++ b/include/mysql/service_encryption.h @@ -24,22 +24,19 @@ *provider* (encryption plugin). */ -#ifdef __cplusplus -extern "C" { -#endif - #ifndef MYSQL_ABI_CHECK +#include #ifdef _WIN32 -#include #ifndef __cplusplus #define inline __inline #endif #else #include -#ifdef HAVE_ALLOCA_H -#include #endif #endif + +#ifdef __cplusplus +extern "C" { #endif /* returned from encryption_key_get_latest_version() */ diff --git a/plugin/cracklib_password_check/cracklib_password_check.c b/plugin/cracklib_password_check/cracklib_password_check.c index 470e6e5280f71..5a7c7f3f234c4 100644 --- a/plugin/cracklib_password_check/cracklib_password_check.c +++ b/plugin/cracklib_password_check/cracklib_password_check.c @@ -13,7 +13,7 @@ along with this program; if not, write to the Free Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1335 USA */ -#include +#include #include #include #include diff --git a/plugin/handler_socket/handlersocket/hstcpsvr_worker.cpp b/plugin/handler_socket/handlersocket/hstcpsvr_worker.cpp index 9863602af7a9e..f6bbe9004c2ea 100644 --- a/plugin/handler_socket/handlersocket/hstcpsvr_worker.cpp +++ b/plugin/handler_socket/handlersocket/hstcpsvr_worker.cpp @@ -6,7 +6,7 @@ * See COPYRIGHT.txt for details. */ -#include +#include #include #include #include @@ -17,9 +17,6 @@ #if __linux__ #include #endif -#ifdef HAVE_ALLOCA_H -#include -#endif #include "hstcpsvr_worker.hpp" #include "string_buffer.hpp" diff --git a/plugin/handler_socket/libhsclient/allocator.hpp b/plugin/handler_socket/libhsclient/allocator.hpp index dd3a28ba7bdca..9df6a1ab75243 100644 --- a/plugin/handler_socket/libhsclient/allocator.hpp +++ b/plugin/handler_socket/libhsclient/allocator.hpp @@ -11,6 +11,7 @@ #include #include +#include #if 0 extern "C" { From e240e2749eeaadc594b05dc600440f316d50eaee Mon Sep 17 00:00:00 2001 From: kevincheng2 Date: Fri, 3 Mar 2023 17:33:07 -0800 Subject: [PATCH 34/92] MDEV-30758 mariabackup --help only lists server groups read in configuration --- extra/mariabackup/xtrabackup.cc | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/extra/mariabackup/xtrabackup.cc b/extra/mariabackup/xtrabackup.cc index c674b3e16e1fd..d2ce3395da8fe 100644 --- a/extra/mariabackup/xtrabackup.cc +++ b/extra/mariabackup/xtrabackup.cc @@ -1817,6 +1817,12 @@ static void print_version(void) my_progname, MYSQL_SERVER_VERSION, SYSTEM_TYPE, MACHINE_TYPE); } +static void concatenate_default_groups(std::vector &backup_load_groups, const char **default_groups) +{ + for ( ; *default_groups ; default_groups++) + backup_load_groups.push_back(*default_groups); +} + static void usage(void) { puts("Open source backup tool for InnoDB and XtraDB\n\ @@ -1837,7 +1843,11 @@ GNU General Public License for more details.\n\ You can download full text of the license on http://www.gnu.org/licenses/gpl-2.0.txt\n"); printf("Usage: %s [--defaults-file=#] [--backup | --prepare | --copy-back | --move-back] [OPTIONS]\n",my_progname); - print_defaults("my", load_default_groups); + std::vector backup_load_default_groups; + concatenate_default_groups(backup_load_default_groups, backup_default_groups); + concatenate_default_groups(backup_load_default_groups, load_default_groups); + backup_load_default_groups.push_back(nullptr); + print_defaults("my", &backup_load_default_groups[0]); my_print_help(xb_client_options); my_print_help(xb_server_options); my_print_variables(xb_server_options); From 8b0f766c6c65a4c4260876688090e2b390014a60 Mon Sep 17 00:00:00 2001 From: Christian Gonzalez Date: Thu, 23 Feb 2023 22:43:14 +0000 Subject: [PATCH 35/92] Minimize unsafe C functions usage Replace calls to `sprintf` and `strcpy` by the safer options `snprintf` and `safe_strcpy` in the following directories: - libmysqld - mysys - sql-common - strings All new code of the whole pull request, including one or several files that are either new files or modified ones, are contributed under the BSD-new license. I am contributing on behalf of my employer Amazon Web Services, Inc. --- libmysqld/libmysql.c | 10 +++++++--- mysys/my_atomic_writes.c | 16 ++++++++++------ mysys/my_conio.c | 2 +- mysys/my_likely.c | 2 +- mysys/my_thr_init.c | 2 +- sql-common/client.c | 2 +- strings/conf_to_src.c | 4 ++-- strings/uctypedump.c | 4 ++-- strings/xml.c | 16 ++++++++-------- 9 files changed, 33 insertions(+), 25 deletions(-) diff --git a/libmysqld/libmysql.c b/libmysqld/libmysql.c index 1ebcae0d8d5e0..b9293d8477133 100644 --- a/libmysqld/libmysql.c +++ b/libmysqld/libmysql.c @@ -2914,7 +2914,8 @@ my_bool STDCALL mysql_stmt_bind_param(MYSQL_STMT *stmt, MYSQL_BIND *my_bind) break; default: strmov(stmt->sqlstate, unknown_sqlstate); - sprintf(stmt->last_error, + snprintf(stmt->last_error, + sizeof(stmt->last_error), ER(stmt->last_errno= CR_UNSUPPORTED_PARAM_TYPE), param->buffer_type, count); DBUG_RETURN(1); @@ -3001,7 +3002,9 @@ mysql_stmt_send_long_data(MYSQL_STMT *stmt, uint param_number, { /* Long data handling should be used only for string/binary types */ strmov(stmt->sqlstate, unknown_sqlstate); - sprintf(stmt->last_error, ER(stmt->last_errno= CR_INVALID_BUFFER_USE), + snprintf(stmt->last_error, + sizeof(stmt->last_error), + ER(stmt->last_errno= CR_INVALID_BUFFER_USE), param->param_number); DBUG_RETURN(1); } @@ -4130,7 +4133,8 @@ my_bool STDCALL mysql_stmt_bind_result(MYSQL_STMT *stmt, MYSQL_BIND *my_bind) if (setup_one_fetch_function(param, field)) { strmov(stmt->sqlstate, unknown_sqlstate); - sprintf(stmt->last_error, + snprintf(stmt->last_error, + sizeof(stmt->last_error), ER(stmt->last_errno= CR_UNSUPPORTED_PARAM_TYPE), field->type, param_count); DBUG_RETURN(1); diff --git a/mysys/my_atomic_writes.c b/mysys/my_atomic_writes.c index b383af11ba8d4..357448d10d23b 100644 --- a/mysys/my_atomic_writes.c +++ b/mysys/my_atomic_writes.c @@ -112,7 +112,7 @@ static my_bool test_if_shannon_card_exists() char path[32]; struct stat stat_buff; - sprintf(path, "/dev/df%c", dev_part); + snprintf(path, sizeof(path), "/dev/df%c", dev_part); #ifdef TEST_SHANNON if (lstat(path, &stat_buff) < 0) { @@ -121,8 +121,10 @@ static my_bool test_if_shannon_card_exists() } #endif shannon_devices[shannon_found_devices].st_dev= stat_buff.st_rdev; - sprintf(shannon_devices[shannon_found_devices].dev_name, "/dev/sct%c", - dev_part); + snprintf(shannon_devices[shannon_found_devices].dev_name, + sizeof(shannon_devices[shannon_found_devices].dev_name), + "/dev/sct%c", + dev_part); #ifdef TEST_SHANNON printf("%s(): i=%d, stat_buff.st_dev=0x%lx, stat_buff.st_rdev=0x%lx, st_rdev=0x%lx, dev_name=%s\n", @@ -145,13 +147,15 @@ static my_bool test_if_shannon_card_exists() for (dev_no= 1 ; dev_no < 9 ; dev_no++) { - sprintf(path, "/dev/df%c%d", dev_part, dev_no); + snprintf(path, sizeof(path), "/dev/df%c%d", dev_part, dev_no); if (lstat(path, &stat_buff) < 0) break; shannon_devices[shannon_found_devices].st_dev= stat_buff.st_rdev; - sprintf(shannon_devices[shannon_found_devices].dev_name, "/dev/sct%c%d", - dev_part, dev_no); + snprintf(shannon_devices[shannon_found_devices].dev_name, + sizeof(shannon_devices[shannon_found_devices].dev_name), + "/dev/sct%c%d", + dev_part, dev_no); #ifdef TEST_SHANNON printf("%s(): i=%d, st_dev=0x%lx, st_rdev=0x%lx, dev_name=%s\n", diff --git a/mysys/my_conio.c b/mysys/my_conio.c index 04750635dd3d2..ec30b9dc6c74f 100644 --- a/mysys/my_conio.c +++ b/mysys/my_conio.c @@ -50,7 +50,7 @@ int my_pthread_auto_mutex_lock(HANDLE* ph, const char* name, int id, int time) DWORD res; char tname[FN_REFLEN]; - sprintf(tname, "%s-%08X", name, id); + snprintf(tname, sizeof(tname), "%s-%08X", name, id); *ph= CreateMutex(NULL, FALSE, tname); if (*ph == NULL) diff --git a/mysys/my_likely.c b/mysys/my_likely.c index c6fca5b71462a..b63e5f4211e20 100644 --- a/mysys/my_likely.c +++ b/mysys/my_likely.c @@ -77,7 +77,7 @@ void end_my_likely(FILE *out) if (!(likely_file= out)) { char name[80]; - sprintf(name, "/tmp/unlikely-%lu.out", (ulong) getpid()); + snprintf(name, sizeof(name), "/tmp/unlikely-%lu.out", (ulong) getpid()); if ((likely_file= my_fopen(name, O_TRUNC | O_WRONLY, MYF(MY_WME)))) do_close= 1; else diff --git a/mysys/my_thr_init.c b/mysys/my_thr_init.c index 66c2543c51db7..57ac2d228fb48 100644 --- a/mysys/my_thr_init.c +++ b/mysys/my_thr_init.c @@ -426,7 +426,7 @@ const char *my_thread_name(void) if (!tmp->name[0]) { my_thread_id id= my_thread_dbug_id(); - sprintf(name_buff,"T@%lu", (ulong) id); + snprintf(name_buff, sizeof(name_buff), "T@%lu", (ulong) id); strmake_buf(tmp->name, name_buff); } return tmp->name; diff --git a/sql-common/client.c b/sql-common/client.c index 89de45cfcfc15..a1bdbebf6393a 100644 --- a/sql-common/client.c +++ b/sql-common/client.c @@ -4164,7 +4164,7 @@ int STDCALL mysql_set_character_set(MYSQL *mysql, const char *cs_name) /* Skip execution of "SET NAMES" for pre-4.1 servers */ if (mysql_get_server_version(mysql) < 40100) return 0; - sprintf(buff, "SET NAMES %s", cs_name); + snprintf(buff, sizeof(buff), "SET NAMES %s", cs_name); if (!mysql_real_query(mysql, buff, (uint) strlen(buff))) { mysql->charset= cs; diff --git a/strings/conf_to_src.c b/strings/conf_to_src.c index 4a3b035aa4933..efb708db8f6a8 100644 --- a/strings/conf_to_src.c +++ b/strings/conf_to_src.c @@ -459,7 +459,7 @@ main(int argc, char **argv __attribute__((unused))) bzero((void*)&all_charsets,sizeof(all_charsets)); bzero((void*) refids, sizeof(refids)); - sprintf(filename,"%s/%s",argv[1],"Index.xml"); + snprintf(filename,sizeof(filename),"%s/%s",argv[1],"Index.xml"); my_read_charset_file(filename); for (cs= all_charsets; @@ -470,7 +470,7 @@ main(int argc, char **argv __attribute__((unused))) { if ( (!simple_cs_is_full(cs)) && (cs->csname)) { - sprintf(filename,"%s/%s.xml",argv[1],cs->csname); + snprintf(filename,sizeof(filename),"%s/%s.xml",argv[1],cs->csname); my_read_charset_file(filename); } cs->state|= MY_CS_LOADED; diff --git a/strings/uctypedump.c b/strings/uctypedump.c index 30ae33afee15b..397b6e586f1ac 100644 --- a/strings/uctypedump.c +++ b/strings/uctypedump.c @@ -120,7 +120,7 @@ int main(int ac, char ** av) } else { - strcpy(tok,s); + safe_strcpy(tok, sizeof(tok), s); } end=tok+strlen(tok); @@ -225,7 +225,7 @@ int main(int ac, char ** av) { char plane_name[128]="NULL"; if(uctype[plane].ctype){ - sprintf(plane_name,"uctype_page%02X",(uint) plane); + snprintf(plane_name,sizeof(plane_name),"uctype_page%02X",(uint) plane); } printf("\t{%d,%s}%s\n",uctype[plane].pctype,plane_name,plane<255?",":""); } diff --git a/strings/xml.c b/strings/xml.c index 0178ea2574e8f..c9df9491abab8 100644 --- a/strings/xml.c +++ b/strings/xml.c @@ -304,10 +304,10 @@ static int my_xml_leave(MY_XML_PARSER *p, const char *str, size_t slen) if (glen) { mstr(g, tag, sizeof(g)-1, glen); - sprintf(p->errstr,"'' unexpected ('' wanted)",s,g); + snprintf(p->errstr,sizeof(p->errstr),"'' unexpected ('' wanted)",s,g); } else - sprintf(p->errstr,"'' unexpected (END-OF-INPUT wanted)", s); + snprintf(p->errstr,sizeof(p->errstr),"'' unexpected (END-OF-INPUT wanted)", s); return MY_XML_ERROR; } @@ -362,7 +362,7 @@ int my_xml_parse(MY_XML_PARSER *p,const char *str, size_t len) { if (MY_XML_IDENT != (lex=my_xml_scan(p,&a))) { - sprintf(p->errstr,"%s unexpected (ident wanted)",lex2str(lex)); + snprintf(p->errstr,sizeof(p->errstr),"%s unexpected (ident wanted)",lex2str(lex)); return MY_XML_ERROR; } if (MY_XML_OK != my_xml_leave(p,a.beg,(size_t) (a.end-a.beg))) @@ -390,7 +390,7 @@ int my_xml_parse(MY_XML_PARSER *p,const char *str, size_t len) } else { - sprintf(p->errstr,"%s unexpected (ident or '/' wanted)", + snprintf(p->errstr,sizeof(p->errstr),"%s unexpected (ident or '/' wanted)", lex2str(lex)); return MY_XML_ERROR; } @@ -412,7 +412,7 @@ int my_xml_parse(MY_XML_PARSER *p,const char *str, size_t len) } else { - sprintf(p->errstr,"%s unexpected (ident or string wanted)", + snprintf(p->errstr,sizeof(p->errstr),"%s unexpected (ident or string wanted)", lex2str(lex)); return MY_XML_ERROR; } @@ -449,7 +449,7 @@ int my_xml_parse(MY_XML_PARSER *p,const char *str, size_t len) { if (lex != MY_XML_QUESTION) { - sprintf(p->errstr,"%s unexpected ('?' wanted)",lex2str(lex)); + snprintf(p->errstr,sizeof(p->errstr),"%s unexpected ('?' wanted)",lex2str(lex)); return MY_XML_ERROR; } if (MY_XML_OK != my_xml_leave(p,NULL,0)) @@ -465,7 +465,7 @@ int my_xml_parse(MY_XML_PARSER *p,const char *str, size_t len) if (lex != MY_XML_GT) { - sprintf(p->errstr,"%s unexpected ('>' wanted)",lex2str(lex)); + snprintf(p->errstr,sizeof(p->errstr),"%s unexpected ('>' wanted)",lex2str(lex)); return MY_XML_ERROR; } } @@ -486,7 +486,7 @@ int my_xml_parse(MY_XML_PARSER *p,const char *str, size_t len) if (p->attr.start[0]) { - sprintf(p->errstr,"unexpected END-OF-INPUT"); + snprintf(p->errstr,sizeof(p->errstr),"unexpected END-OF-INPUT"); return MY_XML_ERROR; } return MY_XML_OK; From fb8c1762ad6100134c3ac00c1f47469d5bb42794 Mon Sep 17 00:00:00 2001 From: Monty Date: Sun, 7 Feb 2021 21:11:53 +0200 Subject: [PATCH 36/92] Ensure that mysqlbinlog frees all memory at exit --- client/mysqlbinlog.cc | 37 +++++++++++++++++++++++-------------- 1 file changed, 23 insertions(+), 14 deletions(-) diff --git a/client/mysqlbinlog.cc b/client/mysqlbinlog.cc index 2810892253846..213fb29e2fdc0 100644 --- a/client/mysqlbinlog.cc +++ b/client/mysqlbinlog.cc @@ -89,6 +89,7 @@ static uint opt_protocol= 0; static FILE *result_file; static char *result_file_name= 0; static const char *output_prefix= ""; +static char **defaults_argv= 0; #ifndef DBUG_OFF static const char *default_dbug_option = "d:t:o,/tmp/mysqlbinlog.trace"; @@ -1881,13 +1882,26 @@ static void cleanup() delete glob_description_event; if (mysql) mysql_close(mysql); + free_defaults(defaults_argv); + free_annotate_event(); + my_free_open_file_info(); + load_processor.destroy(); + mysql_server_end(); DBUG_VOID_RETURN; } +static void die() +{ + cleanup(); + my_end(MY_DONT_FREE_DBUG); + exit(1); +} + + static void print_version() { - printf("%s Ver 3.4 for %s at %s\n", my_progname, SYSTEM_TYPE, MACHINE_TYPE); + printf("%s Ver 3.5 for %s at %s\n", my_progname, SYSTEM_TYPE, MACHINE_TYPE); } @@ -1918,7 +1932,7 @@ static my_time_t convert_str_to_timestamp(const char* str) l_time.time_type != MYSQL_TIMESTAMP_DATETIME || status.warnings) { error("Incorrect date and time argument: %s", str); - exit(1); + die(); } /* Note that Feb 30th, Apr 31st cause no error messages and are mapped to @@ -1977,7 +1991,7 @@ get_one_option(int optid, const struct my_option *opt __attribute__((unused)), opt->name)) <= 0) { sf_leaking_memory= 1; /* no memory leak reports here */ - exit(1); + die(); } break; #ifdef WHEN_FLASHBACK_REVIEW_READY @@ -2002,7 +2016,7 @@ get_one_option(int optid, const struct my_option *opt __attribute__((unused)), opt->name)) <= 0) { sf_leaking_memory= 1; /* no memory leak reports here */ - exit(1); + die(); } opt_base64_output_mode= (enum_base64_output_mode) (val - 1); } @@ -2087,7 +2101,9 @@ static int parse_args(int *argc, char*** argv) int ho_error; if ((ho_error=handle_options(argc, argv, my_options, get_one_option))) - exit(ho_error); + { + die(); + } if (debug_info_flag) my_end_arg= MY_CHECK_ERROR | MY_GIVE_INFO; else if (debug_check_flag) @@ -3007,7 +3023,6 @@ static Exit_status dump_local_log_entries(PRINT_EVENT_INFO *print_event_info, int main(int argc, char** argv) { - char **defaults_argv; Exit_status retval= OK_CONTINUE; ulonglong save_stop_position; MY_INIT(argv[0]); @@ -3058,7 +3073,7 @@ int main(int argc, char** argv) if (!remote_opt) { error("The --raw mode only works with --read-from-remote-server"); - exit(1); + die(); } if (one_database) warning("The --database option is ignored in raw mode"); @@ -3080,7 +3095,7 @@ int main(int argc, char** argv) O_WRONLY | O_BINARY, MYF(MY_WME)))) { error("Could not create log file '%s'", result_file_name); - exit(1); + die(); } } else @@ -3201,11 +3216,6 @@ int main(int argc, char** argv) if (result_file && result_file != stdout) my_fclose(result_file, MYF(0)); cleanup(); - free_annotate_event(); - free_defaults(defaults_argv); - my_free_open_file_info(); - load_processor.destroy(); - mysql_server_end(); /* We cannot free DBUG, it is used in global destructors after exit(). */ my_end(my_end_arg | MY_DONT_FREE_DBUG); @@ -3215,7 +3225,6 @@ int main(int argc, char** argv) err: cleanup(); - free_defaults(defaults_argv); my_end(my_end_arg); exit(retval == ERROR_STOP ? 1 : 0); DBUG_RETURN(retval == ERROR_STOP ? 1 : 0); From f0ab1a28c99f0ac1694f5abe433f958470f51031 Mon Sep 17 00:00:00 2001 From: Anel Husakovic Date: Mon, 20 Feb 2023 14:10:53 +0100 Subject: [PATCH 37/92] MDEV-30697: Memory leak detected when mariadb-binlog is used with option flashback --- client/mysqlbinlog.cc | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/client/mysqlbinlog.cc b/client/mysqlbinlog.cc index 213fb29e2fdc0..fb70ff62d63e8 100644 --- a/client/mysqlbinlog.cc +++ b/client/mysqlbinlog.cc @@ -1887,6 +1887,11 @@ static void cleanup() my_free_open_file_info(); load_processor.destroy(); mysql_server_end(); + if (opt_flashback) + { + delete_dynamic(&binlog_events); + delete_dynamic(&events_in_stmt); + } DBUG_VOID_RETURN; } From 7300ab32cc7fe3865c059d3bce57dc63a32dff13 Mon Sep 17 00:00:00 2001 From: Anel Husakovic Date: Thu, 2 Mar 2023 12:05:36 +0100 Subject: [PATCH 38/92] Update handling of mysqlbinlog's `die()` function - Update per Monty's review for commit 5328dbdaa237d97e443120f2e08437fb274198c2 --- client/mysqlbinlog.cc | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/client/mysqlbinlog.cc b/client/mysqlbinlog.cc index fb70ff62d63e8..8770b3651ccd0 100644 --- a/client/mysqlbinlog.cc +++ b/client/mysqlbinlog.cc @@ -1896,11 +1896,11 @@ static void cleanup() } -static void die() +static void die(int err) { cleanup(); - my_end(MY_DONT_FREE_DBUG); - exit(1); + my_end(0); + exit(err); } @@ -1937,7 +1937,7 @@ static my_time_t convert_str_to_timestamp(const char* str) l_time.time_type != MYSQL_TIMESTAMP_DATETIME || status.warnings) { error("Incorrect date and time argument: %s", str); - die(); + die(1); } /* Note that Feb 30th, Apr 31st cause no error messages and are mapped to @@ -1996,7 +1996,7 @@ get_one_option(int optid, const struct my_option *opt __attribute__((unused)), opt->name)) <= 0) { sf_leaking_memory= 1; /* no memory leak reports here */ - die(); + die(1); } break; #ifdef WHEN_FLASHBACK_REVIEW_READY @@ -2021,7 +2021,7 @@ get_one_option(int optid, const struct my_option *opt __attribute__((unused)), opt->name)) <= 0) { sf_leaking_memory= 1; /* no memory leak reports here */ - die(); + die(1); } opt_base64_output_mode= (enum_base64_output_mode) (val - 1); } @@ -2107,7 +2107,7 @@ static int parse_args(int *argc, char*** argv) if ((ho_error=handle_options(argc, argv, my_options, get_one_option))) { - die(); + die(ho_error); } if (debug_info_flag) my_end_arg= MY_CHECK_ERROR | MY_GIVE_INFO; @@ -3078,7 +3078,7 @@ int main(int argc, char** argv) if (!remote_opt) { error("The --raw mode only works with --read-from-remote-server"); - die(); + die(1); } if (one_database) warning("The --database option is ignored in raw mode"); @@ -3100,7 +3100,7 @@ int main(int argc, char** argv) O_WRONLY | O_BINARY, MYF(MY_WME)))) { error("Could not create log file '%s'", result_file_name); - die(); + die(1); } } else From 2f6bb9cda57e2ddbfffc5bdad00dfb352dab1313 Mon Sep 17 00:00:00 2001 From: Anel Husakovic Date: Mon, 20 Feb 2023 14:11:13 +0100 Subject: [PATCH 39/92] MDEV-30698 Cover missing test cases for mariadb-binlog options --raw [and] --flashback - Adding test case for --raw without -R - Adding unsuported combination of --raw and --flashback parameters and covered with test case --- client/mysqlbinlog.cc | 6 ++++++ .../suite/binlog/r/binlog_mysqlbinlog_raw_flush.result | 4 ++++ mysql-test/suite/binlog/r/flashback.result | 4 ++++ .../suite/binlog/t/binlog_mysqlbinlog_raw_flush.test | 9 +++++++++ mysql-test/suite/binlog/t/flashback.test | 8 ++++++++ 5 files changed, 31 insertions(+) diff --git a/client/mysqlbinlog.cc b/client/mysqlbinlog.cc index 8770b3651ccd0..ec0cae5328ca4 100644 --- a/client/mysqlbinlog.cc +++ b/client/mysqlbinlog.cc @@ -3063,6 +3063,12 @@ int main(int argc, char** argv) my_set_max_open_files(open_files_limit); + if (opt_flashback && opt_raw_mode) + { + error("The --raw mode is not allowed with --flashback mode"); + die(1); + } + if (opt_flashback) { my_init_dynamic_array(&binlog_events, sizeof(LEX_STRING), 1024, 1024, diff --git a/mysql-test/suite/binlog/r/binlog_mysqlbinlog_raw_flush.result b/mysql-test/suite/binlog/r/binlog_mysqlbinlog_raw_flush.result index 9148f0e8c2b98..294e96e59971a 100644 --- a/mysql-test/suite/binlog/r/binlog_mysqlbinlog_raw_flush.result +++ b/mysql-test/suite/binlog/r/binlog_mysqlbinlog_raw_flush.result @@ -1,3 +1,7 @@ +# +# MDEV-30698 Cover missing test cases for mariadb-binlog options +# --raw [and] --flashback +# CREATE TABLE t1 (a int); FLUSH LOGS; INSERT INTO t1 VALUES (1); diff --git a/mysql-test/suite/binlog/r/flashback.result b/mysql-test/suite/binlog/r/flashback.result index eaced02b7a989..12e47363fe2c0 100644 --- a/mysql-test/suite/binlog/r/flashback.result +++ b/mysql-test/suite/binlog/r/flashback.result @@ -702,6 +702,10 @@ include/assert.inc [Table t1 should have 0 rows.] # 6- Rows must be present upon restoring from flashback include/assert.inc [Table t1 should have six rows.] DROP TABLE t1; +# +# MDEV-30698 Cover missing test cases for mariadb-binlog options +# --raw [and] --flashback +# SET binlog_format=statement; Warnings: Warning 1105 MariaDB Galera and flashback do not support binlog format: STATEMENT diff --git a/mysql-test/suite/binlog/t/binlog_mysqlbinlog_raw_flush.test b/mysql-test/suite/binlog/t/binlog_mysqlbinlog_raw_flush.test index f95fc0137a298..252a8577b6c4e 100644 --- a/mysql-test/suite/binlog/t/binlog_mysqlbinlog_raw_flush.test +++ b/mysql-test/suite/binlog/t/binlog_mysqlbinlog_raw_flush.test @@ -5,6 +5,7 @@ # respective log file specified by --result-file, and shown on-disk. This test # ensures that the log files on disk, created by mariadb-binlog, have the most # up-to-date events from the master. +# Option --raw works only with --read-from-remote-server, otherwise returns error. # # Methodology: # On the master, rotate to a newly active binlog file and write an event to @@ -20,6 +21,14 @@ --source include/linux.inc --source include/have_log_bin.inc +--echo # +--echo # MDEV-30698 Cover missing test cases for mariadb-binlog options +--echo # --raw [and] --flashback +--echo # +# Test --raw format without -R (--read-from-remote-server) +--error 1 # Error 1 operation not permitted +--exec $MYSQL_BINLOG --raw --user=root --host=127.0.0.1 --port=$MASTER_MYPORT --stop-never --result-file=$MYSQLTEST_VARDIR/tmp/ master-bin.000001 + # Create newly active log CREATE TABLE t1 (a int); FLUSH LOGS; diff --git a/mysql-test/suite/binlog/t/flashback.test b/mysql-test/suite/binlog/t/flashback.test index abe054e4de03a..50190da6dbe7b 100644 --- a/mysql-test/suite/binlog/t/flashback.test +++ b/mysql-test/suite/binlog/t/flashback.test @@ -364,6 +364,14 @@ FLUSH LOGS; DROP TABLE t1; +--echo # +--echo # MDEV-30698 Cover missing test cases for mariadb-binlog options +--echo # --raw [and] --flashback +--echo # + +--error 1 # --raw mode and --flashback mode are not allowed +--exec $MYSQL_BINLOG -vv -B --raw --read-from-remote-server --user=root --host=127.0.0.1 --port=$MASTER_MYPORT master-bin.000003> $MYSQLTEST_VARDIR/tmp/mysqlbinlog_row_flashback_8.sql + ## Clear SET binlog_format=statement; --error ER_FLASHBACK_NOT_SUPPORTED From 94ed30e505f8a6d9dca8a2006f6dfced1bff9dec Mon Sep 17 00:00:00 2001 From: Daniel Black Date: Fri, 10 Feb 2023 12:58:57 +1100 Subject: [PATCH 40/92] MDEV-30613 output_core_info crashes in my_read() and my_getwd(). The cause is my_errno define which depends on my_thread_var being a not null pointer otherwise it will be de-referenced and cause a SEGV already in the signal handler. Replace uses of these functions in the output_core_info using posix read/getcwd functions instead. The getwd fallback in my_getcwd isn't needed as its been obsolute for a very long time. Thanks Vladislav Vaintroub for diagnosis and posix recommendation. --- sql/signal_handler.cc | 30 +++++++++++++++++------------- 1 file changed, 17 insertions(+), 13 deletions(-) diff --git a/sql/signal_handler.cc b/sql/signal_handler.cc index 2ddda3cec9da4..96c067b717ed0 100644 --- a/sql/signal_handler.cc +++ b/sql/signal_handler.cc @@ -27,6 +27,7 @@ #ifdef __WIN__ #include +#include #define SIGNAL_FMT "exception 0x%x" #else #define SIGNAL_FMT "signal %d" @@ -67,27 +68,27 @@ static inline void output_core_info() my_safe_printf_stderr("Writing a core file...\nWorking directory at %.*s\n", (int) len, buff); } - if ((fd= my_open("/proc/self/limits", O_RDONLY, MYF(0))) >= 0) + if ((fd= open("/proc/self/limits", O_RDONLY, MYF(0))) >= 0) { my_safe_printf_stderr("Resource Limits:\n"); - while ((len= my_read(fd, (uchar*)buff, sizeof(buff), MYF(0))) > 0) + while ((len= read(fd, (uchar*)buff, sizeof(buff))) > 0) { my_write_stderr(buff, len); } - my_close(fd, MYF(0)); + close(fd); } #ifdef __linux__ - if ((fd= my_open("/proc/sys/kernel/core_pattern", O_RDONLY, MYF(0))) >= 0) + if ((fd= open("/proc/sys/kernel/core_pattern", O_RDONLY, MYF(0))) >= 0) { - len= my_read(fd, (uchar*)buff, sizeof(buff), MYF(0)); + len= read(fd, (uchar*)buff, sizeof(buff)); my_safe_printf_stderr("Core pattern: %.*s\n", (int) len, buff); - my_close(fd, MYF(0)); + close(fd); } - if ((fd= my_open("/proc/version", O_RDONLY, MYF(0))) >= 0) + if ((fd= open("/proc/version", O_RDONLY)) >= 0) { - len= my_read(fd, (uchar*)buff, sizeof(buff), MYF(0)); + len= read(fd, (uchar*)buff, sizeof(buff)); my_safe_printf_stderr("Kernel version: %.*s\n", (int) len, buff); - my_close(fd, MYF(0)); + close(fd); } #endif #elif defined(__APPLE__) || defined(__FreeBSD__) @@ -101,11 +102,14 @@ static inline void output_core_info() { my_safe_printf_stderr("Kernel version: %.*s\n", (int) len, buff); } -#else +#elif defined(HAVE_GETCWD) char buff[80]; - my_getwd(buff, sizeof(buff), 0); - my_safe_printf_stderr("Writing a core file at %s\n", buff); - fflush(stderr); + + if (getcwd(buff, sizeof(buff))) + { + my_safe_printf_stderr("Writing a core file at %.*s\n", (int) sizeof(buff), buff); + fflush(stderr); + } #endif } From 2ac832838fd04e22645df6cf6fe8959b44c3853d Mon Sep 17 00:00:00 2001 From: Sergei Golubchik Date: Tue, 7 Mar 2023 20:05:12 +0100 Subject: [PATCH 41/92] post fix for "move alloca() definition from all *.h files to one new header file" --- include/CMakeLists.txt | 1 - include/mysql/service_encryption.h | 2 -- 2 files changed, 3 deletions(-) diff --git a/include/CMakeLists.txt b/include/CMakeLists.txt index fe02098621e82..f6f8735bfdf11 100644 --- a/include/CMakeLists.txt +++ b/include/CMakeLists.txt @@ -106,7 +106,6 @@ ENDMACRO() INSTALL_COMPAT_HEADER(my_global.h "") INSTALL_COMPAT_HEADER(my_config.h "") -INSTALL_COMPAT_HEADER(my_alloca.h "") INSTALL_COMPAT_HEADER(my_sys.h "") INSTALL_COMPAT_HEADER(mysql_version.h " #include diff --git a/include/mysql/service_encryption.h b/include/mysql/service_encryption.h index 280b9c69e3562..4963940758c53 100644 --- a/include/mysql/service_encryption.h +++ b/include/mysql/service_encryption.h @@ -30,8 +30,6 @@ #ifndef __cplusplus #define inline __inline #endif -#else -#include #endif #endif From 8145b308b02ee7ee657851c1faee49c7b7ebf511 Mon Sep 17 00:00:00 2001 From: Sergei Golubchik Date: Fri, 10 Mar 2023 18:14:45 +0100 Subject: [PATCH 42/92] MDEV-30826 Invalid data on mysql.host segfaults the server after an upgrade to 10.4 convert empty host.db to "%", just as it's done for host.hostname (in update_hostname()) --- mysql-test/main/grant5.result | 9 +++++++++ mysql-test/main/grant5.test | 12 ++++++++++++ sql/sql_acl.cc | 7 ++++--- 3 files changed, 25 insertions(+), 3 deletions(-) diff --git a/mysql-test/main/grant5.result b/mysql-test/main/grant5.result index 1038198bd0209..c3a4baad259dc 100644 --- a/mysql-test/main/grant5.result +++ b/mysql-test/main/grant5.result @@ -453,4 +453,13 @@ insert mysql.host values (1); flush privileges; ERROR HY000: Fatal error: mysql.host table is damaged or in unsupported 3.20 format drop table mysql.host; +# +# MDEV-30826 Invalid data on mysql.host segfaults the server after an upgrade to 10.4 +# +create table mysql.host (host char(60) binary default '' not null, db char(64) binary default '' not null, select_priv enum('n','y') collate utf8_general_ci default 'n' not null, insert_priv enum('n','y') collate utf8_general_ci default 'n' not null, update_priv enum('n','y') collate utf8_general_ci default 'n' not null, delete_priv enum('n','y') collate utf8_general_ci default 'n' not null, create_priv enum('n','y') collate utf8_general_ci default 'n' not null, drop_priv enum('n','y') collate utf8_general_ci default 'n' not null, grant_priv enum('n','y') collate utf8_general_ci default 'n' not null, references_priv enum('n','y') collate utf8_general_ci default 'n' not null, index_priv enum('n','y') collate utf8_general_ci default 'n' not null, alter_priv enum('n','y') collate utf8_general_ci default 'n' not null, create_tmp_table_priv enum('n','y') collate utf8_general_ci default 'n' not null, lock_tables_priv enum('n','y') collate utf8_general_ci default 'n' not null, create_view_priv enum('n','y') collate utf8_general_ci default 'n' not null, show_view_priv enum('n','y') collate utf8_general_ci default 'n' not null, create_routine_priv enum('n','y') collate utf8_general_ci default 'n' not null, alter_routine_priv enum('n','y') collate utf8_general_ci default 'n' not null, execute_priv enum('n','y') collate utf8_general_ci default 'n' not null, trigger_priv enum('n','y') collate utf8_general_ci default 'n' not null, primary key /*host*/ (host,db)) engine=myisam character set utf8 collate utf8_bin comment='host privileges; merged with database privileges'; +insert mysql.host values('10.5.0.0/255.255.0.0','','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','N'); +flush privileges; +drop table mysql.host; +# # End of 10.4 tests +# diff --git a/mysql-test/main/grant5.test b/mysql-test/main/grant5.test index c4a302fca865f..49e0ab1abf16c 100644 --- a/mysql-test/main/grant5.test +++ b/mysql-test/main/grant5.test @@ -408,4 +408,16 @@ insert mysql.host values (1); flush privileges; drop table mysql.host; +--echo # +--echo # MDEV-30826 Invalid data on mysql.host segfaults the server after an upgrade to 10.4 +--echo # + +# from mysql_system_tables.sql in 10.3: +create table mysql.host (host char(60) binary default '' not null, db char(64) binary default '' not null, select_priv enum('n','y') collate utf8_general_ci default 'n' not null, insert_priv enum('n','y') collate utf8_general_ci default 'n' not null, update_priv enum('n','y') collate utf8_general_ci default 'n' not null, delete_priv enum('n','y') collate utf8_general_ci default 'n' not null, create_priv enum('n','y') collate utf8_general_ci default 'n' not null, drop_priv enum('n','y') collate utf8_general_ci default 'n' not null, grant_priv enum('n','y') collate utf8_general_ci default 'n' not null, references_priv enum('n','y') collate utf8_general_ci default 'n' not null, index_priv enum('n','y') collate utf8_general_ci default 'n' not null, alter_priv enum('n','y') collate utf8_general_ci default 'n' not null, create_tmp_table_priv enum('n','y') collate utf8_general_ci default 'n' not null, lock_tables_priv enum('n','y') collate utf8_general_ci default 'n' not null, create_view_priv enum('n','y') collate utf8_general_ci default 'n' not null, show_view_priv enum('n','y') collate utf8_general_ci default 'n' not null, create_routine_priv enum('n','y') collate utf8_general_ci default 'n' not null, alter_routine_priv enum('n','y') collate utf8_general_ci default 'n' not null, execute_priv enum('n','y') collate utf8_general_ci default 'n' not null, trigger_priv enum('n','y') collate utf8_general_ci default 'n' not null, primary key /*host*/ (host,db)) engine=myisam character set utf8 collate utf8_bin comment='host privileges; merged with database privileges'; +insert mysql.host values('10.5.0.0/255.255.0.0','','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','N'); +flush privileges; +drop table mysql.host; + +--echo # --echo # End of 10.4 tests +--echo # diff --git a/sql/sql_acl.cc b/sql/sql_acl.cc index 54ad81f94cec1..4bb16e3248d7a 100644 --- a/sql/sql_acl.cc +++ b/sql/sql_acl.cc @@ -2437,6 +2437,8 @@ static bool acl_load(THD *thd, const Grant_tables& tables) "possible to remove this privilege using REVOKE.", host.host.hostname, host.db); } + else if (!host.db) + host.db= const_cast(host_not_specified.str); host.access= host_table.get_access(); host.access= fix_rights_for_db(host.access); host.sort= get_magic_sort("hd", host.host.hostname, host.db); @@ -2445,8 +2447,7 @@ static bool acl_load(THD *thd, const Grant_tables& tables) { sql_print_warning("'host' entry '%s|%s' " "ignored in --skip-name-resolve mode.", - safe_str(host.host.hostname), - safe_str(host.db)); + host.host.hostname, host.db); continue; } #ifndef TO_BE_REMOVED @@ -3533,7 +3534,7 @@ ulong acl_get(const char *host, const char *ip, ACL_HOST *acl_host=dynamic_element(&acl_hosts,i,ACL_HOST*); if (compare_hostname(&acl_host->host,host,ip)) { - if (!acl_host->db || !wild_compare(db,acl_host->db,db_is_pattern)) + if (!wild_compare(db, acl_host->db, db_is_pattern)) { host_access=acl_host->access; // Fully specified. Take it break; From 8b37e79a393dcaef3e09fb72564545e4909cbfb0 Mon Sep 17 00:00:00 2001 From: Julius Goryavsky Date: Mon, 13 Mar 2023 17:41:06 +0100 Subject: [PATCH 43/92] Post-MDEV-30700: moving alloca() definitions from all *.h files to new header file Included config file for proper compilation without --- include/my_alloca.h | 2 ++ 1 file changed, 2 insertions(+) diff --git a/include/my_alloca.h b/include/my_alloca.h index 761c2adb89046..25fd8867e698c 100644 --- a/include/my_alloca.h +++ b/include/my_alloca.h @@ -16,6 +16,8 @@ #ifndef MY_ALLOCA_INCLUDED #define MY_ALLOCA_INCLUDED +#include + #ifdef _WIN32 #include /*for alloca*/ /* From dfdcd7ffab17cfc52545090acb26cb324d9de610 Mon Sep 17 00:00:00 2001 From: Thirunarayanan Balathandayuthapani Date: Mon, 13 Mar 2023 15:41:06 +0530 Subject: [PATCH 44/92] MDEV-26198 Assertion `0' failed in row_log_table_apply_op during redundant table rebuild - InnoDB alter fails to apply the online log during redundant table rebuild. Problem is that InnoDB wrongly reads the length flags of the record while applying the temporary log record. rec_init_offsets_comp_ordinary(): For finding the n_core_null_bytes, InnoDB should use the same logic as rec_convert_dtuple_to_rec_comp(). --- .../suite/innodb/r/instant_alter_crash.result | 24 +++++++++++++++++ .../suite/innodb/t/instant_alter_crash.test | 26 +++++++++++++++++++ storage/innobase/rem/rem0rec.cc | 4 ++- 3 files changed, 53 insertions(+), 1 deletion(-) diff --git a/mysql-test/suite/innodb/r/instant_alter_crash.result b/mysql-test/suite/innodb/r/instant_alter_crash.result index d15c0337c3730..c16d5951c078d 100644 --- a/mysql-test/suite/innodb/r/instant_alter_crash.result +++ b/mysql-test/suite/innodb/r/instant_alter_crash.result @@ -181,3 +181,27 @@ t3 CREATE TABLE `t3` ( ) ENGINE=InnoDB DEFAULT CHARSET=latin1 COLLATE=latin1_swedish_ci DROP TABLE t1,t2,t3; db.opt +# +# MDEV-26198 Assertion `0' failed in row_log_table_apply_op during +# ADD PRIMARY KEY or OPTIMIZE TABLE +# +CREATE TABLE t1(f1 year default null, f2 year default null, +f3 text, f4 year default null, f5 year default null, +f6 year default null, f7 year default null, +f8 year default null)ENGINE=InnoDB ROW_FORMAT=REDUNDANT; +INSERT INTO t1 VALUES(1, 1, 1, 1, 1, 1, 1, 1); +ALTER TABLE t1 ADD COLUMN f9 year default null, ALGORITHM=INPLACE; +set DEBUG_SYNC="row_log_table_apply1_before SIGNAL con1_insert WAIT_FOR con1_finish"; +ALTER TABLE t1 ROW_FORMAT=REDUNDANT, ADD COLUMN f10 YEAR DEFAULT NULL, ALGORITHM=INPLACE; +connect con1,localhost,root,,,; +SET DEBUG_SYNC="now WAIT_FOR con1_insert"; +INSERT IGNORE INTO t1 (f3) VALUES ( 'b' ); +INSERT IGNORE INTO t1 (f3) VALUES ( 'l' ); +SET DEBUG_SYNC="now SIGNAL con1_finish"; +connection default; +disconnect con1; +SET DEBUG_SYNC=RESET; +CHECK TABLE t1; +Table Op Msg_type Msg_text +test.t1 check status OK +DROP TABLE t1; diff --git a/mysql-test/suite/innodb/t/instant_alter_crash.test b/mysql-test/suite/innodb/t/instant_alter_crash.test index 43db8f619f3c3..292de8a802bb6 100644 --- a/mysql-test/suite/innodb/t/instant_alter_crash.test +++ b/mysql-test/suite/innodb/t/instant_alter_crash.test @@ -205,3 +205,29 @@ DROP TABLE t1,t2,t3; --remove_files_wildcard $MYSQLD_DATADIR/test #sql*.frm --list_files $MYSQLD_DATADIR/test + +--echo # +--echo # MDEV-26198 Assertion `0' failed in row_log_table_apply_op during +--echo # ADD PRIMARY KEY or OPTIMIZE TABLE +--echo # +CREATE TABLE t1(f1 year default null, f2 year default null, + f3 text, f4 year default null, f5 year default null, + f6 year default null, f7 year default null, + f8 year default null)ENGINE=InnoDB ROW_FORMAT=REDUNDANT; +INSERT INTO t1 VALUES(1, 1, 1, 1, 1, 1, 1, 1); +ALTER TABLE t1 ADD COLUMN f9 year default null, ALGORITHM=INPLACE; +set DEBUG_SYNC="row_log_table_apply1_before SIGNAL con1_insert WAIT_FOR con1_finish"; +send ALTER TABLE t1 ROW_FORMAT=REDUNDANT, ADD COLUMN f10 YEAR DEFAULT NULL, ALGORITHM=INPLACE; + +connect(con1,localhost,root,,,); +SET DEBUG_SYNC="now WAIT_FOR con1_insert"; +INSERT IGNORE INTO t1 (f3) VALUES ( 'b' ); +INSERT IGNORE INTO t1 (f3) VALUES ( 'l' ); +SET DEBUG_SYNC="now SIGNAL con1_finish"; + +connection default; +reap; +disconnect con1; +SET DEBUG_SYNC=RESET; +CHECK TABLE t1; +DROP TABLE t1; diff --git a/storage/innobase/rem/rem0rec.cc b/storage/innobase/rem/rem0rec.cc index de300bf799a60..3bb417eedfff5 100644 --- a/storage/innobase/rem/rem0rec.cc +++ b/storage/innobase/rem/rem0rec.cc @@ -287,7 +287,9 @@ rec_init_offsets_comp_ordinary( != n_core) ? UT_BITS_IN_BYTES(unsigned(index->get_n_nullable(n_core))) : (redundant_temp - ? UT_BITS_IN_BYTES(index->n_nullable) + ? (index->is_instant() + ? UT_BITS_IN_BYTES(index->get_n_nullable(n_core)) + : UT_BITS_IN_BYTES(index->n_nullable)) : index->n_core_null_bytes); if (mblob) { From d4339620be44091127647eb5ec8f593c0d6fa882 Mon Sep 17 00:00:00 2001 From: Andrei Date: Sun, 5 Mar 2023 15:12:13 +0200 Subject: [PATCH 45/92] MDEV-30780 optimistic parallel slave hangs after hit an error The hang could be seen as show slave status displaying an error like Last_Error: Could not execute Write_rows_v1 along with Slave_SQL_Running: Yes accompanied with one of the replication threads in show-processlist characteristically having status like 2394 | system user | | NULL | Slave_worker | 50852| closing tables It turns out that closing tables worker got entrapped in endless looping in mark_start_commit_inner() across already garbage-collected gco items. The reclaimed gco links are explained with actually possible out-of-order groups of events termination due to the Last_Error. This patch reinforces the correct ordering to perform finish_event_group's cleanup actions, incl unlinking gco:s from the active list. --- .../rpl_parallel_optimistic_error_stop.result | 81 ++++++++ .../t/rpl_parallel_optimistic_error_stop.test | 180 ++++++++++++++++++ sql/rpl_parallel.cc | 38 +++- sql/rpl_parallel.h | 3 + sql/rpl_rli.cc | 5 + 5 files changed, 299 insertions(+), 8 deletions(-) create mode 100644 mysql-test/suite/rpl/r/rpl_parallel_optimistic_error_stop.result create mode 100644 mysql-test/suite/rpl/t/rpl_parallel_optimistic_error_stop.test diff --git a/mysql-test/suite/rpl/r/rpl_parallel_optimistic_error_stop.result b/mysql-test/suite/rpl/r/rpl_parallel_optimistic_error_stop.result new file mode 100644 index 0000000000000..48672651c3608 --- /dev/null +++ b/mysql-test/suite/rpl/r/rpl_parallel_optimistic_error_stop.result @@ -0,0 +1,81 @@ +include/rpl_init.inc [topology=1->2] +call mtr.add_suppression("Slave: Commit failed due to failure of an earlier commit"); +call mtr.add_suppression("Slave: Duplicate entry '99'"); +connection server_1; +ALTER TABLE mysql.gtid_slave_pos ENGINE=InnoDB; +CREATE TABLE t1 (a int PRIMARY KEY, b INT) ENGINE=InnoDB; +INSERT INTO t1 VALUES(1,1); +INSERT INTO t1 VALUES(2,1); +INSERT INTO t1 VALUES(3,1); +INSERT INTO t1 VALUES(4,1); +connection server_2; +SET @old_parallel_threads=@@GLOBAL.slave_parallel_threads; +include/stop_slave.inc +SET @old_debug_dbug = @@global.debug_dbug; +SET @@global.debug_dbug = "d,hold_worker2_favor_worker3"; +SET GLOBAL slave_parallel_threads=4; +CHANGE MASTER TO master_use_gtid=slave_pos; +SET @old_parallel_mode=@@GLOBAL.slave_parallel_mode; +SET GLOBAL slave_parallel_mode='optimistic'; +connection server_1; +SET @@gtid_seq_no = 2001; +BEGIN; +UPDATE t1 SET b = 11 WHERE a = 4; +UPDATE t1 SET b = 11 WHERE a = 3; +UPDATE t1 SET a = 99 WHERE a = 1; +COMMIT; +UPDATE t1 SET b = 2 WHERE a = 2; +UPDATE t1 SET b = 3 WHERE a = 3; +DROP TABLE IF EXISTS phantom_1; +Warnings: +Note 1051 Unknown table 'test.phantom_1' +include/save_master_gtid.inc +connect slave_local_0, 127.0.0.1, root,, test, $SLAVE_MYPORT,; +begin; +UPDATE t1 set b = 11 where a = 4; +connect slave_local_1, 127.0.0.1, root,, test, $SLAVE_MYPORT,; +begin; +INSERT INTO t1 VALUES (99, 11); +connect slave_local_2, 127.0.0.1, root,, test, $SLAVE_MYPORT,; +begin; +UPDATE t1 SET b = 12 WHERE a = 2; +connect slave_local_3, 127.0.0.1, root,, test, $SLAVE_MYPORT,; +begin; +UPDATE t1 SET b = 13 WHERE a = 3; +connection server_2; +include/start_slave.inc +# W4 is waiting to start its DROP +connection slave_local_3; +rollback; +connection slave_local_0; +rollback; +SELECT count(*) = 0 as "W3 undid its commit state" FROM information_schema.processlist WHERE state LIKE "Waiting for prior transaction to commit%"; +W3 undid its commit state +1 +connection slave_local_2; +rollback; +connection slave_local_1; +commit; +SELECT COUNT(*) = 1 as "W4 remains with the same status" FROM information_schema.processlist WHERE state LIKE "Waiting for prior transaction to start commit%"; +W4 remains with the same status +1 +# Slave_SQL_Running YES = Yes +# while W2 is held back ... +SET DEBUG_SYNC = 'now SIGNAL cont_worker2'; +include/wait_for_slave_sql_error.inc [errno=1062] +DELETE FROM t1 WHERE a=99; +include/start_slave.inc +include/sync_with_master_gtid.inc +connection server_2; +include/stop_slave.inc +SET GLOBAL slave_parallel_mode=@old_parallel_mode; +SET GLOBAL slave_parallel_threads=@old_parallel_threads; +SET @@global.debug_dbug = @old_debug_dbug; +SET debug_sync = RESET; +include/start_slave.inc +connection server_1; +DROP TABLE t1; +include/save_master_gtid.inc +connection server_2; +include/sync_with_master_gtid.inc +include/rpl_end.inc diff --git a/mysql-test/suite/rpl/t/rpl_parallel_optimistic_error_stop.test b/mysql-test/suite/rpl/t/rpl_parallel_optimistic_error_stop.test new file mode 100644 index 0000000000000..27f38d47bdbfb --- /dev/null +++ b/mysql-test/suite/rpl/t/rpl_parallel_optimistic_error_stop.test @@ -0,0 +1,180 @@ +--source include/have_innodb.inc +--source include/have_debug.inc +--source include/have_debug_sync.inc +--let $rpl_topology=1->2 +--source include/rpl_init.inc + +call mtr.add_suppression("Slave: Commit failed due to failure of an earlier commit"); +call mtr.add_suppression("Slave: Duplicate entry '99'"); + +--connection server_1 +ALTER TABLE mysql.gtid_slave_pos ENGINE=InnoDB; +CREATE TABLE t1 (a int PRIMARY KEY, b INT) ENGINE=InnoDB; +INSERT INTO t1 VALUES(1,1); # hit a dup entry on slave +INSERT INTO t1 VALUES(2,1); # races to "win" the last exit +INSERT INTO t1 VALUES(3,1); +INSERT INTO t1 VALUES(4,1); # make W3 race over W1 +--save_master_pos + +--connection server_2 +--sync_with_master +SET @old_parallel_threads=@@GLOBAL.slave_parallel_threads; +--source include/stop_slave.inc +SET @old_debug_dbug = @@global.debug_dbug; +# In a group of W1,W2,W3 of the same batch W2 simulates slowness. +SET @@global.debug_dbug = "d,hold_worker2_favor_worker3"; +SET GLOBAL slave_parallel_threads=4; +CHANGE MASTER TO master_use_gtid=slave_pos; +SET @old_parallel_mode=@@GLOBAL.slave_parallel_mode; +SET GLOBAL slave_parallel_mode='optimistic'; + +# MDEV-30780 optimistic parallel slave hangs after hit an error +# Test workers hang scenario to prove it's no more neither +# out-of-order access to the active gco list. +# +# The test provides how to reproduce on the OLD version, false by default. +# That branch approximates the original hang with an assert that +# confirms the OLD version indeed could access already reclaimed gco. +--let $old_version_regression=0 + + +--connection server_1 + +# Let W1,W2,W3,W4 parallel workers that are going to execute +# the following transaction. +# W1 holds on with the 1st statement +# then crashes W3 with the 2nd into retry, +# finally hits with the 3rd a dup entry, on slave. +SET @@gtid_seq_no = 2001; +BEGIN; + UPDATE t1 SET b = 11 WHERE a = 4; + UPDATE t1 SET b = 11 WHERE a = 3; + UPDATE t1 SET a = 99 WHERE a = 1; +COMMIT; +# In the buggy version W2 races to "win" the exit last (of W1..3) +# and by that to access last a gco struct, garbage-collected. +UPDATE t1 SET b = 2 WHERE a = 2; +# W3 garbage-collects the gco struct in the buggy version. +UPDATE t1 SET b = 3 WHERE a = 3; +# W4 resides in following "singleton" batch to a W2 replacement +# in the buggy version to allow W3 reclaim the batch's gco. +DROP TABLE IF EXISTS phantom_1; + +--source include/save_master_gtid.inc + +--connect (slave_local_0, 127.0.0.1, root,, test, $SLAVE_MYPORT,) +begin; + UPDATE t1 set b = 11 where a = 4; +--connect (slave_local_1, 127.0.0.1, root,, test, $SLAVE_MYPORT,) +begin; + INSERT INTO t1 VALUES (99, 11); + +--connect (slave_local_2, 127.0.0.1, root,, test, $SLAVE_MYPORT,) +begin; + UPDATE t1 SET b = 12 WHERE a = 2; + +--connect (slave_local_3, 127.0.0.1, root,, test, $SLAVE_MYPORT,) +begin; + UPDATE t1 SET b = 13 WHERE a = 3; + +--connection server_2 +--source include/start_slave.inc + +--echo # W4 is waiting to start its DROP + +--let $wait_condition= SELECT count(*) = 1 FROM information_schema.processlist WHERE state LIKE "Waiting for prior transaction to start commit%" +--source include/wait_condition.inc + +--connection slave_local_3 +# make W3 to set E.cc <- 1 + rollback; +--let $wait_condition= SELECT count(*) = 1 FROM information_schema.processlist WHERE state LIKE "Waiting for prior transaction to commit%" +--source include/wait_condition.inc + +--connection slave_local_0 +# make W3 into retry and delay it to let W1 hit a dupicate error first, +# see 'commit' by slave_local_1. + rollback; +--let $wait_condition= SELECT count(*) = 1 FROM information_schema.processlist WHERE state LIKE "debug sync point: now" +--source include/wait_condition.inc +SELECT count(*) = 0 as "W3 undid its commit state" FROM information_schema.processlist WHERE state LIKE "Waiting for prior transaction to commit%"; + + +--connection slave_local_2 + rollback; +# wait for W2 to start committing E.cc <- 2 +--let $wait_condition= SELECT count(*) = 1 FROM information_schema.processlist WHERE state like "Waiting for prior transaction to commit" +--source include/wait_condition.inc + +--connection slave_local_1 + +# W1 errors out +# A. to alert W3 +# B. W3 will *not* wake up W4 in the fixed version, having to wait for W2 demise. +# C. W2 will notify W3 that releases W4 as it would do in normal cases. +commit; + +if (!$old_version_regression) +{ +# A. In the fixed version show-processlist W4 is still in the ordered waiting +SELECT COUNT(*) = 1 as "W4 remains with the same status" FROM information_schema.processlist WHERE state LIKE "Waiting for prior transaction to start commit%"; +--let $status= query_get_value("show slave status", Slave_SQL_Running, 1) +--echo # Slave_SQL_Running YES = $status + +# B. In the fixed version W3 is waiting for W2,... +--let $wait_condition= SELECT count(*) = 1 as "W4 is waiting" FROM information_schema.processlist WHERE state LIKE "Waiting for prior transaction to commit%" +--source include/wait_condition.inc +--echo # while W2 is held back ... +--let $wait_condition= SELECT count(*) = 1 as "W2 simulates slowness" FROM information_schema.processlist WHERE state LIKE "debug sync point: now" +--source include/wait_condition.inc + +# C. # ...until NOW. +SET DEBUG_SYNC = 'now SIGNAL cont_worker2'; + +} + +# To reproduce the hang on the OLD version ... +if ($old_version_regression) +{ + # replace the actual fixes block with checking W3,W4 have actually committed, + # followed by signaling to W2 like on behalf of W4 which would end up in the hang. + --let $wait_condition= SELECT COUNT(*) = 0 as "W4 has moved on" FROM information_schema.processlist WHERE state like "Waiting for prior transaction to start commit" + --source include/wait_condition.inc + --let $wait_condition= SELECT count(*) = 0 as "W3 does not wait on W2" FROM information_schema.processlist WHERE state LIKE "Waiting for prior transaction to commit%" +--source include/wait_condition.inc + + --let $wait_condition= SELECT count(*) = 1 as "W2 simulates slowness" FROM information_schema.processlist WHERE state LIKE "debug sync point: now" + --source include/wait_condition.inc + + # Like above, but signaling is done after W4 is done to violate the commit order + # that must fire a debug assert. + SET DEBUG_SYNC = 'now SIGNAL cont_worker2'; +} + +--let $slave_sql_errno= 1062 +--source include/wait_for_slave_sql_error.inc + +# Restore the slave data and resume with replication +DELETE FROM t1 WHERE a=99; +--source include/start_slave.inc +--source include/sync_with_master_gtid.inc + +# +# Clean up. +# +--connection server_2 +--source include/stop_slave.inc +SET GLOBAL slave_parallel_mode=@old_parallel_mode; +SET GLOBAL slave_parallel_threads=@old_parallel_threads; +SET @@global.debug_dbug = @old_debug_dbug; +SET debug_sync = RESET; +--source include/start_slave.inc + +--connection server_1 +DROP TABLE t1; +--source include/save_master_gtid.inc + +--connection server_2 +--source include/sync_with_master_gtid.inc + +--source include/rpl_end.inc diff --git a/sql/rpl_parallel.cc b/sql/rpl_parallel.cc index 8701fc19411b1..7e70e04b857d8 100644 --- a/sql/rpl_parallel.cc +++ b/sql/rpl_parallel.cc @@ -261,6 +261,12 @@ finish_event_group(rpl_parallel_thread *rpt, uint64 sub_id, STRING_WITH_LEN("now WAIT_FOR proceed_by_1000")); } }); + DBUG_EXECUTE_IF("hold_worker2_favor_worker3", { + if (rgi->current_gtid.seq_no == 2001) { + DBUG_ASSERT(!rgi->worker_error || entry->stop_on_error_sub_id == sub_id); + debug_sync_set_action(thd, STRING_WITH_LEN("now SIGNAL cont_worker3")); + } + }); #endif if (rgi->killed_for_retry == rpl_group_info::RETRY_KILL_PENDING) @@ -284,6 +290,11 @@ signal_error_to_sql_driver_thread(THD *thd, rpl_group_info *rgi, int err) In case we get an error during commit, inform following transactions that we aborted our commit. */ + DBUG_EXECUTE_IF("hold_worker2_favor_worker3", { + if (rgi->current_gtid.seq_no == 2002) { + debug_sync_set_action(thd, STRING_WITH_LEN("now WAIT_FOR cont_worker2")); + }}); + rgi->unmark_start_commit(); rgi->cleanup_context(thd, true); rgi->rli->abort_slave= true; @@ -788,7 +799,14 @@ retry_event_group(rpl_group_info *rgi, rpl_parallel_thread *rpt, thd->reset_killed(); thd->clear_error(); rgi->killed_for_retry = rpl_group_info::RETRY_KILL_NONE; - +#ifdef ENABLED_DEBUG_SYNC + DBUG_EXECUTE_IF("hold_worker2_favor_worker3", { + if (rgi->current_gtid.seq_no == 2003) { + debug_sync_set_action(thd, + STRING_WITH_LEN("now WAIT_FOR cont_worker3")); + } + }); +#endif /* If we retry due to a deadlock kill that occurred during the commit step, we might have already updated (but not committed) an update of table @@ -806,15 +824,12 @@ retry_event_group(rpl_group_info *rgi, rpl_parallel_thread *rpt, for (;;) { mysql_mutex_lock(&entry->LOCK_parallel_entry); - if (entry->stop_on_error_sub_id == (uint64) ULONGLONG_MAX || + register_wait_for_prior_event_group_commit(rgi, entry); + if (!(entry->stop_on_error_sub_id == (uint64) ULONGLONG_MAX || #ifndef DBUG_OFF - (DBUG_EVALUATE_IF("simulate_mdev_12746", 1, 0)) || + (DBUG_EVALUATE_IF("simulate_mdev_12746", 1, 0)) || #endif - rgi->gtid_sub_id < entry->stop_on_error_sub_id) - { - register_wait_for_prior_event_group_commit(rgi, entry); - } - else + rgi->gtid_sub_id < entry->stop_on_error_sub_id)) { /* A failure of a preceeding "parent" transaction may not be @@ -1991,6 +2006,9 @@ rpl_parallel_thread::get_gco(uint64 wait_count, group_commit_orderer *prev, gco->prior_sub_id= prior_sub_id; gco->installed= false; gco->flags= 0; +#ifndef DBUG_OFF + gco->gc_done= false; +#endif return gco; } @@ -1998,6 +2016,10 @@ rpl_parallel_thread::get_gco(uint64 wait_count, group_commit_orderer *prev, void rpl_parallel_thread::loc_free_gco(group_commit_orderer *gco) { +#ifndef DBUG_OFF + DBUG_ASSERT(!gco->gc_done); + gco->gc_done= true; +#endif if (!loc_gco_list) loc_gco_last_ptr_ptr= &gco->next_gco; else diff --git a/sql/rpl_parallel.h b/sql/rpl_parallel.h index 0fa28e3229125..650aa06e5040e 100644 --- a/sql/rpl_parallel.h +++ b/sql/rpl_parallel.h @@ -90,6 +90,9 @@ struct group_commit_orderer { FORCE_SWITCH= 2 }; uint8 flags; +#ifndef DBUG_OFF + bool gc_done; +#endif }; diff --git a/sql/rpl_rli.cc b/sql/rpl_rli.cc index 58030db2a8c8a..04fddb3e74bff 100644 --- a/sql/rpl_rli.cc +++ b/sql/rpl_rli.cc @@ -2417,8 +2417,13 @@ mark_start_commit_inner(rpl_parallel_entry *e, group_commit_orderer *gco, uint64 count= ++e->count_committing_event_groups; /* Signal any following GCO whose wait_count has been reached now. */ tmp= gco; + + DBUG_ASSERT(!tmp->gc_done); + while ((tmp= tmp->next_gco)) { + DBUG_ASSERT(!tmp->gc_done); + uint64 wait_count= tmp->wait_count; if (wait_count > count) break; From 26e4ba5eb551570444cc7a6033f24eb7c4a1a763 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marko=20M=C3=A4kel=C3=A4?= Date: Mon, 20 Mar 2023 14:12:52 +0200 Subject: [PATCH 46/92] Fix cmake -DWITH_INNODB_EXTRA_DEBUG (UNIV_ZIP_DEBUG) --- storage/innobase/page/page0zip.cc | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/storage/innobase/page/page0zip.cc b/storage/innobase/page/page0zip.cc index ffe48c4012d6d..13c6f58a171e8 100644 --- a/storage/innobase/page/page0zip.cc +++ b/storage/innobase/page/page0zip.cc @@ -3366,7 +3366,7 @@ page_zip_validate_low( differed. Let us ignore it. */ page_zip_fail(("page_zip_validate:" " min_rec_flag" - " (%s" ULINTPF "," ULINTPF + " (%s" UINT32PF "," UINT32PF ",0x%02x)\n", sloppy ? "ignored, " : "", page_get_space_id(page), @@ -3411,7 +3411,8 @@ page_zip_validate_low( page + PAGE_NEW_INFIMUM, TRUE); trec = page_rec_get_next_low( temp_page + PAGE_NEW_INFIMUM, TRUE); - const ulint n_core = page_is_leaf(page) ? index->n_fields : 0; + const ulint n_core = (index && page_is_leaf(page)) + ? index->n_fields : 0; do { if (page_offset(rec) != page_offset(trec)) { From a2cb6d8760362dbbe874cae3067b20f88242aaf3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vicen=C8=9Biu=20Ciorbaru?= Date: Mon, 20 Mar 2023 16:47:53 +0200 Subject: [PATCH 47/92] Update feedback plugin URL to use feedback.mariadb.org subdomain --- mysql-test/suite/plugins/r/feedback_plugin_install.result | 2 +- mysql-test/suite/plugins/r/feedback_plugin_load.result | 2 +- mysql-test/suite/plugins/r/feedback_plugin_send.result | 4 ++-- plugin/feedback/feedback.cc | 2 +- 4 files changed, 5 insertions(+), 5 deletions(-) diff --git a/mysql-test/suite/plugins/r/feedback_plugin_install.result b/mysql-test/suite/plugins/r/feedback_plugin_install.result index c7f7a5c79f3fd..d2291f20b4f5f 100644 --- a/mysql-test/suite/plugins/r/feedback_plugin_install.result +++ b/mysql-test/suite/plugins/r/feedback_plugin_install.result @@ -11,6 +11,6 @@ FEEDBACK version 1.1 FEEDBACK_HTTP_PROXY FEEDBACK_SEND_RETRY_WAIT 60 FEEDBACK_SEND_TIMEOUT 60 -FEEDBACK_URL http://mariadb.org/feedback_plugin/post +FEEDBACK_URL http://feedback.mariadb.org/rest/v1/post FEEDBACK_USER_INFO mysql-test uninstall plugin feedback; diff --git a/mysql-test/suite/plugins/r/feedback_plugin_load.result b/mysql-test/suite/plugins/r/feedback_plugin_load.result index 4323dcce0a6ad..9043f6bf4a126 100644 --- a/mysql-test/suite/plugins/r/feedback_plugin_load.result +++ b/mysql-test/suite/plugins/r/feedback_plugin_load.result @@ -13,7 +13,7 @@ FEEDBACK version 1.1 FEEDBACK_HTTP_PROXY FEEDBACK_SEND_RETRY_WAIT 60 FEEDBACK_SEND_TIMEOUT 60 -FEEDBACK_URL http://mariadb.org/feedback_plugin/post +FEEDBACK_URL http://feedback.mariadb.org/rest/v1/post FEEDBACK_USER_INFO mysql-test SELECT VARIABLE_VALUE>0, VARIABLE_NAME FROM INFORMATION_SCHEMA.FEEDBACK WHERE VARIABLE_NAME LIKE 'Collation used %' diff --git a/mysql-test/suite/plugins/r/feedback_plugin_send.result b/mysql-test/suite/plugins/r/feedback_plugin_send.result index 69046e16dd90f..028c69c6f16bb 100644 --- a/mysql-test/suite/plugins/r/feedback_plugin_send.result +++ b/mysql-test/suite/plugins/r/feedback_plugin_send.result @@ -13,7 +13,7 @@ FEEDBACK version 1.1 FEEDBACK_HTTP_PROXY FEEDBACK_SEND_RETRY_WAIT 60 FEEDBACK_SEND_TIMEOUT 60 -FEEDBACK_URL http://mariadb.org/feedback_plugin/post +FEEDBACK_URL http://feedback.mariadb.org/rest/v1/post FEEDBACK_USER_INFO mysql-test SELECT VARIABLE_VALUE>0, VARIABLE_NAME FROM INFORMATION_SCHEMA.FEEDBACK WHERE VARIABLE_NAME LIKE 'Collation used %' @@ -42,5 +42,5 @@ VARIABLE_VALUE>0 VARIABLE_NAME deallocate prepare stmt; set global sql_mode=ONLY_FULL_GROUP_BY; # restart -feedback plugin: report to 'http://mariadb.org/feedback_plugin/post' was sent +feedback plugin: report to 'http://feedback.mariadb.org/rest/v1/post' was sent feedback plugin: server replied 'ok' diff --git a/plugin/feedback/feedback.cc b/plugin/feedback/feedback.cc index a7bc1d3d60e56..7f76dc728d114 100644 --- a/plugin/feedback/feedback.cc +++ b/plugin/feedback/feedback.cc @@ -367,7 +367,7 @@ static MYSQL_SYSVAR_STR(user_info, user_info, NULL, NULL, ""); static MYSQL_SYSVAR_STR(url, url, PLUGIN_VAR_READONLY | PLUGIN_VAR_RQCMDARG, "Space separated URLs to send the feedback report to.", NULL, NULL, - DEFAULT_PROTO "mariadb.org/feedback_plugin/post"); + DEFAULT_PROTO "feedback.mariadb.org/rest/v1/post"); static MYSQL_SYSVAR_ULONG(send_timeout, send_timeout, PLUGIN_VAR_RQCMDARG, "Timeout (in seconds) for the sending the report.", NULL, NULL, 60, 1, 60*60*24, 1); From f8c3d4c2d503e2343303fe506826a5a2ecffbae2 Mon Sep 17 00:00:00 2001 From: Vlad Lesin Date: Fri, 17 Mar 2023 18:51:33 +0300 Subject: [PATCH 48/92] MDEV-28187 mariadb-backup doesn't utilise innodb-undo-log-directory (if specified as a relative path) during copy-back operation Make absolute destination path from relative one, basing on mysql data directory. Reviewed by Alexander Barkov. --- extra/mariabackup/backup_copy.cc | 27 ++++++++++---- .../include/restart_and_restore.inc | 2 +- .../suite/mariabackup/relative_path.opt | 1 + .../suite/mariabackup/relative_path.result | 20 +++++++++++ .../suite/mariabackup/relative_path.test | 35 +++++++++++++++++++ 5 files changed, 77 insertions(+), 8 deletions(-) create mode 100644 mysql-test/suite/mariabackup/relative_path.opt create mode 100644 mysql-test/suite/mariabackup/relative_path.result create mode 100644 mysql-test/suite/mariabackup/relative_path.test diff --git a/extra/mariabackup/backup_copy.cc b/extra/mariabackup/backup_copy.cc index e7d69a25b7621..608be7125bd52 100644 --- a/extra/mariabackup/backup_copy.cc +++ b/extra/mariabackup/backup_copy.cc @@ -1816,13 +1816,28 @@ apply_log_finish() return(true); } +class Copy_back_dst_dir +{ + std::string buf; + +public: + const char *make(const char *path) + { + if (!path || !path[0]) + return mysql_data_home; + if (is_absolute_path(path)) + return path; + return buf.assign(mysql_data_home).append(path).c_str(); + } +}; + bool copy_back() { bool ret = false; datadir_iter_t *it = NULL; datadir_node_t node; - char *dst_dir; + const char *dst_dir; memset(&node, 0, sizeof(node)); @@ -1875,9 +1890,9 @@ copy_back() /* copy undo tablespaces */ + Copy_back_dst_dir dst_dir_buf; - dst_dir = (srv_undo_dir && *srv_undo_dir) - ? srv_undo_dir : mysql_data_home; + dst_dir = dst_dir_buf.make(srv_undo_dir); ds_data = ds_create(dst_dir, DS_TYPE_LOCAL); @@ -1898,8 +1913,7 @@ copy_back() /* copy redo logs */ - dst_dir = (srv_log_group_home_dir && *srv_log_group_home_dir) - ? srv_log_group_home_dir : mysql_data_home; + dst_dir = dst_dir_buf.make(srv_log_group_home_dir); /* --backup generates a single ib_logfile0, which we must copy if it exists. */ @@ -1926,8 +1940,7 @@ copy_back() /* copy innodb system tablespace(s) */ - dst_dir = (innobase_data_home_dir && *innobase_data_home_dir) - ? innobase_data_home_dir : mysql_data_home; + dst_dir = dst_dir_buf.make(innobase_data_home_dir); ds_data = ds_create(dst_dir, DS_TYPE_LOCAL); diff --git a/mysql-test/suite/mariabackup/include/restart_and_restore.inc b/mysql-test/suite/mariabackup/include/restart_and_restore.inc index 2d1e5493957a6..aa26d28efba7a 100644 --- a/mysql-test/suite/mariabackup/include/restart_and_restore.inc +++ b/mysql-test/suite/mariabackup/include/restart_and_restore.inc @@ -4,5 +4,5 @@ echo # shutdown server; echo # remove datadir; rmdir $_datadir; echo # xtrabackup move back; -exec $XTRABACKUP --defaults-file=$MYSQLTEST_VARDIR/my.cnf --copy-back --datadir=$_datadir --target-dir=$targetdir --parallel=2 --throttle=1; +exec $XTRABACKUP --defaults-file=$MYSQLTEST_VARDIR/my.cnf --copy-back --datadir=$_datadir --target-dir=$targetdir --parallel=2 --throttle=1 $backup_opts; --source include/start_mysqld.inc diff --git a/mysql-test/suite/mariabackup/relative_path.opt b/mysql-test/suite/mariabackup/relative_path.opt new file mode 100644 index 0000000000000..3e3c33e44f85a --- /dev/null +++ b/mysql-test/suite/mariabackup/relative_path.opt @@ -0,0 +1 @@ +--innodb-undo-tablespaces=2 diff --git a/mysql-test/suite/mariabackup/relative_path.result b/mysql-test/suite/mariabackup/relative_path.result new file mode 100644 index 0000000000000..7aa0c6968f3dc --- /dev/null +++ b/mysql-test/suite/mariabackup/relative_path.result @@ -0,0 +1,20 @@ +CREATE TABLE t(i INT) ENGINE INNODB; +INSERT INTO t VALUES(1); +# xtrabackup backup +# xtrabackup prepare +# shutdown server +# remove datadir +# xtrabackup move back +# restart +# shutdown server +# remove datadir +# xtrabackup move back +# restart +# shutdown server +# remove datadir +# xtrabackup move back +# restart +SELECT * FROM t; +i +1 +DROP TABLE t; diff --git a/mysql-test/suite/mariabackup/relative_path.test b/mysql-test/suite/mariabackup/relative_path.test new file mode 100644 index 0000000000000..bd25a217e711e --- /dev/null +++ b/mysql-test/suite/mariabackup/relative_path.test @@ -0,0 +1,35 @@ +--source include/have_innodb.inc + +CREATE TABLE t(i INT) ENGINE INNODB; +INSERT INTO t VALUES(1); + +echo # xtrabackup backup; +let $targetdir=$MYSQLTEST_VARDIR/tmp/backup; +--let $backup_log=$MYSQLTEST_VARDIR/tmp/backup.log + +--disable_result_log +exec $XTRABACKUP --defaults-file=$MYSQLTEST_VARDIR/my.cnf --backup --target-dir=$targetdir > $backup_log 2>&1; +--enable_result_log + +echo # xtrabackup prepare; +--disable_result_log +exec $XTRABACKUP --prepare --target-dir=$targetdir; + +# If MDEV-28187 is not fixed, the following tries to copy backup to data +# directory will fail, because their destination path will be the same as +# their source path + +--let $backup_opts=--innodb_undo_directory=./ +--source include/restart_and_restore.inc + +--let $backup_opts=--innodb_log_group_home_dir=./ +--source include/restart_and_restore.inc + +--let $backup_opts=--innodb_data_home_dir=./ +--source include/restart_and_restore.inc + +--enable_result_log + +SELECT * FROM t; +DROP TABLE t; +rmdir $targetdir; From c73a65f55bb5af8e27c556fa0e9258b26671ed9e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marko=20M=C3=A4kel=C3=A4?= Date: Tue, 21 Mar 2023 14:33:54 +0200 Subject: [PATCH 49/92] MDEV-29692 Assertion `(writeptr + (i * size)) != local_frame' failed upon IMPORT TABLESPACE fil_iterate(): Allocation bitmap pages are never encrypted. Reviewed by: Thirunarayanan Balathandayuthapani --- .../suite/encryption/r/import_4k.result | 10 ++++++++++ mysql-test/suite/encryption/t/import_4k.opt | 1 + mysql-test/suite/encryption/t/import_4k.test | 20 +++++++++++++++++++ storage/innobase/row/row0import.cc | 6 ++++-- 4 files changed, 35 insertions(+), 2 deletions(-) create mode 100644 mysql-test/suite/encryption/r/import_4k.result create mode 100644 mysql-test/suite/encryption/t/import_4k.opt create mode 100644 mysql-test/suite/encryption/t/import_4k.test diff --git a/mysql-test/suite/encryption/r/import_4k.result b/mysql-test/suite/encryption/r/import_4k.result new file mode 100644 index 0000000000000..959e2498e00ff --- /dev/null +++ b/mysql-test/suite/encryption/r/import_4k.result @@ -0,0 +1,10 @@ +set @save_limit = @@GLOBAL.innodb_limit_optimistic_insert_debug; +set global innodb_limit_optimistic_insert_debug=3; +create table t1 (a INT PRIMARY KEY) engine=InnoDB ENCRYPTED=YES; +insert into t1 select * from seq_1_to_6000; +flush table t1 for export; +unlock tables; +alter table t1 discard tablespace; +alter table t1 import tablespace; +set global innodb_limit_optimistic_insert_debug=@save_limit; +drop table t1; diff --git a/mysql-test/suite/encryption/t/import_4k.opt b/mysql-test/suite/encryption/t/import_4k.opt new file mode 100644 index 0000000000000..e5b58602036b7 --- /dev/null +++ b/mysql-test/suite/encryption/t/import_4k.opt @@ -0,0 +1 @@ +--innodb-page-size=4k diff --git a/mysql-test/suite/encryption/t/import_4k.test b/mysql-test/suite/encryption/t/import_4k.test new file mode 100644 index 0000000000000..aef7c702d1289 --- /dev/null +++ b/mysql-test/suite/encryption/t/import_4k.test @@ -0,0 +1,20 @@ +--source include/have_innodb.inc +--source include/have_sequence.inc +--source include/have_example_key_management_plugin.inc +--source include/have_debug.inc + +set @save_limit = @@GLOBAL.innodb_limit_optimistic_insert_debug; +set global innodb_limit_optimistic_insert_debug=3; +create table t1 (a INT PRIMARY KEY) engine=InnoDB ENCRYPTED=YES; +insert into t1 select * from seq_1_to_6000; +flush table t1 for export; +--let $datadir= `select @@datadir` +--copy_file $datadir/test/t1.ibd $datadir/t1.ibd +--copy_file $datadir/test/t1.cfg $datadir/t1.cfg +unlock tables; +alter table t1 discard tablespace; +--move_file $datadir/t1.ibd $datadir/test/t1.ibd +--move_file $datadir/t1.cfg $datadir/test/t1.cfg +alter table t1 import tablespace; +set global innodb_limit_optimistic_insert_debug=@save_limit; +drop table t1; diff --git a/storage/innobase/row/row0import.cc b/storage/innobase/row/row0import.cc index 2afe7661e208e..c4534938ad5f5 100644 --- a/storage/innobase/row/row0import.cc +++ b/storage/innobase/row/row0import.cc @@ -3971,14 +3971,15 @@ static dberr_t fil_iterate( src + FIL_PAGE_SPACE_ID); } + const uint16_t type = fil_page_get_type(src); page_compressed = (full_crc32 && fil_space_t::is_compressed( callback.get_space_flags()) && buf_page_is_compressed( src, callback.get_space_flags())) - || (fil_page_is_compressed_encrypted(src) - || fil_page_is_compressed(src)); + || type == FIL_PAGE_PAGE_COMPRESSED_ENCRYPTED + || type == FIL_PAGE_PAGE_COMPRESSED; if (page_compressed && block->page.zip.data) { goto page_corrupted; @@ -3997,6 +3998,7 @@ static dberr_t fil_iterate( block->page.zip.data = src; frame_changed = true; } else if (!page_compressed + && type != FIL_PAGE_TYPE_XDES && !block->page.zip.data) { block->frame = src; frame_changed = true; From e0560fc4cfa7b40dd3083a1b78c873ec51689cff Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marko=20M=C3=A4kel=C3=A4?= Date: Tue, 21 Mar 2023 14:36:38 +0200 Subject: [PATCH 50/92] Remove a bogus UNIV_ZIP_DEBUG check buf_LRU_block_remove_hashed(): Ever since commit 2e814d4702d71a04388386a9f591d14a35980bfe we could get page_zip_validate() failures after an ALTER TABLE operation was aborted and BtrBulk::pageCommit() had never been executed on some blocks. --- storage/innobase/buf/buf0lru.cc | 6 ------ 1 file changed, 6 deletions(-) diff --git a/storage/innobase/buf/buf0lru.cc b/storage/innobase/buf/buf0lru.cc index 206256203324b..0043f2c4343aa 100644 --- a/storage/innobase/buf/buf0lru.cc +++ b/storage/innobase/buf/buf0lru.cc @@ -1762,14 +1762,8 @@ buf_LRU_block_remove_hashed( break; case FIL_PAGE_TYPE_ZBLOB: case FIL_PAGE_TYPE_ZBLOB2: - break; case FIL_PAGE_INDEX: case FIL_PAGE_RTREE: -#if defined UNIV_ZIP_DEBUG && defined BTR_CUR_HASH_ADAPT - ut_a(page_zip_validate( - &bpage->zip, page, - ((buf_block_t*) bpage)->index)); -#endif /* UNIV_ZIP_DEBUG && BTR_CUR_HASH_ADAPT */ break; default: ib::error() << "The compressed page to be" From 7c91082e393f1817401b334b3d3584b401d909d7 Mon Sep 17 00:00:00 2001 From: Yuchen Pei Date: Wed, 18 Jan 2023 11:51:28 +1100 Subject: [PATCH 51/92] MDEV-27912 Fixing inconsistency w.r.t. expect files in tests. mtr uses group suffix, but some existing inc and test files use server_id for expect files. This patch aims to fix that. For spider: With this change we will not have to maintain a separate version of restart_mysqld.inc for spider, that duplicates code, just because spider tests use different names for expect files, and shutdown_mysqld requires magical names for them. With this change spider tests will also be able to use other features provided by restart_mysqld.inc without code duplication, like the parameter $restart_parameters (see e.g. the testcase mdev_29904.test in commit ef1161e5d4f). Tests run after this change: default, spider, rocksdb, galera, using the following command mtr --parallel=auto --force --max-test-fail=0 --skip-core-file mtr --suite spider,spider/*,spider/*/* \ --skip-test="spider/oracle.*|.*/t\..*" --parallel=auto --big-test \ --force --max-test-fail=0 --skip-core-file mtr --suite galera --parallel=auto mtr --suite rocksdb --parallel=auto --- mysql-test/include/expect_crash.inc | 4 ++-- mysql-test/include/kill_galera.inc | 4 ++-- mysql-test/include/kill_mysqld.inc | 4 ++-- mysql-test/include/shutdown_mysqld.inc | 4 ++-- mysql-test/main/shutdown.test | 4 ++-- mysql-test/suite/galera/include/kill_galera.inc | 4 ++-- mysql-test/suite/galera/include/shutdown_mysqld.inc | 4 ++-- mysql-test/suite/galera/t/galera_ist_restart_joiner.test | 4 ++-- mysql-test/suite/galera_3nodes_sr/t/GCF-832.test | 4 ++-- mysql-test/suite/innodb/t/alter_crash.test | 4 ++-- mysql-test/suite/innodb/t/innodb-alter-tempfile.test | 4 ++-- .../suite/innodb/t/innodb-change-buffer-recovery.test | 4 ++-- mysql-test/suite/innodb/t/innodb-wl5522-debug.test | 4 ++-- mysql-test/suite/innodb/t/purge_thread_shutdown.test | 4 ++-- mysql-test/suite/innodb/t/redo_log_during_checkpoint.test | 4 ++-- mysql-test/suite/innodb/t/restart.test | 2 -- mysql-test/suite/innodb/t/temporary_table.test | 4 ++-- mysql-test/suite/innodb_fts/t/sync.test | 3 ++- .../rocksdb/include/restart_mysqld_with_option.inc | 4 ++-- .../rocksdb/t/allow_to_start_after_corruption.test | 1 + .../rocksdb/mysql-test/rocksdb/t/persistent_cache.test | 4 ++-- .../rocksdb/mysql-test/rocksdb/t/validate_datadic.test | 4 ++-- .../t/rocksdb_rate_limiter_bytes_per_sec_basic.test | 4 ++-- .../mysql-test/spider/bugfix/include/restart_spider.inc | 8 -------- .../spider/mysql-test/spider/bugfix/r/mdev_29352.result | 1 + storage/spider/mysql-test/spider/bugfix/t/mdev_29352.test | 2 +- 26 files changed, 45 insertions(+), 52 deletions(-) delete mode 100644 storage/spider/mysql-test/spider/bugfix/include/restart_spider.inc diff --git a/mysql-test/include/expect_crash.inc b/mysql-test/include/expect_crash.inc index af8b090810415..b4bd9828a089f 100644 --- a/mysql-test/include/expect_crash.inc +++ b/mysql-test/include/expect_crash.inc @@ -1,5 +1,5 @@ ---let $_server_id= `SELECT @@server_id` ---let $_expect_file_name= $MYSQLTEST_VARDIR/tmp/mysqld.$_server_id.expect +--let $_expect_file_name= `select regexp_replace(@@tmpdir, '^.*/','')` +--let $_expect_file_name= $MYSQLTEST_VARDIR/tmp/$_expect_file_name.expect # There should be a debug crash after using this .inc file --exec echo "wait" > $_expect_file_name diff --git a/mysql-test/include/kill_galera.inc b/mysql-test/include/kill_galera.inc index d7f665df6c750..aba672d8a8928 100644 --- a/mysql-test/include/kill_galera.inc +++ b/mysql-test/include/kill_galera.inc @@ -1,8 +1,8 @@ --echo Killing server ... # Write file to make mysql-test-run.pl expect the crash, but don't start it ---let $_server_id= `SELECT @@server_id` ---let $_expect_file_name= $MYSQLTEST_VARDIR/tmp/mysqld.$_server_id.expect +--let $_expect_file_name= `select regexp_replace(@@tmpdir, '^.*/','')` +--let $_expect_file_name= $MYSQLTEST_VARDIR/tmp/$_expect_file_name.expect --exec echo "wait" > $_expect_file_name # Kill the connected server diff --git a/mysql-test/include/kill_mysqld.inc b/mysql-test/include/kill_mysqld.inc index 86ee048a0f18c..01ee7f82bdc13 100644 --- a/mysql-test/include/kill_mysqld.inc +++ b/mysql-test/include/kill_mysqld.inc @@ -1,5 +1,5 @@ ---let $_server_id= `SELECT @@server_id` ---let $_expect_file_name= $MYSQLTEST_VARDIR/tmp/mysqld.$_server_id.expect +--let $_expect_file_name= `select regexp_replace(@@tmpdir, '^.*/','')` +--let $_expect_file_name= $MYSQLTEST_VARDIR/tmp/$_expect_file_name.expect --echo # Kill the server --exec echo "wait" > $_expect_file_name diff --git a/mysql-test/include/shutdown_mysqld.inc b/mysql-test/include/shutdown_mysqld.inc index 74a3028946dd1..9518b880e898f 100644 --- a/mysql-test/include/shutdown_mysqld.inc +++ b/mysql-test/include/shutdown_mysqld.inc @@ -22,8 +22,8 @@ if ($rpl_inited) } # Write file to make mysql-test-run.pl expect the "crash", but don't start it ---let $_server_id= `SELECT @@server_id` ---let $_expect_file_name= $MYSQLTEST_VARDIR/tmp/mysqld.$_server_id.expect +--let $_expect_file_name= `select regexp_replace(@@tmpdir, '^.*/','')` +--let $_expect_file_name= $MYSQLTEST_VARDIR/tmp/$_expect_file_name.expect --exec echo "wait" > $_expect_file_name --let $server_shutdown_timeout= 60 diff --git a/mysql-test/main/shutdown.test b/mysql-test/main/shutdown.test index b670cfc26990f..1e9d8e9ba9248 100644 --- a/mysql-test/main/shutdown.test +++ b/mysql-test/main/shutdown.test @@ -18,8 +18,8 @@ disconnect c1; create procedure try_shutdown() shutdown; drop procedure try_shutdown; ---let $_server_id= `SELECT @@server_id` ---let $_expect_file_name= $MYSQLTEST_VARDIR/tmp/mysqld.$_server_id.expect +--let $_expect_file_name= `select regexp_replace(@@tmpdir, '^.*/','')` +--let $_expect_file_name= $MYSQLTEST_VARDIR/tmp/$_expect_file_name.expect --exec echo "wait" > $_expect_file_name --send shutdown diff --git a/mysql-test/suite/galera/include/kill_galera.inc b/mysql-test/suite/galera/include/kill_galera.inc index 56118df84f976..28a1b0f368c3c 100644 --- a/mysql-test/suite/galera/include/kill_galera.inc +++ b/mysql-test/suite/galera/include/kill_galera.inc @@ -6,8 +6,8 @@ if (!$kill_signal) } # Write file to make mysql-test-run.pl expect the crash, but don't start it ---let $_server_id= `SELECT @@server_id` ---let $_expect_file_name= $MYSQLTEST_VARDIR/tmp/mysqld.$_server_id.expect +--let $_expect_file_name= `select regexp_replace(@@tmpdir, '^.*/','')` +--let $_expect_file_name= $MYSQLTEST_VARDIR/tmp/$_expect_file_name.expect --exec echo "wait" > $_expect_file_name # Kill the connected server diff --git a/mysql-test/suite/galera/include/shutdown_mysqld.inc b/mysql-test/suite/galera/include/shutdown_mysqld.inc index 54bba1318e717..793be8d76acb2 100644 --- a/mysql-test/suite/galera/include/shutdown_mysqld.inc +++ b/mysql-test/suite/galera/include/shutdown_mysqld.inc @@ -8,8 +8,8 @@ if ($rpl_inited) } # Write file to make mysql-test-run.pl expect the "crash", but don't start it ---let $_server_id= `SELECT @@server_id` ---let $_expect_file_name= $MYSQLTEST_VARDIR/tmp/mysqld.$_server_id.expect +--let $_expect_file_name= `select regexp_replace(@@tmpdir, '^.*/','')` +--let $_expect_file_name= $MYSQLTEST_VARDIR/tmp/$_expect_file_name.expect --exec echo "wait" > $_expect_file_name # Send shutdown to the connected server diff --git a/mysql-test/suite/galera/t/galera_ist_restart_joiner.test b/mysql-test/suite/galera/t/galera_ist_restart_joiner.test index c535ac455b9a8..b36a0de57b6ee 100644 --- a/mysql-test/suite/galera/t/galera_ist_restart_joiner.test +++ b/mysql-test/suite/galera/t/galera_ist_restart_joiner.test @@ -35,8 +35,8 @@ UPDATE t1 SET f2 = 'c' WHERE f1 > 2; --connection node_2 # Write file to make mysql-test-run.pl expect the crash, but don't start it ---let $_server_id= `SELECT @@server_id` ---let $_expect_file_name= $MYSQLTEST_VARDIR/tmp/mysqld.$_server_id.expect +--let $_expect_file_name= `select regexp_replace(@@tmpdir, '^.*/','')` +--let $_expect_file_name= $MYSQLTEST_VARDIR/tmp/$_expect_file_name.expect --exec echo "wait" > $_expect_file_name --let KILL_NODE_PIDFILE = `SELECT @@pid_file` diff --git a/mysql-test/suite/galera_3nodes_sr/t/GCF-832.test b/mysql-test/suite/galera_3nodes_sr/t/GCF-832.test index eb7f5603452ee..ab8b62b969a91 100644 --- a/mysql-test/suite/galera_3nodes_sr/t/GCF-832.test +++ b/mysql-test/suite/galera_3nodes_sr/t/GCF-832.test @@ -15,8 +15,8 @@ --connection node_2 SET GLOBAL debug_dbug="d,crash_last_fragment_commit_after_fragment_removal"; ---let $_server_id= `SELECT @@server_id` ---let $_expect_file_name= $MYSQLTEST_VARDIR/tmp/mysqld.$_server_id.expect +--let $_expect_file_name= `select regexp_replace(@@tmpdir, '^.*/','')` +--let $_expect_file_name= $MYSQLTEST_VARDIR/tmp/$_expect_file_name.expect --exec echo "wait" > $_expect_file_name CREATE TABLE t1 (f1 VARCHAR(30)) ENGINE=InnoDB; diff --git a/mysql-test/suite/innodb/t/alter_crash.test b/mysql-test/suite/innodb/t/alter_crash.test index 7a2f4452f4df4..6f6a6dc5cbc7e 100644 --- a/mysql-test/suite/innodb/t/alter_crash.test +++ b/mysql-test/suite/innodb/t/alter_crash.test @@ -51,8 +51,8 @@ let $MYSQLD_DATADIR= `select @@datadir`; let datadir= `select @@datadir`; # These are from include/shutdown_mysqld.inc and allow to call start_mysqld.inc ---let $_server_id= `SELECT @@server_id` ---let $_expect_file_name= $MYSQLTEST_VARDIR/tmp/mysqld.$_server_id.expect +--let $_expect_file_name= `select regexp_replace(@@tmpdir, '^.*/','')` +--let $_expect_file_name= $MYSQLTEST_VARDIR/tmp/$_expect_file_name.expect --echo # --echo # Bug #14669848 CRASH DURING ALTER MAKES ORIGINAL TABLE INACCESSIBLE diff --git a/mysql-test/suite/innodb/t/innodb-alter-tempfile.test b/mysql-test/suite/innodb/t/innodb-alter-tempfile.test index dac176f3b77cd..26576129a16ca 100644 --- a/mysql-test/suite/innodb/t/innodb-alter-tempfile.test +++ b/mysql-test/suite/innodb/t/innodb-alter-tempfile.test @@ -29,8 +29,8 @@ call mtr.add_suppression("InnoDB could not find key no 1 with name f2 from dict let datadir= `select @@datadir`; ---let $_server_id= `SELECT @@server_id` ---let $_expect_file_name=$MYSQLTEST_VARDIR/tmp/mysqld.$_server_id.expect +--let $_expect_file_name= `select regexp_replace(@@tmpdir, '^.*/','')` +--let $_expect_file_name= $MYSQLTEST_VARDIR/tmp/$_expect_file_name.expect CREATE TABLE t1 (f1 INT NOT NULL, f2 INT NOT NULL) ENGINE=innodb; SET debug_dbug='+d,innodb_alter_commit_crash_before_commit'; diff --git a/mysql-test/suite/innodb/t/innodb-change-buffer-recovery.test b/mysql-test/suite/innodb/t/innodb-change-buffer-recovery.test index 79d9cc814a0d7..2f0377ff80efc 100644 --- a/mysql-test/suite/innodb/t/innodb-change-buffer-recovery.test +++ b/mysql-test/suite/innodb/t/innodb-change-buffer-recovery.test @@ -25,8 +25,8 @@ CREATE TABLE t1( INDEX(b)) ENGINE=InnoDB STATS_PERSISTENT=0; ---let $_server_id= `SELECT @@server_id` ---let $_expect_file_name= $MYSQLTEST_VARDIR/tmp/mysqld.$_server_id.expect +--let $_expect_file_name= `select regexp_replace(@@tmpdir, '^.*/','')` +--let $_expect_file_name= $MYSQLTEST_VARDIR/tmp/$_expect_file_name.expect # The flag innodb_change_buffering_debug is only available in debug builds. # It instructs InnoDB to try to evict pages from the buffer pool when diff --git a/mysql-test/suite/innodb/t/innodb-wl5522-debug.test b/mysql-test/suite/innodb/t/innodb-wl5522-debug.test index 79ea475390447..272afc0a2ba0c 100644 --- a/mysql-test/suite/innodb/t/innodb-wl5522-debug.test +++ b/mysql-test/suite/innodb/t/innodb-wl5522-debug.test @@ -37,8 +37,8 @@ SET GLOBAL innodb_file_per_table = 1; CREATE TABLE t1 (c1 INT) ENGINE = InnoDB; INSERT INTO t1 VALUES(1),(2),(3); ---let $_server_id= `SELECT @@server_id` ---let $_expect_file_name= $MYSQLTEST_VARDIR/tmp/mysqld.$_server_id.expect +--let $_expect_file_name= `select regexp_replace(@@tmpdir, '^.*/','')` +--let $_expect_file_name= $MYSQLTEST_VARDIR/tmp/$_expect_file_name.expect --exec echo wait > $_expect_file_name SET SESSION debug_dbug="+d,ib_discard_before_commit_crash"; diff --git a/mysql-test/suite/innodb/t/purge_thread_shutdown.test b/mysql-test/suite/innodb/t/purge_thread_shutdown.test index 5be29b7a6a3b8..762336cf0d14d 100644 --- a/mysql-test/suite/innodb/t/purge_thread_shutdown.test +++ b/mysql-test/suite/innodb/t/purge_thread_shutdown.test @@ -12,8 +12,8 @@ select user,state from information_schema.processlist order by 2; set global debug_dbug='+d,only_kill_system_threads'; set global innodb_fast_shutdown=0; -let $_server_id= `SELECT @@server_id`; -let $_expect_file_name= $MYSQLTEST_VARDIR/tmp/mysqld.$_server_id.expect; +--let $_expect_file_name= `select regexp_replace(@@tmpdir, '^.*/','')` +--let $_expect_file_name= $MYSQLTEST_VARDIR/tmp/$_expect_file_name.expect exec echo "wait" > $_expect_file_name; send shutdown; diff --git a/mysql-test/suite/innodb/t/redo_log_during_checkpoint.test b/mysql-test/suite/innodb/t/redo_log_during_checkpoint.test index 645ae8c78553e..fcacd9a10d4ee 100644 --- a/mysql-test/suite/innodb/t/redo_log_during_checkpoint.test +++ b/mysql-test/suite/innodb/t/redo_log_during_checkpoint.test @@ -30,8 +30,8 @@ while ($i) } --enable_query_log ---let $_server_id= `SELECT @@server_id` ---let $_expect_file_name= $MYSQLTEST_VARDIR/tmp/mysqld.$_server_id.expect +--let $_expect_file_name= `select regexp_replace(@@tmpdir, '^.*/','')` +--let $_expect_file_name= $MYSQLTEST_VARDIR/tmp/$_expect_file_name.expect --exec echo "wait" > $_expect_file_name SET debug_dbug = '+d,increase_mtr_checkpoint_size'; diff --git a/mysql-test/suite/innodb/t/restart.test b/mysql-test/suite/innodb/t/restart.test index 32058b3abf54f..3e726c971abf4 100644 --- a/mysql-test/suite/innodb/t/restart.test +++ b/mysql-test/suite/innodb/t/restart.test @@ -110,8 +110,6 @@ SET GLOBAL innodb_buffer_pool_size = @innodb_buffer_pool_size_orig; --echo # --let MYSQLD_DATADIR= `SELECT @@datadir` ---let SERVER_ID= `SELECT @@server_id` ---let EXPECT_FILE_NAME= $MYSQLTEST_VARDIR/tmp/mysqld.$SERVER_ID.expect --source include/shutdown_mysqld.inc diff --git a/mysql-test/suite/innodb/t/temporary_table.test b/mysql-test/suite/innodb/t/temporary_table.test index cc290b03c3461..0549bab2779ee 100644 --- a/mysql-test/suite/innodb/t/temporary_table.test +++ b/mysql-test/suite/innodb/t/temporary_table.test @@ -11,7 +11,7 @@ --source include/no_valgrind_without_big.inc --disable_query_log -call mtr.add_suppression("Can't create/write to file '/dev/null/nonexistent/ib"); +call mtr.add_suppression("Can't create/write to file '/dev/null/.*/ib"); call mtr.add_suppression("InnoDB: Unable to create temporary file"); call mtr.add_suppression("last file in setting innodb_temp_data_file_path"); call mtr.add_suppression("The table 't1' is full"); @@ -134,7 +134,7 @@ AND support IN ('YES', 'DEFAULT', 'ENABLED'); # We cannot use include/restart_mysqld.inc in this particular test, # because SHOW STATUS would fail due to unwritable (nonexistent) tmpdir. --source include/shutdown_mysqld.inc ---exec echo "restart: --tmpdir=/dev/null/nonexistent" > $_expect_file_name +--exec echo "restart: --tmpdir=/dev/null/$MYSQL_TMP_DIR" > $_expect_file_name --enable_reconnect --disable_result_log --disable_query_log diff --git a/mysql-test/suite/innodb_fts/t/sync.test b/mysql-test/suite/innodb_fts/t/sync.test index 3bd5b56a21bd6..e4f04ef426943 100644 --- a/mysql-test/suite/innodb_fts/t/sync.test +++ b/mysql-test/suite/innodb_fts/t/sync.test @@ -104,7 +104,8 @@ disconnect con1; DROP TABLE t1; --echo # Case 3: Test insert crash recovery ---let $_expect_file_name=$MYSQLTEST_VARDIR/tmp/mysqld.$_server_id.expect +--let $_expect_file_name= `select regexp_replace(@@tmpdir, '^.*/','')` +--let $_expect_file_name= $MYSQLTEST_VARDIR/tmp/$_expect_file_name.expect CREATE TABLE t1 ( FTS_DOC_ID BIGINT UNSIGNED AUTO_INCREMENT NOT NULL PRIMARY KEY, diff --git a/storage/rocksdb/mysql-test/rocksdb/include/restart_mysqld_with_option.inc b/storage/rocksdb/mysql-test/rocksdb/include/restart_mysqld_with_option.inc index 81cd2200ae06c..a87fe01b3a1ce 100644 --- a/storage/rocksdb/mysql-test/rocksdb/include/restart_mysqld_with_option.inc +++ b/storage/rocksdb/mysql-test/rocksdb/include/restart_mysqld_with_option.inc @@ -9,8 +9,8 @@ if ($rpl_inited) # Write file to make mysql-test-run.pl expect the "crash", but don't start # it until it's told to ---let $_server_id= `SELECT @@server_id` ---let $_expect_file_name= $MYSQLTEST_VARDIR/tmp/mysqld.$_server_id.expect +--let $_expect_file_name= `select regexp_replace(@@tmpdir, '^.*/','')` +--let $_expect_file_name= $MYSQLTEST_VARDIR/tmp/$_expect_file_name.expect --exec echo "wait" > $_expect_file_name # Send shutdown to the connected server and give diff --git a/storage/rocksdb/mysql-test/rocksdb/t/allow_to_start_after_corruption.test b/storage/rocksdb/mysql-test/rocksdb/t/allow_to_start_after_corruption.test index e084b57fbdaf8..88a02c469bb2c 100644 --- a/storage/rocksdb/mysql-test/rocksdb/t/allow_to_start_after_corruption.test +++ b/storage/rocksdb/mysql-test/rocksdb/t/allow_to_start_after_corruption.test @@ -16,6 +16,7 @@ # restart server to change error log and ignore corruptopn on startup --let $_mysqld_option=--log-error=$LOG --rocksdb_allow_to_start_after_corruption=1 --source include/restart_mysqld_with_option.inc +--let $_server_id= `SELECT @@server_id` --echo # --echo # Test server crashes on corrupted data and restarts diff --git a/storage/rocksdb/mysql-test/rocksdb/t/persistent_cache.test b/storage/rocksdb/mysql-test/rocksdb/t/persistent_cache.test index 49e5e5c11726f..da9d8602c011c 100644 --- a/storage/rocksdb/mysql-test/rocksdb/t/persistent_cache.test +++ b/storage/rocksdb/mysql-test/rocksdb/t/persistent_cache.test @@ -4,8 +4,8 @@ DROP TABLE IF EXISTS t1; --enable_warnings ---let $_server_id= `SELECT @@server_id` ---let $_expect_file_name= $MYSQLTEST_VARDIR/tmp/mysqld.$_server_id.expect +--let $_expect_file_name= `select regexp_replace(@@tmpdir, '^.*/','')` +--let $_expect_file_name= $MYSQLTEST_VARDIR/tmp/$_expect_file_name.expect --let $_cache_file_name= $MYSQLTEST_VARDIR/tmp/persistent_cache --exec echo "wait" >$_expect_file_name diff --git a/storage/rocksdb/mysql-test/rocksdb/t/validate_datadic.test b/storage/rocksdb/mysql-test/rocksdb/t/validate_datadic.test index e7ab37d2658be..b2647b38e088d 100644 --- a/storage/rocksdb/mysql-test/rocksdb/t/validate_datadic.test +++ b/storage/rocksdb/mysql-test/rocksdb/t/validate_datadic.test @@ -17,8 +17,8 @@ CREATE TABLE t2 (pk int primary key) ENGINE=ROCKSDB PARTITION BY KEY(pk) PARTITI # Write file to make mysql-test-run.pl expect the "crash", but don't restart the # server until it is told to ---let $_server_id= `SELECT @@server_id` ---let $_expect_file_name= $MYSQLTEST_VARDIR/tmp/mysqld.$_server_id.expect +--let $_expect_file_name= `select regexp_replace(@@tmpdir, '^.*/','')` +--let $_expect_file_name= $MYSQLTEST_VARDIR/tmp/$_expect_file_name.expect --let LOG=$MYSQLTEST_VARDIR/tmp/validate_datadic.err --exec echo "wait" >$_expect_file_name diff --git a/storage/rocksdb/mysql-test/rocksdb_sys_vars/t/rocksdb_rate_limiter_bytes_per_sec_basic.test b/storage/rocksdb/mysql-test/rocksdb_sys_vars/t/rocksdb_rate_limiter_bytes_per_sec_basic.test index 743f942af9cd2..1daa9898c1ae6 100644 --- a/storage/rocksdb/mysql-test/rocksdb_sys_vars/t/rocksdb_rate_limiter_bytes_per_sec_basic.test +++ b/storage/rocksdb/mysql-test/rocksdb_sys_vars/t/rocksdb_rate_limiter_bytes_per_sec_basic.test @@ -7,8 +7,8 @@ SET @@global.rocksdb_rate_limiter_bytes_per_sec = 10000; # Write file to make mysql-test-run.pl expect the "crash", but don't restart the # server until it is told to ---let $_server_id= `SELECT @@server_id` ---let $_expect_file_name= $MYSQLTEST_VARDIR/tmp/mysqld.$_server_id.expect +--let $_expect_file_name= `select regexp_replace(@@tmpdir, '^.*/','')` +--let $_expect_file_name= $MYSQLTEST_VARDIR/tmp/$_expect_file_name.expect --exec echo "wait" >$_expect_file_name # Send shutdown to the connected server and give it 10 seconds to die before diff --git a/storage/spider/mysql-test/spider/bugfix/include/restart_spider.inc b/storage/spider/mysql-test/spider/bugfix/include/restart_spider.inc deleted file mode 100644 index a5446a6188dc0..0000000000000 --- a/storage/spider/mysql-test/spider/bugfix/include/restart_spider.inc +++ /dev/null @@ -1,8 +0,0 @@ ---let $_expect_file_name= $MYSQLTEST_VARDIR/tmp/mysqld.1.1.expect - ---exec echo "wait" > $_expect_file_name ---shutdown_server ---source include/wait_until_disconnected.inc ---exec echo "restart" > $_expect_file_name ---enable_reconnect ---source include/wait_until_connected_again.inc diff --git a/storage/spider/mysql-test/spider/bugfix/r/mdev_29352.result b/storage/spider/mysql-test/spider/bugfix/r/mdev_29352.result index 5715edf2bd686..975d3834d4258 100644 --- a/storage/spider/mysql-test/spider/bugfix/r/mdev_29352.result +++ b/storage/spider/mysql-test/spider/bugfix/r/mdev_29352.result @@ -9,4 +9,5 @@ CREATE FUNCTION spider_bg_direct_sql RETURNS INT SONAME 'ha_spider.so'; ERROR HY000: Can't execute the query because you have a conflicting read lock SELECT * FROM t; c +# restart DROP TABLE t; diff --git a/storage/spider/mysql-test/spider/bugfix/t/mdev_29352.test b/storage/spider/mysql-test/spider/bugfix/t/mdev_29352.test index 00d8ee73ebc9b..626364efb99a5 100644 --- a/storage/spider/mysql-test/spider/bugfix/t/mdev_29352.test +++ b/storage/spider/mysql-test/spider/bugfix/t/mdev_29352.test @@ -6,6 +6,6 @@ FLUSH TABLES WITH READ LOCK; CREATE FUNCTION spider_bg_direct_sql RETURNS INT SONAME 'ha_spider.so'; SELECT * FROM t; ---source include/restart_spider.inc +--source include/restart_mysqld.inc DROP TABLE t; From ff3d4395d808b6421d2e0714e10d48c7aa2f3c3a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marko=20M=C3=A4kel=C3=A4?= Date: Wed, 22 Mar 2023 14:31:00 +0200 Subject: [PATCH 52/92] MDEV-30882 Crash on ROLLBACK in a ROW_FORMAT=COMPRESSED table MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit row_upd_rec_in_place(): Avoid calling page_zip_write_rec() if we are not modifying any fields that are stored in compressed format. btr_cur_update_in_place_zip_check(): New function to check if a ROW_FORMAT=COMPRESSED record can actually be updated in place. btr_cur_pessimistic_update(): If the BTR_KEEP_POS_FLAG is not set (we are in a ROLLBACK and cannot write any BLOBs), ignore the potential overflow and let page_zip_reorganize() or page_zip_compress() handle it. This avoids a failure when an attempted UPDATE of an NULL column to 0 is rolled back. During the ROLLBACK, we would try to move a non-updated long column to off-page storage in order to avoid a compression failure of the ROW_FORMAT=COMPRESSED page. page_zip_write_trx_id_and_roll_ptr(): Remove an assertion that would fail in row_upd_rec_in_place() because the uncompressed page would already have been modified there. Thanks to Jean-François Gagné for providing a copy of a page that triggered these bugs on the ROLLBACK of UPDATE and DELETE. A 10.6 version of this was tested by Matthias Leich using cmake -DWITH_INNODB_EXTRA_DEBUG=ON a.k.a. UNIV_ZIP_DEBUG. --- storage/innobase/btr/btr0cur.cc | 69 +++++++++++++++++++++++++------ storage/innobase/page/page0zip.cc | 3 -- storage/innobase/row/row0upd.cc | 37 ++++++++++++++++- 3 files changed, 92 insertions(+), 17 deletions(-) diff --git a/storage/innobase/btr/btr0cur.cc b/storage/innobase/btr/btr0cur.cc index 3164352892e05..d4e1497d9b31f 100644 --- a/storage/innobase/btr/btr0cur.cc +++ b/storage/innobase/btr/btr0cur.cc @@ -4210,6 +4210,52 @@ btr_cur_update_alloc_zip_func( return(false); } +/** Check if a ROW_FORMAT=COMPRESSED page can be updated in place +@param cur cursor pointing to ROW_FORMAT=COMPRESSED page +@param offsets rec_get_offsets(btr_cur_get_rec(cur)) +@param update index fields being updated +@param mtr mini-transaction +@return the record in the ROW_FORMAT=COMPRESSED page +@retval nullptr if the page cannot be updated in place */ +ATTRIBUTE_COLD static +rec_t *btr_cur_update_in_place_zip_check(btr_cur_t *cur, rec_offs *offsets, + const upd_t& update, mtr_t *mtr) +{ + dict_index_t *index= cur->index; + ut_ad(!index->table->is_temporary()); + + switch (update.n_fields) { + case 0: + /* We are only changing the delete-mark flag. */ + break; + case 1: + if (!index->is_clust() || + update.fields[0].field_no != index->db_roll_ptr()) + goto check_for_overflow; + /* We are only changing the delete-mark flag and DB_ROLL_PTR. */ + break; + case 2: + if (!index->is_clust() || + update.fields[0].field_no != index->db_trx_id() || + update.fields[1].field_no != index->db_roll_ptr()) + goto check_for_overflow; + /* We are only changing DB_TRX_ID, DB_ROLL_PTR, and the delete-mark. + They can be updated in place in the uncompressed part of the + ROW_FORMAT=COMPRESSED page. */ + break; + check_for_overflow: + default: + if (!btr_cur_update_alloc_zip(btr_cur_get_page_zip(cur), + btr_cur_get_page_cur(cur), + index, + offsets, rec_offs_size(offsets), + false, mtr)) + return nullptr; + } + + return btr_cur_get_rec(cur); +} + /*************************************************************//** Updates a record when the update causes no size changes in its fields. We assume here that the ordering fields of the record do not change. @@ -4271,17 +4317,10 @@ btr_cur_update_in_place( page_zip = buf_block_get_page_zip(block); /* Check that enough space is available on the compressed page. */ - if (page_zip) { - ut_ad(!index->table->is_temporary()); - - if (!btr_cur_update_alloc_zip( - page_zip, btr_cur_get_page_cur(cursor), - index, offsets, rec_offs_size(offsets), - false, mtr)) { - return(DB_ZIP_OVERFLOW); - } - - rec = btr_cur_get_rec(cursor); + if (UNIV_LIKELY_NULL(page_zip) + && !(rec = btr_cur_update_in_place_zip_check( + cursor, offsets, *update, mtr))) { + return DB_ZIP_OVERFLOW; } /* Do lock checking and undo logging */ @@ -5034,7 +5073,13 @@ btr_cur_pessimistic_update( ut_ad(page_is_leaf(page)); ut_ad(dict_index_is_clust(index)); - ut_ad(flags & BTR_KEEP_POS_FLAG); + if (UNIV_UNLIKELY(!(flags & BTR_KEEP_POS_FLAG))) { + ut_ad(page_zip != NULL); + dtuple_convert_back_big_rec(index, new_entry, + big_rec_vec); + big_rec_vec = NULL; + n_ext = dtuple_get_n_ext(new_entry); + } } /* Do lock checking and undo logging */ diff --git a/storage/innobase/page/page0zip.cc b/storage/innobase/page/page0zip.cc index 13c6f58a171e8..742c91606b2c5 100644 --- a/storage/innobase/page/page0zip.cc +++ b/storage/innobase/page/page0zip.cc @@ -4132,9 +4132,6 @@ page_zip_write_trx_id_and_roll_ptr( ut_ad(field + DATA_TRX_ID_LEN == rec_get_nth_field(rec, offsets, trx_id_col + 1, &len)); ut_ad(len == DATA_ROLL_PTR_LEN); -#if defined UNIV_DEBUG || defined UNIV_ZIP_DEBUG - ut_a(!memcmp(storage, field, DATA_TRX_ID_LEN + DATA_ROLL_PTR_LEN)); -#endif /* UNIV_DEBUG || UNIV_ZIP_DEBUG */ compile_time_assert(DATA_TRX_ID_LEN == 6); mach_write_to_6(field, trx_id); compile_time_assert(DATA_ROLL_PTR_LEN == 7); diff --git a/storage/innobase/row/row0upd.cc b/storage/innobase/row/row0upd.cc index c7087559f4744..0ea7aea7fb1e0 100644 --- a/storage/innobase/row/row0upd.cc +++ b/storage/innobase/row/row0upd.cc @@ -692,9 +692,42 @@ row_upd_rec_in_place( dfield_get_len(new_val)); } - if (page_zip) { - page_zip_write_rec(page_zip, rec, index, offsets, 0); + if (UNIV_LIKELY(!page_zip)) { + return; } + + switch (update->n_fields) { + case 0: + /* We only changed the delete-mark flag. */ + update_del_mark: + page_zip_rec_set_deleted(page_zip, rec, + rec_get_deleted_flag(rec, true)); + return; + case 1: + if (!index->is_clust() + || update->fields[0].field_no != index->db_roll_ptr()) { + break; + } + goto update_sys; + case 2: + if (!index->is_clust() + || update->fields[0].field_no != index->db_trx_id() + || update->fields[1].field_no != index->db_roll_ptr()) { + break; + } + update_sys: + ulint len; + const byte* sys = rec_get_nth_field(rec, offsets, + index->db_trx_id(), &len); + ut_ad(len == DATA_TRX_ID_LEN); + page_zip_write_trx_id_and_roll_ptr( + page_zip, rec, offsets, index->db_trx_id(), + trx_read_trx_id(sys), + trx_read_roll_ptr(sys + DATA_TRX_ID_LEN)); + goto update_del_mark; + } + + page_zip_write_rec(page_zip, rec, index, offsets, 0); } /*********************************************************************//** From c596ad734daad090a766d71ef0446444fdc83904 Mon Sep 17 00:00:00 2001 From: Anel Husakovic Date: Wed, 8 Mar 2023 12:59:50 +0100 Subject: [PATCH 53/92] MDEV-30269: Remove rpl_semi_sync_[slave,master] usage in code - Description: - Before 10.3.8 semisync was a plugin that is built into the server with MDEV-13073,starting with commit cbc71485e24c31fc822277625512e55c2a8b650b. There are still some usage of `rpl_semi_sync_master` in mtr. Note: - To recognize the replica in the `dump_thread`, replica is creating local variable `rpl_semi_sync_slave` (the keyword of plugin) in function `request_transmit`, that is catched by primary in `is_semi_sync_slave()`. This is the user variable and as such not related to the obsolete plugin. - Found in `sys_vars.all_vars` and `rpl_semi_sync_wait_point` tests, usage of plugins `rpl_semi_sync_master`, `rpl_semi_sync_slave`. The former test is disabled by default (`sys_vars/disabled.def`) and marked as `obsolete`, however this patch will remove the queries. - Add cosmetic fixes to semisync codebase Reviewer: Closes PR #2528, PR #2380 --- mysql-test/suite/rpl/r/rpl_semi_sync_wait_point.result | 2 -- mysql-test/suite/rpl/t/rpl_semi_sync_wait_point.test | 2 -- mysql-test/suite/sys_vars/t/all_vars.test | 2 -- sql/semisync_master.cc | 6 ++---- sql/sql_repl.cc | 2 +- 5 files changed, 3 insertions(+), 11 deletions(-) diff --git a/mysql-test/suite/rpl/r/rpl_semi_sync_wait_point.result b/mysql-test/suite/rpl/r/rpl_semi_sync_wait_point.result index a0ea06afa89da..c303abc672c0d 100644 --- a/mysql-test/suite/rpl/r/rpl_semi_sync_wait_point.result +++ b/mysql-test/suite/rpl/r/rpl_semi_sync_wait_point.result @@ -7,8 +7,6 @@ SET @@global.rpl_semi_sync_master_timeout = 60000; SET @@global.rpl_semi_sync_master_wait_no_slave = 1; # It's okay to see "Killed" but we should not see "Timeout" in the log. call mtr.add_suppression("Killed waiting for reply of binlog"); -call mtr.add_suppression("Run function 'after_commit' in plugin 'rpl_semi_sync_master' failed"); -call mtr.add_suppression("Run function 'after_sync' in plugin 'rpl_semi_sync_master' failed"); # # Test wait point = AFTER_COMMIT # diff --git a/mysql-test/suite/rpl/t/rpl_semi_sync_wait_point.test b/mysql-test/suite/rpl/t/rpl_semi_sync_wait_point.test index dcff4030fdbb5..5eae91a55f25b 100644 --- a/mysql-test/suite/rpl/t/rpl_semi_sync_wait_point.test +++ b/mysql-test/suite/rpl/t/rpl_semi_sync_wait_point.test @@ -23,8 +23,6 @@ SET @@global.rpl_semi_sync_master_wait_no_slave = 1; --echo # It's okay to see "Killed" but we should not see "Timeout" in the log. call mtr.add_suppression("Killed waiting for reply of binlog"); -call mtr.add_suppression("Run function 'after_commit' in plugin 'rpl_semi_sync_master' failed"); -call mtr.add_suppression("Run function 'after_sync' in plugin 'rpl_semi_sync_master' failed"); --echo # --echo # Test wait point = AFTER_COMMIT diff --git a/mysql-test/suite/sys_vars/t/all_vars.test b/mysql-test/suite/sys_vars/t/all_vars.test index c0127e1ef1236..570c0f140de07 100644 --- a/mysql-test/suite/sys_vars/t/all_vars.test +++ b/mysql-test/suite/sys_vars/t/all_vars.test @@ -13,8 +13,6 @@ eval INSTALL PLUGIN federated SONAME "$HA_FEDERATEDX_SO"; eval INSTALL PLUGIN oqgraph SONAME "$HA_OQGRAPH_SO"; eval INSTALL PLUGIN sphinx SONAME "$HA_SPHINX_SO"; eval INSTALL PLUGIN innodb SONAME "$HA_INNODB_SO"; -eval INSTALL PLUGIN rpl_semi_sync_master SONAME "$SEMISYNC_MASTER_SO"; -eval INSTALL PLUGIN rpl_semi_sync_slave SONAME "$SEMISYNC_SLAVE_SO"; --enable_abort_on_error --enable_result_log --enable_query_log diff --git a/sql/semisync_master.cc b/sql/semisync_master.cc index ee4a01610851f..63a50539e5066 100644 --- a/sql/semisync_master.cc +++ b/sql/semisync_master.cc @@ -317,8 +317,8 @@ void Active_tranx::clear_active_tranx_nodes(const char *log_file_name, /******************************************************************************* * - * class: the basic code layer for syncsync master. - * class: the basic code layer for syncsync slave. + * class: the basic code layer for semisync master. + * class: the basic code layer for semisync slave. * * The most important functions during semi-syn replication listed: * @@ -809,8 +809,6 @@ void Repl_semi_sync_master::dump_end(THD* thd) remove_slave(); ack_receiver.remove_slave(thd); - - return; } int Repl_semi_sync_master::commit_trx(const char* trx_wait_binlog_name, diff --git a/sql/sql_repl.cc b/sql/sql_repl.cc index 82663c3ca2cc7..d9b9374219549 100644 --- a/sql/sql_repl.cc +++ b/sql/sql_repl.cc @@ -433,7 +433,7 @@ static int send_file(THD *thd) /** Internal to mysql_binlog_send() routine that recalculates checksum for - 1. FD event (asserted) that needs additional arranment prior sending to slave. + 1. FD event (asserted) that needs additional arrangement prior sending to slave. 2. Start_encryption_log_event whose Ignored flag is set TODO DBUG_ASSERT can be removed if this function is used for more general cases */ From bdf5580611f8a052b21227666f38107936f7f771 Mon Sep 17 00:00:00 2001 From: Aleksey Midenkov Date: Thu, 23 Mar 2023 21:07:32 +0300 Subject: [PATCH 54/92] MDEV-30421 rpl_parallel.test cleanup Moved rpl_parallel.inc to rpl_parallel.test --- .../suite/binlog_encryption/rpl_parallel.test | 2 +- mysql-test/suite/rpl/include/rpl_parallel.inc | 2218 ---------------- mysql-test/suite/rpl/t/rpl_parallel.test | 2219 ++++++++++++++++- 3 files changed, 2219 insertions(+), 2220 deletions(-) delete mode 100644 mysql-test/suite/rpl/include/rpl_parallel.inc diff --git a/mysql-test/suite/binlog_encryption/rpl_parallel.test b/mysql-test/suite/binlog_encryption/rpl_parallel.test index dba54e4fd7a18..9985e23796545 100644 --- a/mysql-test/suite/binlog_encryption/rpl_parallel.test +++ b/mysql-test/suite/binlog_encryption/rpl_parallel.test @@ -1 +1 @@ ---source suite/rpl/include/rpl_parallel.inc +--source suite/rpl/t/rpl_parallel.test diff --git a/mysql-test/suite/rpl/include/rpl_parallel.inc b/mysql-test/suite/rpl/include/rpl_parallel.inc deleted file mode 100644 index 9ba7a30f2eb7f..0000000000000 --- a/mysql-test/suite/rpl/include/rpl_parallel.inc +++ /dev/null @@ -1,2218 +0,0 @@ -# -# This include file is used by more than one test suite -# (currently rpl and binlog_encryption). -# Please check all dependent tests after modifying it -# - ---source include/have_innodb.inc ---source include/have_debug.inc ---source include/have_debug_sync.inc ---source include/master-slave.inc - -# Test various aspects of parallel replication. - ---connection server_2 -SET @old_parallel_threads=@@GLOBAL.slave_parallel_threads; ---error ER_SLAVE_MUST_STOP -SET GLOBAL slave_parallel_threads=10; ---source include/stop_slave.inc -SET GLOBAL slave_parallel_threads=10; - -# Check that we do not spawn any worker threads when no slave is running. -SELECT IF(COUNT(*) < 10, "OK", CONCAT("Found too many system user processes: ", COUNT(*))) FROM information_schema.processlist WHERE user = "system user"; - -CHANGE MASTER TO master_use_gtid=slave_pos; ---source include/start_slave.inc - -# Check that worker threads get spawned when slave starts. -SELECT IF(COUNT(*) >= 10, "OK", CONCAT("Found too few system user processes: ", COUNT(*))) FROM information_schema.processlist WHERE user = "system user"; -# ... and that worker threads get removed when slave stops. ---source include/stop_slave.inc -SELECT IF(COUNT(*) < 10, "OK", CONCAT("Found too many system user processes: ", COUNT(*))) FROM information_schema.processlist WHERE user = "system user"; ---source include/start_slave.inc -SELECT IF(COUNT(*) >= 10, "OK", CONCAT("Found too few system user processes: ", COUNT(*))) FROM information_schema.processlist WHERE user = "system user"; - ---echo *** Test long-running query in domain 1 can run in parallel with short queries in domain 0 *** - ---connection server_1 -ALTER TABLE mysql.gtid_slave_pos ENGINE=InnoDB; -CREATE TABLE t1 (a int PRIMARY KEY) ENGINE=MyISAM; -CREATE TABLE t2 (a int PRIMARY KEY) ENGINE=InnoDB; -INSERT INTO t1 VALUES (1); -INSERT INTO t2 VALUES (1); ---save_master_pos - ---connection server_2 ---sync_with_master - -# Block the table t1 to simulate a replicated query taking a long time. ---connect (con_temp1,127.0.0.1,root,,test,$SERVER_MYPORT_2,) -LOCK TABLE t1 WRITE; - ---connection server_1 -SET gtid_domain_id=1; -# This query will be blocked on the slave until UNLOCK TABLES. -INSERT INTO t1 VALUES (2); -SET gtid_domain_id=0; -# These t2 queries can be replicated in parallel with the prior t1 query, as -# they are in a separate replication domain. -INSERT INTO t2 VALUES (2); -INSERT INTO t2 VALUES (3); -BEGIN; -INSERT INTO t2 VALUES (4); -INSERT INTO t2 VALUES (5); -COMMIT; -INSERT INTO t2 VALUES (6); - ---connection server_2 ---let $wait_condition= SELECT COUNT(*) = 6 FROM t2 ---source include/wait_condition.inc - -SELECT * FROM t2 ORDER by a; - ---connection con_temp1 -SELECT * FROM t1; -UNLOCK TABLES; - ---connection server_2 ---let $wait_condition= SELECT COUNT(*) = 2 FROM t1 ---source include/wait_condition.inc - -SELECT * FROM t1 ORDER BY a; - - ---echo *** Test two transactions in different domains committed in opposite order on slave but in a single group commit. *** ---connection server_2 ---source include/stop_slave.inc - ---connection server_1 -# Use a stored function to inject a debug_sync into the appropriate THD. -# The function does nothing on the master, and on the slave it injects the -# desired debug_sync action(s). -SET sql_log_bin=0; ---delimiter || -CREATE FUNCTION foo(x INT, d1 VARCHAR(500), d2 VARCHAR(500)) - RETURNS INT DETERMINISTIC - BEGIN - RETURN x; - END -|| ---delimiter ; -SET sql_log_bin=1; - -SET @old_format= @@SESSION.binlog_format; -SET binlog_format='statement'; -SET gtid_domain_id=1; -INSERT INTO t2 VALUES (foo(10, - 'commit_before_enqueue SIGNAL ready1 WAIT_FOR cont1', - 'commit_after_release_LOCK_prepare_ordered SIGNAL ready2')); - ---connection server_2 -FLUSH LOGS; ---source include/wait_for_binlog_checkpoint.inc -SET sql_log_bin=0; ---delimiter || -CREATE FUNCTION foo(x INT, d1 VARCHAR(500), d2 VARCHAR(500)) - RETURNS INT DETERMINISTIC - BEGIN - IF d1 != '' THEN - SET debug_sync = d1; - END IF; - IF d2 != '' THEN - SET debug_sync = d2; - END IF; - RETURN x; - END -|| ---delimiter ; -SET sql_log_bin=1; -SET @old_format=@@GLOBAL.binlog_format; -SET GLOBAL binlog_format=statement; -# We need to restart all parallel threads for the new global setting to -# be copied to the session-level values. -SET GLOBAL slave_parallel_threads=0; -SET GLOBAL slave_parallel_threads=10; ---source include/start_slave.inc - -# First make sure the first insert is ready to commit, but not queued yet. -SET debug_sync='now WAIT_FOR ready1'; - ---connection server_1 -SET gtid_domain_id=2; -INSERT INTO t2 VALUES (foo(11, - 'commit_before_enqueue SIGNAL ready3 WAIT_FOR cont3', - 'commit_after_release_LOCK_prepare_ordered SIGNAL ready4 WAIT_FOR cont4')); -SET gtid_domain_id=0; -SELECT * FROM t2 WHERE a >= 10 ORDER BY a; - ---connection server_2 -# Now wait for the second insert to queue itself as the leader, and then -# wait for more commits to queue up. -SET debug_sync='now WAIT_FOR ready3'; -SET debug_sync='now SIGNAL cont3'; -SET debug_sync='now WAIT_FOR ready4'; -# Now allow the first insert to queue up to participate in group commit. -SET debug_sync='now SIGNAL cont1'; -SET debug_sync='now WAIT_FOR ready2'; -# Finally allow the second insert to proceed and do the group commit. -SET debug_sync='now SIGNAL cont4'; - ---let $wait_condition= SELECT COUNT(*) = 2 FROM t2 WHERE a >= 10 ---source include/wait_condition.inc -SELECT * FROM t2 WHERE a >= 10 ORDER BY a; -# The two INSERT transactions should have been committed in opposite order, -# but in the same group commit (seen by precense of cid=# in the SHOW -# BINLOG output). ---let $binlog_file= slave-bin.000002 ---source include/show_binlog_events.inc -FLUSH LOGS; ---source include/wait_for_binlog_checkpoint.inc - -# Restart all the slave parallel worker threads, to clear all debug_sync actions. ---connection server_2 ---source include/stop_slave.inc -SET GLOBAL slave_parallel_threads=0; -SET GLOBAL slave_parallel_threads=10; -SET debug_sync='RESET'; ---source include/start_slave.inc - - ---echo *** Test that group-committed transactions on the master can replicate in parallel on the slave. *** ---connection server_1 -SET debug_sync='RESET'; -FLUSH LOGS; ---source include/wait_for_binlog_checkpoint.inc -CREATE TABLE t3 (a INT PRIMARY KEY, b INT) ENGINE=InnoDB; -# Create some sentinel rows so that the rows inserted in parallel fall into -# separate gaps and do not cause gap lock conflicts. -INSERT INTO t3 VALUES (1,1), (3,3), (5,5), (7,7); ---save_master_pos ---connection server_2 ---sync_with_master - -# We want to test that the transactions can execute out-of-order on -# the slave, but still end up committing in-order, and in a single -# group commit. -# -# The idea is to group-commit three transactions together on the master: -# A, B, and C. On the slave, C will execute the insert first, then A, -# and then B. But B manages to complete before A has time to commit, so -# all three end up committing together. -# -# So we start by setting up some row locks that will block transactions -# A and B from executing, allowing C to run first. - ---connection con_temp1 -BEGIN; -INSERT INTO t3 VALUES (2,102); ---connect (con_temp2,127.0.0.1,root,,test,$SERVER_MYPORT_2,) -BEGIN; -INSERT INTO t3 VALUES (4,104); - -# On the master, queue three INSERT transactions as a single group commit. ---connect (con_temp3,127.0.0.1,root,,test,$SERVER_MYPORT_1,) -SET debug_sync='commit_after_release_LOCK_prepare_ordered SIGNAL master_queued1 WAIT_FOR master_cont1'; -SET binlog_format=statement; -send INSERT INTO t3 VALUES (2, foo(12, - 'commit_after_release_LOCK_prepare_ordered SIGNAL slave_queued1 WAIT_FOR slave_cont1', - '')); - ---connection server_1 -SET debug_sync='now WAIT_FOR master_queued1'; - ---connect (con_temp4,127.0.0.1,root,,test,$SERVER_MYPORT_1,) -SET debug_sync='commit_after_release_LOCK_prepare_ordered SIGNAL master_queued2'; -SET binlog_format=statement; -send INSERT INTO t3 VALUES (4, foo(14, - 'commit_after_release_LOCK_prepare_ordered SIGNAL slave_queued2', - '')); - ---connection server_1 -SET debug_sync='now WAIT_FOR master_queued2'; - ---connect (con_temp5,127.0.0.1,root,,test,$SERVER_MYPORT_1,) -SET debug_sync='commit_after_release_LOCK_prepare_ordered SIGNAL master_queued3'; -SET binlog_format=statement; -send INSERT INTO t3 VALUES (6, foo(16, - 'group_commit_waiting_for_prior SIGNAL slave_queued3', - '')); - ---connection server_1 -SET debug_sync='now WAIT_FOR master_queued3'; -SET debug_sync='now SIGNAL master_cont1'; - ---connection con_temp3 -REAP; ---connection con_temp4 -REAP; ---connection con_temp5 -REAP; -SET debug_sync='RESET'; - ---connection server_1 -SELECT * FROM t3 ORDER BY a; ---let $binlog_file= master-bin.000002 ---source include/show_binlog_events.inc - -# First, wait until insert 3 is ready to queue up for group commit, but is -# waiting for insert 2 to commit before it can do so itself. ---connection server_2 -SET debug_sync='now WAIT_FOR slave_queued3'; - -# Next, let insert 1 proceed, and allow it to queue up as the group commit -# leader, but let it wait for insert 2 to also queue up before proceeding. ---connection con_temp1 -ROLLBACK; ---connection server_2 -SET debug_sync='now WAIT_FOR slave_queued1'; - -# Now let insert 2 proceed and queue up. ---connection con_temp2 -ROLLBACK; ---connection server_2 -SET debug_sync='now WAIT_FOR slave_queued2'; -# And finally, we can let insert 1 proceed and do the group commit with all -# three insert transactions together. -SET debug_sync='now SIGNAL slave_cont1'; - -# Wait for the commit to complete and check that all three transactions -# group-committed together (will be seen in the binlog as all three having -# cid=# on their GTID event). ---let $wait_condition= SELECT COUNT(*) = 3 FROM t3 WHERE a IN (2,4,6) ---source include/wait_condition.inc -SELECT * FROM t3 ORDER BY a; ---let $binlog_file= slave-bin.000003 ---source include/show_binlog_events.inc - - ---echo *** Test STOP SLAVE in parallel mode *** ---connection server_2 ---source include/stop_slave.inc -# Respawn all worker threads to clear any left-over debug_sync or other stuff. -SET debug_sync='RESET'; -SET GLOBAL slave_parallel_threads=0; -SET GLOBAL slave_parallel_threads=10; - ---connection server_1 -# Set up a couple of transactions. The first will be blocked halfway -# through on a lock, and while it is blocked we initiate STOP SLAVE. -# We then test that the halfway-initiated transaction is allowed to -# complete, but no subsequent ones. -# We have to use statement-based mode and set -# binlog_direct_non_transactional_updates=0; otherwise the binlog will -# be split into two event groups, one for the MyISAM part and one for the -# InnoDB part. -SET binlog_direct_non_transactional_updates=0; -SET sql_log_bin=0; -CALL mtr.add_suppression("Statement is unsafe because it accesses a non-transactional table after accessing a transactional table within the same transaction"); -SET sql_log_bin=1; -BEGIN; -INSERT INTO t2 VALUES (20); ---disable_warnings -INSERT INTO t1 VALUES (20); ---enable_warnings -INSERT INTO t2 VALUES (21); -INSERT INTO t3 VALUES (20, 20); -COMMIT; -INSERT INTO t3 VALUES(21, 21); -INSERT INTO t3 VALUES(22, 22); -SET binlog_format=@old_format; ---save_master_pos - -# Start a connection that will block the replicated transaction halfway. ---connection con_temp1 -BEGIN; -INSERT INTO t2 VALUES (21); - ---connection server_2 -START SLAVE; -# Wait for the MyISAM change to be visible, after which replication will wait -# for con_temp1 to roll back. ---let $wait_condition= SELECT COUNT(*) = 1 FROM t1 WHERE a=20 ---source include/wait_condition.inc - ---connection con_temp2 -# Initiate slave stop. It will have to wait for the current event group -# to complete. -# The dbug injection causes debug_sync to signal 'wait_for_done_waiting' -# when the SQL driver thread is ready. -SET @old_dbug= @@GLOBAL.debug_dbug; -SET GLOBAL debug_dbug="+d,rpl_parallel_wait_for_done_trigger"; -send STOP SLAVE; - ---connection con_temp1 -SET debug_sync='now WAIT_FOR wait_for_done_waiting'; -ROLLBACK; - ---connection con_temp2 -reap; -SET GLOBAL debug_dbug=@old_dbug; -SET debug_sync='RESET'; - ---connection server_2 ---source include/wait_for_slave_to_stop.inc -# We should see the first transaction applied, but not the two others. -SELECT * FROM t1 WHERE a >= 20 ORDER BY a; -SELECT * FROM t2 WHERE a >= 20 ORDER BY a; -SELECT * FROM t3 WHERE a >= 20 ORDER BY a; - ---source include/start_slave.inc ---sync_with_master -SELECT * FROM t1 WHERE a >= 20 ORDER BY a; -SELECT * FROM t2 WHERE a >= 20 ORDER BY a; -SELECT * FROM t3 WHERE a >= 20 ORDER BY a; - - ---connection server_2 -# Respawn all worker threads to clear any left-over debug_sync or other stuff. ---source include/stop_slave.inc -SET GLOBAL binlog_format=@old_format; -SET GLOBAL slave_parallel_threads=0; -SET GLOBAL slave_parallel_threads=10; ---source include/start_slave.inc - - ---echo *** Test killing slave threads at various wait points *** ---echo *** 1. Test killing transaction waiting in commit for previous transaction to commit *** - -# Set up three transactions on the master that will be group-committed -# together so they can be replicated in parallel on the slave. ---connection con_temp3 -SET debug_sync='commit_after_release_LOCK_prepare_ordered SIGNAL master_queued1 WAIT_FOR master_cont1'; -SET binlog_format=statement; -send INSERT INTO t3 VALUES (31, foo(31, - 'commit_before_prepare_ordered WAIT_FOR t2_waiting', - 'commit_after_prepare_ordered SIGNAL t1_ready WAIT_FOR t1_cont')); - ---connection server_1 -SET debug_sync='now WAIT_FOR master_queued1'; - ---connection con_temp4 -SET debug_sync='commit_after_release_LOCK_prepare_ordered SIGNAL master_queued2'; -SET binlog_format=statement; -BEGIN; -# This insert is just so we can get T2 to wait while a query is running that we -# can see in SHOW PROCESSLIST so we can get its thread_id to kill later. -INSERT INTO t3 VALUES (32, foo(32, - 'ha_write_row_end SIGNAL t2_query WAIT_FOR t2_cont', - '')); -# This insert sets up debug_sync points so that T2 will tell when it is at its -# wait point where we want to kill it - and when it has been killed. -INSERT INTO t3 VALUES (33, foo(33, - 'group_commit_waiting_for_prior SIGNAL t2_waiting', - 'group_commit_waiting_for_prior_killed SIGNAL t2_killed')); -send COMMIT; - ---connection server_1 -SET debug_sync='now WAIT_FOR master_queued2'; - ---connection con_temp5 -SET debug_sync='commit_after_release_LOCK_prepare_ordered SIGNAL master_queued3'; -SET binlog_format=statement; -send INSERT INTO t3 VALUES (34, foo(34, - '', - '')); - ---connection server_1 -SET debug_sync='now WAIT_FOR master_queued3'; -SET debug_sync='now SIGNAL master_cont1'; - ---connection con_temp3 -REAP; ---connection con_temp4 -REAP; ---connection con_temp5 -REAP; - ---connection server_1 -SELECT * FROM t3 WHERE a >= 30 ORDER BY a; -SET debug_sync='RESET'; - ---connection server_2 -SET sql_log_bin=0; -CALL mtr.add_suppression("Query execution was interrupted"); -CALL mtr.add_suppression("Commit failed due to failure of an earlier commit on which this one depends"); -CALL mtr.add_suppression("Slave: Connection was killed"); -SET sql_log_bin=1; -# Wait until T2 is inside executing its insert of 32, then find it in SHOW -# PROCESSLIST to know its thread id for KILL later. -SET debug_sync='now WAIT_FOR t2_query'; ---let $thd_id= `SELECT ID FROM INFORMATION_SCHEMA.PROCESSLIST WHERE INFO LIKE '%foo(32%' AND INFO NOT LIKE '%LIKE%'` -SET debug_sync='now SIGNAL t2_cont'; - -# Wait until T2 has entered its wait for T1 to commit, and T1 has -# progressed into its commit phase. -SET debug_sync='now WAIT_FOR t1_ready'; - -# Now kill the transaction T2. ---replace_result $thd_id THD_ID -eval KILL $thd_id; - -# Wait until T2 has reacted on the kill. -SET debug_sync='now WAIT_FOR t2_killed'; - -# Now we can allow T1 to proceed. -SET debug_sync='now SIGNAL t1_cont'; - ---let $slave_sql_errno= 1317,1927,1964 ---source include/wait_for_slave_sql_error.inc -STOP SLAVE IO_THREAD; -SELECT * FROM t3 WHERE a >= 30 ORDER BY a; - -# Now we have to disable the debug_sync statements, so they do not trigger -# when the events are retried. -SET debug_sync='RESET'; -SET GLOBAL slave_parallel_threads=0; -SET GLOBAL slave_parallel_threads=10; -SET sql_log_bin=0; -DROP FUNCTION foo; ---delimiter || -CREATE FUNCTION foo(x INT, d1 VARCHAR(500), d2 VARCHAR(500)) - RETURNS INT DETERMINISTIC - BEGIN - RETURN x; - END -|| ---delimiter ; -SET sql_log_bin=1; - ---connection server_1 -INSERT INTO t3 VALUES (39,0); ---save_master_pos - ---connection server_2 ---source include/start_slave.inc ---sync_with_master -SELECT * FROM t3 WHERE a >= 30 ORDER BY a; -# Restore the foo() function. -SET sql_log_bin=0; -DROP FUNCTION foo; ---delimiter || -CREATE FUNCTION foo(x INT, d1 VARCHAR(500), d2 VARCHAR(500)) - RETURNS INT DETERMINISTIC - BEGIN - IF d1 != '' THEN - SET debug_sync = d1; - END IF; - IF d2 != '' THEN - SET debug_sync = d2; - END IF; - RETURN x; - END -|| ---delimiter ; -SET sql_log_bin=1; - - ---connection server_2 -# Respawn all worker threads to clear any left-over debug_sync or other stuff. ---source include/stop_slave.inc -SET GLOBAL binlog_format=@old_format; -SET GLOBAL slave_parallel_threads=0; -SET GLOBAL slave_parallel_threads=10; ---source include/start_slave.inc - - ---echo *** 2. Same as (1), but without restarting IO thread after kill of SQL threads *** - -# Set up three transactions on the master that will be group-committed -# together so they can be replicated in parallel on the slave. ---connection con_temp3 -SET debug_sync='commit_after_release_LOCK_prepare_ordered SIGNAL master_queued1 WAIT_FOR master_cont1'; -SET binlog_format=statement; -send INSERT INTO t3 VALUES (41, foo(41, - 'commit_before_prepare_ordered WAIT_FOR t2_waiting', - 'commit_after_prepare_ordered SIGNAL t1_ready WAIT_FOR t1_cont')); - ---connection server_1 -SET debug_sync='now WAIT_FOR master_queued1'; - ---connection con_temp4 -SET debug_sync='commit_after_release_LOCK_prepare_ordered SIGNAL master_queued2'; -SET binlog_format=statement; -BEGIN; -# This insert is just so we can get T2 to wait while a query is running that we -# can see in SHOW PROCESSLIST so we can get its thread_id to kill later. -INSERT INTO t3 VALUES (42, foo(42, - 'ha_write_row_end SIGNAL t2_query WAIT_FOR t2_cont', - '')); -# This insert sets up debug_sync points so that T2 will tell when it is at its -# wait point where we want to kill it - and when it has been killed. -INSERT INTO t3 VALUES (43, foo(43, - 'group_commit_waiting_for_prior SIGNAL t2_waiting', - 'group_commit_waiting_for_prior_killed SIGNAL t2_killed')); -send COMMIT; - ---connection server_1 -SET debug_sync='now WAIT_FOR master_queued2'; - ---connection con_temp5 -SET debug_sync='commit_after_release_LOCK_prepare_ordered SIGNAL master_queued3'; -SET binlog_format=statement; -send INSERT INTO t3 VALUES (44, foo(44, - '', - '')); - ---connection server_1 -SET debug_sync='now WAIT_FOR master_queued3'; -SET debug_sync='now SIGNAL master_cont1'; - ---connection con_temp3 -REAP; ---connection con_temp4 -REAP; ---connection con_temp5 -REAP; - ---connection server_1 -SELECT * FROM t3 WHERE a >= 40 ORDER BY a; -SET debug_sync='RESET'; - ---connection server_2 -# Wait until T2 is inside executing its insert of 42, then find it in SHOW -# PROCESSLIST to know its thread id for KILL later. -SET debug_sync='now WAIT_FOR t2_query'; ---let $thd_id= `SELECT ID FROM INFORMATION_SCHEMA.PROCESSLIST WHERE INFO LIKE '%foo(42%' AND INFO NOT LIKE '%LIKE%'` -SET debug_sync='now SIGNAL t2_cont'; - -# Wait until T2 has entered its wait for T1 to commit, and T1 has -# progressed into its commit phase. -SET debug_sync='now WAIT_FOR t1_ready'; - -# Now kill the transaction T2. ---replace_result $thd_id THD_ID -eval KILL $thd_id; - -# Wait until T2 has reacted on the kill. -SET debug_sync='now WAIT_FOR t2_killed'; - -# Now we can allow T1 to proceed. -SET debug_sync='now SIGNAL t1_cont'; - ---let $slave_sql_errno= 1317,1927,1964 ---source include/wait_for_slave_sql_error.inc - -# Now we have to disable the debug_sync statements, so they do not trigger -# when the events are retried. -SET debug_sync='RESET'; -SET GLOBAL slave_parallel_threads=0; -SET GLOBAL slave_parallel_threads=10; -SET sql_log_bin=0; -DROP FUNCTION foo; ---delimiter || -CREATE FUNCTION foo(x INT, d1 VARCHAR(500), d2 VARCHAR(500)) - RETURNS INT DETERMINISTIC - BEGIN - RETURN x; - END -|| ---delimiter ; -SET sql_log_bin=1; - ---connection server_1 -INSERT INTO t3 VALUES (49,0); ---save_master_pos - ---connection server_2 -START SLAVE SQL_THREAD; ---sync_with_master -SELECT * FROM t3 WHERE a >= 40 ORDER BY a; -# Restore the foo() function. -SET sql_log_bin=0; -DROP FUNCTION foo; ---delimiter || -CREATE FUNCTION foo(x INT, d1 VARCHAR(500), d2 VARCHAR(500)) - RETURNS INT DETERMINISTIC - BEGIN - IF d1 != '' THEN - SET debug_sync = d1; - END IF; - IF d2 != '' THEN - SET debug_sync = d2; - END IF; - RETURN x; - END -|| ---delimiter ; -SET sql_log_bin=1; - - ---connection server_2 -# Respawn all worker threads to clear any left-over debug_sync or other stuff. ---source include/stop_slave.inc -SET GLOBAL binlog_format=@old_format; -SET GLOBAL slave_parallel_threads=0; -SET GLOBAL slave_parallel_threads=10; ---source include/start_slave.inc - - ---echo *** 3. Same as (2), but not using gtid mode *** - ---connection server_2 ---source include/stop_slave.inc -CHANGE MASTER TO master_use_gtid=no; ---source include/start_slave.inc - ---connection server_1 -# Set up three transactions on the master that will be group-committed -# together so they can be replicated in parallel on the slave. ---connection con_temp3 -SET debug_sync='commit_after_release_LOCK_prepare_ordered SIGNAL master_queued1 WAIT_FOR master_cont1'; -SET binlog_format=statement; -send INSERT INTO t3 VALUES (51, foo(51, - 'commit_before_prepare_ordered WAIT_FOR t2_waiting', - 'commit_after_prepare_ordered SIGNAL t1_ready WAIT_FOR t1_cont')); - ---connection server_1 -SET debug_sync='now WAIT_FOR master_queued1'; - ---connection con_temp4 -SET debug_sync='commit_after_release_LOCK_prepare_ordered SIGNAL master_queued2'; -SET binlog_format=statement; -BEGIN; -# This insert is just so we can get T2 to wait while a query is running that we -# can see in SHOW PROCESSLIST so we can get its thread_id to kill later. -INSERT INTO t3 VALUES (52, foo(52, - 'ha_write_row_end SIGNAL t2_query WAIT_FOR t2_cont', - '')); -# This insert sets up debug_sync points so that T2 will tell when it is at its -# wait point where we want to kill it - and when it has been killed. -INSERT INTO t3 VALUES (53, foo(53, - 'group_commit_waiting_for_prior SIGNAL t2_waiting', - 'group_commit_waiting_for_prior_killed SIGNAL t2_killed')); -send COMMIT; - ---connection server_1 -SET debug_sync='now WAIT_FOR master_queued2'; - ---connection con_temp5 -SET debug_sync='commit_after_release_LOCK_prepare_ordered SIGNAL master_queued3'; -SET binlog_format=statement; -send INSERT INTO t3 VALUES (54, foo(54, - '', - '')); - ---connection server_1 -SET debug_sync='now WAIT_FOR master_queued3'; -SET debug_sync='now SIGNAL master_cont1'; - ---connection con_temp3 -REAP; ---connection con_temp4 -REAP; ---connection con_temp5 -REAP; - ---connection server_1 -SELECT * FROM t3 WHERE a >= 50 ORDER BY a; -SET debug_sync='RESET'; - ---connection server_2 -# Wait until T2 is inside executing its insert of 52, then find it in SHOW -# PROCESSLIST to know its thread id for KILL later. -SET debug_sync='now WAIT_FOR t2_query'; ---let $thd_id= `SELECT ID FROM INFORMATION_SCHEMA.PROCESSLIST WHERE INFO LIKE '%foo(52%' AND INFO NOT LIKE '%LIKE%'` -SET debug_sync='now SIGNAL t2_cont'; - -# Wait until T2 has entered its wait for T1 to commit, and T1 has -# progressed into its commit phase. -SET debug_sync='now WAIT_FOR t1_ready'; - -# Now kill the transaction T2. ---replace_result $thd_id THD_ID -eval KILL $thd_id; - -# Wait until T2 has reacted on the kill. -SET debug_sync='now WAIT_FOR t2_killed'; - -# Now we can allow T1 to proceed. -SET debug_sync='now SIGNAL t1_cont'; - ---let $slave_sql_errno= 1317,1927,1964 ---source include/wait_for_slave_sql_error.inc -SELECT * FROM t3 WHERE a >= 50 ORDER BY a; - -# Now we have to disable the debug_sync statements, so they do not trigger -# when the events are retried. -SET debug_sync='RESET'; -SET GLOBAL slave_parallel_threads=0; -SET GLOBAL slave_parallel_threads=10; -SET sql_log_bin=0; -DROP FUNCTION foo; ---delimiter || -CREATE FUNCTION foo(x INT, d1 VARCHAR(500), d2 VARCHAR(500)) - RETURNS INT DETERMINISTIC - BEGIN - RETURN x; - END -|| ---delimiter ; -SET sql_log_bin=1; - ---connection server_1 -INSERT INTO t3 VALUES (59,0); ---save_master_pos - ---connection server_2 -START SLAVE SQL_THREAD; ---sync_with_master -SELECT * FROM t3 WHERE a >= 50 ORDER BY a; -# Restore the foo() function. -SET sql_log_bin=0; -DROP FUNCTION foo; ---delimiter || -CREATE FUNCTION foo(x INT, d1 VARCHAR(500), d2 VARCHAR(500)) - RETURNS INT DETERMINISTIC - BEGIN - IF d1 != '' THEN - SET debug_sync = d1; - END IF; - IF d2 != '' THEN - SET debug_sync = d2; - END IF; - RETURN x; - END -|| ---delimiter ; -SET sql_log_bin=1; - - ---source include/stop_slave.inc -CHANGE MASTER TO master_use_gtid=slave_pos; ---source include/start_slave.inc - ---connection server_2 -# Respawn all worker threads to clear any left-over debug_sync or other stuff. ---source include/stop_slave.inc -SET GLOBAL binlog_format=@old_format; -SET GLOBAL slave_parallel_threads=0; -SET GLOBAL slave_parallel_threads=4; ---source include/start_slave.inc - - ---echo *** 4. Test killing thread that is waiting to start transaction until previous transaction commits *** - -# We set up four transactions T1, T2, T3, and T4 on the master. T2, T3, and T4 -# can run in parallel with each other (same group commit and commit id), -# but not in parallel with T1. -# -# We use four worker threads, each Ti will be queued on each their own -# worker thread. We will delay T1 commit, T3 will wait for T1 to begin -# commit before it can start. We will kill T3 during this wait, and -# check that everything works correctly. -# -# It is rather tricky to get the correct thread id of the worker to kill. -# We start by injecting four dummy transactions in a debug_sync-controlled -# manner to be able to get known thread ids for the workers in a pool with -# just 4 worker threads. Then we let in each of the real test transactions -# T1-T4 one at a time in a way which allows us to know which transaction -# ends up with which thread id. - ---connection server_1 -SET binlog_format=statement; -SET gtid_domain_id=2; -BEGIN; -# This debug_sync will linger on and be used to control T4 later. -INSERT INTO t3 VALUES (70, foo(70, - 'rpl_parallel_start_waiting_for_prior SIGNAL t4_waiting', '')); -INSERT INTO t3 VALUES (60, foo(60, - 'ha_write_row_end SIGNAL d2_query WAIT_FOR d2_cont2', - 'rpl_parallel_end_of_group SIGNAL d2_done WAIT_FOR d2_cont')); -COMMIT; -SET gtid_domain_id=0; - ---connection server_2 -SET debug_sync='now WAIT_FOR d2_query'; ---let $d2_thd_id= `SELECT ID FROM INFORMATION_SCHEMA.PROCESSLIST WHERE INFO LIKE '%foo(60%' AND INFO NOT LIKE '%LIKE%'` - ---connection server_1 -SET gtid_domain_id=1; -BEGIN; -# These debug_sync's will linger on and be used to control T3 later. -INSERT INTO t3 VALUES (61, foo(61, - 'rpl_parallel_start_waiting_for_prior SIGNAL t3_waiting', - 'rpl_parallel_start_waiting_for_prior_killed SIGNAL t3_killed')); -INSERT INTO t3 VALUES (62, foo(62, - 'ha_write_row_end SIGNAL d1_query WAIT_FOR d1_cont2', - 'rpl_parallel_end_of_group SIGNAL d1_done WAIT_FOR d1_cont')); -COMMIT; -SET gtid_domain_id=0; - ---connection server_2 -SET debug_sync='now WAIT_FOR d1_query'; ---let $d1_thd_id= `SELECT ID FROM INFORMATION_SCHEMA.PROCESSLIST WHERE INFO LIKE '%foo(62%' AND INFO NOT LIKE '%LIKE%'` - ---connection server_1 -SET gtid_domain_id=0; -INSERT INTO t3 VALUES (63, foo(63, - 'ha_write_row_end SIGNAL d0_query WAIT_FOR d0_cont2', - 'rpl_parallel_end_of_group SIGNAL d0_done WAIT_FOR d0_cont')); - ---connection server_2 -SET debug_sync='now WAIT_FOR d0_query'; ---let $d0_thd_id= `SELECT ID FROM INFORMATION_SCHEMA.PROCESSLIST WHERE INFO LIKE '%foo(63%' AND INFO NOT LIKE '%LIKE%'` - ---connection server_1 -SET gtid_domain_id=3; -BEGIN; -# These debug_sync's will linger on and be used to control T2 later. -INSERT INTO t3 VALUES (68, foo(68, - 'rpl_parallel_start_waiting_for_prior SIGNAL t2_waiting', '')); -INSERT INTO t3 VALUES (69, foo(69, - 'ha_write_row_end SIGNAL d3_query WAIT_FOR d3_cont2', - 'rpl_parallel_end_of_group SIGNAL d3_done WAIT_FOR d3_cont')); -COMMIT; -SET gtid_domain_id=0; - ---connection server_2 -SET debug_sync='now WAIT_FOR d3_query'; ---let $d3_thd_id= `SELECT ID FROM INFORMATION_SCHEMA.PROCESSLIST WHERE INFO LIKE '%foo(69%' AND INFO NOT LIKE '%LIKE%'` - -SET debug_sync='now SIGNAL d2_cont2'; -SET debug_sync='now WAIT_FOR d2_done'; -SET debug_sync='now SIGNAL d1_cont2'; -SET debug_sync='now WAIT_FOR d1_done'; -SET debug_sync='now SIGNAL d0_cont2'; -SET debug_sync='now WAIT_FOR d0_done'; -SET debug_sync='now SIGNAL d3_cont2'; -SET debug_sync='now WAIT_FOR d3_done'; - -# Now prepare the real transactions T1, T2, T3, T4 on the master. - ---connection con_temp3 -# Create transaction T1. -SET binlog_format=statement; -INSERT INTO t3 VALUES (64, foo(64, - 'rpl_parallel_before_mark_start_commit SIGNAL t1_waiting WAIT_FOR t1_cont', '')); - -# Create transaction T2, as a group commit leader on the master. -SET debug_sync='commit_after_release_LOCK_prepare_ordered SIGNAL master_queued2 WAIT_FOR master_cont2'; -send INSERT INTO t3 VALUES (65, foo(65, '', '')); - ---connection server_1 -SET debug_sync='now WAIT_FOR master_queued2'; - ---connection con_temp4 -# Create transaction T3, participating in T2's group commit. -SET debug_sync='commit_after_release_LOCK_prepare_ordered SIGNAL master_queued3'; -send INSERT INTO t3 VALUES (66, foo(66, '', '')); - ---connection server_1 -SET debug_sync='now WAIT_FOR master_queued3'; - ---connection con_temp5 -# Create transaction T4, participating in group commit with T2 and T3. -SET debug_sync='commit_after_release_LOCK_prepare_ordered SIGNAL master_queued4'; -send INSERT INTO t3 VALUES (67, foo(67, '', '')); - ---connection server_1 -SET debug_sync='now WAIT_FOR master_queued4'; -SET debug_sync='now SIGNAL master_cont2'; - ---connection con_temp3 -REAP; ---connection con_temp4 -REAP; ---connection con_temp5 -REAP; - ---connection server_1 -SELECT * FROM t3 WHERE a >= 60 ORDER BY a; -SET debug_sync='RESET'; - ---connection server_2 -# Now we have the four transactions pending for replication on the slave. -# Let them be queued for our three worker threads in a controlled fashion. -# We put them at a stage where T1 is delayed and T3 is waiting for T1 to -# commit before T3 can start. Then we kill T3. - -# Make the worker D0 free, and wait for T1 to be queued in it. -SET debug_sync='now SIGNAL d0_cont'; -SET debug_sync='now WAIT_FOR t1_waiting'; - -# Make the worker D3 free, and wait for T2 to be queued in it. -SET debug_sync='now SIGNAL d3_cont'; -SET debug_sync='now WAIT_FOR t2_waiting'; - -# Now release worker D1, and wait for T3 to be queued in it. -# T3 will wait for T1 to commit before it can start. -SET debug_sync='now SIGNAL d1_cont'; -SET debug_sync='now WAIT_FOR t3_waiting'; - -# Release worker D2. Wait for T4 to be queued, so we are sure it has -# received the debug_sync signal (else we might overwrite it with the -# next debug_sync). -SET debug_sync='now SIGNAL d2_cont'; -SET debug_sync='now WAIT_FOR t4_waiting'; - -# Now we kill the waiting transaction T3 in worker D1. ---replace_result $d1_thd_id THD_ID -eval KILL $d1_thd_id; - -# Wait until T3 has reacted on the kill. -SET debug_sync='now WAIT_FOR t3_killed'; - -# Now we can allow T1 to proceed. -SET debug_sync='now SIGNAL t1_cont'; - ---let $slave_sql_errno= 1317,1927,1964 ---source include/wait_for_slave_sql_error.inc -STOP SLAVE IO_THREAD; -# Since T2, T3, and T4 run in parallel, we can not be sure if T2 will have time -# to commit or not before the stop. However, T1 should commit, and T3/T4 may -# not have committed. (After slave restart we check that all become committed -# eventually). -SELECT * FROM t3 WHERE a >= 60 AND a != 65 ORDER BY a; - -# Now we have to disable the debug_sync statements, so they do not trigger -# when the events are retried. -SET debug_sync='RESET'; -SET GLOBAL slave_parallel_threads=0; -SET GLOBAL slave_parallel_threads=10; -SET sql_log_bin=0; -DROP FUNCTION foo; ---delimiter || -CREATE FUNCTION foo(x INT, d1 VARCHAR(500), d2 VARCHAR(500)) - RETURNS INT DETERMINISTIC - BEGIN - RETURN x; - END -|| ---delimiter ; -SET sql_log_bin=1; - ---connection server_1 -UPDATE t3 SET b=b+1 WHERE a=60; ---save_master_pos - ---connection server_2 ---source include/start_slave.inc ---sync_with_master -SELECT * FROM t3 WHERE a >= 60 ORDER BY a; -# Restore the foo() function. -SET sql_log_bin=0; -DROP FUNCTION foo; ---delimiter || -CREATE FUNCTION foo(x INT, d1 VARCHAR(500), d2 VARCHAR(500)) - RETURNS INT DETERMINISTIC - BEGIN - IF d1 != '' THEN - SET debug_sync = d1; - END IF; - IF d2 != '' THEN - SET debug_sync = d2; - END IF; - RETURN x; - END -|| ---delimiter ; -SET sql_log_bin=1; - ---connection server_2 -# Respawn all worker threads to clear any left-over debug_sync or other stuff. ---source include/stop_slave.inc -SET GLOBAL binlog_format=@old_format; -SET GLOBAL slave_parallel_threads=0; -SET GLOBAL slave_parallel_threads=10; ---source include/start_slave.inc - - ---echo *** 5. Test killing thread that is waiting for queue of max length to shorten *** - -# Find the thread id of the driver SQL thread that we want to kill. ---let $wait_condition= SELECT COUNT(*) = 1 FROM INFORMATION_SCHEMA.PROCESSLIST WHERE STATE LIKE '%Slave has read all relay log%' ---source include/wait_condition.inc ---let $thd_id= `SELECT ID FROM INFORMATION_SCHEMA.PROCESSLIST WHERE STATE LIKE '%Slave has read all relay log%'` -SET @old_max_queued= @@GLOBAL.slave_parallel_max_queued; -SET GLOBAL slave_parallel_max_queued=9000; - ---connection server_1 ---let bigstring= `SELECT REPEAT('x', 10000)` -SET binlog_format=statement; -# Create an event that will wait to be signalled. -INSERT INTO t3 VALUES (80, foo(0, - 'ha_write_row_end SIGNAL query_waiting WAIT_FOR query_cont', '')); - ---connection server_2 -SET debug_sync='now WAIT_FOR query_waiting'; -# Inject that the SQL driver thread will signal `wait_queue_ready' to debug_sync -# as it goes to wait for the event queue to become smaller than the value of -# @@slave_parallel_max_queued. -SET @old_dbug= @@GLOBAL.debug_dbug; -SET GLOBAL debug_dbug="+d,rpl_parallel_wait_queue_max"; - ---connection server_1 ---disable_query_log -# Create an event that will fill up the queue. -# The Xid event at the end of the event group will have to wait for the Query -# event with the INSERT to drain so the queue becomes shorter. However that in -# turn waits for the prior event group to continue. -eval INSERT INTO t3 VALUES (81, LENGTH('$bigstring')); ---enable_query_log -SELECT * FROM t3 WHERE a >= 80 ORDER BY a; - ---connection server_2 -SET debug_sync='now WAIT_FOR wait_queue_ready'; - ---replace_result $thd_id THD_ID -eval KILL $thd_id; - -SET debug_sync='now WAIT_FOR wait_queue_killed'; -SET debug_sync='now SIGNAL query_cont'; - ---let $slave_sql_errno= 1317,1927,1964 ---source include/wait_for_slave_sql_error.inc -STOP SLAVE IO_THREAD; - -SET GLOBAL debug_dbug=@old_dbug; -SET GLOBAL slave_parallel_max_queued= @old_max_queued; - ---connection server_1 -INSERT INTO t3 VALUES (82,0); -SET binlog_format=@old_format; ---save_master_pos - ---connection server_2 -SET debug_sync='RESET'; ---source include/start_slave.inc ---sync_with_master -SELECT * FROM t3 WHERE a >= 80 ORDER BY a; - - ---connection server_2 ---source include/stop_slave.inc -SET GLOBAL binlog_format=@old_format; -SET GLOBAL slave_parallel_threads=0; -SET GLOBAL slave_parallel_threads=10; ---source include/start_slave.inc - ---echo *** MDEV-5788 Incorrect free of rgi->deferred_events in parallel replication *** - ---connection server_2 -# Use just two worker threads, so we are sure to get the rpl_group_info added -# to the free list, which is what triggered the bug. ---source include/stop_slave.inc -SET GLOBAL replicate_ignore_table="test.t3"; -SET GLOBAL slave_parallel_threads=2; ---source include/start_slave.inc - ---connection server_1 -INSERT INTO t3 VALUES (100, rand()); -INSERT INTO t3 VALUES (101, rand()); - ---save_master_pos - ---connection server_2 ---sync_with_master - ---connection server_1 -INSERT INTO t3 VALUES (102, rand()); -INSERT INTO t3 VALUES (103, rand()); -INSERT INTO t3 VALUES (104, rand()); -INSERT INTO t3 VALUES (105, rand()); - ---save_master_pos - ---connection server_2 ---sync_with_master ---source include/stop_slave.inc -SET GLOBAL replicate_ignore_table=""; ---source include/start_slave.inc - ---connection server_1 -INSERT INTO t3 VALUES (106, rand()); -INSERT INTO t3 VALUES (107, rand()); ---save_master_pos - ---connection server_2 ---sync_with_master ---replace_column 2 # -SELECT * FROM t3 WHERE a >= 100 ORDER BY a; - - ---echo *** MDEV-5921: In parallel replication, an error is not correctly signalled to the next transaction *** - ---connection server_2 ---source include/stop_slave.inc -SET GLOBAL slave_parallel_threads=10; ---source include/start_slave.inc - ---connection server_1 -INSERT INTO t3 VALUES (110, 1); ---save_master_pos - ---connection server_2 ---sync_with_master -SELECT * FROM t3 WHERE a >= 110 ORDER BY a; -# Inject a duplicate key error. -SET sql_log_bin=0; -INSERT INTO t3 VALUES (111, 666); -SET sql_log_bin=1; - ---connection server_1 - -# Create a group commit with two inserts, the first one conflicts with a row on the slave ---connect (con1,127.0.0.1,root,,test,$SERVER_MYPORT_1,) -SET debug_sync='commit_after_release_LOCK_prepare_ordered SIGNAL master_queued1 WAIT_FOR master_cont1'; -send INSERT INTO t3 VALUES (111, 2); ---connection server_1 -SET debug_sync='now WAIT_FOR master_queued1'; - ---connect (con2,127.0.0.1,root,,test,$SERVER_MYPORT_1,) -SET debug_sync='commit_after_release_LOCK_prepare_ordered SIGNAL master_queued2'; -send INSERT INTO t3 VALUES (112, 3); - ---connection server_1 -SET debug_sync='now WAIT_FOR master_queued2'; -SET debug_sync='now SIGNAL master_cont1'; - ---connection con1 -REAP; ---connection con2 -REAP; -SET debug_sync='RESET'; ---save_master_pos - ---connection server_2 ---let $slave_sql_errno= 1062 ---source include/wait_for_slave_sql_error.inc ---source include/wait_for_slave_sql_to_stop.inc -# We should not see the row (112,3) here, it should be rolled back due to -# error signal from the prior transaction. -SELECT * FROM t3 WHERE a >= 110 ORDER BY a; -SET sql_log_bin=0; -DELETE FROM t3 WHERE a=111 AND b=666; -SET sql_log_bin=1; -START SLAVE SQL_THREAD; ---sync_with_master -SELECT * FROM t3 WHERE a >= 110 ORDER BY a; - - ---echo ***MDEV-5914: Parallel replication deadlock due to InnoDB lock conflicts *** ---connection server_2 ---source include/stop_slave.inc - ---connection server_1 -CREATE TABLE t4 (a INT PRIMARY KEY, b INT, KEY b_idx(b)) ENGINE=InnoDB; -INSERT INTO t4 VALUES (1,NULL), (2,2), (3,NULL), (4,4), (5, NULL), (6, 6); - -# Create a group commit with UPDATE and DELETE, in that order. -# The bug was that while the UPDATE's row lock does not block the DELETE, the -# DELETE's gap lock _does_ block the UPDATE. This could cause a deadlock -# on the slave. ---connection con1 -SET debug_sync='commit_after_release_LOCK_prepare_ordered SIGNAL master_queued1 WAIT_FOR master_cont1'; -send UPDATE t4 SET b=NULL WHERE a=6; ---connection server_1 -SET debug_sync='now WAIT_FOR master_queued1'; - ---connection con2 -SET debug_sync='commit_after_release_LOCK_prepare_ordered SIGNAL master_queued2'; -send DELETE FROM t4 WHERE b <= 3; - ---connection server_1 -SET debug_sync='now WAIT_FOR master_queued2'; -SET debug_sync='now SIGNAL master_cont1'; - ---connection con1 -REAP; ---connection con2 -REAP; -SET debug_sync='RESET'; ---save_master_pos - ---connection server_2 ---source include/start_slave.inc ---sync_with_master ---source include/stop_slave.inc - -SELECT * FROM t4 ORDER BY a; - - -# Another example, this one with INSERT vs. DELETE ---connection server_1 -DELETE FROM t4; -INSERT INTO t4 VALUES (1,NULL), (2,2), (3,NULL), (4,4), (5, NULL), (6, 6); - -# Create a group commit with INSERT and DELETE, in that order. -# The bug was that while the INSERT's insert intention lock does not block -# the DELETE, the DELETE's gap lock _does_ block the INSERT. This could cause -# a deadlock on the slave. ---connection con1 -SET debug_sync='commit_after_release_LOCK_prepare_ordered SIGNAL master_queued1 WAIT_FOR master_cont1'; -send INSERT INTO t4 VALUES (7, NULL); ---connection server_1 -SET debug_sync='now WAIT_FOR master_queued1'; - ---connection con2 -SET debug_sync='commit_after_release_LOCK_prepare_ordered SIGNAL master_queued2'; -send DELETE FROM t4 WHERE b <= 3; - ---connection server_1 -SET debug_sync='now WAIT_FOR master_queued2'; -SET debug_sync='now SIGNAL master_cont1'; - ---connection con1 -REAP; ---connection con2 -REAP; -SET debug_sync='RESET'; ---save_master_pos - ---connection server_2 ---source include/start_slave.inc ---sync_with_master ---source include/stop_slave.inc - -SELECT * FROM t4 ORDER BY a; - - -# MDEV-6549, failing to update gtid_slave_pos for a transaction that was retried. -# The problem was that when a transaction updates the mysql.gtid_slave_pos -# table, it clears the flag that marks that there is a GTID position that -# needs to be updated. Then, if the transaction got killed after that due -# to a deadlock, the subsequent retry would fail to notice that the GTID needs -# to be recorded in gtid_slave_pos. -# -# (In the original bug report, the symptom was an assertion; this was however -# just a side effect of the missing update of gtid_slave_pos, which also -# happened to cause a missing clear of OPTION_GTID_BEGIN). ---connection server_1 -DELETE FROM t4; -INSERT INTO t4 VALUES (1,NULL), (2,2), (3,NULL), (4,4), (5, NULL), (6, 6); - -# Create two transactions that can run in parallel on the slave but cause -# a deadlock if the second runs before the first. ---connection con1 -SET debug_sync='commit_after_release_LOCK_prepare_ordered SIGNAL master_queued1 WAIT_FOR master_cont1'; -send UPDATE t4 SET b=NULL WHERE a=6; ---connection server_1 -SET debug_sync='now WAIT_FOR master_queued1'; - ---connection con2 -# Must use statement-based binlogging. Otherwise the transaction will not be -# binlogged at all, as it modifies no rows. -SET @old_format= @@SESSION.binlog_format; -SET binlog_format='statement'; -SET debug_sync='commit_after_release_LOCK_prepare_ordered SIGNAL master_queued2'; -send DELETE FROM t4 WHERE b <= 1; - ---connection server_1 -SET debug_sync='now WAIT_FOR master_queued2'; -SET debug_sync='now SIGNAL master_cont1'; - ---connection con1 -REAP; ---connection con2 -REAP; -SET @old_format=@@GLOBAL.binlog_format; -SET debug_sync='RESET'; ---save_master_pos ---let $last_gtid= `SELECT @@last_gtid` - ---connection server_2 -# Disable the usual skip of gap locks for transactions that are run in -# parallel, using DBUG. This allows the deadlock to occur, and this in turn -# triggers a retry of the second transaction, and the code that was buggy and -# caused the gtid_slave_pos update to be skipped in the retry. -SET @old_dbug= @@GLOBAL.debug_dbug; -SET GLOBAL debug_dbug="+d,disable_thd_need_ordering_with"; ---source include/start_slave.inc ---sync_with_master -SET GLOBAL debug_dbug=@old_dbug; - -SELECT * FROM t4 ORDER BY a; -# Check that the GTID of the second transaction was correctly recorded in -# gtid_slave_pos, in the variable as well as in the table. ---replace_result $last_gtid GTID -eval SET @last_gtid= '$last_gtid'; -SELECT IF(@@gtid_slave_pos LIKE CONCAT('%',@last_gtid,'%'), "GTID found ok", - CONCAT("GTID ", @last_gtid, " not found in gtid_slave_pos=", @@gtid_slave_pos)) - AS result; -SELECT "ROW FOUND" AS `Is the row found?` - FROM mysql.gtid_slave_pos - WHERE CONCAT(domain_id, "-", server_id, "-", seq_no) = @last_gtid; - - ---echo *** MDEV-5938: Exec_master_log_pos not updated at log rotate in parallel replication *** ---connection server_2 ---source include/stop_slave.inc -SET GLOBAL slave_parallel_threads=1; -SET DEBUG_SYNC= 'RESET'; ---source include/start_slave.inc - ---connection server_1 -CREATE TABLE t5 (a INT PRIMARY KEY, b INT); -INSERT INTO t5 VALUES (1,1); -INSERT INTO t5 VALUES (2,2), (3,8); -INSERT INTO t5 VALUES (4,16); ---save_master_pos - ---connection server_2 ---sync_with_master -let $io_file= query_get_value(SHOW SLAVE STATUS, Master_Log_File, 1); -let $io_pos= query_get_value(SHOW SLAVE STATUS, Read_Master_Log_Pos, 1); -let $sql_file= query_get_value(SHOW SLAVE STATUS, Relay_Master_Log_File, 1); -let $sql_pos= query_get_value(SHOW SLAVE STATUS, Exec_Master_Log_Pos, 1); ---disable_query_log -eval SELECT IF('$io_file' = '$sql_file', "OK", "Not ok, $io_file <> $sql_file") AS test_check; -eval SELECT IF('$io_pos' = '$sql_pos', "OK", "Not ok, $io_pos <> $sql_pos") AS test_check; ---enable_query_log - ---connection server_1 -FLUSH LOGS; ---source include/wait_for_binlog_checkpoint.inc ---save_master_pos - ---connection server_2 ---sync_with_master -let $io_file= query_get_value(SHOW SLAVE STATUS, Master_Log_File, 1); -let $io_pos= query_get_value(SHOW SLAVE STATUS, Read_Master_Log_Pos, 1); -let $sql_file= query_get_value(SHOW SLAVE STATUS, Relay_Master_Log_File, 1); -let $sql_pos= query_get_value(SHOW SLAVE STATUS, Exec_Master_Log_Pos, 1); ---disable_query_log -eval SELECT IF('$io_file' = '$sql_file', "OK", "Not ok, $io_file <> $sql_file") AS test_check; -eval SELECT IF('$io_pos' = '$sql_pos', "OK", "Not ok, $io_pos <> $sql_pos") AS test_check; ---enable_query_log - - ---echo *** MDEV_6435: Incorrect error handling when query binlogged partially on master with "killed" error *** - ---connection server_1 -CREATE TABLE t6 (a INT) ENGINE=MyISAM; -CREATE TRIGGER tr AFTER INSERT ON t6 FOR EACH ROW SET @a = 1; - ---connection con1 -SET @old_format= @@binlog_format; -SET binlog_format= statement; ---let $conid = `SELECT CONNECTION_ID()` -SET debug_sync='sp_head_execute_before_loop SIGNAL ready WAIT_FOR cont'; -send INSERT INTO t6 VALUES (1), (2), (3); - ---connection server_1 -SET debug_sync='now WAIT_FOR ready'; ---replace_result $conid CONID -eval KILL QUERY $conid; -SET debug_sync='now SIGNAL cont'; - ---connection con1 ---error ER_QUERY_INTERRUPTED ---reap -SET binlog_format= @old_format; -SET debug_sync='RESET'; ---let $after_error_gtid_pos= `SELECT @@gtid_binlog_pos` - ---connection server_1 -SET debug_sync='RESET'; - - ---connection server_2 ---let $slave_sql_errno= 1317 ---source include/wait_for_slave_sql_error.inc -STOP SLAVE IO_THREAD; ---replace_result $after_error_gtid_pos AFTER_ERROR_GTID_POS -eval SET GLOBAL gtid_slave_pos= '$after_error_gtid_pos'; ---source include/start_slave.inc - ---connection server_1 -INSERT INTO t6 VALUES (4); -SELECT * FROM t6 ORDER BY a; ---save_master_pos - ---connection server_2 ---sync_with_master -SELECT * FROM t6 ORDER BY a; - - ---echo *** MDEV-6551: Some replication errors are ignored if slave_parallel_threads > 0 *** - ---connection server_1 -INSERT INTO t2 VALUES (31); ---let $gtid1= `SELECT @@LAST_GTID` ---source include/save_master_gtid.inc - ---connection server_2 ---source include/sync_with_master_gtid.inc ---source include/stop_slave.inc -SET GLOBAL slave_parallel_threads= 0; ---source include/start_slave.inc - -# Force a duplicate key error on the slave. -SET sql_log_bin= 0; -INSERT INTO t2 VALUES (32); -SET sql_log_bin= 1; - ---connection server_1 -INSERT INTO t2 VALUES (32); ---let $gtid2= `SELECT @@LAST_GTID` -# Rotate the binlog; the bug is triggered when the master binlog file changes -# after the event group that causes the duplicate key error. -FLUSH LOGS; -INSERT INTO t2 VALUES (33); -INSERT INTO t2 VALUES (34); -SELECT * FROM t2 WHERE a >= 30 ORDER BY a; ---source include/save_master_gtid.inc - ---connection server_2 ---let $slave_sql_errno= 1062 ---source include/wait_for_slave_sql_error.inc - ---connection server_2 ---source include/stop_slave_io.inc -SET GLOBAL slave_parallel_threads=10; -START SLAVE; - ---let $slave_sql_errno= 1062 ---source include/wait_for_slave_sql_error.inc - -# Note: IO thread is still running at this point. -# The bug seems to have been that restarting the SQL thread after an error with -# the IO thread still running, somehow picks up a later relay log position and -# thus ends up skipping the failing event, rather than re-executing. - -START SLAVE SQL_THREAD; ---let $slave_sql_errno= 1062 ---source include/wait_for_slave_sql_error.inc - -SELECT * FROM t2 WHERE a >= 30 ORDER BY a; - -# Skip the duplicate error, so we can proceed. ---error ER_SLAVE_SKIP_NOT_IN_GTID -SET sql_slave_skip_counter= 1; ---source include/stop_slave_io.inc ---disable_query_log -eval SET GLOBAL gtid_slave_pos = REPLACE(@@gtid_slave_pos, "$gtid1", "$gtid2"); ---enable_query_log ---source include/start_slave.inc ---source include/sync_with_master_gtid.inc - -SELECT * FROM t2 WHERE a >= 30 ORDER BY a; - - ---echo *** MDEV-6775: Wrong binlog order in parallel replication *** ---connection server_1 -# A bit tricky bug to reproduce. On the master, we binlog in statement-mode -# two transactions, an UPDATE followed by a DELETE. On the slave, we replicate -# with binlog-mode set to ROW, which means the DELETE, which modifies no rows, -# is not binlogged. Then we inject a wait in the group commit code on the -# slave, shortly before the actual commit of the UPDATE. The bug was that the -# DELETE could wake up from wait_for_prior_commit() before the commit of the -# UPDATE. So the test could see the slave position updated to after DELETE, -# while the UPDATE was still not visible. -DELETE FROM t4; -INSERT INTO t4 VALUES (1,NULL), (3,NULL), (4,4), (5, NULL), (6, 6); ---source include/save_master_gtid.inc - ---connection server_2 ---source include/sync_with_master_gtid.inc ---source include/stop_slave.inc -SET @old_dbug= @@GLOBAL.debug_dbug; -SET GLOBAL debug_dbug="+d,inject_binlog_commit_before_get_LOCK_log"; -SET @old_format=@@GLOBAL.binlog_format; -SET GLOBAL binlog_format=ROW; -# Re-spawn the worker threads to be sure they pick up the new binlog format -SET GLOBAL slave_parallel_threads=0; -SET GLOBAL slave_parallel_threads=10; - ---connection con1 -SET @old_format= @@binlog_format; -SET binlog_format= statement; -SET debug_sync='commit_after_release_LOCK_prepare_ordered SIGNAL master_queued1 WAIT_FOR master_cont1'; -send UPDATE t4 SET b=NULL WHERE a=6; ---connection server_1 -SET debug_sync='now WAIT_FOR master_queued1'; - ---connection con2 -SET @old_format= @@binlog_format; -SET binlog_format= statement; -SET debug_sync='commit_after_release_LOCK_prepare_ordered SIGNAL master_queued2'; -send DELETE FROM t4 WHERE b <= 3; - ---connection server_1 -SET debug_sync='now WAIT_FOR master_queued2'; -SET debug_sync='now SIGNAL master_cont1'; - ---connection con1 -REAP; -SET binlog_format= @old_format; ---connection con2 -REAP; -SET binlog_format= @old_format; -SET debug_sync='RESET'; ---save_master_pos -SELECT * FROM t4 ORDER BY a; - ---connection server_2 ---source include/start_slave.inc -SET debug_sync= 'now WAIT_FOR waiting'; ---sync_with_master -SELECT * FROM t4 ORDER BY a; -SET debug_sync= 'now SIGNAL cont'; - -# Re-spawn the worker threads to remove any DBUG injections or DEBUG_SYNC. ---source include/stop_slave.inc -SET GLOBAL debug_dbug=@old_dbug; -SET GLOBAL binlog_format= @old_format; -SET GLOBAL slave_parallel_threads=0; -SET GLOBAL slave_parallel_threads=10; ---source include/start_slave.inc - - ---echo *** MDEV-7237: Parallel replication: incorrect relaylog position after stop/start the slave *** ---connection server_1 -INSERT INTO t2 VALUES (40); ---save_master_pos - ---connection server_2 ---sync_with_master ---source include/stop_slave.inc -CHANGE MASTER TO master_use_gtid=no; -SET @old_dbug= @@GLOBAL.debug_dbug; -# This DBUG injection causes a DEBUG_SYNC signal "scheduled_gtid_0_x_100" when -# GTID 0-1-100 has been scheduled for and fetched by a worker thread. -SET GLOBAL debug_dbug="+d,rpl_parallel_scheduled_gtid_0_x_100"; -# This DBUG injection causes a DEBUG_SYNC signal "wait_for_done_waiting" when -# STOP SLAVE has signalled all worker threads to stop. -SET GLOBAL debug_dbug="+d,rpl_parallel_wait_for_done_trigger"; -# Reset worker threads to make DBUG setting catch on. -SET GLOBAL slave_parallel_threads=0; -SET GLOBAL slave_parallel_threads=10; - - ---connection server_1 -# Setup some transaction for the slave to replicate. -INSERT INTO t2 VALUES (41); -INSERT INTO t2 VALUES (42); -# Need to log the DELETE in statement format, so we can see it in processlist. -SET @old_format= @@binlog_format; -SET binlog_format= statement; -DELETE FROM t2 WHERE a=40; -SET binlog_format= @old_format; -INSERT INTO t2 VALUES (43); -INSERT INTO t2 VALUES (44); -# Force the slave to switch to a new relay log file. -FLUSH LOGS; -INSERT INTO t2 VALUES (45); -# Inject a GTID 0-1-100, which will trigger a DEBUG_SYNC signal when this -# transaction has been fetched by a worker thread. -SET gtid_seq_no=100; -INSERT INTO t2 VALUES (46); ---save_master_pos - ---connection con_temp2 -# Temporarily block the DELETE on a=40 from completing. -BEGIN; -SELECT * FROM t2 WHERE a=40 FOR UPDATE; - - ---connection server_2 ---source include/start_slave.inc - -# Wait for a worker thread to start on the DELETE that will be blocked -# temporarily by the SELECT FOR UPDATE. ---let $wait_condition= SELECT count(*) > 0 FROM information_schema.processlist WHERE state='updating' and info LIKE '%DELETE FROM t2 WHERE a=40%' ---source include/wait_condition.inc - -# The DBUG injection set above will make the worker thread signal the following -# debug_sync when the GTID 0-1-100 has been reached by a worker thread. -# Thus, at this point, the SQL driver thread has reached the next -# relay log file name, while a worker thread is still processing a -# transaction in the previous relay log file, blocked on the SELECT FOR -# UPDATE. -SET debug_sync= 'now WAIT_FOR scheduled_gtid_0_x_100'; -# At this point, the SQL driver thread is in the new relay log file, while -# the DELETE from the old relay log file is not yet complete. We will stop -# the slave at this point. The bug was that the DELETE statement would -# update the slave position to the _new_ relay log file name instead of -# its own old file name. Thus, by stoping and restarting the slave at this -# point, we would get an error at restart due to incorrect position. (If -# we would let the slave catch up before stopping, the incorrect position -# would be corrected by a later transaction). - -send STOP SLAVE; - ---connection con_temp2 -# Wait for STOP SLAVE to have proceeded sufficiently that it has signalled -# all worker threads to stop; this ensures that we will stop after the DELETE -# transaction (and not after a later transaction that might have been able -# to set a fixed position). -SET debug_sync= 'now WAIT_FOR wait_for_done_waiting'; -# Now release the row lock that was blocking the replication of DELETE. -ROLLBACK; - ---connection server_2 -reap; ---source include/wait_for_slave_sql_to_stop.inc -SELECT * FROM t2 WHERE a >= 40 ORDER BY a; -# Now restart the slave. With the bug present, this would start at an -# incorrect relay log position, causing relay log read error (or if unlucky, -# silently skip a number of events). ---source include/start_slave.inc ---sync_with_master -SELECT * FROM t2 WHERE a >= 40 ORDER BY a; ---source include/stop_slave.inc -SET GLOBAL debug_dbug=@old_dbug; -SET DEBUG_SYNC= 'RESET'; -SET GLOBAL slave_parallel_threads=0; -SET GLOBAL slave_parallel_threads=10; -CHANGE MASTER TO master_use_gtid=slave_pos; ---source include/start_slave.inc - - ---echo *** MDEV-7326 Server deadlock in connection with parallel replication *** -# We use three transactions, each in a separate group commit. -# T1 does mark_start_commit(), then gets a deadlock error. -# T2 wakes up and starts running -# T1 does unmark_start_commit() -# T3 goes to wait for T2 to start its commit -# T2 does mark_start_commit() -# The bug was that at this point, T3 got deadlocked. Because T1 has unmarked(), -# T3 did not yet see the count_committing_event_groups reach its target value -# yet. But when T1 later re-did mark_start_commit(), it failed to send a wakeup -# to T3. - ---connection server_2 ---source include/stop_slave.inc -SET GLOBAL slave_parallel_threads=0; -SET GLOBAL slave_parallel_threads=3; -SET GLOBAL debug_dbug="+d,rpl_parallel_simulate_temp_err_xid"; ---source include/start_slave.inc - ---connection server_1 -SET @old_format= @@SESSION.binlog_format; -SET binlog_format= STATEMENT; -# This debug_sync will linger on and be used to control T3 later. -INSERT INTO t1 VALUES (foo(50, - "rpl_parallel_start_waiting_for_prior SIGNAL t3_ready", - "rpl_parallel_end_of_group SIGNAL prep_ready WAIT_FOR prep_cont")); ---save_master_pos ---connection server_2 -# Wait for the debug_sync point for T3 to be set. But let the preparation -# transaction remain hanging, so that T1 and T2 will be scheduled for the -# remaining two worker threads. -SET DEBUG_SYNC= "now WAIT_FOR prep_ready"; - ---connection server_1 -INSERT INTO t2 VALUES (foo(50, - "rpl_parallel_simulate_temp_err_xid SIGNAL t1_ready1 WAIT_FOR t1_cont1", - "rpl_parallel_retry_after_unmark SIGNAL t1_ready2 WAIT_FOR t1_cont2")); ---save_master_pos - ---connection server_2 -SET DEBUG_SYNC= "now WAIT_FOR t1_ready1"; -# T1 has now done mark_start_commit(). It will later do a rollback and retry. - ---connection server_1 -# Use a MyISAM table for T2 and T3, so they do not trigger the -# rpl_parallel_simulate_temp_err_xid DBUG insertion on XID event. -INSERT INTO t1 VALUES (foo(51, - "rpl_parallel_before_mark_start_commit SIGNAL t2_ready1 WAIT_FOR t2_cont1", - "rpl_parallel_after_mark_start_commit SIGNAL t2_ready2")); - ---connection server_2 -SET DEBUG_SYNC= "now WAIT_FOR t2_ready1"; -# T2 has now started running, but has not yet done mark_start_commit() -SET DEBUG_SYNC= "now SIGNAL t1_cont1"; -SET DEBUG_SYNC= "now WAIT_FOR t1_ready2"; -# T1 has now done unmark_start_commit() in preparation for its retry. - ---connection server_1 -INSERT INTO t1 VALUES (52); -SET BINLOG_FORMAT= @old_format; -SELECT * FROM t2 WHERE a>=50 ORDER BY a; -SELECT * FROM t1 WHERE a>=50 ORDER BY a; - ---connection server_2 -# Let the preparation transaction complete, so that the same worker thread -# can continue with the transaction T3. -SET DEBUG_SYNC= "now SIGNAL prep_cont"; -SET DEBUG_SYNC= "now WAIT_FOR t3_ready"; -# T3 has now gone to wait for T2 to start committing -SET DEBUG_SYNC= "now SIGNAL t2_cont1"; -SET DEBUG_SYNC= "now WAIT_FOR t2_ready2"; -# T2 has now done mark_start_commit(). -# Let things run, and check that T3 does not get deadlocked. -SET DEBUG_SYNC= "now SIGNAL t1_cont2"; ---sync_with_master - ---connection server_1 ---save_master_pos ---connection server_2 ---sync_with_master -SELECT * FROM t2 WHERE a>=50 ORDER BY a; -SELECT * FROM t1 WHERE a>=50 ORDER BY a; -SET DEBUG_SYNC="reset"; - -# Re-spawn the worker threads to remove any DBUG injections or DEBUG_SYNC. ---source include/stop_slave.inc -SET GLOBAL debug_dbug=@old_dbug; -SET GLOBAL slave_parallel_threads=0; -SET GLOBAL slave_parallel_threads=10; ---source include/start_slave.inc - - ---echo *** MDEV-7326 Server deadlock in connection with parallel replication *** -# Similar to the previous test, but with T2 and T3 in the same GCO. -# We use three transactions, T1 in one group commit and T2/T3 in another. -# T1 does mark_start_commit(), then gets a deadlock error. -# T2 wakes up and starts running -# T1 does unmark_start_commit() -# T3 goes to wait for T1 to start its commit -# T2 does mark_start_commit() -# The bug was that at this point, T3 got deadlocked. T2 increments the -# count_committing_event_groups but does not signal T3, as they are in -# the same GCO. Then later when T1 increments, it would also not signal -# T3, because now the count_committing_event_groups is not equal to the -# wait_count of T3 (it is one larger). - ---connection server_2 ---source include/stop_slave.inc -SET GLOBAL slave_parallel_threads=0; -SET GLOBAL slave_parallel_threads=3; -SET GLOBAL debug_dbug="+d,rpl_parallel_simulate_temp_err_xid"; ---source include/start_slave.inc - ---connection server_1 -SET @old_format= @@SESSION.binlog_format; -SET binlog_format= STATEMENT; -# This debug_sync will linger on and be used to control T3 later. -INSERT INTO t1 VALUES (foo(60, - "rpl_parallel_start_waiting_for_prior SIGNAL t3_ready", - "rpl_parallel_end_of_group SIGNAL prep_ready WAIT_FOR prep_cont")); ---save_master_pos ---connection server_2 -# Wait for the debug_sync point for T3 to be set. But let the preparation -# transaction remain hanging, so that T1 and T2 will be scheduled for the -# remaining two worker threads. -SET DEBUG_SYNC= "now WAIT_FOR prep_ready"; - ---connection server_1 -INSERT INTO t2 VALUES (foo(60, - "rpl_parallel_simulate_temp_err_xid SIGNAL t1_ready1 WAIT_FOR t1_cont1", - "rpl_parallel_retry_after_unmark SIGNAL t1_ready2 WAIT_FOR t1_cont2")); ---save_master_pos - ---connection server_2 -SET DEBUG_SYNC= "now WAIT_FOR t1_ready1"; -# T1 has now done mark_start_commit(). It will later do a rollback and retry. - -# Do T2 and T3 in a single group commit. -# Use a MyISAM table for T2 and T3, so they do not trigger the -# rpl_parallel_simulate_temp_err_xid DBUG insertion on XID event. ---connection con_temp3 -SET debug_sync='commit_after_release_LOCK_prepare_ordered SIGNAL master_queued1 WAIT_FOR master_cont1'; -SET binlog_format=statement; -send INSERT INTO t1 VALUES (foo(61, - "rpl_parallel_before_mark_start_commit SIGNAL t2_ready1 WAIT_FOR t2_cont1", - "rpl_parallel_after_mark_start_commit SIGNAL t2_ready2")); - ---connection server_1 -SET debug_sync='now WAIT_FOR master_queued1'; - ---connection con_temp4 -SET debug_sync='commit_after_release_LOCK_prepare_ordered SIGNAL master_queued2'; -send INSERT INTO t6 VALUES (62); - ---connection server_1 -SET debug_sync='now WAIT_FOR master_queued2'; -SET debug_sync='now SIGNAL master_cont1'; - ---connection con_temp3 -REAP; ---connection con_temp4 -REAP; - ---connection server_1 -SET debug_sync='RESET'; -SET BINLOG_FORMAT= @old_format; -SELECT * FROM t2 WHERE a>=60 ORDER BY a; -SELECT * FROM t1 WHERE a>=60 ORDER BY a; -SELECT * FROM t6 WHERE a>=60 ORDER BY a; - ---connection server_2 -SET DEBUG_SYNC= "now WAIT_FOR t2_ready1"; -# T2 has now started running, but has not yet done mark_start_commit() -SET DEBUG_SYNC= "now SIGNAL t1_cont1"; -SET DEBUG_SYNC= "now WAIT_FOR t1_ready2"; -# T1 has now done unmark_start_commit() in preparation for its retry. - ---connection server_2 -# Let the preparation transaction complete, so that the same worker thread -# can continue with the transaction T3. -SET DEBUG_SYNC= "now SIGNAL prep_cont"; -SET DEBUG_SYNC= "now WAIT_FOR t3_ready"; -# T3 has now gone to wait for T2 to start committing -SET DEBUG_SYNC= "now SIGNAL t2_cont1"; -SET DEBUG_SYNC= "now WAIT_FOR t2_ready2"; -# T2 has now done mark_start_commit(). -# Let things run, and check that T3 does not get deadlocked. -SET DEBUG_SYNC= "now SIGNAL t1_cont2"; ---sync_with_master - ---connection server_1 ---save_master_pos ---connection server_2 ---sync_with_master -SELECT * FROM t2 WHERE a>=60 ORDER BY a; -SELECT * FROM t1 WHERE a>=60 ORDER BY a; -SELECT * FROM t6 WHERE a>=60 ORDER BY a; -SET DEBUG_SYNC="reset"; - -# Re-spawn the worker threads to remove any DBUG injections or DEBUG_SYNC. ---source include/stop_slave.inc -SET GLOBAL debug_dbug=@old_dbug; -SET GLOBAL slave_parallel_threads=0; -SET GLOBAL slave_parallel_threads=10; ---source include/start_slave.inc - ---echo *** MDEV-7335: Potential parallel slave deadlock with specific binlog corruption *** - ---connection server_2 ---source include/stop_slave.inc -SET GLOBAL slave_parallel_threads=1; -SET @old_dbug= @@GLOBAL.debug_dbug; -SET GLOBAL debug_dbug="+d,slave_discard_xid_for_gtid_0_x_1000"; -CALL mtr.add_suppression("Unexpected break of being relay-logged GTID"); - ---connection server_1 -INSERT INTO t2 VALUES (101); -INSERT INTO t2 VALUES (102); -INSERT INTO t2 VALUES (103); -INSERT INTO t2 VALUES (104); -INSERT INTO t2 VALUES (105); -# Inject a partial event group (missing XID at the end). The bug was that such -# partial group was not handled appropriately, leading to server deadlock. -SET gtid_seq_no=1000; -INSERT INTO t2 VALUES (106); -INSERT INTO t2 VALUES (107); -INSERT INTO t2 VALUES (108); -INSERT INTO t2 VALUES (109); -INSERT INTO t2 VALUES (110); -INSERT INTO t2 VALUES (111); -INSERT INTO t2 VALUES (112); -INSERT INTO t2 VALUES (113); -INSERT INTO t2 VALUES (114); -INSERT INTO t2 VALUES (115); -INSERT INTO t2 VALUES (116); -INSERT INTO t2 VALUES (117); -INSERT INTO t2 VALUES (118); -INSERT INTO t2 VALUES (119); -INSERT INTO t2 VALUES (120); -INSERT INTO t2 VALUES (121); -INSERT INTO t2 VALUES (122); -INSERT INTO t2 VALUES (123); -INSERT INTO t2 VALUES (124); -INSERT INTO t2 VALUES (125); -INSERT INTO t2 VALUES (126); -INSERT INTO t2 VALUES (127); -INSERT INTO t2 VALUES (128); -INSERT INTO t2 VALUES (129); -INSERT INTO t2 VALUES (130); ---source include/save_master_gtid.inc - ---connection server_2 ---source include/start_slave.inc ---source include/sync_with_master_gtid.inc -# The partial event group (a=106) should be rolled back and thus missing. -SELECT * FROM t2 WHERE a >= 100 ORDER BY a; - ---source include/stop_slave.inc -SET GLOBAL debug_dbug=@old_dbug; -SET GLOBAL slave_parallel_threads=10; ---source include/start_slave.inc - ---echo *** MDEV-6676 - test syntax of @@slave_parallel_mode *** ---connection server_2 - ---let $status_items= Parallel_Mode ---source include/show_slave_status.inc ---source include/stop_slave.inc -SET GLOBAL slave_parallel_mode='aggressive'; ---let $status_items= Parallel_Mode ---source include/show_slave_status.inc -SET GLOBAL slave_parallel_mode='conservative'; ---let $status_items= Parallel_Mode ---source include/show_slave_status.inc - - ---echo *** MDEV-6676 - test that empty parallel_mode does not replicate in parallel *** ---connection server_1 -INSERT INTO t2 VALUES (1040); ---source include/save_master_gtid.inc - ---connection server_2 -SET GLOBAL slave_parallel_mode='none'; -# Test that we do not use parallel apply, by injecting an unconditional -# crash in the parallel apply code. -SET @old_dbug= @@GLOBAL.debug_dbug; -SET GLOBAL debug_dbug="+d,slave_crash_if_parallel_apply"; ---source include/start_slave.inc ---source include/sync_with_master_gtid.inc -SELECT * FROM t2 WHERE a >= 1040 ORDER BY a; ---source include/stop_slave.inc -SET GLOBAL debug_dbug=@old_dbug; - ---echo *** MDEV-6676 - test disabling domain-based parallel replication *** ---connection server_1 -# Let's do a bunch of transactions that will conflict if run out-of-order in -# domain-based parallel replication mode. -SET gtid_domain_id = 1; -INSERT INTO t2 VALUES (1041); -INSERT INTO t2 VALUES (1042); -INSERT INTO t2 VALUES (1043); -INSERT INTO t2 VALUES (1044); -INSERT INTO t2 VALUES (1045); -INSERT INTO t2 VALUES (1046); -DELETE FROM t2 WHERE a >= 1041; -SET gtid_domain_id = 2; -INSERT INTO t2 VALUES (1041); -INSERT INTO t2 VALUES (1042); -INSERT INTO t2 VALUES (1043); -INSERT INTO t2 VALUES (1044); -INSERT INTO t2 VALUES (1045); -INSERT INTO t2 VALUES (1046); -SET gtid_domain_id = 0; ---source include/save_master_gtid.inc ---connection server_2 -SET GLOBAL slave_parallel_mode=minimal; ---source include/start_slave.inc ---source include/sync_with_master_gtid.inc -SELECT * FROM t2 WHERE a >= 1040 ORDER BY a; - ---echo *** MDEV-7888: ANALYZE TABLE does wakeup_subsequent_commits(), causing wrong binlog order and parallel replication hang *** - ---connection server_2 ---source include/stop_slave.inc -SET GLOBAL slave_parallel_mode='conservative'; -SET GLOBAL slave_parallel_threads=10; - -SET @old_dbug= @@GLOBAL.debug_dbug; -SET GLOBAL debug_dbug= '+d,inject_analyze_table_sleep'; - ---connection server_1 -# Inject two group commits. The bug was that ANALYZE TABLE would call -# wakeup_subsequent_commits() too early, allowing the following transaction -# in the same group to run ahead and binlog and free the GCO. Then we get -# wrong binlog order and later access freed GCO, which causes lost wakeup -# of following GCO and thus replication hang. -# We injected a small sleep in ANALYZE to make the race easier to hit (this -# can only cause false negatives in versions with the bug, not false positives, -# so sleep is ok here. And it's in general not possible to trigger reliably -# the race with debug_sync, since the bugfix makes the race impossible). - -SET @old_dbug_slave= @@SESSION.debug_dbug; -SET SESSION debug_dbug="+d,binlog_force_commit_id"; - -# Group commit with cid=10000, two event groups. -SET @commit_id= 10000; -ANALYZE TABLE t2; -INSERT INTO t3 VALUES (120, 0); - -# Group commit with cid=10001, one event group. -SET @commit_id= 10001; -INSERT INTO t3 VALUES (121, 0); - -SET SESSION debug_dbug=@old_dbug_slave; - -SELECT * FROM t3 WHERE a >= 120 ORDER BY a; ---source include/save_master_gtid.inc - ---connection server_2 ---source include/start_slave.inc ---source include/sync_with_master_gtid.inc - -SELECT * FROM t3 WHERE a >= 120 ORDER BY a; - ---source include/stop_slave.inc -SET GLOBAL debug_dbug= @old_dbug; ---source include/start_slave.inc - - ---echo *** MDEV-7929: record_gtid() for non-transactional event group calls wakeup_subsequent_commits() too early, causing slave hang. *** - ---connection server_2 ---source include/stop_slave.inc -SET @old_dbug= @@GLOBAL.debug_dbug; -SET GLOBAL debug_dbug= '+d,inject_record_gtid_serverid_100_sleep'; - ---connection server_1 -# Inject two group commits. The bug was that record_gtid for a -# non-transactional event group would commit its own transaction, which would -# cause ha_commit_trans() to call wakeup_subsequent_commits() too early. This -# in turn lead to access to freed group_commit_orderer object, losing a wakeup -# and causing slave threads to hang. -# We inject a small sleep in the corresponding record_gtid() to make the race -# easier to hit. - -SET @old_dbug_slave= @@SESSION.debug_dbug; -SET SESSION debug_dbug="+d,binlog_force_commit_id"; - -# Group commit with cid=10010, two event groups. -SET @old_server_id= @@SESSION.server_id; -SET SESSION server_id= 100; -SET @commit_id= 10010; -ALTER TABLE t1 COMMENT "Hulubulu!"; -SET SESSION server_id= @old_server_id; -INSERT INTO t3 VALUES (130, 0); - -# Group commit with cid=10011, one event group. -SET @commit_id= 10011; -INSERT INTO t3 VALUES (131, 0); - -SET SESSION debug_dbug=@old_dbug_slave; -SELECT * FROM t3 WHERE a >= 130 ORDER BY a; ---source include/save_master_gtid.inc - ---connection server_2 ---source include/start_slave.inc ---source include/sync_with_master_gtid.inc - -SELECT * FROM t3 WHERE a >= 130 ORDER BY a; - ---source include/stop_slave.inc -SET GLOBAL debug_dbug= @old_dbug; ---source include/start_slave.inc - - ---echo *** MDEV-8031: Parallel replication stops on "connection killed" error (probably incorrectly handled deadlock kill) *** - ---connection server_1 -INSERT INTO t3 VALUES (201,0), (202,0); ---source include/save_master_gtid.inc - ---connection server_2 ---source include/sync_with_master_gtid.inc ---source include/stop_slave.inc -SET @old_dbug= @@GLOBAL.debug_dbug; -SET GLOBAL debug_dbug= '+d,inject_mdev8031'; - ---connection server_1 -# We artificially create a situation that hopefully resembles the original -# bug which was only seen "in the wild", and only once. -# Setup a fake group commit with lots of conflicts that will lead to deadloc -# kill. The slave DBUG injection causes the slave to be deadlock killed at -# a particular point during the retry, and then later do a small sleep at -# another critical point where the prior transaction then has a chance to -# complete. Finally an extra KILL check catches an unhandled, lingering -# deadlock kill. So rather artificial, but at least it exercises the -# relevant code paths. -SET @old_dbug_slave= @@SESSION.debug_dbug; -SET SESSION debug_dbug="+d,binlog_force_commit_id"; - -SET @commit_id= 10200; -INSERT INTO t3 VALUES (203, 1); -INSERT INTO t3 VALUES (204, 1); -INSERT INTO t3 VALUES (205, 1); -UPDATE t3 SET b=b+1 WHERE a=201; -UPDATE t3 SET b=b+1 WHERE a=201; -UPDATE t3 SET b=b+1 WHERE a=201; -UPDATE t3 SET b=b+1 WHERE a=202; -UPDATE t3 SET b=b+1 WHERE a=202; -UPDATE t3 SET b=b+1 WHERE a=202; -UPDATE t3 SET b=b+1 WHERE a=202; -UPDATE t3 SET b=b+1 WHERE a=203; -UPDATE t3 SET b=b+1 WHERE a=203; -UPDATE t3 SET b=b+1 WHERE a=204; -UPDATE t3 SET b=b+1 WHERE a=204; -UPDATE t3 SET b=b+1 WHERE a=204; -UPDATE t3 SET b=b+1 WHERE a=203; -UPDATE t3 SET b=b+1 WHERE a=205; -UPDATE t3 SET b=b+1 WHERE a=205; -SET SESSION debug_dbug=@old_dbug_slave; - -SELECT * FROM t3 WHERE a>=200 ORDER BY a; ---source include/save_master_gtid.inc - ---connection server_2 ---source include/start_slave.inc ---source include/sync_with_master_gtid.inc - -SELECT * FROM t3 WHERE a>=200 ORDER BY a; ---source include/stop_slave.inc -SET GLOBAL debug_dbug= @old_dbug; ---source include/start_slave.inc - - ---echo *** Check getting deadlock killed inside open_binlog() during retry. *** - ---connection server_2 ---source include/stop_slave.inc -SET @old_dbug= @@GLOBAL.debug_dbug; -SET GLOBAL debug_dbug= '+d,inject_retry_event_group_open_binlog_kill'; -SET @old_max= @@GLOBAL.max_relay_log_size; -SET GLOBAL max_relay_log_size= 4096; - ---connection server_1 -SET @old_dbug_slave= @@SESSION.debug_dbug; -SET SESSION debug_dbug="+d,binlog_force_commit_id"; - ---let $large= `SELECT REPEAT("*", 8192)` -SET @commit_id= 10210; ---echo Omit long queries that cause relaylog rotations and transaction retries... ---disable_query_log -eval UPDATE t3 SET b=b+1 WHERE a=201 /* $large */; -eval UPDATE t3 SET b=b+1 WHERE a=201 /* $large */; -eval UPDATE t3 SET b=b+1 WHERE a=201 /* $large */; -eval UPDATE t3 SET b=b+1 WHERE a=202 /* $large */; -eval UPDATE t3 SET b=b+1 WHERE a=202 /* $large */; -eval UPDATE t3 SET b=b+1 WHERE a=202 /* $large */; -eval UPDATE t3 SET b=b+1 WHERE a=202 /* $large */; -eval UPDATE t3 SET b=b+1 WHERE a=203 /* $large */; -eval UPDATE t3 SET b=b+1 WHERE a=203 /* $large */; -eval UPDATE t3 SET b=b+1 WHERE a=204 /* $large */; -eval UPDATE t3 SET b=b+1 WHERE a=204 /* $large */; -eval UPDATE t3 SET b=b+1 WHERE a=204 /* $large */; -eval UPDATE t3 SET b=b+1 WHERE a=203 /* $large */; -eval UPDATE t3 SET b=b+1 WHERE a=205 /* $large */; -eval UPDATE t3 SET b=b+1 WHERE a=205 /* $large */; ---enable_query_log -SET SESSION debug_dbug=@old_dbug_slave; - -SELECT * FROM t3 WHERE a>=200 ORDER BY a; ---source include/save_master_gtid.inc - ---connection server_2 ---source include/start_slave.inc ---source include/sync_with_master_gtid.inc - -SELECT * FROM t3 WHERE a>=200 ORDER BY a; ---source include/stop_slave.inc -SET GLOBAL debug_dbug= @old_dbug; -SET GLOBAL max_relay_log_size= @old_max; ---source include/start_slave.inc - ---echo *** MDEV-8725: Assertion on ROLLBACK statement in the binary log *** ---connection server_1 -# Inject an event group terminated by ROLLBACK, by mixing MyISAM and InnoDB -# in a transaction. The bug was an assertion on the ROLLBACK due to -# mark_start_commit() being already called. ---disable_warnings -BEGIN; -INSERT INTO t2 VALUES (2000); -INSERT INTO t1 VALUES (2000); -INSERT INTO t2 VALUES (2001); -ROLLBACK; ---enable_warnings -SELECT * FROM t1 WHERE a>=2000 ORDER BY a; -SELECT * FROM t2 WHERE a>=2000 ORDER BY a; ---source include/save_master_gtid.inc - ---connection server_2 ---source include/sync_with_master_gtid.inc -SELECT * FROM t1 WHERE a>=2000 ORDER BY a; -SELECT * FROM t2 WHERE a>=2000 ORDER BY a; - - -# Clean up. ---connection server_2 ---source include/stop_slave.inc -SET GLOBAL slave_parallel_threads=@old_parallel_threads; ---source include/start_slave.inc -SET DEBUG_SYNC= 'RESET'; - ---connection server_1 -DROP function foo; -DROP TABLE t1,t2,t3,t4,t5,t6; -SET DEBUG_SYNC= 'RESET'; - ---source include/rpl_end.inc diff --git a/mysql-test/suite/rpl/t/rpl_parallel.test b/mysql-test/suite/rpl/t/rpl_parallel.test index ee39bfa7a391e..9ba7a30f2eb7f 100644 --- a/mysql-test/suite/rpl/t/rpl_parallel.test +++ b/mysql-test/suite/rpl/t/rpl_parallel.test @@ -1 +1,2218 @@ ---source include/rpl_parallel.inc +# +# This include file is used by more than one test suite +# (currently rpl and binlog_encryption). +# Please check all dependent tests after modifying it +# + +--source include/have_innodb.inc +--source include/have_debug.inc +--source include/have_debug_sync.inc +--source include/master-slave.inc + +# Test various aspects of parallel replication. + +--connection server_2 +SET @old_parallel_threads=@@GLOBAL.slave_parallel_threads; +--error ER_SLAVE_MUST_STOP +SET GLOBAL slave_parallel_threads=10; +--source include/stop_slave.inc +SET GLOBAL slave_parallel_threads=10; + +# Check that we do not spawn any worker threads when no slave is running. +SELECT IF(COUNT(*) < 10, "OK", CONCAT("Found too many system user processes: ", COUNT(*))) FROM information_schema.processlist WHERE user = "system user"; + +CHANGE MASTER TO master_use_gtid=slave_pos; +--source include/start_slave.inc + +# Check that worker threads get spawned when slave starts. +SELECT IF(COUNT(*) >= 10, "OK", CONCAT("Found too few system user processes: ", COUNT(*))) FROM information_schema.processlist WHERE user = "system user"; +# ... and that worker threads get removed when slave stops. +--source include/stop_slave.inc +SELECT IF(COUNT(*) < 10, "OK", CONCAT("Found too many system user processes: ", COUNT(*))) FROM information_schema.processlist WHERE user = "system user"; +--source include/start_slave.inc +SELECT IF(COUNT(*) >= 10, "OK", CONCAT("Found too few system user processes: ", COUNT(*))) FROM information_schema.processlist WHERE user = "system user"; + +--echo *** Test long-running query in domain 1 can run in parallel with short queries in domain 0 *** + +--connection server_1 +ALTER TABLE mysql.gtid_slave_pos ENGINE=InnoDB; +CREATE TABLE t1 (a int PRIMARY KEY) ENGINE=MyISAM; +CREATE TABLE t2 (a int PRIMARY KEY) ENGINE=InnoDB; +INSERT INTO t1 VALUES (1); +INSERT INTO t2 VALUES (1); +--save_master_pos + +--connection server_2 +--sync_with_master + +# Block the table t1 to simulate a replicated query taking a long time. +--connect (con_temp1,127.0.0.1,root,,test,$SERVER_MYPORT_2,) +LOCK TABLE t1 WRITE; + +--connection server_1 +SET gtid_domain_id=1; +# This query will be blocked on the slave until UNLOCK TABLES. +INSERT INTO t1 VALUES (2); +SET gtid_domain_id=0; +# These t2 queries can be replicated in parallel with the prior t1 query, as +# they are in a separate replication domain. +INSERT INTO t2 VALUES (2); +INSERT INTO t2 VALUES (3); +BEGIN; +INSERT INTO t2 VALUES (4); +INSERT INTO t2 VALUES (5); +COMMIT; +INSERT INTO t2 VALUES (6); + +--connection server_2 +--let $wait_condition= SELECT COUNT(*) = 6 FROM t2 +--source include/wait_condition.inc + +SELECT * FROM t2 ORDER by a; + +--connection con_temp1 +SELECT * FROM t1; +UNLOCK TABLES; + +--connection server_2 +--let $wait_condition= SELECT COUNT(*) = 2 FROM t1 +--source include/wait_condition.inc + +SELECT * FROM t1 ORDER BY a; + + +--echo *** Test two transactions in different domains committed in opposite order on slave but in a single group commit. *** +--connection server_2 +--source include/stop_slave.inc + +--connection server_1 +# Use a stored function to inject a debug_sync into the appropriate THD. +# The function does nothing on the master, and on the slave it injects the +# desired debug_sync action(s). +SET sql_log_bin=0; +--delimiter || +CREATE FUNCTION foo(x INT, d1 VARCHAR(500), d2 VARCHAR(500)) + RETURNS INT DETERMINISTIC + BEGIN + RETURN x; + END +|| +--delimiter ; +SET sql_log_bin=1; + +SET @old_format= @@SESSION.binlog_format; +SET binlog_format='statement'; +SET gtid_domain_id=1; +INSERT INTO t2 VALUES (foo(10, + 'commit_before_enqueue SIGNAL ready1 WAIT_FOR cont1', + 'commit_after_release_LOCK_prepare_ordered SIGNAL ready2')); + +--connection server_2 +FLUSH LOGS; +--source include/wait_for_binlog_checkpoint.inc +SET sql_log_bin=0; +--delimiter || +CREATE FUNCTION foo(x INT, d1 VARCHAR(500), d2 VARCHAR(500)) + RETURNS INT DETERMINISTIC + BEGIN + IF d1 != '' THEN + SET debug_sync = d1; + END IF; + IF d2 != '' THEN + SET debug_sync = d2; + END IF; + RETURN x; + END +|| +--delimiter ; +SET sql_log_bin=1; +SET @old_format=@@GLOBAL.binlog_format; +SET GLOBAL binlog_format=statement; +# We need to restart all parallel threads for the new global setting to +# be copied to the session-level values. +SET GLOBAL slave_parallel_threads=0; +SET GLOBAL slave_parallel_threads=10; +--source include/start_slave.inc + +# First make sure the first insert is ready to commit, but not queued yet. +SET debug_sync='now WAIT_FOR ready1'; + +--connection server_1 +SET gtid_domain_id=2; +INSERT INTO t2 VALUES (foo(11, + 'commit_before_enqueue SIGNAL ready3 WAIT_FOR cont3', + 'commit_after_release_LOCK_prepare_ordered SIGNAL ready4 WAIT_FOR cont4')); +SET gtid_domain_id=0; +SELECT * FROM t2 WHERE a >= 10 ORDER BY a; + +--connection server_2 +# Now wait for the second insert to queue itself as the leader, and then +# wait for more commits to queue up. +SET debug_sync='now WAIT_FOR ready3'; +SET debug_sync='now SIGNAL cont3'; +SET debug_sync='now WAIT_FOR ready4'; +# Now allow the first insert to queue up to participate in group commit. +SET debug_sync='now SIGNAL cont1'; +SET debug_sync='now WAIT_FOR ready2'; +# Finally allow the second insert to proceed and do the group commit. +SET debug_sync='now SIGNAL cont4'; + +--let $wait_condition= SELECT COUNT(*) = 2 FROM t2 WHERE a >= 10 +--source include/wait_condition.inc +SELECT * FROM t2 WHERE a >= 10 ORDER BY a; +# The two INSERT transactions should have been committed in opposite order, +# but in the same group commit (seen by precense of cid=# in the SHOW +# BINLOG output). +--let $binlog_file= slave-bin.000002 +--source include/show_binlog_events.inc +FLUSH LOGS; +--source include/wait_for_binlog_checkpoint.inc + +# Restart all the slave parallel worker threads, to clear all debug_sync actions. +--connection server_2 +--source include/stop_slave.inc +SET GLOBAL slave_parallel_threads=0; +SET GLOBAL slave_parallel_threads=10; +SET debug_sync='RESET'; +--source include/start_slave.inc + + +--echo *** Test that group-committed transactions on the master can replicate in parallel on the slave. *** +--connection server_1 +SET debug_sync='RESET'; +FLUSH LOGS; +--source include/wait_for_binlog_checkpoint.inc +CREATE TABLE t3 (a INT PRIMARY KEY, b INT) ENGINE=InnoDB; +# Create some sentinel rows so that the rows inserted in parallel fall into +# separate gaps and do not cause gap lock conflicts. +INSERT INTO t3 VALUES (1,1), (3,3), (5,5), (7,7); +--save_master_pos +--connection server_2 +--sync_with_master + +# We want to test that the transactions can execute out-of-order on +# the slave, but still end up committing in-order, and in a single +# group commit. +# +# The idea is to group-commit three transactions together on the master: +# A, B, and C. On the slave, C will execute the insert first, then A, +# and then B. But B manages to complete before A has time to commit, so +# all three end up committing together. +# +# So we start by setting up some row locks that will block transactions +# A and B from executing, allowing C to run first. + +--connection con_temp1 +BEGIN; +INSERT INTO t3 VALUES (2,102); +--connect (con_temp2,127.0.0.1,root,,test,$SERVER_MYPORT_2,) +BEGIN; +INSERT INTO t3 VALUES (4,104); + +# On the master, queue three INSERT transactions as a single group commit. +--connect (con_temp3,127.0.0.1,root,,test,$SERVER_MYPORT_1,) +SET debug_sync='commit_after_release_LOCK_prepare_ordered SIGNAL master_queued1 WAIT_FOR master_cont1'; +SET binlog_format=statement; +send INSERT INTO t3 VALUES (2, foo(12, + 'commit_after_release_LOCK_prepare_ordered SIGNAL slave_queued1 WAIT_FOR slave_cont1', + '')); + +--connection server_1 +SET debug_sync='now WAIT_FOR master_queued1'; + +--connect (con_temp4,127.0.0.1,root,,test,$SERVER_MYPORT_1,) +SET debug_sync='commit_after_release_LOCK_prepare_ordered SIGNAL master_queued2'; +SET binlog_format=statement; +send INSERT INTO t3 VALUES (4, foo(14, + 'commit_after_release_LOCK_prepare_ordered SIGNAL slave_queued2', + '')); + +--connection server_1 +SET debug_sync='now WAIT_FOR master_queued2'; + +--connect (con_temp5,127.0.0.1,root,,test,$SERVER_MYPORT_1,) +SET debug_sync='commit_after_release_LOCK_prepare_ordered SIGNAL master_queued3'; +SET binlog_format=statement; +send INSERT INTO t3 VALUES (6, foo(16, + 'group_commit_waiting_for_prior SIGNAL slave_queued3', + '')); + +--connection server_1 +SET debug_sync='now WAIT_FOR master_queued3'; +SET debug_sync='now SIGNAL master_cont1'; + +--connection con_temp3 +REAP; +--connection con_temp4 +REAP; +--connection con_temp5 +REAP; +SET debug_sync='RESET'; + +--connection server_1 +SELECT * FROM t3 ORDER BY a; +--let $binlog_file= master-bin.000002 +--source include/show_binlog_events.inc + +# First, wait until insert 3 is ready to queue up for group commit, but is +# waiting for insert 2 to commit before it can do so itself. +--connection server_2 +SET debug_sync='now WAIT_FOR slave_queued3'; + +# Next, let insert 1 proceed, and allow it to queue up as the group commit +# leader, but let it wait for insert 2 to also queue up before proceeding. +--connection con_temp1 +ROLLBACK; +--connection server_2 +SET debug_sync='now WAIT_FOR slave_queued1'; + +# Now let insert 2 proceed and queue up. +--connection con_temp2 +ROLLBACK; +--connection server_2 +SET debug_sync='now WAIT_FOR slave_queued2'; +# And finally, we can let insert 1 proceed and do the group commit with all +# three insert transactions together. +SET debug_sync='now SIGNAL slave_cont1'; + +# Wait for the commit to complete and check that all three transactions +# group-committed together (will be seen in the binlog as all three having +# cid=# on their GTID event). +--let $wait_condition= SELECT COUNT(*) = 3 FROM t3 WHERE a IN (2,4,6) +--source include/wait_condition.inc +SELECT * FROM t3 ORDER BY a; +--let $binlog_file= slave-bin.000003 +--source include/show_binlog_events.inc + + +--echo *** Test STOP SLAVE in parallel mode *** +--connection server_2 +--source include/stop_slave.inc +# Respawn all worker threads to clear any left-over debug_sync or other stuff. +SET debug_sync='RESET'; +SET GLOBAL slave_parallel_threads=0; +SET GLOBAL slave_parallel_threads=10; + +--connection server_1 +# Set up a couple of transactions. The first will be blocked halfway +# through on a lock, and while it is blocked we initiate STOP SLAVE. +# We then test that the halfway-initiated transaction is allowed to +# complete, but no subsequent ones. +# We have to use statement-based mode and set +# binlog_direct_non_transactional_updates=0; otherwise the binlog will +# be split into two event groups, one for the MyISAM part and one for the +# InnoDB part. +SET binlog_direct_non_transactional_updates=0; +SET sql_log_bin=0; +CALL mtr.add_suppression("Statement is unsafe because it accesses a non-transactional table after accessing a transactional table within the same transaction"); +SET sql_log_bin=1; +BEGIN; +INSERT INTO t2 VALUES (20); +--disable_warnings +INSERT INTO t1 VALUES (20); +--enable_warnings +INSERT INTO t2 VALUES (21); +INSERT INTO t3 VALUES (20, 20); +COMMIT; +INSERT INTO t3 VALUES(21, 21); +INSERT INTO t3 VALUES(22, 22); +SET binlog_format=@old_format; +--save_master_pos + +# Start a connection that will block the replicated transaction halfway. +--connection con_temp1 +BEGIN; +INSERT INTO t2 VALUES (21); + +--connection server_2 +START SLAVE; +# Wait for the MyISAM change to be visible, after which replication will wait +# for con_temp1 to roll back. +--let $wait_condition= SELECT COUNT(*) = 1 FROM t1 WHERE a=20 +--source include/wait_condition.inc + +--connection con_temp2 +# Initiate slave stop. It will have to wait for the current event group +# to complete. +# The dbug injection causes debug_sync to signal 'wait_for_done_waiting' +# when the SQL driver thread is ready. +SET @old_dbug= @@GLOBAL.debug_dbug; +SET GLOBAL debug_dbug="+d,rpl_parallel_wait_for_done_trigger"; +send STOP SLAVE; + +--connection con_temp1 +SET debug_sync='now WAIT_FOR wait_for_done_waiting'; +ROLLBACK; + +--connection con_temp2 +reap; +SET GLOBAL debug_dbug=@old_dbug; +SET debug_sync='RESET'; + +--connection server_2 +--source include/wait_for_slave_to_stop.inc +# We should see the first transaction applied, but not the two others. +SELECT * FROM t1 WHERE a >= 20 ORDER BY a; +SELECT * FROM t2 WHERE a >= 20 ORDER BY a; +SELECT * FROM t3 WHERE a >= 20 ORDER BY a; + +--source include/start_slave.inc +--sync_with_master +SELECT * FROM t1 WHERE a >= 20 ORDER BY a; +SELECT * FROM t2 WHERE a >= 20 ORDER BY a; +SELECT * FROM t3 WHERE a >= 20 ORDER BY a; + + +--connection server_2 +# Respawn all worker threads to clear any left-over debug_sync or other stuff. +--source include/stop_slave.inc +SET GLOBAL binlog_format=@old_format; +SET GLOBAL slave_parallel_threads=0; +SET GLOBAL slave_parallel_threads=10; +--source include/start_slave.inc + + +--echo *** Test killing slave threads at various wait points *** +--echo *** 1. Test killing transaction waiting in commit for previous transaction to commit *** + +# Set up three transactions on the master that will be group-committed +# together so they can be replicated in parallel on the slave. +--connection con_temp3 +SET debug_sync='commit_after_release_LOCK_prepare_ordered SIGNAL master_queued1 WAIT_FOR master_cont1'; +SET binlog_format=statement; +send INSERT INTO t3 VALUES (31, foo(31, + 'commit_before_prepare_ordered WAIT_FOR t2_waiting', + 'commit_after_prepare_ordered SIGNAL t1_ready WAIT_FOR t1_cont')); + +--connection server_1 +SET debug_sync='now WAIT_FOR master_queued1'; + +--connection con_temp4 +SET debug_sync='commit_after_release_LOCK_prepare_ordered SIGNAL master_queued2'; +SET binlog_format=statement; +BEGIN; +# This insert is just so we can get T2 to wait while a query is running that we +# can see in SHOW PROCESSLIST so we can get its thread_id to kill later. +INSERT INTO t3 VALUES (32, foo(32, + 'ha_write_row_end SIGNAL t2_query WAIT_FOR t2_cont', + '')); +# This insert sets up debug_sync points so that T2 will tell when it is at its +# wait point where we want to kill it - and when it has been killed. +INSERT INTO t3 VALUES (33, foo(33, + 'group_commit_waiting_for_prior SIGNAL t2_waiting', + 'group_commit_waiting_for_prior_killed SIGNAL t2_killed')); +send COMMIT; + +--connection server_1 +SET debug_sync='now WAIT_FOR master_queued2'; + +--connection con_temp5 +SET debug_sync='commit_after_release_LOCK_prepare_ordered SIGNAL master_queued3'; +SET binlog_format=statement; +send INSERT INTO t3 VALUES (34, foo(34, + '', + '')); + +--connection server_1 +SET debug_sync='now WAIT_FOR master_queued3'; +SET debug_sync='now SIGNAL master_cont1'; + +--connection con_temp3 +REAP; +--connection con_temp4 +REAP; +--connection con_temp5 +REAP; + +--connection server_1 +SELECT * FROM t3 WHERE a >= 30 ORDER BY a; +SET debug_sync='RESET'; + +--connection server_2 +SET sql_log_bin=0; +CALL mtr.add_suppression("Query execution was interrupted"); +CALL mtr.add_suppression("Commit failed due to failure of an earlier commit on which this one depends"); +CALL mtr.add_suppression("Slave: Connection was killed"); +SET sql_log_bin=1; +# Wait until T2 is inside executing its insert of 32, then find it in SHOW +# PROCESSLIST to know its thread id for KILL later. +SET debug_sync='now WAIT_FOR t2_query'; +--let $thd_id= `SELECT ID FROM INFORMATION_SCHEMA.PROCESSLIST WHERE INFO LIKE '%foo(32%' AND INFO NOT LIKE '%LIKE%'` +SET debug_sync='now SIGNAL t2_cont'; + +# Wait until T2 has entered its wait for T1 to commit, and T1 has +# progressed into its commit phase. +SET debug_sync='now WAIT_FOR t1_ready'; + +# Now kill the transaction T2. +--replace_result $thd_id THD_ID +eval KILL $thd_id; + +# Wait until T2 has reacted on the kill. +SET debug_sync='now WAIT_FOR t2_killed'; + +# Now we can allow T1 to proceed. +SET debug_sync='now SIGNAL t1_cont'; + +--let $slave_sql_errno= 1317,1927,1964 +--source include/wait_for_slave_sql_error.inc +STOP SLAVE IO_THREAD; +SELECT * FROM t3 WHERE a >= 30 ORDER BY a; + +# Now we have to disable the debug_sync statements, so they do not trigger +# when the events are retried. +SET debug_sync='RESET'; +SET GLOBAL slave_parallel_threads=0; +SET GLOBAL slave_parallel_threads=10; +SET sql_log_bin=0; +DROP FUNCTION foo; +--delimiter || +CREATE FUNCTION foo(x INT, d1 VARCHAR(500), d2 VARCHAR(500)) + RETURNS INT DETERMINISTIC + BEGIN + RETURN x; + END +|| +--delimiter ; +SET sql_log_bin=1; + +--connection server_1 +INSERT INTO t3 VALUES (39,0); +--save_master_pos + +--connection server_2 +--source include/start_slave.inc +--sync_with_master +SELECT * FROM t3 WHERE a >= 30 ORDER BY a; +# Restore the foo() function. +SET sql_log_bin=0; +DROP FUNCTION foo; +--delimiter || +CREATE FUNCTION foo(x INT, d1 VARCHAR(500), d2 VARCHAR(500)) + RETURNS INT DETERMINISTIC + BEGIN + IF d1 != '' THEN + SET debug_sync = d1; + END IF; + IF d2 != '' THEN + SET debug_sync = d2; + END IF; + RETURN x; + END +|| +--delimiter ; +SET sql_log_bin=1; + + +--connection server_2 +# Respawn all worker threads to clear any left-over debug_sync or other stuff. +--source include/stop_slave.inc +SET GLOBAL binlog_format=@old_format; +SET GLOBAL slave_parallel_threads=0; +SET GLOBAL slave_parallel_threads=10; +--source include/start_slave.inc + + +--echo *** 2. Same as (1), but without restarting IO thread after kill of SQL threads *** + +# Set up three transactions on the master that will be group-committed +# together so they can be replicated in parallel on the slave. +--connection con_temp3 +SET debug_sync='commit_after_release_LOCK_prepare_ordered SIGNAL master_queued1 WAIT_FOR master_cont1'; +SET binlog_format=statement; +send INSERT INTO t3 VALUES (41, foo(41, + 'commit_before_prepare_ordered WAIT_FOR t2_waiting', + 'commit_after_prepare_ordered SIGNAL t1_ready WAIT_FOR t1_cont')); + +--connection server_1 +SET debug_sync='now WAIT_FOR master_queued1'; + +--connection con_temp4 +SET debug_sync='commit_after_release_LOCK_prepare_ordered SIGNAL master_queued2'; +SET binlog_format=statement; +BEGIN; +# This insert is just so we can get T2 to wait while a query is running that we +# can see in SHOW PROCESSLIST so we can get its thread_id to kill later. +INSERT INTO t3 VALUES (42, foo(42, + 'ha_write_row_end SIGNAL t2_query WAIT_FOR t2_cont', + '')); +# This insert sets up debug_sync points so that T2 will tell when it is at its +# wait point where we want to kill it - and when it has been killed. +INSERT INTO t3 VALUES (43, foo(43, + 'group_commit_waiting_for_prior SIGNAL t2_waiting', + 'group_commit_waiting_for_prior_killed SIGNAL t2_killed')); +send COMMIT; + +--connection server_1 +SET debug_sync='now WAIT_FOR master_queued2'; + +--connection con_temp5 +SET debug_sync='commit_after_release_LOCK_prepare_ordered SIGNAL master_queued3'; +SET binlog_format=statement; +send INSERT INTO t3 VALUES (44, foo(44, + '', + '')); + +--connection server_1 +SET debug_sync='now WAIT_FOR master_queued3'; +SET debug_sync='now SIGNAL master_cont1'; + +--connection con_temp3 +REAP; +--connection con_temp4 +REAP; +--connection con_temp5 +REAP; + +--connection server_1 +SELECT * FROM t3 WHERE a >= 40 ORDER BY a; +SET debug_sync='RESET'; + +--connection server_2 +# Wait until T2 is inside executing its insert of 42, then find it in SHOW +# PROCESSLIST to know its thread id for KILL later. +SET debug_sync='now WAIT_FOR t2_query'; +--let $thd_id= `SELECT ID FROM INFORMATION_SCHEMA.PROCESSLIST WHERE INFO LIKE '%foo(42%' AND INFO NOT LIKE '%LIKE%'` +SET debug_sync='now SIGNAL t2_cont'; + +# Wait until T2 has entered its wait for T1 to commit, and T1 has +# progressed into its commit phase. +SET debug_sync='now WAIT_FOR t1_ready'; + +# Now kill the transaction T2. +--replace_result $thd_id THD_ID +eval KILL $thd_id; + +# Wait until T2 has reacted on the kill. +SET debug_sync='now WAIT_FOR t2_killed'; + +# Now we can allow T1 to proceed. +SET debug_sync='now SIGNAL t1_cont'; + +--let $slave_sql_errno= 1317,1927,1964 +--source include/wait_for_slave_sql_error.inc + +# Now we have to disable the debug_sync statements, so they do not trigger +# when the events are retried. +SET debug_sync='RESET'; +SET GLOBAL slave_parallel_threads=0; +SET GLOBAL slave_parallel_threads=10; +SET sql_log_bin=0; +DROP FUNCTION foo; +--delimiter || +CREATE FUNCTION foo(x INT, d1 VARCHAR(500), d2 VARCHAR(500)) + RETURNS INT DETERMINISTIC + BEGIN + RETURN x; + END +|| +--delimiter ; +SET sql_log_bin=1; + +--connection server_1 +INSERT INTO t3 VALUES (49,0); +--save_master_pos + +--connection server_2 +START SLAVE SQL_THREAD; +--sync_with_master +SELECT * FROM t3 WHERE a >= 40 ORDER BY a; +# Restore the foo() function. +SET sql_log_bin=0; +DROP FUNCTION foo; +--delimiter || +CREATE FUNCTION foo(x INT, d1 VARCHAR(500), d2 VARCHAR(500)) + RETURNS INT DETERMINISTIC + BEGIN + IF d1 != '' THEN + SET debug_sync = d1; + END IF; + IF d2 != '' THEN + SET debug_sync = d2; + END IF; + RETURN x; + END +|| +--delimiter ; +SET sql_log_bin=1; + + +--connection server_2 +# Respawn all worker threads to clear any left-over debug_sync or other stuff. +--source include/stop_slave.inc +SET GLOBAL binlog_format=@old_format; +SET GLOBAL slave_parallel_threads=0; +SET GLOBAL slave_parallel_threads=10; +--source include/start_slave.inc + + +--echo *** 3. Same as (2), but not using gtid mode *** + +--connection server_2 +--source include/stop_slave.inc +CHANGE MASTER TO master_use_gtid=no; +--source include/start_slave.inc + +--connection server_1 +# Set up three transactions on the master that will be group-committed +# together so they can be replicated in parallel on the slave. +--connection con_temp3 +SET debug_sync='commit_after_release_LOCK_prepare_ordered SIGNAL master_queued1 WAIT_FOR master_cont1'; +SET binlog_format=statement; +send INSERT INTO t3 VALUES (51, foo(51, + 'commit_before_prepare_ordered WAIT_FOR t2_waiting', + 'commit_after_prepare_ordered SIGNAL t1_ready WAIT_FOR t1_cont')); + +--connection server_1 +SET debug_sync='now WAIT_FOR master_queued1'; + +--connection con_temp4 +SET debug_sync='commit_after_release_LOCK_prepare_ordered SIGNAL master_queued2'; +SET binlog_format=statement; +BEGIN; +# This insert is just so we can get T2 to wait while a query is running that we +# can see in SHOW PROCESSLIST so we can get its thread_id to kill later. +INSERT INTO t3 VALUES (52, foo(52, + 'ha_write_row_end SIGNAL t2_query WAIT_FOR t2_cont', + '')); +# This insert sets up debug_sync points so that T2 will tell when it is at its +# wait point where we want to kill it - and when it has been killed. +INSERT INTO t3 VALUES (53, foo(53, + 'group_commit_waiting_for_prior SIGNAL t2_waiting', + 'group_commit_waiting_for_prior_killed SIGNAL t2_killed')); +send COMMIT; + +--connection server_1 +SET debug_sync='now WAIT_FOR master_queued2'; + +--connection con_temp5 +SET debug_sync='commit_after_release_LOCK_prepare_ordered SIGNAL master_queued3'; +SET binlog_format=statement; +send INSERT INTO t3 VALUES (54, foo(54, + '', + '')); + +--connection server_1 +SET debug_sync='now WAIT_FOR master_queued3'; +SET debug_sync='now SIGNAL master_cont1'; + +--connection con_temp3 +REAP; +--connection con_temp4 +REAP; +--connection con_temp5 +REAP; + +--connection server_1 +SELECT * FROM t3 WHERE a >= 50 ORDER BY a; +SET debug_sync='RESET'; + +--connection server_2 +# Wait until T2 is inside executing its insert of 52, then find it in SHOW +# PROCESSLIST to know its thread id for KILL later. +SET debug_sync='now WAIT_FOR t2_query'; +--let $thd_id= `SELECT ID FROM INFORMATION_SCHEMA.PROCESSLIST WHERE INFO LIKE '%foo(52%' AND INFO NOT LIKE '%LIKE%'` +SET debug_sync='now SIGNAL t2_cont'; + +# Wait until T2 has entered its wait for T1 to commit, and T1 has +# progressed into its commit phase. +SET debug_sync='now WAIT_FOR t1_ready'; + +# Now kill the transaction T2. +--replace_result $thd_id THD_ID +eval KILL $thd_id; + +# Wait until T2 has reacted on the kill. +SET debug_sync='now WAIT_FOR t2_killed'; + +# Now we can allow T1 to proceed. +SET debug_sync='now SIGNAL t1_cont'; + +--let $slave_sql_errno= 1317,1927,1964 +--source include/wait_for_slave_sql_error.inc +SELECT * FROM t3 WHERE a >= 50 ORDER BY a; + +# Now we have to disable the debug_sync statements, so they do not trigger +# when the events are retried. +SET debug_sync='RESET'; +SET GLOBAL slave_parallel_threads=0; +SET GLOBAL slave_parallel_threads=10; +SET sql_log_bin=0; +DROP FUNCTION foo; +--delimiter || +CREATE FUNCTION foo(x INT, d1 VARCHAR(500), d2 VARCHAR(500)) + RETURNS INT DETERMINISTIC + BEGIN + RETURN x; + END +|| +--delimiter ; +SET sql_log_bin=1; + +--connection server_1 +INSERT INTO t3 VALUES (59,0); +--save_master_pos + +--connection server_2 +START SLAVE SQL_THREAD; +--sync_with_master +SELECT * FROM t3 WHERE a >= 50 ORDER BY a; +# Restore the foo() function. +SET sql_log_bin=0; +DROP FUNCTION foo; +--delimiter || +CREATE FUNCTION foo(x INT, d1 VARCHAR(500), d2 VARCHAR(500)) + RETURNS INT DETERMINISTIC + BEGIN + IF d1 != '' THEN + SET debug_sync = d1; + END IF; + IF d2 != '' THEN + SET debug_sync = d2; + END IF; + RETURN x; + END +|| +--delimiter ; +SET sql_log_bin=1; + + +--source include/stop_slave.inc +CHANGE MASTER TO master_use_gtid=slave_pos; +--source include/start_slave.inc + +--connection server_2 +# Respawn all worker threads to clear any left-over debug_sync or other stuff. +--source include/stop_slave.inc +SET GLOBAL binlog_format=@old_format; +SET GLOBAL slave_parallel_threads=0; +SET GLOBAL slave_parallel_threads=4; +--source include/start_slave.inc + + +--echo *** 4. Test killing thread that is waiting to start transaction until previous transaction commits *** + +# We set up four transactions T1, T2, T3, and T4 on the master. T2, T3, and T4 +# can run in parallel with each other (same group commit and commit id), +# but not in parallel with T1. +# +# We use four worker threads, each Ti will be queued on each their own +# worker thread. We will delay T1 commit, T3 will wait for T1 to begin +# commit before it can start. We will kill T3 during this wait, and +# check that everything works correctly. +# +# It is rather tricky to get the correct thread id of the worker to kill. +# We start by injecting four dummy transactions in a debug_sync-controlled +# manner to be able to get known thread ids for the workers in a pool with +# just 4 worker threads. Then we let in each of the real test transactions +# T1-T4 one at a time in a way which allows us to know which transaction +# ends up with which thread id. + +--connection server_1 +SET binlog_format=statement; +SET gtid_domain_id=2; +BEGIN; +# This debug_sync will linger on and be used to control T4 later. +INSERT INTO t3 VALUES (70, foo(70, + 'rpl_parallel_start_waiting_for_prior SIGNAL t4_waiting', '')); +INSERT INTO t3 VALUES (60, foo(60, + 'ha_write_row_end SIGNAL d2_query WAIT_FOR d2_cont2', + 'rpl_parallel_end_of_group SIGNAL d2_done WAIT_FOR d2_cont')); +COMMIT; +SET gtid_domain_id=0; + +--connection server_2 +SET debug_sync='now WAIT_FOR d2_query'; +--let $d2_thd_id= `SELECT ID FROM INFORMATION_SCHEMA.PROCESSLIST WHERE INFO LIKE '%foo(60%' AND INFO NOT LIKE '%LIKE%'` + +--connection server_1 +SET gtid_domain_id=1; +BEGIN; +# These debug_sync's will linger on and be used to control T3 later. +INSERT INTO t3 VALUES (61, foo(61, + 'rpl_parallel_start_waiting_for_prior SIGNAL t3_waiting', + 'rpl_parallel_start_waiting_for_prior_killed SIGNAL t3_killed')); +INSERT INTO t3 VALUES (62, foo(62, + 'ha_write_row_end SIGNAL d1_query WAIT_FOR d1_cont2', + 'rpl_parallel_end_of_group SIGNAL d1_done WAIT_FOR d1_cont')); +COMMIT; +SET gtid_domain_id=0; + +--connection server_2 +SET debug_sync='now WAIT_FOR d1_query'; +--let $d1_thd_id= `SELECT ID FROM INFORMATION_SCHEMA.PROCESSLIST WHERE INFO LIKE '%foo(62%' AND INFO NOT LIKE '%LIKE%'` + +--connection server_1 +SET gtid_domain_id=0; +INSERT INTO t3 VALUES (63, foo(63, + 'ha_write_row_end SIGNAL d0_query WAIT_FOR d0_cont2', + 'rpl_parallel_end_of_group SIGNAL d0_done WAIT_FOR d0_cont')); + +--connection server_2 +SET debug_sync='now WAIT_FOR d0_query'; +--let $d0_thd_id= `SELECT ID FROM INFORMATION_SCHEMA.PROCESSLIST WHERE INFO LIKE '%foo(63%' AND INFO NOT LIKE '%LIKE%'` + +--connection server_1 +SET gtid_domain_id=3; +BEGIN; +# These debug_sync's will linger on and be used to control T2 later. +INSERT INTO t3 VALUES (68, foo(68, + 'rpl_parallel_start_waiting_for_prior SIGNAL t2_waiting', '')); +INSERT INTO t3 VALUES (69, foo(69, + 'ha_write_row_end SIGNAL d3_query WAIT_FOR d3_cont2', + 'rpl_parallel_end_of_group SIGNAL d3_done WAIT_FOR d3_cont')); +COMMIT; +SET gtid_domain_id=0; + +--connection server_2 +SET debug_sync='now WAIT_FOR d3_query'; +--let $d3_thd_id= `SELECT ID FROM INFORMATION_SCHEMA.PROCESSLIST WHERE INFO LIKE '%foo(69%' AND INFO NOT LIKE '%LIKE%'` + +SET debug_sync='now SIGNAL d2_cont2'; +SET debug_sync='now WAIT_FOR d2_done'; +SET debug_sync='now SIGNAL d1_cont2'; +SET debug_sync='now WAIT_FOR d1_done'; +SET debug_sync='now SIGNAL d0_cont2'; +SET debug_sync='now WAIT_FOR d0_done'; +SET debug_sync='now SIGNAL d3_cont2'; +SET debug_sync='now WAIT_FOR d3_done'; + +# Now prepare the real transactions T1, T2, T3, T4 on the master. + +--connection con_temp3 +# Create transaction T1. +SET binlog_format=statement; +INSERT INTO t3 VALUES (64, foo(64, + 'rpl_parallel_before_mark_start_commit SIGNAL t1_waiting WAIT_FOR t1_cont', '')); + +# Create transaction T2, as a group commit leader on the master. +SET debug_sync='commit_after_release_LOCK_prepare_ordered SIGNAL master_queued2 WAIT_FOR master_cont2'; +send INSERT INTO t3 VALUES (65, foo(65, '', '')); + +--connection server_1 +SET debug_sync='now WAIT_FOR master_queued2'; + +--connection con_temp4 +# Create transaction T3, participating in T2's group commit. +SET debug_sync='commit_after_release_LOCK_prepare_ordered SIGNAL master_queued3'; +send INSERT INTO t3 VALUES (66, foo(66, '', '')); + +--connection server_1 +SET debug_sync='now WAIT_FOR master_queued3'; + +--connection con_temp5 +# Create transaction T4, participating in group commit with T2 and T3. +SET debug_sync='commit_after_release_LOCK_prepare_ordered SIGNAL master_queued4'; +send INSERT INTO t3 VALUES (67, foo(67, '', '')); + +--connection server_1 +SET debug_sync='now WAIT_FOR master_queued4'; +SET debug_sync='now SIGNAL master_cont2'; + +--connection con_temp3 +REAP; +--connection con_temp4 +REAP; +--connection con_temp5 +REAP; + +--connection server_1 +SELECT * FROM t3 WHERE a >= 60 ORDER BY a; +SET debug_sync='RESET'; + +--connection server_2 +# Now we have the four transactions pending for replication on the slave. +# Let them be queued for our three worker threads in a controlled fashion. +# We put them at a stage where T1 is delayed and T3 is waiting for T1 to +# commit before T3 can start. Then we kill T3. + +# Make the worker D0 free, and wait for T1 to be queued in it. +SET debug_sync='now SIGNAL d0_cont'; +SET debug_sync='now WAIT_FOR t1_waiting'; + +# Make the worker D3 free, and wait for T2 to be queued in it. +SET debug_sync='now SIGNAL d3_cont'; +SET debug_sync='now WAIT_FOR t2_waiting'; + +# Now release worker D1, and wait for T3 to be queued in it. +# T3 will wait for T1 to commit before it can start. +SET debug_sync='now SIGNAL d1_cont'; +SET debug_sync='now WAIT_FOR t3_waiting'; + +# Release worker D2. Wait for T4 to be queued, so we are sure it has +# received the debug_sync signal (else we might overwrite it with the +# next debug_sync). +SET debug_sync='now SIGNAL d2_cont'; +SET debug_sync='now WAIT_FOR t4_waiting'; + +# Now we kill the waiting transaction T3 in worker D1. +--replace_result $d1_thd_id THD_ID +eval KILL $d1_thd_id; + +# Wait until T3 has reacted on the kill. +SET debug_sync='now WAIT_FOR t3_killed'; + +# Now we can allow T1 to proceed. +SET debug_sync='now SIGNAL t1_cont'; + +--let $slave_sql_errno= 1317,1927,1964 +--source include/wait_for_slave_sql_error.inc +STOP SLAVE IO_THREAD; +# Since T2, T3, and T4 run in parallel, we can not be sure if T2 will have time +# to commit or not before the stop. However, T1 should commit, and T3/T4 may +# not have committed. (After slave restart we check that all become committed +# eventually). +SELECT * FROM t3 WHERE a >= 60 AND a != 65 ORDER BY a; + +# Now we have to disable the debug_sync statements, so they do not trigger +# when the events are retried. +SET debug_sync='RESET'; +SET GLOBAL slave_parallel_threads=0; +SET GLOBAL slave_parallel_threads=10; +SET sql_log_bin=0; +DROP FUNCTION foo; +--delimiter || +CREATE FUNCTION foo(x INT, d1 VARCHAR(500), d2 VARCHAR(500)) + RETURNS INT DETERMINISTIC + BEGIN + RETURN x; + END +|| +--delimiter ; +SET sql_log_bin=1; + +--connection server_1 +UPDATE t3 SET b=b+1 WHERE a=60; +--save_master_pos + +--connection server_2 +--source include/start_slave.inc +--sync_with_master +SELECT * FROM t3 WHERE a >= 60 ORDER BY a; +# Restore the foo() function. +SET sql_log_bin=0; +DROP FUNCTION foo; +--delimiter || +CREATE FUNCTION foo(x INT, d1 VARCHAR(500), d2 VARCHAR(500)) + RETURNS INT DETERMINISTIC + BEGIN + IF d1 != '' THEN + SET debug_sync = d1; + END IF; + IF d2 != '' THEN + SET debug_sync = d2; + END IF; + RETURN x; + END +|| +--delimiter ; +SET sql_log_bin=1; + +--connection server_2 +# Respawn all worker threads to clear any left-over debug_sync or other stuff. +--source include/stop_slave.inc +SET GLOBAL binlog_format=@old_format; +SET GLOBAL slave_parallel_threads=0; +SET GLOBAL slave_parallel_threads=10; +--source include/start_slave.inc + + +--echo *** 5. Test killing thread that is waiting for queue of max length to shorten *** + +# Find the thread id of the driver SQL thread that we want to kill. +--let $wait_condition= SELECT COUNT(*) = 1 FROM INFORMATION_SCHEMA.PROCESSLIST WHERE STATE LIKE '%Slave has read all relay log%' +--source include/wait_condition.inc +--let $thd_id= `SELECT ID FROM INFORMATION_SCHEMA.PROCESSLIST WHERE STATE LIKE '%Slave has read all relay log%'` +SET @old_max_queued= @@GLOBAL.slave_parallel_max_queued; +SET GLOBAL slave_parallel_max_queued=9000; + +--connection server_1 +--let bigstring= `SELECT REPEAT('x', 10000)` +SET binlog_format=statement; +# Create an event that will wait to be signalled. +INSERT INTO t3 VALUES (80, foo(0, + 'ha_write_row_end SIGNAL query_waiting WAIT_FOR query_cont', '')); + +--connection server_2 +SET debug_sync='now WAIT_FOR query_waiting'; +# Inject that the SQL driver thread will signal `wait_queue_ready' to debug_sync +# as it goes to wait for the event queue to become smaller than the value of +# @@slave_parallel_max_queued. +SET @old_dbug= @@GLOBAL.debug_dbug; +SET GLOBAL debug_dbug="+d,rpl_parallel_wait_queue_max"; + +--connection server_1 +--disable_query_log +# Create an event that will fill up the queue. +# The Xid event at the end of the event group will have to wait for the Query +# event with the INSERT to drain so the queue becomes shorter. However that in +# turn waits for the prior event group to continue. +eval INSERT INTO t3 VALUES (81, LENGTH('$bigstring')); +--enable_query_log +SELECT * FROM t3 WHERE a >= 80 ORDER BY a; + +--connection server_2 +SET debug_sync='now WAIT_FOR wait_queue_ready'; + +--replace_result $thd_id THD_ID +eval KILL $thd_id; + +SET debug_sync='now WAIT_FOR wait_queue_killed'; +SET debug_sync='now SIGNAL query_cont'; + +--let $slave_sql_errno= 1317,1927,1964 +--source include/wait_for_slave_sql_error.inc +STOP SLAVE IO_THREAD; + +SET GLOBAL debug_dbug=@old_dbug; +SET GLOBAL slave_parallel_max_queued= @old_max_queued; + +--connection server_1 +INSERT INTO t3 VALUES (82,0); +SET binlog_format=@old_format; +--save_master_pos + +--connection server_2 +SET debug_sync='RESET'; +--source include/start_slave.inc +--sync_with_master +SELECT * FROM t3 WHERE a >= 80 ORDER BY a; + + +--connection server_2 +--source include/stop_slave.inc +SET GLOBAL binlog_format=@old_format; +SET GLOBAL slave_parallel_threads=0; +SET GLOBAL slave_parallel_threads=10; +--source include/start_slave.inc + +--echo *** MDEV-5788 Incorrect free of rgi->deferred_events in parallel replication *** + +--connection server_2 +# Use just two worker threads, so we are sure to get the rpl_group_info added +# to the free list, which is what triggered the bug. +--source include/stop_slave.inc +SET GLOBAL replicate_ignore_table="test.t3"; +SET GLOBAL slave_parallel_threads=2; +--source include/start_slave.inc + +--connection server_1 +INSERT INTO t3 VALUES (100, rand()); +INSERT INTO t3 VALUES (101, rand()); + +--save_master_pos + +--connection server_2 +--sync_with_master + +--connection server_1 +INSERT INTO t3 VALUES (102, rand()); +INSERT INTO t3 VALUES (103, rand()); +INSERT INTO t3 VALUES (104, rand()); +INSERT INTO t3 VALUES (105, rand()); + +--save_master_pos + +--connection server_2 +--sync_with_master +--source include/stop_slave.inc +SET GLOBAL replicate_ignore_table=""; +--source include/start_slave.inc + +--connection server_1 +INSERT INTO t3 VALUES (106, rand()); +INSERT INTO t3 VALUES (107, rand()); +--save_master_pos + +--connection server_2 +--sync_with_master +--replace_column 2 # +SELECT * FROM t3 WHERE a >= 100 ORDER BY a; + + +--echo *** MDEV-5921: In parallel replication, an error is not correctly signalled to the next transaction *** + +--connection server_2 +--source include/stop_slave.inc +SET GLOBAL slave_parallel_threads=10; +--source include/start_slave.inc + +--connection server_1 +INSERT INTO t3 VALUES (110, 1); +--save_master_pos + +--connection server_2 +--sync_with_master +SELECT * FROM t3 WHERE a >= 110 ORDER BY a; +# Inject a duplicate key error. +SET sql_log_bin=0; +INSERT INTO t3 VALUES (111, 666); +SET sql_log_bin=1; + +--connection server_1 + +# Create a group commit with two inserts, the first one conflicts with a row on the slave +--connect (con1,127.0.0.1,root,,test,$SERVER_MYPORT_1,) +SET debug_sync='commit_after_release_LOCK_prepare_ordered SIGNAL master_queued1 WAIT_FOR master_cont1'; +send INSERT INTO t3 VALUES (111, 2); +--connection server_1 +SET debug_sync='now WAIT_FOR master_queued1'; + +--connect (con2,127.0.0.1,root,,test,$SERVER_MYPORT_1,) +SET debug_sync='commit_after_release_LOCK_prepare_ordered SIGNAL master_queued2'; +send INSERT INTO t3 VALUES (112, 3); + +--connection server_1 +SET debug_sync='now WAIT_FOR master_queued2'; +SET debug_sync='now SIGNAL master_cont1'; + +--connection con1 +REAP; +--connection con2 +REAP; +SET debug_sync='RESET'; +--save_master_pos + +--connection server_2 +--let $slave_sql_errno= 1062 +--source include/wait_for_slave_sql_error.inc +--source include/wait_for_slave_sql_to_stop.inc +# We should not see the row (112,3) here, it should be rolled back due to +# error signal from the prior transaction. +SELECT * FROM t3 WHERE a >= 110 ORDER BY a; +SET sql_log_bin=0; +DELETE FROM t3 WHERE a=111 AND b=666; +SET sql_log_bin=1; +START SLAVE SQL_THREAD; +--sync_with_master +SELECT * FROM t3 WHERE a >= 110 ORDER BY a; + + +--echo ***MDEV-5914: Parallel replication deadlock due to InnoDB lock conflicts *** +--connection server_2 +--source include/stop_slave.inc + +--connection server_1 +CREATE TABLE t4 (a INT PRIMARY KEY, b INT, KEY b_idx(b)) ENGINE=InnoDB; +INSERT INTO t4 VALUES (1,NULL), (2,2), (3,NULL), (4,4), (5, NULL), (6, 6); + +# Create a group commit with UPDATE and DELETE, in that order. +# The bug was that while the UPDATE's row lock does not block the DELETE, the +# DELETE's gap lock _does_ block the UPDATE. This could cause a deadlock +# on the slave. +--connection con1 +SET debug_sync='commit_after_release_LOCK_prepare_ordered SIGNAL master_queued1 WAIT_FOR master_cont1'; +send UPDATE t4 SET b=NULL WHERE a=6; +--connection server_1 +SET debug_sync='now WAIT_FOR master_queued1'; + +--connection con2 +SET debug_sync='commit_after_release_LOCK_prepare_ordered SIGNAL master_queued2'; +send DELETE FROM t4 WHERE b <= 3; + +--connection server_1 +SET debug_sync='now WAIT_FOR master_queued2'; +SET debug_sync='now SIGNAL master_cont1'; + +--connection con1 +REAP; +--connection con2 +REAP; +SET debug_sync='RESET'; +--save_master_pos + +--connection server_2 +--source include/start_slave.inc +--sync_with_master +--source include/stop_slave.inc + +SELECT * FROM t4 ORDER BY a; + + +# Another example, this one with INSERT vs. DELETE +--connection server_1 +DELETE FROM t4; +INSERT INTO t4 VALUES (1,NULL), (2,2), (3,NULL), (4,4), (5, NULL), (6, 6); + +# Create a group commit with INSERT and DELETE, in that order. +# The bug was that while the INSERT's insert intention lock does not block +# the DELETE, the DELETE's gap lock _does_ block the INSERT. This could cause +# a deadlock on the slave. +--connection con1 +SET debug_sync='commit_after_release_LOCK_prepare_ordered SIGNAL master_queued1 WAIT_FOR master_cont1'; +send INSERT INTO t4 VALUES (7, NULL); +--connection server_1 +SET debug_sync='now WAIT_FOR master_queued1'; + +--connection con2 +SET debug_sync='commit_after_release_LOCK_prepare_ordered SIGNAL master_queued2'; +send DELETE FROM t4 WHERE b <= 3; + +--connection server_1 +SET debug_sync='now WAIT_FOR master_queued2'; +SET debug_sync='now SIGNAL master_cont1'; + +--connection con1 +REAP; +--connection con2 +REAP; +SET debug_sync='RESET'; +--save_master_pos + +--connection server_2 +--source include/start_slave.inc +--sync_with_master +--source include/stop_slave.inc + +SELECT * FROM t4 ORDER BY a; + + +# MDEV-6549, failing to update gtid_slave_pos for a transaction that was retried. +# The problem was that when a transaction updates the mysql.gtid_slave_pos +# table, it clears the flag that marks that there is a GTID position that +# needs to be updated. Then, if the transaction got killed after that due +# to a deadlock, the subsequent retry would fail to notice that the GTID needs +# to be recorded in gtid_slave_pos. +# +# (In the original bug report, the symptom was an assertion; this was however +# just a side effect of the missing update of gtid_slave_pos, which also +# happened to cause a missing clear of OPTION_GTID_BEGIN). +--connection server_1 +DELETE FROM t4; +INSERT INTO t4 VALUES (1,NULL), (2,2), (3,NULL), (4,4), (5, NULL), (6, 6); + +# Create two transactions that can run in parallel on the slave but cause +# a deadlock if the second runs before the first. +--connection con1 +SET debug_sync='commit_after_release_LOCK_prepare_ordered SIGNAL master_queued1 WAIT_FOR master_cont1'; +send UPDATE t4 SET b=NULL WHERE a=6; +--connection server_1 +SET debug_sync='now WAIT_FOR master_queued1'; + +--connection con2 +# Must use statement-based binlogging. Otherwise the transaction will not be +# binlogged at all, as it modifies no rows. +SET @old_format= @@SESSION.binlog_format; +SET binlog_format='statement'; +SET debug_sync='commit_after_release_LOCK_prepare_ordered SIGNAL master_queued2'; +send DELETE FROM t4 WHERE b <= 1; + +--connection server_1 +SET debug_sync='now WAIT_FOR master_queued2'; +SET debug_sync='now SIGNAL master_cont1'; + +--connection con1 +REAP; +--connection con2 +REAP; +SET @old_format=@@GLOBAL.binlog_format; +SET debug_sync='RESET'; +--save_master_pos +--let $last_gtid= `SELECT @@last_gtid` + +--connection server_2 +# Disable the usual skip of gap locks for transactions that are run in +# parallel, using DBUG. This allows the deadlock to occur, and this in turn +# triggers a retry of the second transaction, and the code that was buggy and +# caused the gtid_slave_pos update to be skipped in the retry. +SET @old_dbug= @@GLOBAL.debug_dbug; +SET GLOBAL debug_dbug="+d,disable_thd_need_ordering_with"; +--source include/start_slave.inc +--sync_with_master +SET GLOBAL debug_dbug=@old_dbug; + +SELECT * FROM t4 ORDER BY a; +# Check that the GTID of the second transaction was correctly recorded in +# gtid_slave_pos, in the variable as well as in the table. +--replace_result $last_gtid GTID +eval SET @last_gtid= '$last_gtid'; +SELECT IF(@@gtid_slave_pos LIKE CONCAT('%',@last_gtid,'%'), "GTID found ok", + CONCAT("GTID ", @last_gtid, " not found in gtid_slave_pos=", @@gtid_slave_pos)) + AS result; +SELECT "ROW FOUND" AS `Is the row found?` + FROM mysql.gtid_slave_pos + WHERE CONCAT(domain_id, "-", server_id, "-", seq_no) = @last_gtid; + + +--echo *** MDEV-5938: Exec_master_log_pos not updated at log rotate in parallel replication *** +--connection server_2 +--source include/stop_slave.inc +SET GLOBAL slave_parallel_threads=1; +SET DEBUG_SYNC= 'RESET'; +--source include/start_slave.inc + +--connection server_1 +CREATE TABLE t5 (a INT PRIMARY KEY, b INT); +INSERT INTO t5 VALUES (1,1); +INSERT INTO t5 VALUES (2,2), (3,8); +INSERT INTO t5 VALUES (4,16); +--save_master_pos + +--connection server_2 +--sync_with_master +let $io_file= query_get_value(SHOW SLAVE STATUS, Master_Log_File, 1); +let $io_pos= query_get_value(SHOW SLAVE STATUS, Read_Master_Log_Pos, 1); +let $sql_file= query_get_value(SHOW SLAVE STATUS, Relay_Master_Log_File, 1); +let $sql_pos= query_get_value(SHOW SLAVE STATUS, Exec_Master_Log_Pos, 1); +--disable_query_log +eval SELECT IF('$io_file' = '$sql_file', "OK", "Not ok, $io_file <> $sql_file") AS test_check; +eval SELECT IF('$io_pos' = '$sql_pos', "OK", "Not ok, $io_pos <> $sql_pos") AS test_check; +--enable_query_log + +--connection server_1 +FLUSH LOGS; +--source include/wait_for_binlog_checkpoint.inc +--save_master_pos + +--connection server_2 +--sync_with_master +let $io_file= query_get_value(SHOW SLAVE STATUS, Master_Log_File, 1); +let $io_pos= query_get_value(SHOW SLAVE STATUS, Read_Master_Log_Pos, 1); +let $sql_file= query_get_value(SHOW SLAVE STATUS, Relay_Master_Log_File, 1); +let $sql_pos= query_get_value(SHOW SLAVE STATUS, Exec_Master_Log_Pos, 1); +--disable_query_log +eval SELECT IF('$io_file' = '$sql_file', "OK", "Not ok, $io_file <> $sql_file") AS test_check; +eval SELECT IF('$io_pos' = '$sql_pos', "OK", "Not ok, $io_pos <> $sql_pos") AS test_check; +--enable_query_log + + +--echo *** MDEV_6435: Incorrect error handling when query binlogged partially on master with "killed" error *** + +--connection server_1 +CREATE TABLE t6 (a INT) ENGINE=MyISAM; +CREATE TRIGGER tr AFTER INSERT ON t6 FOR EACH ROW SET @a = 1; + +--connection con1 +SET @old_format= @@binlog_format; +SET binlog_format= statement; +--let $conid = `SELECT CONNECTION_ID()` +SET debug_sync='sp_head_execute_before_loop SIGNAL ready WAIT_FOR cont'; +send INSERT INTO t6 VALUES (1), (2), (3); + +--connection server_1 +SET debug_sync='now WAIT_FOR ready'; +--replace_result $conid CONID +eval KILL QUERY $conid; +SET debug_sync='now SIGNAL cont'; + +--connection con1 +--error ER_QUERY_INTERRUPTED +--reap +SET binlog_format= @old_format; +SET debug_sync='RESET'; +--let $after_error_gtid_pos= `SELECT @@gtid_binlog_pos` + +--connection server_1 +SET debug_sync='RESET'; + + +--connection server_2 +--let $slave_sql_errno= 1317 +--source include/wait_for_slave_sql_error.inc +STOP SLAVE IO_THREAD; +--replace_result $after_error_gtid_pos AFTER_ERROR_GTID_POS +eval SET GLOBAL gtid_slave_pos= '$after_error_gtid_pos'; +--source include/start_slave.inc + +--connection server_1 +INSERT INTO t6 VALUES (4); +SELECT * FROM t6 ORDER BY a; +--save_master_pos + +--connection server_2 +--sync_with_master +SELECT * FROM t6 ORDER BY a; + + +--echo *** MDEV-6551: Some replication errors are ignored if slave_parallel_threads > 0 *** + +--connection server_1 +INSERT INTO t2 VALUES (31); +--let $gtid1= `SELECT @@LAST_GTID` +--source include/save_master_gtid.inc + +--connection server_2 +--source include/sync_with_master_gtid.inc +--source include/stop_slave.inc +SET GLOBAL slave_parallel_threads= 0; +--source include/start_slave.inc + +# Force a duplicate key error on the slave. +SET sql_log_bin= 0; +INSERT INTO t2 VALUES (32); +SET sql_log_bin= 1; + +--connection server_1 +INSERT INTO t2 VALUES (32); +--let $gtid2= `SELECT @@LAST_GTID` +# Rotate the binlog; the bug is triggered when the master binlog file changes +# after the event group that causes the duplicate key error. +FLUSH LOGS; +INSERT INTO t2 VALUES (33); +INSERT INTO t2 VALUES (34); +SELECT * FROM t2 WHERE a >= 30 ORDER BY a; +--source include/save_master_gtid.inc + +--connection server_2 +--let $slave_sql_errno= 1062 +--source include/wait_for_slave_sql_error.inc + +--connection server_2 +--source include/stop_slave_io.inc +SET GLOBAL slave_parallel_threads=10; +START SLAVE; + +--let $slave_sql_errno= 1062 +--source include/wait_for_slave_sql_error.inc + +# Note: IO thread is still running at this point. +# The bug seems to have been that restarting the SQL thread after an error with +# the IO thread still running, somehow picks up a later relay log position and +# thus ends up skipping the failing event, rather than re-executing. + +START SLAVE SQL_THREAD; +--let $slave_sql_errno= 1062 +--source include/wait_for_slave_sql_error.inc + +SELECT * FROM t2 WHERE a >= 30 ORDER BY a; + +# Skip the duplicate error, so we can proceed. +--error ER_SLAVE_SKIP_NOT_IN_GTID +SET sql_slave_skip_counter= 1; +--source include/stop_slave_io.inc +--disable_query_log +eval SET GLOBAL gtid_slave_pos = REPLACE(@@gtid_slave_pos, "$gtid1", "$gtid2"); +--enable_query_log +--source include/start_slave.inc +--source include/sync_with_master_gtid.inc + +SELECT * FROM t2 WHERE a >= 30 ORDER BY a; + + +--echo *** MDEV-6775: Wrong binlog order in parallel replication *** +--connection server_1 +# A bit tricky bug to reproduce. On the master, we binlog in statement-mode +# two transactions, an UPDATE followed by a DELETE. On the slave, we replicate +# with binlog-mode set to ROW, which means the DELETE, which modifies no rows, +# is not binlogged. Then we inject a wait in the group commit code on the +# slave, shortly before the actual commit of the UPDATE. The bug was that the +# DELETE could wake up from wait_for_prior_commit() before the commit of the +# UPDATE. So the test could see the slave position updated to after DELETE, +# while the UPDATE was still not visible. +DELETE FROM t4; +INSERT INTO t4 VALUES (1,NULL), (3,NULL), (4,4), (5, NULL), (6, 6); +--source include/save_master_gtid.inc + +--connection server_2 +--source include/sync_with_master_gtid.inc +--source include/stop_slave.inc +SET @old_dbug= @@GLOBAL.debug_dbug; +SET GLOBAL debug_dbug="+d,inject_binlog_commit_before_get_LOCK_log"; +SET @old_format=@@GLOBAL.binlog_format; +SET GLOBAL binlog_format=ROW; +# Re-spawn the worker threads to be sure they pick up the new binlog format +SET GLOBAL slave_parallel_threads=0; +SET GLOBAL slave_parallel_threads=10; + +--connection con1 +SET @old_format= @@binlog_format; +SET binlog_format= statement; +SET debug_sync='commit_after_release_LOCK_prepare_ordered SIGNAL master_queued1 WAIT_FOR master_cont1'; +send UPDATE t4 SET b=NULL WHERE a=6; +--connection server_1 +SET debug_sync='now WAIT_FOR master_queued1'; + +--connection con2 +SET @old_format= @@binlog_format; +SET binlog_format= statement; +SET debug_sync='commit_after_release_LOCK_prepare_ordered SIGNAL master_queued2'; +send DELETE FROM t4 WHERE b <= 3; + +--connection server_1 +SET debug_sync='now WAIT_FOR master_queued2'; +SET debug_sync='now SIGNAL master_cont1'; + +--connection con1 +REAP; +SET binlog_format= @old_format; +--connection con2 +REAP; +SET binlog_format= @old_format; +SET debug_sync='RESET'; +--save_master_pos +SELECT * FROM t4 ORDER BY a; + +--connection server_2 +--source include/start_slave.inc +SET debug_sync= 'now WAIT_FOR waiting'; +--sync_with_master +SELECT * FROM t4 ORDER BY a; +SET debug_sync= 'now SIGNAL cont'; + +# Re-spawn the worker threads to remove any DBUG injections or DEBUG_SYNC. +--source include/stop_slave.inc +SET GLOBAL debug_dbug=@old_dbug; +SET GLOBAL binlog_format= @old_format; +SET GLOBAL slave_parallel_threads=0; +SET GLOBAL slave_parallel_threads=10; +--source include/start_slave.inc + + +--echo *** MDEV-7237: Parallel replication: incorrect relaylog position after stop/start the slave *** +--connection server_1 +INSERT INTO t2 VALUES (40); +--save_master_pos + +--connection server_2 +--sync_with_master +--source include/stop_slave.inc +CHANGE MASTER TO master_use_gtid=no; +SET @old_dbug= @@GLOBAL.debug_dbug; +# This DBUG injection causes a DEBUG_SYNC signal "scheduled_gtid_0_x_100" when +# GTID 0-1-100 has been scheduled for and fetched by a worker thread. +SET GLOBAL debug_dbug="+d,rpl_parallel_scheduled_gtid_0_x_100"; +# This DBUG injection causes a DEBUG_SYNC signal "wait_for_done_waiting" when +# STOP SLAVE has signalled all worker threads to stop. +SET GLOBAL debug_dbug="+d,rpl_parallel_wait_for_done_trigger"; +# Reset worker threads to make DBUG setting catch on. +SET GLOBAL slave_parallel_threads=0; +SET GLOBAL slave_parallel_threads=10; + + +--connection server_1 +# Setup some transaction for the slave to replicate. +INSERT INTO t2 VALUES (41); +INSERT INTO t2 VALUES (42); +# Need to log the DELETE in statement format, so we can see it in processlist. +SET @old_format= @@binlog_format; +SET binlog_format= statement; +DELETE FROM t2 WHERE a=40; +SET binlog_format= @old_format; +INSERT INTO t2 VALUES (43); +INSERT INTO t2 VALUES (44); +# Force the slave to switch to a new relay log file. +FLUSH LOGS; +INSERT INTO t2 VALUES (45); +# Inject a GTID 0-1-100, which will trigger a DEBUG_SYNC signal when this +# transaction has been fetched by a worker thread. +SET gtid_seq_no=100; +INSERT INTO t2 VALUES (46); +--save_master_pos + +--connection con_temp2 +# Temporarily block the DELETE on a=40 from completing. +BEGIN; +SELECT * FROM t2 WHERE a=40 FOR UPDATE; + + +--connection server_2 +--source include/start_slave.inc + +# Wait for a worker thread to start on the DELETE that will be blocked +# temporarily by the SELECT FOR UPDATE. +--let $wait_condition= SELECT count(*) > 0 FROM information_schema.processlist WHERE state='updating' and info LIKE '%DELETE FROM t2 WHERE a=40%' +--source include/wait_condition.inc + +# The DBUG injection set above will make the worker thread signal the following +# debug_sync when the GTID 0-1-100 has been reached by a worker thread. +# Thus, at this point, the SQL driver thread has reached the next +# relay log file name, while a worker thread is still processing a +# transaction in the previous relay log file, blocked on the SELECT FOR +# UPDATE. +SET debug_sync= 'now WAIT_FOR scheduled_gtid_0_x_100'; +# At this point, the SQL driver thread is in the new relay log file, while +# the DELETE from the old relay log file is not yet complete. We will stop +# the slave at this point. The bug was that the DELETE statement would +# update the slave position to the _new_ relay log file name instead of +# its own old file name. Thus, by stoping and restarting the slave at this +# point, we would get an error at restart due to incorrect position. (If +# we would let the slave catch up before stopping, the incorrect position +# would be corrected by a later transaction). + +send STOP SLAVE; + +--connection con_temp2 +# Wait for STOP SLAVE to have proceeded sufficiently that it has signalled +# all worker threads to stop; this ensures that we will stop after the DELETE +# transaction (and not after a later transaction that might have been able +# to set a fixed position). +SET debug_sync= 'now WAIT_FOR wait_for_done_waiting'; +# Now release the row lock that was blocking the replication of DELETE. +ROLLBACK; + +--connection server_2 +reap; +--source include/wait_for_slave_sql_to_stop.inc +SELECT * FROM t2 WHERE a >= 40 ORDER BY a; +# Now restart the slave. With the bug present, this would start at an +# incorrect relay log position, causing relay log read error (or if unlucky, +# silently skip a number of events). +--source include/start_slave.inc +--sync_with_master +SELECT * FROM t2 WHERE a >= 40 ORDER BY a; +--source include/stop_slave.inc +SET GLOBAL debug_dbug=@old_dbug; +SET DEBUG_SYNC= 'RESET'; +SET GLOBAL slave_parallel_threads=0; +SET GLOBAL slave_parallel_threads=10; +CHANGE MASTER TO master_use_gtid=slave_pos; +--source include/start_slave.inc + + +--echo *** MDEV-7326 Server deadlock in connection with parallel replication *** +# We use three transactions, each in a separate group commit. +# T1 does mark_start_commit(), then gets a deadlock error. +# T2 wakes up and starts running +# T1 does unmark_start_commit() +# T3 goes to wait for T2 to start its commit +# T2 does mark_start_commit() +# The bug was that at this point, T3 got deadlocked. Because T1 has unmarked(), +# T3 did not yet see the count_committing_event_groups reach its target value +# yet. But when T1 later re-did mark_start_commit(), it failed to send a wakeup +# to T3. + +--connection server_2 +--source include/stop_slave.inc +SET GLOBAL slave_parallel_threads=0; +SET GLOBAL slave_parallel_threads=3; +SET GLOBAL debug_dbug="+d,rpl_parallel_simulate_temp_err_xid"; +--source include/start_slave.inc + +--connection server_1 +SET @old_format= @@SESSION.binlog_format; +SET binlog_format= STATEMENT; +# This debug_sync will linger on and be used to control T3 later. +INSERT INTO t1 VALUES (foo(50, + "rpl_parallel_start_waiting_for_prior SIGNAL t3_ready", + "rpl_parallel_end_of_group SIGNAL prep_ready WAIT_FOR prep_cont")); +--save_master_pos +--connection server_2 +# Wait for the debug_sync point for T3 to be set. But let the preparation +# transaction remain hanging, so that T1 and T2 will be scheduled for the +# remaining two worker threads. +SET DEBUG_SYNC= "now WAIT_FOR prep_ready"; + +--connection server_1 +INSERT INTO t2 VALUES (foo(50, + "rpl_parallel_simulate_temp_err_xid SIGNAL t1_ready1 WAIT_FOR t1_cont1", + "rpl_parallel_retry_after_unmark SIGNAL t1_ready2 WAIT_FOR t1_cont2")); +--save_master_pos + +--connection server_2 +SET DEBUG_SYNC= "now WAIT_FOR t1_ready1"; +# T1 has now done mark_start_commit(). It will later do a rollback and retry. + +--connection server_1 +# Use a MyISAM table for T2 and T3, so they do not trigger the +# rpl_parallel_simulate_temp_err_xid DBUG insertion on XID event. +INSERT INTO t1 VALUES (foo(51, + "rpl_parallel_before_mark_start_commit SIGNAL t2_ready1 WAIT_FOR t2_cont1", + "rpl_parallel_after_mark_start_commit SIGNAL t2_ready2")); + +--connection server_2 +SET DEBUG_SYNC= "now WAIT_FOR t2_ready1"; +# T2 has now started running, but has not yet done mark_start_commit() +SET DEBUG_SYNC= "now SIGNAL t1_cont1"; +SET DEBUG_SYNC= "now WAIT_FOR t1_ready2"; +# T1 has now done unmark_start_commit() in preparation for its retry. + +--connection server_1 +INSERT INTO t1 VALUES (52); +SET BINLOG_FORMAT= @old_format; +SELECT * FROM t2 WHERE a>=50 ORDER BY a; +SELECT * FROM t1 WHERE a>=50 ORDER BY a; + +--connection server_2 +# Let the preparation transaction complete, so that the same worker thread +# can continue with the transaction T3. +SET DEBUG_SYNC= "now SIGNAL prep_cont"; +SET DEBUG_SYNC= "now WAIT_FOR t3_ready"; +# T3 has now gone to wait for T2 to start committing +SET DEBUG_SYNC= "now SIGNAL t2_cont1"; +SET DEBUG_SYNC= "now WAIT_FOR t2_ready2"; +# T2 has now done mark_start_commit(). +# Let things run, and check that T3 does not get deadlocked. +SET DEBUG_SYNC= "now SIGNAL t1_cont2"; +--sync_with_master + +--connection server_1 +--save_master_pos +--connection server_2 +--sync_with_master +SELECT * FROM t2 WHERE a>=50 ORDER BY a; +SELECT * FROM t1 WHERE a>=50 ORDER BY a; +SET DEBUG_SYNC="reset"; + +# Re-spawn the worker threads to remove any DBUG injections or DEBUG_SYNC. +--source include/stop_slave.inc +SET GLOBAL debug_dbug=@old_dbug; +SET GLOBAL slave_parallel_threads=0; +SET GLOBAL slave_parallel_threads=10; +--source include/start_slave.inc + + +--echo *** MDEV-7326 Server deadlock in connection with parallel replication *** +# Similar to the previous test, but with T2 and T3 in the same GCO. +# We use three transactions, T1 in one group commit and T2/T3 in another. +# T1 does mark_start_commit(), then gets a deadlock error. +# T2 wakes up and starts running +# T1 does unmark_start_commit() +# T3 goes to wait for T1 to start its commit +# T2 does mark_start_commit() +# The bug was that at this point, T3 got deadlocked. T2 increments the +# count_committing_event_groups but does not signal T3, as they are in +# the same GCO. Then later when T1 increments, it would also not signal +# T3, because now the count_committing_event_groups is not equal to the +# wait_count of T3 (it is one larger). + +--connection server_2 +--source include/stop_slave.inc +SET GLOBAL slave_parallel_threads=0; +SET GLOBAL slave_parallel_threads=3; +SET GLOBAL debug_dbug="+d,rpl_parallel_simulate_temp_err_xid"; +--source include/start_slave.inc + +--connection server_1 +SET @old_format= @@SESSION.binlog_format; +SET binlog_format= STATEMENT; +# This debug_sync will linger on and be used to control T3 later. +INSERT INTO t1 VALUES (foo(60, + "rpl_parallel_start_waiting_for_prior SIGNAL t3_ready", + "rpl_parallel_end_of_group SIGNAL prep_ready WAIT_FOR prep_cont")); +--save_master_pos +--connection server_2 +# Wait for the debug_sync point for T3 to be set. But let the preparation +# transaction remain hanging, so that T1 and T2 will be scheduled for the +# remaining two worker threads. +SET DEBUG_SYNC= "now WAIT_FOR prep_ready"; + +--connection server_1 +INSERT INTO t2 VALUES (foo(60, + "rpl_parallel_simulate_temp_err_xid SIGNAL t1_ready1 WAIT_FOR t1_cont1", + "rpl_parallel_retry_after_unmark SIGNAL t1_ready2 WAIT_FOR t1_cont2")); +--save_master_pos + +--connection server_2 +SET DEBUG_SYNC= "now WAIT_FOR t1_ready1"; +# T1 has now done mark_start_commit(). It will later do a rollback and retry. + +# Do T2 and T3 in a single group commit. +# Use a MyISAM table for T2 and T3, so they do not trigger the +# rpl_parallel_simulate_temp_err_xid DBUG insertion on XID event. +--connection con_temp3 +SET debug_sync='commit_after_release_LOCK_prepare_ordered SIGNAL master_queued1 WAIT_FOR master_cont1'; +SET binlog_format=statement; +send INSERT INTO t1 VALUES (foo(61, + "rpl_parallel_before_mark_start_commit SIGNAL t2_ready1 WAIT_FOR t2_cont1", + "rpl_parallel_after_mark_start_commit SIGNAL t2_ready2")); + +--connection server_1 +SET debug_sync='now WAIT_FOR master_queued1'; + +--connection con_temp4 +SET debug_sync='commit_after_release_LOCK_prepare_ordered SIGNAL master_queued2'; +send INSERT INTO t6 VALUES (62); + +--connection server_1 +SET debug_sync='now WAIT_FOR master_queued2'; +SET debug_sync='now SIGNAL master_cont1'; + +--connection con_temp3 +REAP; +--connection con_temp4 +REAP; + +--connection server_1 +SET debug_sync='RESET'; +SET BINLOG_FORMAT= @old_format; +SELECT * FROM t2 WHERE a>=60 ORDER BY a; +SELECT * FROM t1 WHERE a>=60 ORDER BY a; +SELECT * FROM t6 WHERE a>=60 ORDER BY a; + +--connection server_2 +SET DEBUG_SYNC= "now WAIT_FOR t2_ready1"; +# T2 has now started running, but has not yet done mark_start_commit() +SET DEBUG_SYNC= "now SIGNAL t1_cont1"; +SET DEBUG_SYNC= "now WAIT_FOR t1_ready2"; +# T1 has now done unmark_start_commit() in preparation for its retry. + +--connection server_2 +# Let the preparation transaction complete, so that the same worker thread +# can continue with the transaction T3. +SET DEBUG_SYNC= "now SIGNAL prep_cont"; +SET DEBUG_SYNC= "now WAIT_FOR t3_ready"; +# T3 has now gone to wait for T2 to start committing +SET DEBUG_SYNC= "now SIGNAL t2_cont1"; +SET DEBUG_SYNC= "now WAIT_FOR t2_ready2"; +# T2 has now done mark_start_commit(). +# Let things run, and check that T3 does not get deadlocked. +SET DEBUG_SYNC= "now SIGNAL t1_cont2"; +--sync_with_master + +--connection server_1 +--save_master_pos +--connection server_2 +--sync_with_master +SELECT * FROM t2 WHERE a>=60 ORDER BY a; +SELECT * FROM t1 WHERE a>=60 ORDER BY a; +SELECT * FROM t6 WHERE a>=60 ORDER BY a; +SET DEBUG_SYNC="reset"; + +# Re-spawn the worker threads to remove any DBUG injections or DEBUG_SYNC. +--source include/stop_slave.inc +SET GLOBAL debug_dbug=@old_dbug; +SET GLOBAL slave_parallel_threads=0; +SET GLOBAL slave_parallel_threads=10; +--source include/start_slave.inc + +--echo *** MDEV-7335: Potential parallel slave deadlock with specific binlog corruption *** + +--connection server_2 +--source include/stop_slave.inc +SET GLOBAL slave_parallel_threads=1; +SET @old_dbug= @@GLOBAL.debug_dbug; +SET GLOBAL debug_dbug="+d,slave_discard_xid_for_gtid_0_x_1000"; +CALL mtr.add_suppression("Unexpected break of being relay-logged GTID"); + +--connection server_1 +INSERT INTO t2 VALUES (101); +INSERT INTO t2 VALUES (102); +INSERT INTO t2 VALUES (103); +INSERT INTO t2 VALUES (104); +INSERT INTO t2 VALUES (105); +# Inject a partial event group (missing XID at the end). The bug was that such +# partial group was not handled appropriately, leading to server deadlock. +SET gtid_seq_no=1000; +INSERT INTO t2 VALUES (106); +INSERT INTO t2 VALUES (107); +INSERT INTO t2 VALUES (108); +INSERT INTO t2 VALUES (109); +INSERT INTO t2 VALUES (110); +INSERT INTO t2 VALUES (111); +INSERT INTO t2 VALUES (112); +INSERT INTO t2 VALUES (113); +INSERT INTO t2 VALUES (114); +INSERT INTO t2 VALUES (115); +INSERT INTO t2 VALUES (116); +INSERT INTO t2 VALUES (117); +INSERT INTO t2 VALUES (118); +INSERT INTO t2 VALUES (119); +INSERT INTO t2 VALUES (120); +INSERT INTO t2 VALUES (121); +INSERT INTO t2 VALUES (122); +INSERT INTO t2 VALUES (123); +INSERT INTO t2 VALUES (124); +INSERT INTO t2 VALUES (125); +INSERT INTO t2 VALUES (126); +INSERT INTO t2 VALUES (127); +INSERT INTO t2 VALUES (128); +INSERT INTO t2 VALUES (129); +INSERT INTO t2 VALUES (130); +--source include/save_master_gtid.inc + +--connection server_2 +--source include/start_slave.inc +--source include/sync_with_master_gtid.inc +# The partial event group (a=106) should be rolled back and thus missing. +SELECT * FROM t2 WHERE a >= 100 ORDER BY a; + +--source include/stop_slave.inc +SET GLOBAL debug_dbug=@old_dbug; +SET GLOBAL slave_parallel_threads=10; +--source include/start_slave.inc + +--echo *** MDEV-6676 - test syntax of @@slave_parallel_mode *** +--connection server_2 + +--let $status_items= Parallel_Mode +--source include/show_slave_status.inc +--source include/stop_slave.inc +SET GLOBAL slave_parallel_mode='aggressive'; +--let $status_items= Parallel_Mode +--source include/show_slave_status.inc +SET GLOBAL slave_parallel_mode='conservative'; +--let $status_items= Parallel_Mode +--source include/show_slave_status.inc + + +--echo *** MDEV-6676 - test that empty parallel_mode does not replicate in parallel *** +--connection server_1 +INSERT INTO t2 VALUES (1040); +--source include/save_master_gtid.inc + +--connection server_2 +SET GLOBAL slave_parallel_mode='none'; +# Test that we do not use parallel apply, by injecting an unconditional +# crash in the parallel apply code. +SET @old_dbug= @@GLOBAL.debug_dbug; +SET GLOBAL debug_dbug="+d,slave_crash_if_parallel_apply"; +--source include/start_slave.inc +--source include/sync_with_master_gtid.inc +SELECT * FROM t2 WHERE a >= 1040 ORDER BY a; +--source include/stop_slave.inc +SET GLOBAL debug_dbug=@old_dbug; + +--echo *** MDEV-6676 - test disabling domain-based parallel replication *** +--connection server_1 +# Let's do a bunch of transactions that will conflict if run out-of-order in +# domain-based parallel replication mode. +SET gtid_domain_id = 1; +INSERT INTO t2 VALUES (1041); +INSERT INTO t2 VALUES (1042); +INSERT INTO t2 VALUES (1043); +INSERT INTO t2 VALUES (1044); +INSERT INTO t2 VALUES (1045); +INSERT INTO t2 VALUES (1046); +DELETE FROM t2 WHERE a >= 1041; +SET gtid_domain_id = 2; +INSERT INTO t2 VALUES (1041); +INSERT INTO t2 VALUES (1042); +INSERT INTO t2 VALUES (1043); +INSERT INTO t2 VALUES (1044); +INSERT INTO t2 VALUES (1045); +INSERT INTO t2 VALUES (1046); +SET gtid_domain_id = 0; +--source include/save_master_gtid.inc +--connection server_2 +SET GLOBAL slave_parallel_mode=minimal; +--source include/start_slave.inc +--source include/sync_with_master_gtid.inc +SELECT * FROM t2 WHERE a >= 1040 ORDER BY a; + +--echo *** MDEV-7888: ANALYZE TABLE does wakeup_subsequent_commits(), causing wrong binlog order and parallel replication hang *** + +--connection server_2 +--source include/stop_slave.inc +SET GLOBAL slave_parallel_mode='conservative'; +SET GLOBAL slave_parallel_threads=10; + +SET @old_dbug= @@GLOBAL.debug_dbug; +SET GLOBAL debug_dbug= '+d,inject_analyze_table_sleep'; + +--connection server_1 +# Inject two group commits. The bug was that ANALYZE TABLE would call +# wakeup_subsequent_commits() too early, allowing the following transaction +# in the same group to run ahead and binlog and free the GCO. Then we get +# wrong binlog order and later access freed GCO, which causes lost wakeup +# of following GCO and thus replication hang. +# We injected a small sleep in ANALYZE to make the race easier to hit (this +# can only cause false negatives in versions with the bug, not false positives, +# so sleep is ok here. And it's in general not possible to trigger reliably +# the race with debug_sync, since the bugfix makes the race impossible). + +SET @old_dbug_slave= @@SESSION.debug_dbug; +SET SESSION debug_dbug="+d,binlog_force_commit_id"; + +# Group commit with cid=10000, two event groups. +SET @commit_id= 10000; +ANALYZE TABLE t2; +INSERT INTO t3 VALUES (120, 0); + +# Group commit with cid=10001, one event group. +SET @commit_id= 10001; +INSERT INTO t3 VALUES (121, 0); + +SET SESSION debug_dbug=@old_dbug_slave; + +SELECT * FROM t3 WHERE a >= 120 ORDER BY a; +--source include/save_master_gtid.inc + +--connection server_2 +--source include/start_slave.inc +--source include/sync_with_master_gtid.inc + +SELECT * FROM t3 WHERE a >= 120 ORDER BY a; + +--source include/stop_slave.inc +SET GLOBAL debug_dbug= @old_dbug; +--source include/start_slave.inc + + +--echo *** MDEV-7929: record_gtid() for non-transactional event group calls wakeup_subsequent_commits() too early, causing slave hang. *** + +--connection server_2 +--source include/stop_slave.inc +SET @old_dbug= @@GLOBAL.debug_dbug; +SET GLOBAL debug_dbug= '+d,inject_record_gtid_serverid_100_sleep'; + +--connection server_1 +# Inject two group commits. The bug was that record_gtid for a +# non-transactional event group would commit its own transaction, which would +# cause ha_commit_trans() to call wakeup_subsequent_commits() too early. This +# in turn lead to access to freed group_commit_orderer object, losing a wakeup +# and causing slave threads to hang. +# We inject a small sleep in the corresponding record_gtid() to make the race +# easier to hit. + +SET @old_dbug_slave= @@SESSION.debug_dbug; +SET SESSION debug_dbug="+d,binlog_force_commit_id"; + +# Group commit with cid=10010, two event groups. +SET @old_server_id= @@SESSION.server_id; +SET SESSION server_id= 100; +SET @commit_id= 10010; +ALTER TABLE t1 COMMENT "Hulubulu!"; +SET SESSION server_id= @old_server_id; +INSERT INTO t3 VALUES (130, 0); + +# Group commit with cid=10011, one event group. +SET @commit_id= 10011; +INSERT INTO t3 VALUES (131, 0); + +SET SESSION debug_dbug=@old_dbug_slave; +SELECT * FROM t3 WHERE a >= 130 ORDER BY a; +--source include/save_master_gtid.inc + +--connection server_2 +--source include/start_slave.inc +--source include/sync_with_master_gtid.inc + +SELECT * FROM t3 WHERE a >= 130 ORDER BY a; + +--source include/stop_slave.inc +SET GLOBAL debug_dbug= @old_dbug; +--source include/start_slave.inc + + +--echo *** MDEV-8031: Parallel replication stops on "connection killed" error (probably incorrectly handled deadlock kill) *** + +--connection server_1 +INSERT INTO t3 VALUES (201,0), (202,0); +--source include/save_master_gtid.inc + +--connection server_2 +--source include/sync_with_master_gtid.inc +--source include/stop_slave.inc +SET @old_dbug= @@GLOBAL.debug_dbug; +SET GLOBAL debug_dbug= '+d,inject_mdev8031'; + +--connection server_1 +# We artificially create a situation that hopefully resembles the original +# bug which was only seen "in the wild", and only once. +# Setup a fake group commit with lots of conflicts that will lead to deadloc +# kill. The slave DBUG injection causes the slave to be deadlock killed at +# a particular point during the retry, and then later do a small sleep at +# another critical point where the prior transaction then has a chance to +# complete. Finally an extra KILL check catches an unhandled, lingering +# deadlock kill. So rather artificial, but at least it exercises the +# relevant code paths. +SET @old_dbug_slave= @@SESSION.debug_dbug; +SET SESSION debug_dbug="+d,binlog_force_commit_id"; + +SET @commit_id= 10200; +INSERT INTO t3 VALUES (203, 1); +INSERT INTO t3 VALUES (204, 1); +INSERT INTO t3 VALUES (205, 1); +UPDATE t3 SET b=b+1 WHERE a=201; +UPDATE t3 SET b=b+1 WHERE a=201; +UPDATE t3 SET b=b+1 WHERE a=201; +UPDATE t3 SET b=b+1 WHERE a=202; +UPDATE t3 SET b=b+1 WHERE a=202; +UPDATE t3 SET b=b+1 WHERE a=202; +UPDATE t3 SET b=b+1 WHERE a=202; +UPDATE t3 SET b=b+1 WHERE a=203; +UPDATE t3 SET b=b+1 WHERE a=203; +UPDATE t3 SET b=b+1 WHERE a=204; +UPDATE t3 SET b=b+1 WHERE a=204; +UPDATE t3 SET b=b+1 WHERE a=204; +UPDATE t3 SET b=b+1 WHERE a=203; +UPDATE t3 SET b=b+1 WHERE a=205; +UPDATE t3 SET b=b+1 WHERE a=205; +SET SESSION debug_dbug=@old_dbug_slave; + +SELECT * FROM t3 WHERE a>=200 ORDER BY a; +--source include/save_master_gtid.inc + +--connection server_2 +--source include/start_slave.inc +--source include/sync_with_master_gtid.inc + +SELECT * FROM t3 WHERE a>=200 ORDER BY a; +--source include/stop_slave.inc +SET GLOBAL debug_dbug= @old_dbug; +--source include/start_slave.inc + + +--echo *** Check getting deadlock killed inside open_binlog() during retry. *** + +--connection server_2 +--source include/stop_slave.inc +SET @old_dbug= @@GLOBAL.debug_dbug; +SET GLOBAL debug_dbug= '+d,inject_retry_event_group_open_binlog_kill'; +SET @old_max= @@GLOBAL.max_relay_log_size; +SET GLOBAL max_relay_log_size= 4096; + +--connection server_1 +SET @old_dbug_slave= @@SESSION.debug_dbug; +SET SESSION debug_dbug="+d,binlog_force_commit_id"; + +--let $large= `SELECT REPEAT("*", 8192)` +SET @commit_id= 10210; +--echo Omit long queries that cause relaylog rotations and transaction retries... +--disable_query_log +eval UPDATE t3 SET b=b+1 WHERE a=201 /* $large */; +eval UPDATE t3 SET b=b+1 WHERE a=201 /* $large */; +eval UPDATE t3 SET b=b+1 WHERE a=201 /* $large */; +eval UPDATE t3 SET b=b+1 WHERE a=202 /* $large */; +eval UPDATE t3 SET b=b+1 WHERE a=202 /* $large */; +eval UPDATE t3 SET b=b+1 WHERE a=202 /* $large */; +eval UPDATE t3 SET b=b+1 WHERE a=202 /* $large */; +eval UPDATE t3 SET b=b+1 WHERE a=203 /* $large */; +eval UPDATE t3 SET b=b+1 WHERE a=203 /* $large */; +eval UPDATE t3 SET b=b+1 WHERE a=204 /* $large */; +eval UPDATE t3 SET b=b+1 WHERE a=204 /* $large */; +eval UPDATE t3 SET b=b+1 WHERE a=204 /* $large */; +eval UPDATE t3 SET b=b+1 WHERE a=203 /* $large */; +eval UPDATE t3 SET b=b+1 WHERE a=205 /* $large */; +eval UPDATE t3 SET b=b+1 WHERE a=205 /* $large */; +--enable_query_log +SET SESSION debug_dbug=@old_dbug_slave; + +SELECT * FROM t3 WHERE a>=200 ORDER BY a; +--source include/save_master_gtid.inc + +--connection server_2 +--source include/start_slave.inc +--source include/sync_with_master_gtid.inc + +SELECT * FROM t3 WHERE a>=200 ORDER BY a; +--source include/stop_slave.inc +SET GLOBAL debug_dbug= @old_dbug; +SET GLOBAL max_relay_log_size= @old_max; +--source include/start_slave.inc + +--echo *** MDEV-8725: Assertion on ROLLBACK statement in the binary log *** +--connection server_1 +# Inject an event group terminated by ROLLBACK, by mixing MyISAM and InnoDB +# in a transaction. The bug was an assertion on the ROLLBACK due to +# mark_start_commit() being already called. +--disable_warnings +BEGIN; +INSERT INTO t2 VALUES (2000); +INSERT INTO t1 VALUES (2000); +INSERT INTO t2 VALUES (2001); +ROLLBACK; +--enable_warnings +SELECT * FROM t1 WHERE a>=2000 ORDER BY a; +SELECT * FROM t2 WHERE a>=2000 ORDER BY a; +--source include/save_master_gtid.inc + +--connection server_2 +--source include/sync_with_master_gtid.inc +SELECT * FROM t1 WHERE a>=2000 ORDER BY a; +SELECT * FROM t2 WHERE a>=2000 ORDER BY a; + + +# Clean up. +--connection server_2 +--source include/stop_slave.inc +SET GLOBAL slave_parallel_threads=@old_parallel_threads; +--source include/start_slave.inc +SET DEBUG_SYNC= 'RESET'; + +--connection server_1 +DROP function foo; +DROP TABLE t1,t2,t3,t4,t5,t6; +SET DEBUG_SYNC= 'RESET'; + +--source include/rpl_end.inc From 91e5e47a50134a7375d832d75a1d3febfcfc9671 Mon Sep 17 00:00:00 2001 From: Aleksey Midenkov Date: Thu, 23 Mar 2023 21:07:32 +0300 Subject: [PATCH 55/92] MDEV-30421 more tests cleaned up All the .inc files that included from binlog_encryption are refactored. --- .../binlog_encryption/rpl_binlog_errors.test | 2 +- .../rpl_cant_read_event_incident.test | 2 +- .../suite/binlog_encryption/rpl_checksum.test | 2 +- .../binlog_encryption/rpl_checksum_cache.test | 2 +- .../binlog_encryption/rpl_corruption.test | 2 +- .../binlog_encryption/rpl_gtid_basic.result | 24 + .../binlog_encryption/rpl_gtid_basic.test | 2 +- .../suite/binlog_encryption/rpl_incident.test | 2 +- .../rpl_init_slave_errors.test | 2 +- .../binlog_encryption/rpl_loaddata_local.test | 2 +- .../suite/binlog_encryption/rpl_loadfile.test | 2 +- .../suite/binlog_encryption/rpl_packet.test | 2 +- .../rpl_parallel_ignored_errors.test | 2 +- ...arallel_show_binlog_events_purge_logs.test | 2 +- .../binlog_encryption/rpl_relayrotate.test | 2 +- .../binlog_encryption/rpl_semi_sync.test | 2 +- .../rpl_skip_replication.test | 2 +- .../rpl_special_charset.test | 2 +- .../rpl_sporadic_master.test | 2 +- .../suite/binlog_encryption/rpl_ssl.test | 2 +- .../rpl_stm_relay_ign_space.test | 2 +- .../rpl_switch_stm_row_mixed.test | 2 +- .../suite/binlog_encryption/rpl_sync.test | 2 +- ...pl_temporal_format_default_to_default.test | 2 +- ..._temporal_format_mariadb53_to_mysql56.test | 2 +- ..._temporal_format_mysql56_to_mariadb53.test | 2 +- .../suite/binlog_encryption/rpl_typeconv.test | 2 +- .../funcs/t/rpl_switch_stm_row_mixed.test | 2 +- .../suite/rpl/include/rpl_binlog_errors.inc | 438 ------------ .../include/rpl_cant_read_event_incident.inc | 83 --- mysql-test/suite/rpl/include/rpl_checksum.inc | 335 --------- .../suite/rpl/include/rpl_checksum_cache.inc | 261 ------- .../suite/rpl/include/rpl_corruption.inc | 175 ----- .../suite/rpl/include/rpl_gtid_basic.inc | 572 ---------------- mysql-test/suite/rpl/include/rpl_incident.inc | 61 -- .../rpl/include/rpl_init_slave_errors.inc | 96 --- mysql-test/suite/rpl/include/rpl_loadfile.inc | 120 ---- mysql-test/suite/rpl/include/rpl_packet.inc | 184 ----- .../include/rpl_parallel_ignored_errors.inc | 112 ---- ...parallel_show_binlog_events_purge_logs.inc | 38 -- .../suite/rpl/include/rpl_relayrotate.inc | 18 - .../suite/rpl/include/rpl_semi_sync.inc | 525 --------------- .../rpl/include/rpl_skip_replication.inc | 402 ----------- .../suite/rpl/include/rpl_special_charset.inc | 32 - .../suite/rpl/include/rpl_sporadic_master.inc | 32 - mysql-test/suite/rpl/include/rpl_ssl.inc | 116 ---- .../rpl/include/rpl_stm_relay_ign_space.inc | 107 --- .../rpl/include/rpl_switch_stm_row_mixed.inc | 633 ----------------- .../suite/rpl/include/rpl_sync_test.inc | 159 ----- ...rpl_temporal_format_default_to_default.inc | 82 --- mysql-test/suite/rpl/include/rpl_typeconv.inc | 78 --- mysql-test/suite/rpl/t/rpl_binlog_errors.test | 439 +++++++++++- .../rpl/t/rpl_cant_read_event_incident.test | 84 ++- mysql-test/suite/rpl/t/rpl_checksum.test | 336 +++++++++- .../suite/rpl/t/rpl_checksum_cache.test | 262 +++++++- mysql-test/suite/rpl/t/rpl_corruption.test | 176 ++++- mysql-test/suite/rpl/t/rpl_gtid_basic.test | 573 +++++++++++++++- mysql-test/suite/rpl/t/rpl_incident.test | 62 +- .../suite/rpl/t/rpl_init_slave_errors.test | 97 ++- .../rpl_loaddata_local.test} | 0 mysql-test/suite/rpl/t/rpl_loaddatalocal.test | 1 - mysql-test/suite/rpl/t/rpl_loadfile.test | 121 +++- mysql-test/suite/rpl/t/rpl_packet.test | 185 ++++- .../rpl/t/rpl_parallel_ignored_errors.test | 113 +++- ...arallel_show_binlog_events_purge_logs.test | 39 +- mysql-test/suite/rpl/t/rpl_relayrotate.test | 19 +- mysql-test/suite/rpl/t/rpl_semi_sync.test | 526 ++++++++++++++- .../suite/rpl/t/rpl_skip_replication.test | 403 ++++++++++- .../suite/rpl/t/rpl_special_charset.test | 33 +- .../suite/rpl/t/rpl_sporadic_master.test | 33 +- mysql-test/suite/rpl/t/rpl_ssl.test | 117 +++- .../suite/rpl/t/rpl_stm_relay_ign_space.test | 108 ++- .../suite/rpl/t/rpl_switch_stm_row_mixed.test | 634 +++++++++++++++++- mysql-test/suite/rpl/t/rpl_sync.test | 159 ++++- ...pl_temporal_format_default_to_default.test | 83 ++- mysql-test/suite/rpl/t/rpl_typeconv.test | 79 ++- 76 files changed, 4709 insertions(+), 4710 deletions(-) delete mode 100644 mysql-test/suite/rpl/include/rpl_binlog_errors.inc delete mode 100644 mysql-test/suite/rpl/include/rpl_cant_read_event_incident.inc delete mode 100644 mysql-test/suite/rpl/include/rpl_checksum.inc delete mode 100644 mysql-test/suite/rpl/include/rpl_checksum_cache.inc delete mode 100644 mysql-test/suite/rpl/include/rpl_corruption.inc delete mode 100644 mysql-test/suite/rpl/include/rpl_gtid_basic.inc delete mode 100644 mysql-test/suite/rpl/include/rpl_incident.inc delete mode 100644 mysql-test/suite/rpl/include/rpl_init_slave_errors.inc delete mode 100644 mysql-test/suite/rpl/include/rpl_loadfile.inc delete mode 100644 mysql-test/suite/rpl/include/rpl_packet.inc delete mode 100644 mysql-test/suite/rpl/include/rpl_parallel_ignored_errors.inc delete mode 100644 mysql-test/suite/rpl/include/rpl_parallel_show_binlog_events_purge_logs.inc delete mode 100644 mysql-test/suite/rpl/include/rpl_relayrotate.inc delete mode 100644 mysql-test/suite/rpl/include/rpl_semi_sync.inc delete mode 100644 mysql-test/suite/rpl/include/rpl_skip_replication.inc delete mode 100644 mysql-test/suite/rpl/include/rpl_special_charset.inc delete mode 100644 mysql-test/suite/rpl/include/rpl_sporadic_master.inc delete mode 100644 mysql-test/suite/rpl/include/rpl_ssl.inc delete mode 100644 mysql-test/suite/rpl/include/rpl_stm_relay_ign_space.inc delete mode 100644 mysql-test/suite/rpl/include/rpl_switch_stm_row_mixed.inc delete mode 100644 mysql-test/suite/rpl/include/rpl_sync_test.inc delete mode 100644 mysql-test/suite/rpl/include/rpl_temporal_format_default_to_default.inc delete mode 100644 mysql-test/suite/rpl/include/rpl_typeconv.inc rename mysql-test/suite/rpl/{include/rpl_loaddata_local.inc => t/rpl_loaddata_local.test} (100%) delete mode 100644 mysql-test/suite/rpl/t/rpl_loaddatalocal.test diff --git a/mysql-test/suite/binlog_encryption/rpl_binlog_errors.test b/mysql-test/suite/binlog_encryption/rpl_binlog_errors.test index c2a7ec9d27aa8..25849c111a72d 100644 --- a/mysql-test/suite/binlog_encryption/rpl_binlog_errors.test +++ b/mysql-test/suite/binlog_encryption/rpl_binlog_errors.test @@ -1,2 +1,2 @@ --let $binlog_limit= 5,1 ---source suite/rpl/include/rpl_binlog_errors.inc +--source suite/rpl/t/rpl_binlog_errors.test diff --git a/mysql-test/suite/binlog_encryption/rpl_cant_read_event_incident.test b/mysql-test/suite/binlog_encryption/rpl_cant_read_event_incident.test index acbe0d59a5ed1..406af58c03b10 100644 --- a/mysql-test/suite/binlog_encryption/rpl_cant_read_event_incident.test +++ b/mysql-test/suite/binlog_encryption/rpl_cant_read_event_incident.test @@ -1 +1 @@ ---source suite/rpl/include/rpl_cant_read_event_incident.inc +--source suite/rpl/t/rpl_cant_read_event_incident.test diff --git a/mysql-test/suite/binlog_encryption/rpl_checksum.test b/mysql-test/suite/binlog_encryption/rpl_checksum.test index ca8cdc06726d5..a2abd019e24f5 100644 --- a/mysql-test/suite/binlog_encryption/rpl_checksum.test +++ b/mysql-test/suite/binlog_encryption/rpl_checksum.test @@ -1 +1 @@ ---source suite/rpl/include/rpl_checksum.inc +--source suite/rpl/t/rpl_checksum.test diff --git a/mysql-test/suite/binlog_encryption/rpl_checksum_cache.test b/mysql-test/suite/binlog_encryption/rpl_checksum_cache.test index 8fa44136fc2f2..56fb2be0ce395 100644 --- a/mysql-test/suite/binlog_encryption/rpl_checksum_cache.test +++ b/mysql-test/suite/binlog_encryption/rpl_checksum_cache.test @@ -1 +1 @@ ---source suite/rpl/include/rpl_checksum_cache.inc +--source suite/rpl/t/rpl_checksum_cache.test diff --git a/mysql-test/suite/binlog_encryption/rpl_corruption.test b/mysql-test/suite/binlog_encryption/rpl_corruption.test index 1abf2c882ec25..f6ba294439878 100644 --- a/mysql-test/suite/binlog_encryption/rpl_corruption.test +++ b/mysql-test/suite/binlog_encryption/rpl_corruption.test @@ -1 +1 @@ ---source suite/rpl/include/rpl_corruption.inc +--source suite/rpl/t/rpl_corruption.test diff --git a/mysql-test/suite/binlog_encryption/rpl_gtid_basic.result b/mysql-test/suite/binlog_encryption/rpl_gtid_basic.result index 4e17669605f59..0e066fc04188c 100644 --- a/mysql-test/suite/binlog_encryption/rpl_gtid_basic.result +++ b/mysql-test/suite/binlog_encryption/rpl_gtid_basic.result @@ -558,3 +558,27 @@ a connection server_1; DROP TABLE t1; include/rpl_end.inc +# +# Start of 10.2 tests +# +# +# MDEV-10134 Add full support for DEFAULT +# +CREATE TABLE t1 (a VARCHAR(100) DEFAULT BINLOG_GTID_POS("master-bin.000001", 600)); +ERROR HY000: Function or expression 'binlog_gtid_pos()' cannot be used in the DEFAULT clause of `a` +# +# End of 10.2 tests +# +# +# Start of 10.3 tests +# +# +# MDEV-13967 Parameter data type control for Item_long_func +# +SELECT MASTER_GTID_WAIT(ROW(1,1),'str'); +ERROR HY000: Illegal parameter data type row for operation 'master_gtid_wait' +SELECT MASTER_GTID_WAIT('str',ROW(1,1)); +ERROR HY000: Illegal parameter data type row for operation 'master_gtid_wait' +# +# End of 10.3 tests +# diff --git a/mysql-test/suite/binlog_encryption/rpl_gtid_basic.test b/mysql-test/suite/binlog_encryption/rpl_gtid_basic.test index b9f5a18a58893..b183c1d4b4ec7 100644 --- a/mysql-test/suite/binlog_encryption/rpl_gtid_basic.test +++ b/mysql-test/suite/binlog_encryption/rpl_gtid_basic.test @@ -1 +1 @@ ---source suite/rpl/include/rpl_gtid_basic.inc +--source suite/rpl/t/rpl_gtid_basic.test diff --git a/mysql-test/suite/binlog_encryption/rpl_incident.test b/mysql-test/suite/binlog_encryption/rpl_incident.test index b6d2a24a71e10..5a707774f3c86 100644 --- a/mysql-test/suite/binlog_encryption/rpl_incident.test +++ b/mysql-test/suite/binlog_encryption/rpl_incident.test @@ -1 +1 @@ ---source suite/rpl/include/rpl_incident.inc +--source suite/rpl/t/rpl_incident.test diff --git a/mysql-test/suite/binlog_encryption/rpl_init_slave_errors.test b/mysql-test/suite/binlog_encryption/rpl_init_slave_errors.test index 872b8cd35981e..532db963e63c1 100644 --- a/mysql-test/suite/binlog_encryption/rpl_init_slave_errors.test +++ b/mysql-test/suite/binlog_encryption/rpl_init_slave_errors.test @@ -1 +1 @@ ---source suite/rpl/include/rpl_init_slave_errors.inc +--source suite/rpl/t/rpl_init_slave_errors.test diff --git a/mysql-test/suite/binlog_encryption/rpl_loaddata_local.test b/mysql-test/suite/binlog_encryption/rpl_loaddata_local.test index 9e0bb9598bf13..35ad09647a6e2 100644 --- a/mysql-test/suite/binlog_encryption/rpl_loaddata_local.test +++ b/mysql-test/suite/binlog_encryption/rpl_loaddata_local.test @@ -1 +1 @@ ---source suite/rpl/include/rpl_loaddata_local.inc +--source suite/rpl/t/rpl_loaddata_local.test diff --git a/mysql-test/suite/binlog_encryption/rpl_loadfile.test b/mysql-test/suite/binlog_encryption/rpl_loadfile.test index 84e6ecd7a0db9..235c4a3d29e86 100644 --- a/mysql-test/suite/binlog_encryption/rpl_loadfile.test +++ b/mysql-test/suite/binlog_encryption/rpl_loadfile.test @@ -1,4 +1,4 @@ ---source suite/rpl/include/rpl_loadfile.inc +--source suite/rpl/t/rpl_loadfile.test --let $datadir= `SELECT @@datadir` diff --git a/mysql-test/suite/binlog_encryption/rpl_packet.test b/mysql-test/suite/binlog_encryption/rpl_packet.test index 43637314236ea..28beae1a91c97 100644 --- a/mysql-test/suite/binlog_encryption/rpl_packet.test +++ b/mysql-test/suite/binlog_encryption/rpl_packet.test @@ -1 +1 @@ ---source suite/rpl/include/rpl_packet.inc +--source suite/rpl/t/rpl_packet.test diff --git a/mysql-test/suite/binlog_encryption/rpl_parallel_ignored_errors.test b/mysql-test/suite/binlog_encryption/rpl_parallel_ignored_errors.test index 8a26778c8f2df..0c3e538693084 100644 --- a/mysql-test/suite/binlog_encryption/rpl_parallel_ignored_errors.test +++ b/mysql-test/suite/binlog_encryption/rpl_parallel_ignored_errors.test @@ -1 +1 @@ ---source suite/rpl/include/rpl_parallel_ignored_errors.inc +--source suite/rpl/t/rpl_parallel_ignored_errors.test diff --git a/mysql-test/suite/binlog_encryption/rpl_parallel_show_binlog_events_purge_logs.test b/mysql-test/suite/binlog_encryption/rpl_parallel_show_binlog_events_purge_logs.test index 7bdfaaf9adb7b..e342e4d61ffae 100644 --- a/mysql-test/suite/binlog_encryption/rpl_parallel_show_binlog_events_purge_logs.test +++ b/mysql-test/suite/binlog_encryption/rpl_parallel_show_binlog_events_purge_logs.test @@ -1 +1 @@ ---source suite/rpl/include/rpl_parallel_show_binlog_events_purge_logs.inc +--source suite/rpl/t/rpl_parallel_show_binlog_events_purge_logs.test diff --git a/mysql-test/suite/binlog_encryption/rpl_relayrotate.test b/mysql-test/suite/binlog_encryption/rpl_relayrotate.test index e52f5159fcc81..a8dabdc3e8dc2 100644 --- a/mysql-test/suite/binlog_encryption/rpl_relayrotate.test +++ b/mysql-test/suite/binlog_encryption/rpl_relayrotate.test @@ -1 +1 @@ ---source suite/rpl/include/rpl_relayrotate.inc +--source suite/rpl/t/rpl_relayrotate.test diff --git a/mysql-test/suite/binlog_encryption/rpl_semi_sync.test b/mysql-test/suite/binlog_encryption/rpl_semi_sync.test index dfc68b699c00c..2e0907cce3039 100644 --- a/mysql-test/suite/binlog_encryption/rpl_semi_sync.test +++ b/mysql-test/suite/binlog_encryption/rpl_semi_sync.test @@ -1 +1 @@ ---source suite/rpl/include/rpl_semi_sync.inc +--source suite/rpl/t/rpl_semi_sync.test diff --git a/mysql-test/suite/binlog_encryption/rpl_skip_replication.test b/mysql-test/suite/binlog_encryption/rpl_skip_replication.test index 40992586c7c64..11c5b33b36290 100644 --- a/mysql-test/suite/binlog_encryption/rpl_skip_replication.test +++ b/mysql-test/suite/binlog_encryption/rpl_skip_replication.test @@ -1,2 +1,2 @@ --let $use_remote_mysqlbinlog= 1 ---source suite/rpl/include/rpl_skip_replication.inc +--source suite/rpl/t/rpl_skip_replication.test diff --git a/mysql-test/suite/binlog_encryption/rpl_special_charset.test b/mysql-test/suite/binlog_encryption/rpl_special_charset.test index eb6972048601d..c74f8915798e1 100644 --- a/mysql-test/suite/binlog_encryption/rpl_special_charset.test +++ b/mysql-test/suite/binlog_encryption/rpl_special_charset.test @@ -1 +1 @@ ---source suite/rpl/include/rpl_special_charset.inc +--source suite/rpl/t/rpl_special_charset.test diff --git a/mysql-test/suite/binlog_encryption/rpl_sporadic_master.test b/mysql-test/suite/binlog_encryption/rpl_sporadic_master.test index 0dab68a4b08b0..1e3992dc5d9e8 100644 --- a/mysql-test/suite/binlog_encryption/rpl_sporadic_master.test +++ b/mysql-test/suite/binlog_encryption/rpl_sporadic_master.test @@ -1 +1 @@ ---source suite/rpl/include/rpl_sporadic_master.inc +--source suite/rpl/t/rpl_sporadic_master.test diff --git a/mysql-test/suite/binlog_encryption/rpl_ssl.test b/mysql-test/suite/binlog_encryption/rpl_ssl.test index 9a4788c1d2d03..fb30d83ab5e24 100644 --- a/mysql-test/suite/binlog_encryption/rpl_ssl.test +++ b/mysql-test/suite/binlog_encryption/rpl_ssl.test @@ -1 +1 @@ ---source suite/rpl/include/rpl_ssl.inc +--source suite/rpl/t/rpl_ssl.test diff --git a/mysql-test/suite/binlog_encryption/rpl_stm_relay_ign_space.test b/mysql-test/suite/binlog_encryption/rpl_stm_relay_ign_space.test index 45d18a2541055..d5a08bde96904 100644 --- a/mysql-test/suite/binlog_encryption/rpl_stm_relay_ign_space.test +++ b/mysql-test/suite/binlog_encryption/rpl_stm_relay_ign_space.test @@ -1 +1 @@ ---source suite/rpl/include/rpl_stm_relay_ign_space.inc +--source suite/rpl/t/rpl_stm_relay_ign_space.test diff --git a/mysql-test/suite/binlog_encryption/rpl_switch_stm_row_mixed.test b/mysql-test/suite/binlog_encryption/rpl_switch_stm_row_mixed.test index 2a16d90f9aded..c65cc202ba24c 100644 --- a/mysql-test/suite/binlog_encryption/rpl_switch_stm_row_mixed.test +++ b/mysql-test/suite/binlog_encryption/rpl_switch_stm_row_mixed.test @@ -1 +1 @@ ---source suite/rpl/include/rpl_switch_stm_row_mixed.inc +--source suite/rpl/t/rpl_switch_stm_row_mixed.test diff --git a/mysql-test/suite/binlog_encryption/rpl_sync.test b/mysql-test/suite/binlog_encryption/rpl_sync.test index 8dbd6ff254b87..1ff7222856560 100644 --- a/mysql-test/suite/binlog_encryption/rpl_sync.test +++ b/mysql-test/suite/binlog_encryption/rpl_sync.test @@ -1 +1 @@ ---source suite/rpl/include/rpl_sync_test.inc +--source suite/rpl/t/rpl_sync.test diff --git a/mysql-test/suite/binlog_encryption/rpl_temporal_format_default_to_default.test b/mysql-test/suite/binlog_encryption/rpl_temporal_format_default_to_default.test index 30f5f247c23f5..5a9a79bad423e 100644 --- a/mysql-test/suite/binlog_encryption/rpl_temporal_format_default_to_default.test +++ b/mysql-test/suite/binlog_encryption/rpl_temporal_format_default_to_default.test @@ -1 +1 @@ ---source suite/rpl/include/rpl_temporal_format_default_to_default.inc +--source suite/rpl/t/rpl_temporal_format_default_to_default.test diff --git a/mysql-test/suite/binlog_encryption/rpl_temporal_format_mariadb53_to_mysql56.test b/mysql-test/suite/binlog_encryption/rpl_temporal_format_mariadb53_to_mysql56.test index 68afb4148ef46..b9576b30f924a 100644 --- a/mysql-test/suite/binlog_encryption/rpl_temporal_format_mariadb53_to_mysql56.test +++ b/mysql-test/suite/binlog_encryption/rpl_temporal_format_mariadb53_to_mysql56.test @@ -3,4 +3,4 @@ --let $force_master_mysql56_temporal_format=false; --let $force_slave_mysql56_temporal_format=true; ---source suite/rpl/include/rpl_temporal_format_default_to_default.inc +--source suite/rpl/t/rpl_temporal_format_default_to_default.test diff --git a/mysql-test/suite/binlog_encryption/rpl_temporal_format_mysql56_to_mariadb53.test b/mysql-test/suite/binlog_encryption/rpl_temporal_format_mysql56_to_mariadb53.test index 96d928fcf086b..7d09942814e30 100644 --- a/mysql-test/suite/binlog_encryption/rpl_temporal_format_mysql56_to_mariadb53.test +++ b/mysql-test/suite/binlog_encryption/rpl_temporal_format_mysql56_to_mariadb53.test @@ -1,4 +1,4 @@ --let $force_master_mysql56_temporal_format=true; --let $force_slave_mysql56_temporal_format=false; ---source suite/rpl/include/rpl_temporal_format_default_to_default.inc +--source suite/rpl/t/rpl_temporal_format_default_to_default.test diff --git a/mysql-test/suite/binlog_encryption/rpl_typeconv.test b/mysql-test/suite/binlog_encryption/rpl_typeconv.test index fe56a14825641..6761cddfb87f8 100644 --- a/mysql-test/suite/binlog_encryption/rpl_typeconv.test +++ b/mysql-test/suite/binlog_encryption/rpl_typeconv.test @@ -1 +1 @@ ---source suite/rpl/include/rpl_typeconv.inc +--source suite/rpl/t/rpl_typeconv.test diff --git a/mysql-test/suite/engines/funcs/t/rpl_switch_stm_row_mixed.test b/mysql-test/suite/engines/funcs/t/rpl_switch_stm_row_mixed.test index 2a16d90f9aded..c65cc202ba24c 100644 --- a/mysql-test/suite/engines/funcs/t/rpl_switch_stm_row_mixed.test +++ b/mysql-test/suite/engines/funcs/t/rpl_switch_stm_row_mixed.test @@ -1 +1 @@ ---source suite/rpl/include/rpl_switch_stm_row_mixed.inc +--source suite/rpl/t/rpl_switch_stm_row_mixed.test diff --git a/mysql-test/suite/rpl/include/rpl_binlog_errors.inc b/mysql-test/suite/rpl/include/rpl_binlog_errors.inc deleted file mode 100644 index bf92736a2afbc..0000000000000 --- a/mysql-test/suite/rpl/include/rpl_binlog_errors.inc +++ /dev/null @@ -1,438 +0,0 @@ -# -# This include file is used by more than one test suite -# (currently rpl and binlog_encryption). -# Please check all dependent tests after modifying it -# -# Usage: -# --let $binlog_limit= X[,Y] # optional -# -# Semantics of the value is the same as in include/show_binlog_events.inc -# which the script calls as a part of the test flow. -# The goal is to print the event demonstrating the triggered error, -# so normally Y should be 1 (print the exact event only); -# however, depending on test-specific server options, the offset X -# can be different. -# - -# BUG#46166: MYSQL_BIN_LOG::new_file_impl is not propagating error -# when generating new name. -# -# WHY -# === -# -# We want to check whether error is reported or not when -# new_file_impl fails (this may happen when rotation is not -# possible because there is some problem finding an -# unique filename). -# -# HOW -# === -# -# Test cases are documented inline. - --- source include/have_innodb.inc --- source include/have_debug.inc --- source include/master-slave.inc - --- echo ####################################################################### --- echo ####################### PART 1: MASTER TESTS ########################## --- echo ####################################################################### - - -### ACTION: stopping slave as it is not needed for the first part of -### the test - --- connection slave --- source include/stop_slave.inc --- connection master - -call mtr.add_suppression("Can't generate a unique log-filename"); -call mtr.add_suppression("Writing one row to the row-based binary log failed.*"); -call mtr.add_suppression("Error writing file .*"); -call mtr.add_suppression("Could not use master-bin for logging"); - -SET @old_debug= @@global.debug_dbug; - -### ACTION: create a large file (> 4096 bytes) that will be later used -### in LOAD DATA INFILE to check binlog errors in its vacinity --- let $load_file= $MYSQLTEST_VARDIR/tmp/bug_46166.data --- let $MYSQLD_DATADIR= `select @@datadir` --- replace_result $MYSQLTEST_VARDIR MYSQLTEST_VARDIR --- eval SELECT repeat('x',8192) INTO OUTFILE '$load_file' - -### ACTION: create a small file (< 4096 bytes) that will be later used -### in LOAD DATA INFILE to check for absence of binlog errors -### when file loading this file does not force flushing and -### rotating the binary log --- let $load_file2= $MYSQLTEST_VARDIR/tmp/bug_46166-2.data --- let $MYSQLD_DATADIR= `select @@datadir` --- replace_result $MYSQLTEST_VARDIR MYSQLTEST_VARDIR --- eval SELECT repeat('x',10) INTO OUTFILE '$load_file2' - -RESET MASTER; - --- echo ###################### TEST #1 - -### ASSERTION: no problem flushing logs (should show two binlogs) -FLUSH LOGS; --- echo # assert: must show two binlogs --- source include/show_binary_logs.inc - --- echo ###################### TEST #2 - -### ASSERTION: check that FLUSH LOGS actually fails and reports -### failure back to the user if find_uniq_filename fails -### (should show just one binlog) - -RESET MASTER; -SET @@global.debug_dbug="d,error_unique_log_filename"; --- error ER_NO_UNIQUE_LOGFILE -FLUSH LOGS; --- echo # assert: must show one binlog --- source include/show_binary_logs.inc - -### ACTION: clean up and move to next test -SET @@global.debug_dbug=@old_debug; -RESET MASTER; - --- echo ###################### TEST #3 - -### ACTION: create some tables (t1, t2, t4) and insert some values in -### table t1 -CREATE TABLE t1 (a INT); -CREATE TABLE t2 (a VARCHAR(16384)) Engine=InnoDB; -CREATE TABLE t4 (a VARCHAR(16384)); -INSERT INTO t1 VALUES (1); -RESET MASTER; - -### ASSERTION: we force rotation of the binary log because it exceeds -### the max_binlog_size option (should show two binary -### logs) - --- replace_result $MYSQLTEST_VARDIR MYSQLTEST_VARDIR --- eval LOAD DATA INFILE '$load_file' INTO TABLE t2 - -# shows two binary logs --- echo # assert: must show two binlog --- source include/show_binary_logs.inc - -# clean up the table and the binlog to be used in next part of test -SET @@global.debug_dbug=@old_debug; -DELETE FROM t2; -RESET MASTER; - --- echo ###################### TEST #4 - -### ASSERTION: load the big file into a transactional table and check -### that it reports error. The table will contain the -### changes performed despite the fact that it reported an -### error. - -SET @@global.debug_dbug="d,error_unique_log_filename"; --- replace_result $MYSQLTEST_VARDIR MYSQLTEST_VARDIR --- error ER_NO_UNIQUE_LOGFILE --- eval LOAD DATA INFILE '$load_file' INTO TABLE t2 - -# show table --- echo # assert: must show one entry -SELECT count(*) FROM t2; - -# clean up the table and the binlog to be used in next part of test -SET @@global.debug_dbug=@old_debug; -DELETE FROM t2; -RESET MASTER; - --- echo ###################### TEST #5 - -### ASSERTION: load the small file into a transactional table and -### check that it succeeds - -SET @@global.debug_dbug="d,error_unique_log_filename"; --- replace_result $MYSQLTEST_VARDIR MYSQLTEST_VARDIR --- eval LOAD DATA INFILE '$load_file2' INTO TABLE t2 - -# show table --- echo # assert: must show one entry -SELECT count(*) FROM t2; - -# clean up the table and the binlog to be used in next part of test -SET @@global.debug_dbug=@old_debug; -DELETE FROM t2; -RESET MASTER; - --- echo ###################### TEST #6 - -### ASSERTION: check that even if one is using a transactional table -### and explicit transactions (no autocommit) if rotation -### fails we get the error. Transaction is not rolledback -### because rotation happens after the commit. - -SET @@global.debug_dbug="d,error_unique_log_filename"; -SET AUTOCOMMIT=0; -INSERT INTO t2 VALUES ('muse'); --- replace_result $MYSQLTEST_VARDIR MYSQLTEST_VARDIR --- eval LOAD DATA INFILE '$load_file' INTO TABLE t2 -INSERT INTO t2 VALUES ('muse'); --- error ER_NO_UNIQUE_LOGFILE -COMMIT; - -### ACTION: Show the contents of the table after the test --- echo # assert: must show three entries -SELECT count(*) FROM t2; - -### ACTION: clean up and move to the next test -SET AUTOCOMMIT= 1; -SET @@global.debug_dbug=@old_debug; -DELETE FROM t2; -RESET MASTER; - --- echo ###################### TEST #7 - -### ASSERTION: check that on a non-transactional table, if rotation -### fails then an error is reported and an incident event -### is written to the current binary log. - -SET @@global.debug_dbug="d,error_unique_log_filename"; - -# Disable logging Annotate_rows events to preserve events count. -let $binlog_annotate_row_events_saved= `SELECT @@binlog_annotate_row_events`; -SET @@binlog_annotate_row_events= 0; - -SELECT count(*) FROM t4; --- replace_result $MYSQLTEST_VARDIR MYSQLTEST_VARDIR --- error ER_NO_UNIQUE_LOGFILE --- eval LOAD DATA INFILE '$load_file' INTO TABLE t4 - --- echo # assert: must show 1 entry -SELECT count(*) FROM t4; - --- echo ### check that the incident event is written to the current log -SET @@global.debug_dbug=@old_debug; -if (!$binlog_limit) -{ - -- let $binlog_limit= 4,1 -} --- source include/show_binlog_events.inc - -# clean up and move to next test -DELETE FROM t4; - ---disable_query_log -eval SET @@binlog_annotate_row_events= $binlog_annotate_row_events_saved; ---enable_query_log - -RESET MASTER; - --- echo ###################### TEST #8 - -### ASSERTION: check that statements end up in error but they succeed -### on changing the data. - -SET @@global.debug_dbug="d,error_unique_log_filename"; --- echo # must show 0 entries -SELECT count(*) FROM t4; -SELECT count(*) FROM t2; - --- replace_result $MYSQLTEST_VARDIR MYSQLTEST_VARDIR --- error ER_NO_UNIQUE_LOGFILE --- eval LOAD DATA INFILE '$load_file' INTO TABLE t4 --- replace_result $MYSQLTEST_VARDIR MYSQLTEST_VARDIR --- error ER_NO_UNIQUE_LOGFILE --- eval LOAD DATA INFILE '$load_file' INTO TABLE t2 --- error ER_NO_UNIQUE_LOGFILE -INSERT INTO t2 VALUES ('aaa'), ('bbb'), ('ccc'); - --- echo # INFO: Count(*) Before Offending DELETEs --- echo # assert: must show 1 entry -SELECT count(*) FROM t4; --- echo # assert: must show 4 entries -SELECT count(*) FROM t2; - --- error ER_NO_UNIQUE_LOGFILE -DELETE FROM t4; --- error ER_NO_UNIQUE_LOGFILE -DELETE FROM t2; - --- echo # INFO: Count(*) After Offending DELETEs --- echo # assert: must show zero entries -SELECT count(*) FROM t4; -SELECT count(*) FROM t2; - -# remove fault injection -SET @@global.debug_dbug=@old_debug; - --- echo ###################### TEST #9 - -### ASSERTION: check that if we disable binlogging, then statements -### succeed. -SET @@global.debug_dbug="d,error_unique_log_filename"; -SET SQL_LOG_BIN=0; -INSERT INTO t2 VALUES ('aaa'), ('bbb'), ('ccc'), ('ddd'); -INSERT INTO t4 VALUES ('eee'), ('fff'), ('ggg'), ('hhh'); --- echo # assert: must show four entries -SELECT count(*) FROM t2; -SELECT count(*) FROM t4; -DELETE FROM t2; -DELETE FROM t4; --- echo # assert: must show zero entries -SELECT count(*) FROM t2; -SELECT count(*) FROM t4; -SET SQL_LOG_BIN=1; -SET @@global.debug_dbug=@old_debug; - --- echo ###################### TEST #10 - -### ASSERTION: check that error is reported if there is a failure -### while registering the index file and the binary log -### file or failure to write the rotate event. - -call mtr.add_suppression("MYSQL_BIN_LOG::open failed to sync the index file."); -call mtr.add_suppression("Could not use .*"); - -RESET MASTER; -SHOW WARNINGS; - -# +d,fault_injection_registering_index => injects fault on MYSQL_BIN_LOG::open -SET @@global.debug_dbug="d,fault_injection_registering_index"; --- replace_regex /\.[\\\/]master/master/ --- error ER_CANT_OPEN_FILE -FLUSH LOGS; -SET @@global.debug_dbug=@old_debug; - --- error ER_NO_BINARY_LOGGING -SHOW BINARY LOGS; - -# issue some statements and check that they don't fail -CREATE TABLE t5 (a INT); -INSERT INTO t4 VALUES ('bbbbb'); -INSERT INTO t2 VALUES ('aaaaa'); -DELETE FROM t4; -DELETE FROM t2; -DROP TABLE t5; -flush tables; - --- echo ###################### TEST #11 - -### ASSERTION: check that error is reported if there is a failure -### while opening the index file and the binary log file or -### failure to write the rotate event. - -# restart the server so that we have binlog again ---let $rpl_server_number= 1 ---source include/rpl_restart_server.inc - -# +d,fault_injection_openning_index => injects fault on MYSQL_BIN_LOG::open_index_file -SET @@global.debug_dbug="d,fault_injection_openning_index"; --- replace_regex /\.[\\\/]master/master/ --- error ER_CANT_OPEN_FILE -FLUSH LOGS; -SET @@global.debug_dbug=@old_debug; - --- error ER_FLUSH_MASTER_BINLOG_CLOSED -RESET MASTER; - -# issue some statements and check that they don't fail -CREATE TABLE t5 (a INT); -INSERT INTO t4 VALUES ('bbbbb'); -INSERT INTO t2 VALUES ('aaaaa'); -DELETE FROM t4; -DELETE FROM t2; -DROP TABLE t5; -flush tables; - -# restart the server so that we have binlog again ---let $rpl_server_number= 1 ---source include/rpl_restart_server.inc - --- echo ###################### TEST #12 - -### ASSERTION: check that error is reported if there is a failure -### while writing the rotate event when creating a new log -### file. - -# +d,fault_injection_new_file_rotate_event => injects fault on MYSQL_BIN_LOG::MYSQL_BIN_LOG::new_file_impl -SET @@global.debug_dbug="d,fault_injection_new_file_rotate_event"; --- error ER_ERROR_ON_WRITE -FLUSH LOGS; -SET @@global.debug_dbug=@old_debug; - --- error ER_FLUSH_MASTER_BINLOG_CLOSED -RESET MASTER; - -# issue some statements and check that they don't fail -CREATE TABLE t5 (a INT); -INSERT INTO t4 VALUES ('bbbbb'); -INSERT INTO t2 VALUES ('aaaaa'); -DELETE FROM t4; -DELETE FROM t2; -DROP TABLE t5; -flush tables; - -# restart the server so that we have binlog again ---let $rpl_server_number= 1 ---source include/rpl_restart_server.inc - -## clean up -DROP TABLE t1, t2, t4; -RESET MASTER; - -# restart slave again --- connection slave --- source include/start_slave.inc --- connection master - --- echo ####################################################################### --- echo ####################### PART 2: SLAVE TESTS ########################### --- echo ####################################################################### - -### setup ---source include/rpl_reset.inc --- connection slave - -# slave suppressions - -call mtr.add_suppression("Slave I/O: Relay log write failure: could not queue event from master.*"); -call mtr.add_suppression("Error writing file .*"); -call mtr.add_suppression("Could not use .*"); -call mtr.add_suppression("MYSQL_BIN_LOG::open failed to sync the index file."); -call mtr.add_suppression("Can't generate a unique log-filename .*"); --- echo ###################### TEST #13 - -#### ASSERTION: check against unique log filename error --- let $io_thd_injection_fault_flag= error_unique_log_filename --- let $slave_io_errno= 1595 --- let $show_slave_io_error= 1 --- source include/io_thd_fault_injection.inc - --- echo ###################### TEST #14 - -#### ASSERTION: check against rotate failing --- let $io_thd_injection_fault_flag= fault_injection_new_file_rotate_event --- let $slave_io_errno= 1595 --- let $show_slave_io_error= 1 --- source include/io_thd_fault_injection.inc - --- echo ###################### TEST #15 - -#### ASSERTION: check against relay log open failure --- let $io_thd_injection_fault_flag= fault_injection_registering_index --- let $slave_io_errno= 1595 --- let $show_slave_io_error= 1 --- source include/io_thd_fault_injection.inc - --- echo ###################### TEST #16 - -#### ASSERTION: check against relay log index open failure --- let $io_thd_injection_fault_flag= fault_injection_openning_index --- let $slave_io_errno= 1595 --- let $show_slave_io_error= 1 --- source include/io_thd_fault_injection.inc - -### clean up --- source include/stop_slave_sql.inc -RESET SLAVE; -RESET MASTER; ---remove_file $load_file ---remove_file $load_file2 ---let $rpl_only_running_threads= 1 ---source include/rpl_end.inc diff --git a/mysql-test/suite/rpl/include/rpl_cant_read_event_incident.inc b/mysql-test/suite/rpl/include/rpl_cant_read_event_incident.inc deleted file mode 100644 index 7dfef023947a9..0000000000000 --- a/mysql-test/suite/rpl/include/rpl_cant_read_event_incident.inc +++ /dev/null @@ -1,83 +0,0 @@ -# -# This include file is used by more than one test suite -# (currently rpl and binlog_encryption). -# Please check all dependent tests after modifying it -# - -# -# Bug#11747416 : 32228 A disk full makes binary log corrupt. -# -# -# The test demonstrates reading from binlog error propagation to slave -# and reporting there. -# Conditions for the bug include a crash at time of the last event to -# the binlog was written partly. With the fixes the event is not sent out -# any longer, but rather the dump thread sends out a sound error message. -# -# Crash is not simulated. A binlog with partly written event in its end is installed -# and replication is started from it. -# - ---source include/have_binlog_format_mixed.inc ---source include/master-slave.inc - ---connection slave -# Make sure the slave is stopped while we are messing with master. -# Otherwise we get occasional failures as the slave manages to re-connect -# to the newly started master and we get extra events applied, causing -# conflicts. ---source include/stop_slave.inc - ---connection master -call mtr.add_suppression("Error in Log_event::read_log_event()"); ---let $datadir= `SELECT @@datadir` - ---let $rpl_server_number= 1 ---source include/rpl_stop_server.inc - ---remove_file $datadir/master-bin.000001 ---copy_file $MYSQL_TEST_DIR/std_data/bug11747416_32228_binlog.000001 $datadir/master-bin.000001 - ---let $rpl_server_number= 1 ---source include/rpl_start_server.inc - ---source include/wait_until_connected_again.inc - -# evidence of the partial binlog ---error ER_ERROR_WHEN_EXECUTING_COMMAND -show binlog events; - ---connection slave -call mtr.add_suppression("Slave I/O: Got fatal error 1236 from master when reading data from binary log"); -reset slave; -start slave; - -# ER_MASTER_FATAL_ERROR_READING_BINLOG 1236 ---let $slave_param=Last_IO_Errno ---let $slave_param_value=1236 ---source include/wait_for_slave_param.inc - ---let $slave_field_result_replace= / at [0-9]*/ at XXX/ ---let $status_items= Last_IO_Errno, Last_IO_Error ---source include/show_slave_status.inc - -# -# Cleanup -# - ---connection master -reset master; - ---connection slave -stop slave; -reset slave; -# Table was created from binlog, it may not be created if SQL thread is running -# slowly and IO thread reaches incident before SQL thread applies it. ---disable_warnings -drop table if exists t; ---enable_warnings -reset master; - ---echo End of the tests ---let $rpl_only_running_threads= 1 ---source include/rpl_end.inc diff --git a/mysql-test/suite/rpl/include/rpl_checksum.inc b/mysql-test/suite/rpl/include/rpl_checksum.inc deleted file mode 100644 index 17a986dc30801..0000000000000 --- a/mysql-test/suite/rpl/include/rpl_checksum.inc +++ /dev/null @@ -1,335 +0,0 @@ -# -# This include file is used by more than one test suite -# (currently rpl and binlog_encryption). -# Please check all dependent tests after modifying it -# - -# WL2540 replication events checksum -# Testing configuration parameters - ---source include/have_debug.inc ---source include/have_binlog_format_mixed.inc ---source include/master-slave.inc - -call mtr.add_suppression('Slave can not handle replication events with the checksum that master is configured to log'); -call mtr.add_suppression('Replication event checksum verification failed'); -# due to C failure simulation -call mtr.add_suppression('Relay log write failure: could not queue event from master'); -call mtr.add_suppression('Master is configured to log replication events with checksum, but will not send such events to slaves that cannot process them'); - -# A. read/write access to the global vars: -# binlog_checksum master_verify_checksum slave_sql_verify_checksum - -connection master; - -set @master_save_binlog_checksum= @@global.binlog_checksum; -set @save_master_verify_checksum = @@global.master_verify_checksum; - -select @@global.binlog_checksum as 'must be CRC32 because of the command line option'; ---error ER_INCORRECT_GLOBAL_LOCAL_VAR -select @@session.binlog_checksum as 'no session var'; - -select @@global.master_verify_checksum as 'must be zero because of default'; ---error ER_INCORRECT_GLOBAL_LOCAL_VAR -select @@session.master_verify_checksum as 'no session var'; - -connection slave; - -set @slave_save_binlog_checksum= @@global.binlog_checksum; -set @save_slave_sql_verify_checksum = @@global.slave_sql_verify_checksum; - -select @@global.slave_sql_verify_checksum as 'must be one because of default'; ---error ER_INCORRECT_GLOBAL_LOCAL_VAR -select @@session.slave_sql_verify_checksum as 'no session var'; - -connection master; - -source include/show_binary_logs.inc; -set @@global.binlog_checksum = NONE; -select @@global.binlog_checksum; ---echo *** must be rotations seen *** -source include/show_binary_logs.inc; - -set @@global.binlog_checksum = default; -select @@global.binlog_checksum; - -# testing lack of side-effects in non-effective update of binlog_checksum: -set @@global.binlog_checksum = CRC32; -select @@global.binlog_checksum; -set @@global.binlog_checksum = CRC32; - -set @@global.master_verify_checksum = 0; -set @@global.master_verify_checksum = default; - ---error ER_WRONG_VALUE_FOR_VAR -set @@global.binlog_checksum = ADLER32; ---error ER_WRONG_VALUE_FOR_VAR -set @@global.master_verify_checksum = 2; # the var is of bool type - -connection slave; - -set @@global.slave_sql_verify_checksum = 0; -set @@global.slave_sql_verify_checksum = default; ---error ER_WRONG_VALUE_FOR_VAR -set @@global.slave_sql_verify_checksum = 2; # the var is of bool type - -# -# B. Old Slave to New master conditions -# -# while master does not send a checksum-ed binlog the Old Slave can -# work with the New Master - -connection master; - -set @@global.binlog_checksum = NONE; -create table t1 (a int); - -# testing that binlog rotation preserves opt_binlog_checksum value -flush logs; -flush logs; --- source include/wait_for_binlog_checkpoint.inc -flush logs; - -sync_slave_with_master; -#connection slave; -# checking that rotation on the slave side leaves slave stable -flush logs; -flush logs; -flush logs; -select count(*) as zero from t1; - -source include/stop_slave.inc; - -connection master; -set @@global.binlog_checksum = CRC32; --- source include/wait_for_binlog_checkpoint.inc -insert into t1 values (1) /* will not be applied on slave due to simulation */; - -# instruction to the dump thread - -connection slave; -set @saved_dbug = @@global.debug_dbug; -set @@global.debug_dbug='d,simulate_slave_unaware_checksum'; -start slave; ---let $slave_io_errno= 1236 ---let $show_slave_io_error= 1 -source include/wait_for_slave_io_error.inc; - -select count(*) as zero from t1; - -set @@global.debug_dbug = @saved_dbug; - -connection slave; -source include/start_slave.inc; - -# -# C. checksum failure simulations -# - -# C1. Failure by a client thread -connection master; -set @@global.master_verify_checksum = 1; -set @save_dbug = @@session.debug_dbug; -set @@session.debug_dbug='d,simulate_checksum_test_failure'; ---error ER_ERROR_WHEN_EXECUTING_COMMAND -show binlog events; -SET debug_dbug= @save_dbug; -set @@global.master_verify_checksum = default; - -#connection master; -sync_slave_with_master; - -connection slave; -source include/stop_slave.inc; - -connection master; -create table t2 (a int); -let $pos_master= query_get_value(SHOW MASTER STATUS, Position, 1); - -connection slave; - -# C2. Failure by IO thread -# instruction to io thread -set @saved_dbug = @@global.debug_dbug; -set @@global.debug_dbug='d,simulate_checksum_test_failure'; -start slave io_thread; -# When the checksum error is detected, the slave sets error code 1913 -# (ER_NETWORK_READ_EVENT_CHECKSUM_FAILURE) in queue_event(), then immediately -# sets error 1595 (ER_SLAVE_RELAY_LOG_WRITE_FAILURE) in handle_slave_io(). -# So we usually get 1595, but it is occasionally possible to get 1913. ---let $slave_io_errno= 1595,1913 ---let $show_slave_io_error= 0 -source include/wait_for_slave_io_error.inc; -set @@global.debug_dbug = @saved_dbug; - -# to make IO thread re-read it again w/o the failure -start slave io_thread; -let $slave_param= Read_Master_Log_Pos; -let $slave_param_value= $pos_master; -source include/wait_for_slave_param.inc; - -# C3. Failure by SQL thread -# instruction to sql thread; -set @@global.slave_sql_verify_checksum = 1; - -set @@global.debug_dbug='d,simulate_checksum_test_failure'; - -start slave sql_thread; ---let $slave_sql_errno= 1593 ---let $show_slave_sql_error= 1 -source include/wait_for_slave_sql_error.inc; - -# resuming SQL thread to parse out the event w/o the failure - -set @@global.debug_dbug = @saved_dbug; -source include/start_slave.inc; - -connection master; -sync_slave_with_master; - -#connection slave; -select count(*) as 'must be zero' from t2; - -# -# D. Reset slave, Change-Master, Binlog & Relay-log rotations with -# random value on binlog_checksum on both master and slave -# -connection slave; -stop slave; -reset slave; - -# randomize slave server's own checksum policy -set @@global.binlog_checksum= IF(floor((rand()*1000)%2), "CRC32", "NONE"); -flush logs; - -connection master; -set @@global.binlog_checksum= CRC32; -reset master; -flush logs; -create table t3 (a int, b char(5)); - -connection slave; -source include/start_slave.inc; - -connection master; -sync_slave_with_master; - -#connection slave; -select count(*) as 'must be zero' from t3; -source include/stop_slave.inc; ---replace_result $MASTER_MYPORT MASTER_PORT -eval change master to master_host='127.0.0.1',master_port=$MASTER_MYPORT, master_user='root'; - -connection master; -flush logs; -reset master; -insert into t3 value (1, @@global.binlog_checksum); - -connection slave; -source include/start_slave.inc; -flush logs; - -connection master; -sync_slave_with_master; - -#connection slave; -select count(*) as 'must be one' from t3; - -connection master; -set @@global.binlog_checksum= IF(floor((rand()*1000)%2), "CRC32", "NONE"); -insert into t3 value (1, @@global.binlog_checksum); -sync_slave_with_master; - -#connection slave; - -#clean-up - -connection master; -drop table t1, t2, t3; -set @@global.binlog_checksum = @master_save_binlog_checksum; -set @@global.master_verify_checksum = @save_master_verify_checksum; - -# -# BUG#58564: flush_read_lock fails in mysql-trunk-bugfixing after merging with WL#2540 -# -# Sanity check that verifies that no assertions are triggered because -# of old FD events (generated by versions prior to server released with -# checksums feature) -# -# There is no need for query log, if something wrong this should trigger -# an assertion - ---disable_query_log - -BINLOG ' -MfmqTA8BAAAAZwAAAGsAAAABAAQANS41LjctbTMtZGVidWctbG9nAAAAAAAAAAAAAAAAAAAAAAAA -AAAAAAAAAAAAAAAAAAAx+apMEzgNAAgAEgAEBAQEEgAAVAAEGggAAAAICAgCAA== -'; - ---enable_query_log - -#connection slave; -sync_slave_with_master; - - ---echo *** Bug#59123 / MDEV-5799: INCIDENT_EVENT checksum written to error log as garbage characters *** - ---connection master - ---source include/wait_for_binlog_checkpoint.inc -CREATE TABLE t4 (a INT PRIMARY KEY); -INSERT INTO t4 VALUES (1); - -SET sql_log_bin=0; -CALL mtr.add_suppression("\\[ERROR\\] Can't generate a unique log-filename"); -SET sql_log_bin=1; -SET @old_dbug= @@GLOBAL.debug_dbug; -SET debug_dbug= '+d,binlog_inject_new_name_error'; ---error ER_NO_UNIQUE_LOGFILE -FLUSH LOGS; -SET debug_dbug= @old_dbug; - -INSERT INTO t4 VALUES (2); - ---connection slave ---let $slave_sql_errno= 1590 ---source include/wait_for_slave_sql_error.inc - -# Search the error log for the error message. -# The bug was that 4 garbage bytes were output in the middle of the error -# message; by searching for a pattern that spans that location, we can -# catch the error. -let $log_error_= `SELECT @@GLOBAL.log_error`; -if(!$log_error_) -{ - # MySQL Server on windows is started with --console and thus - # does not know the location of its .err log, use default location - let $log_error_ = $MYSQLTEST_VARDIR/log/mysqld.2.err; -} ---let SEARCH_FILE= $log_error_ ---let SEARCH_PATTERN= Slave SQL: The incident LOST_EVENTS occurred on the master\. Message: error writing to the binary log, Internal MariaDB error code: 1590 ---source include/search_pattern_in_file.inc - -SELECT * FROM t4 ORDER BY a; -STOP SLAVE IO_THREAD; -SET sql_slave_skip_counter= 1; ---source include/start_slave.inc - ---connection master ---save_master_pos - ---connection slave ---sync_with_master -SELECT * FROM t4 ORDER BY a; - - ---connection slave -set @@global.binlog_checksum = @slave_save_binlog_checksum; -set @@global.slave_sql_verify_checksum = @save_slave_sql_verify_checksum; - ---echo End of tests - ---connection master -DROP TABLE t4; - ---source include/rpl_end.inc diff --git a/mysql-test/suite/rpl/include/rpl_checksum_cache.inc b/mysql-test/suite/rpl/include/rpl_checksum_cache.inc deleted file mode 100644 index e04f618b81ea1..0000000000000 --- a/mysql-test/suite/rpl/include/rpl_checksum_cache.inc +++ /dev/null @@ -1,261 +0,0 @@ -# -# This include file is used by more than one test suite -# (currently rpl and binlog_encryption). -# Please check all dependent tests after modifying it -# - --- source include/have_innodb.inc --- source include/master-slave.inc - ---disable_warnings -call mtr.add_suppression("Unsafe statement written to the binary log using statement format since BINLOG_FORMAT = STATEMENT. .*Statement: insert into t2 set data=repeat.*'a', @act_size.*"); -call mtr.add_suppression("Unsafe statement written to the binary log using statement format since BINLOG_FORMAT = STATEMENT. .*Statement: insert into t1 values.* NAME_CONST.*'n',.*, @data .*"); ---enable_warnings - -connection master; -set @save_binlog_cache_size = @@global.binlog_cache_size; -set @save_binlog_checksum = @@global.binlog_checksum; -set @save_master_verify_checksum = @@global.master_verify_checksum; -set @@global.binlog_cache_size = 4096; -set @@global.binlog_checksum = CRC32; -set @@global.master_verify_checksum = 1; - -# restart slave to force the dump thread to verify events (on master side) -connection slave; -source include/stop_slave.inc; -source include/start_slave.inc; - -connection master; - -# -# Testing a critical part of checksum handling dealing with transaction cache. -# The cache's buffer size is set to be less than the transaction's footprint -# in binlog. -# -# To verify combined buffer-by-buffer read out of the file and fixing crc per event -# there are the following parts: -# -# 1. the event size is much less than the cache's buffer -# 2. the event size is bigger than the cache's buffer -# 3. the event size if approximately the same as the cache's buffer -# 4. all in above - -# -# 1. the event size is much less than the cache's buffer -# - -flush status; -show status like "binlog_cache_use"; -show status like "binlog_cache_disk_use"; ---disable_warnings -drop table if exists t1; ---enable_warnings - -# -# parameter to ensure the test slightly varies binlog content -# between different invocations -# -let $deviation_size=32; -eval create table t1 (a int PRIMARY KEY, b CHAR($deviation_size)) engine=innodb; - -# Now we are going to create transaction which is long enough so its -# transaction binlog will be flushed to disk... - -delimiter |; -create procedure test.p_init (n int, size int) -begin - while n > 0 do - select round(RAND() * size) into @act_size; - set @data = repeat('a', @act_size); - insert into t1 values(n, @data ); - set n= n-1; - end while; -end| - -delimiter ;| - -let $1 = 4000; # PB2 can run it slow to time out on following sync_slave_with_master:s - -begin; ---disable_warnings -# todo: check if it is really so. -#+Note 1592 Unsafe statement binlogged in statement format since BINLOG_FORMAT = STATEMENT. Reason for unsafeness: Statement uses a system function whose value may differ on slave. -eval call test.p_init($1, $deviation_size); ---enable_warnings -commit; - -show status like "binlog_cache_use"; ---echo *** binlog_cache_disk_use must be non-zero *** -show status like "binlog_cache_disk_use"; - -sync_slave_with_master; - -let $diff_tables=master:test.t1, slave:test.t1; -source include/diff_tables.inc; - -# undoing changes with verifying the above once again -connection master; - -begin; -delete from t1; -commit; - -sync_slave_with_master; - - -# -# 2. the event size is bigger than the cache's buffer -# -connection master; - -flush status; -let $t2_data_size= `select 3 * @@global.binlog_cache_size`; -let $t2_aver_size= `select 2 * @@global.binlog_cache_size`; -let $t2_max_rand= `select 1 * @@global.binlog_cache_size`; - -eval create table t2(a int auto_increment primary key, data VARCHAR($t2_data_size)) ENGINE=Innodb; -let $1=100; ---disable_query_log -begin; -while ($1) -{ - eval select round($t2_aver_size + RAND() * $t2_max_rand) into @act_size; - set @data = repeat('a', @act_size); - insert into t2 set data = @data; - dec $1; -} -commit; ---enable_query_log -show status like "binlog_cache_use"; ---echo *** binlog_cache_disk_use must be non-zero *** -show status like "binlog_cache_disk_use"; - -sync_slave_with_master; - -let $diff_tables=master:test.t2, slave:test.t2; -source include/diff_tables.inc; - -# undoing changes with verifying the above once again -connection master; - -begin; -delete from t2; -commit; - -sync_slave_with_master; - -# -# 3. the event size if approximately the same as the cache's buffer -# - -connection master; - -flush status; -let $t3_data_size= `select 2 * @@global.binlog_cache_size`; -let $t3_aver_size= `select (9 * @@global.binlog_cache_size) / 10`; -let $t3_max_rand= `select (2 * @@global.binlog_cache_size) / 10`; - -eval create table t3(a int auto_increment primary key, data VARCHAR($t3_data_size)) engine=innodb; - -let $1= 300; ---disable_query_log -begin; -while ($1) -{ - eval select round($t3_aver_size + RAND() * $t3_max_rand) into @act_size; - insert into t3 set data= repeat('a', @act_size); - dec $1; -} -commit; ---enable_query_log -show status like "binlog_cache_use"; ---echo *** binlog_cache_disk_use must be non-zero *** -show status like "binlog_cache_disk_use"; - -sync_slave_with_master; - -let $diff_tables=master:test.t3, slave:test.t3; -source include/diff_tables.inc; - -# undoing changes with verifying the above once again -connection master; - -begin; -delete from t3; -commit; - -sync_slave_with_master; - - -# -# 4. all in above -# - -connection master; -flush status; - -delimiter |; -eval create procedure test.p1 (n int) -begin - while n > 0 do - case (select (round(rand()*100) % 3) + 1) - when 1 then - select round(RAND() * $deviation_size) into @act_size; - set @data = repeat('a', @act_size); - insert into t1 values(n, @data); - when 2 then - begin - select round($t2_aver_size + RAND() * $t2_max_rand) into @act_size; - insert into t2 set data=repeat('a', @act_size); - end; - when 3 then - begin - select round($t3_aver_size + RAND() * $t3_max_rand) into @act_size; - insert into t3 set data= repeat('a', @act_size); - end; - end case; - set n= n-1; - end while; -end| -delimiter ;| - -let $1= 1000; -set autocommit= 0; -begin; ---disable_warnings -eval call test.p1($1); ---enable_warnings -commit; - -show status like "binlog_cache_use"; ---echo *** binlog_cache_disk_use must be non-zero *** -show status like "binlog_cache_disk_use"; - -sync_slave_with_master; - -let $diff_tables=master:test.t1, slave:test.t1; -source include/diff_tables.inc; - -let $diff_tables=master:test.t2, slave:test.t2; -source include/diff_tables.inc; - -let $diff_tables=master:test.t3, slave:test.t3; -source include/diff_tables.inc; - - -connection master; - -begin; -delete from t1; -delete from t2; -delete from t3; -commit; - -drop table t1, t2, t3; -set @@global.binlog_cache_size = @save_binlog_cache_size; -set @@global.binlog_checksum = @save_binlog_checksum; -set @@global.master_verify_checksum = @save_master_verify_checksum; -drop procedure test.p_init; -drop procedure test.p1; - ---source include/rpl_end.inc diff --git a/mysql-test/suite/rpl/include/rpl_corruption.inc b/mysql-test/suite/rpl/include/rpl_corruption.inc deleted file mode 100644 index c7a913af9d7f2..0000000000000 --- a/mysql-test/suite/rpl/include/rpl_corruption.inc +++ /dev/null @@ -1,175 +0,0 @@ -# -# This include file is used by more than one test suite -# (currently rpl and binlog_encryption). -# Please check all dependent tests after modifying it -# - -############################################################ -# Purpose: WL#5064 Testing with corrupted events. -# The test emulates the corruption at the vary stages -# of replication: -# - in binlog file -# - in network -# - in relay log -############################################################ - -# -# The tests intensively utilize @@global.debug. Note, -# Bug#11765758 - 58754, -# @@global.debug is read by the slave threads through dbug-interface. -# Hence, before a client thread set @@global.debug we have to ensure that: -# (a) the slave threads are stopped, or (b) the slave threads are in -# sync and waiting. - ---source include/have_debug.inc ---source include/master-slave.inc - -# Block legal errors for MTR -call mtr.add_suppression('Found invalid event in binary log'); -call mtr.add_suppression('Slave I/O: Relay log write failure: could not queue event from master'); -call mtr.add_suppression('event read from binlog did not pass crc check'); -call mtr.add_suppression('Replication event checksum verification failed'); -call mtr.add_suppression('Event crc check failed! Most likely there is event corruption'); -call mtr.add_suppression('Slave SQL: Error initializing relay log position: I/O error reading event at position .*, error.* 1593'); - -SET @old_master_verify_checksum = @@master_verify_checksum; - -# Creating test table/data and set corruption position for testing ---echo # 1. Creating test table/data and set corruption position for testing ---connection master ---echo * insert/update/delete rows in table t1 * -# Corruption algorithm modifies only the first event and -# then will be reset. To avoid checking always the first event -# from binlog (usually it is FD) we randomly execute different -# statements and set position for corruption inside events. - -CREATE TABLE t1 (a INT NOT NULL PRIMARY KEY, b VARCHAR(10), c VARCHAR(100)); ---disable_query_log -let $i=`SELECT 3+CEILING(10*RAND())`; -let $j=1; -let $pos=0; -while ($i) { - eval INSERT INTO t1 VALUES ($j, 'a', NULL); - if (`SELECT RAND() > 0.7`) - { - eval UPDATE t1 SET c = REPEAT('a', 20) WHERE a = $j; - } - if (`SELECT RAND() > 0.8`) - { - eval DELETE FROM t1 WHERE a = $j; - } - if (!$pos) { - let $pos= query_get_value(SHOW MASTER STATUS, Position, 1); - --sync_slave_with_master - --source include/stop_slave.inc - --disable_query_log - --connection master - } - dec $i; - inc $j; -} ---enable_query_log - - -# Emulate corruption in binlog file when SHOW BINLOG EVENTS is executing ---echo # 2. Corruption in master binlog and SHOW BINLOG EVENTS -SET @saved_dbug = @@global.debug_dbug; -SET @@global.debug_dbug="d,corrupt_read_log_event_char"; ---echo SHOW BINLOG EVENTS; ---disable_query_log -send_eval SHOW BINLOG EVENTS FROM $pos; ---enable_query_log ---error ER_ERROR_WHEN_EXECUTING_COMMAND -reap; - -SET @@global.debug_dbug=@saved_dbug; - -# Emulate corruption on master with crc checking on master ---echo # 3. Master read a corrupted event from binlog and send the error to slave - -# We have a rare but nasty potential race here: if the dump thread on -# the master for the _old_ slave connection has not yet discovered -# that the slave has disconnected, we will inject the corrupt event on -# the wrong connection, and the test will fail -# (+d,corrupt_read_log_event2 corrupts only one event). -# So kill any lingering dump thread (we need to kill; otherwise dump thread -# could manage to send all events down the socket before seeing it close, and -# hang forever waiting for new binlog events to be created). -let $id= `select id from information_schema.processlist where command = "Binlog Dump"`; -if ($id) -{ - --disable_query_log - --error 0,1094 - eval kill $id; - --enable_query_log -} -let $wait_condition= - SELECT COUNT(*)=0 FROM INFORMATION_SCHEMA.PROCESSLIST WHERE command = 'Binlog Dump'; ---source include/wait_condition.inc - -SET @@global.debug_dbug="d,corrupt_read_log_event2_set"; ---connection slave -START SLAVE IO_THREAD; -let $slave_io_errno= 1236; ---let $slave_timeout= 10 ---source include/wait_for_slave_io_error.inc ---connection master -SET @@global.debug_dbug=@saved_dbug; - -# Emulate corruption on master without crc checking on master ---echo # 4. Master read a corrupted event from binlog and send it to slave ---connection master -SET GLOBAL master_verify_checksum=0; -SET @@global.debug_dbug="d,corrupt_read_log_event2_set"; ---connection slave -START SLAVE IO_THREAD; -# When the checksum error is detected, the slave sets error code 1743 -# (ER_NETWORK_READ_EVENT_CHECKSUM_FAILURE) in queue_event(), then immediately -# sets error 1595 (ER_SLAVE_RELAY_LOG_WRITE_FAILURE) in handle_slave_io(). -# So we usually get 1595, but it is occasionally possible to get 1743. -let $slave_io_errno= 1595,1743; # ER_SLAVE_RELAY_LOG_WRITE_FAILURE, ER_NETWORK_READ_EVENT_CHECKSUM_FAILURE ---source include/wait_for_slave_io_error.inc ---connection master -SET @@global.debug_dbug=@saved_dbug; -SET GLOBAL master_verify_checksum=1; - -# Emulate corruption in network ---echo # 5. Slave. Corruption in network ---connection slave -SET @saved_dbug_slave = @@GLOBAL.debug_dbug; -SET @@global.debug_dbug="d,corrupt_queue_event"; -START SLAVE IO_THREAD; -let $slave_io_errno= 1595,1743; # ER_SLAVE_RELAY_LOG_WRITE_FAILURE, ER_NETWORK_READ_EVENT_CHECKSUM_FAILURE ---source include/wait_for_slave_io_error.inc -SET @@global.debug_dbug=@saved_dbug_slave; - -# Emulate corruption in relay log ---echo # 6. Slave. Corruption in relay log - -SET @@global.debug_dbug="d,corrupt_read_log_event_char"; - -START SLAVE SQL_THREAD; -let $slave_sql_errno= 1593; ---source include/wait_for_slave_sql_error.inc - -SET @@global.debug_dbug=@saved_dbug_slave; - -# Start normal replication and compare same table on master -# and slave ---echo # 7. Seek diff for tables on master and slave ---connection slave ---source include/start_slave.inc ---connection master ---sync_slave_with_master -let $diff_tables= master:test.t1, slave:test.t1; ---source include/diff_tables.inc - -# Clean up ---echo # 8. Clean up ---connection master -set @@global.debug_dbug = @saved_dbug; -SET GLOBAL master_verify_checksum = @old_master_verify_checksum; -DROP TABLE t1; ---sync_slave_with_master - ---source include/rpl_end.inc diff --git a/mysql-test/suite/rpl/include/rpl_gtid_basic.inc b/mysql-test/suite/rpl/include/rpl_gtid_basic.inc deleted file mode 100644 index 68a5d05ffe947..0000000000000 --- a/mysql-test/suite/rpl/include/rpl_gtid_basic.inc +++ /dev/null @@ -1,572 +0,0 @@ -# -# This include file is used by more than one test suite -# (currently rpl and binlog_encryption). -# Please check all dependent tests after modifying it -# - ---source include/have_innodb.inc ---let $rpl_topology=1->2->3->4 ---source include/rpl_init.inc - -# Set up a 4-deep replication topology, then test various fail-overs -# using GTID. -# -# A -> B -> C -> D - -connection server_1; ---source include/wait_for_binlog_checkpoint.inc ---let $binlog_file = query_get_value(SHOW MASTER STATUS,File,1) ---let $binlog_pos = query_get_value(SHOW MASTER STATUS,Position,1) ---echo *** GTID position should be empty here *** ---replace_result $binlog_file $binlog_pos -eval SELECT BINLOG_GTID_POS('$binlog_file',$binlog_pos); - -CREATE TABLE t1 (a INT PRIMARY KEY, b VARCHAR(10)) ENGINE=MyISAM; -CREATE TABLE t2 (a INT PRIMARY KEY, b VARCHAR(10)) ENGINE=InnoDB; -INSERT INTO t1 VALUES (1, "m1"); -INSERT INTO t1 VALUES (2, "m2"), (3, "m3"), (4, "m4"); -INSERT INTO t2 VALUES (1, "i1"); -BEGIN; -INSERT INTO t2 VALUES (2, "i2"), (3, "i3"); -INSERT INTO t2 VALUES (4, "i4"); -COMMIT; -save_master_pos; -source include/wait_for_binlog_checkpoint.inc; ---let $binlog_file = query_get_value(SHOW MASTER STATUS,File,1) ---let $binlog_pos = query_get_value(SHOW MASTER STATUS,Position,1) ---let $gtid_pos_server_1 = `SELECT @@gtid_binlog_pos` ---echo *** GTID position should be non-empty here *** ---replace_result $binlog_file $binlog_pos $gtid_pos_server_1 -eval SELECT BINLOG_GTID_POS('$binlog_file',$binlog_pos); - -connection server_2; -sync_with_master; -source include/wait_for_binlog_checkpoint.inc; ---let $binlog_file = query_get_value(SHOW MASTER STATUS,File,1) ---let $binlog_pos = query_get_value(SHOW MASTER STATUS,Position,1) ---echo *** GTID position should be the same as on server_1 *** ---replace_result $binlog_file $binlog_pos $gtid_pos_server_1 -eval SELECT BINLOG_GTID_POS('$binlog_file',$binlog_pos); -SELECT * FROM t1 ORDER BY a; -SELECT * FROM t2 ORDER BY a; -save_master_pos; - -connection server_3; -sync_with_master; -SELECT * FROM t1 ORDER BY a; -SELECT * FROM t2 ORDER BY a; -save_master_pos; - -connection server_4; -sync_with_master; -SELECT * FROM t1 ORDER BY a; -SELECT * FROM t2 ORDER BY a; - - ---echo *** Now take out D, let it fall behind a bit, and then test re-attaching it to A *** -connection server_4; ---source include/stop_slave.inc - -connection server_1; -INSERT INTO t1 VALUES (5, "m1a"); -INSERT INTO t2 VALUES (5, "i1a"); -save_master_pos; - -connection server_4; ---replace_result $MASTER_MYPORT MASTER_PORT -eval CHANGE MASTER TO master_host = '127.0.0.1', master_port = $MASTER_MYPORT, - MASTER_USE_GTID=CURRENT_POS; ---source include/start_slave.inc -sync_with_master; -SELECT * FROM t1 ORDER BY a; -SELECT * FROM t2 ORDER BY a; - ---echo *** Now move B to D (C is still replicating from B) *** -connection server_2; ---source include/stop_slave.inc ---replace_result $SERVER_MYPORT_4 SERVER_MYPORT_4 -eval CHANGE MASTER TO master_host = '127.0.0.1', master_port = $SERVER_MYPORT_4, - MASTER_USE_GTID=CURRENT_POS; ---source include/start_slave.inc - -connection server_4; -UPDATE t2 SET b="j1a" WHERE a=5; -save_master_pos; - -connection server_2; -sync_with_master; -SELECT * FROM t1 ORDER BY a; -SELECT * FROM t2 ORDER BY a; - ---echo *** Now move C to D, after letting it fall a little behind *** -connection server_3; ---source include/stop_slave.inc - -connection server_1; -INSERT INTO t2 VALUES (6, "i6b"); -INSERT INTO t2 VALUES (7, "i7b"); ---source include/save_master_gtid.inc - -connection server_3; ---replace_result $SERVER_MYPORT_4 SERVER_MYPORT_4 -eval CHANGE MASTER TO master_host = '127.0.0.1', master_port = $SERVER_MYPORT_4, - MASTER_USE_GTID=CURRENT_POS; ---source include/start_slave.inc ---source include/sync_with_master_gtid.inc -SELECT * FROM t2 ORDER BY a; - ---echo *** Now change everything back to what it was, to make rpl_end.inc happy -# Also check that MASTER_USE_GTID=CURRENT_POS is still enabled. -connection server_2; -# We need to sync up server_2 before switching. If it happened to have reached -# the point 'UPDATE t2 SET b="j1a" WHERE a=5' it will fail to connect to -# server_1, which is (deliberately) missing that transaction. ---source include/sync_with_master_gtid.inc ---source include/stop_slave.inc ---replace_result $MASTER_MYPORT MASTER_MYPORT -eval CHANGE MASTER TO master_host = '127.0.0.1', master_port = $MASTER_MYPORT; ---source include/start_slave.inc ---source include/wait_for_slave_to_start.inc - -connection server_3; ---source include/stop_slave.inc ---replace_result $SLAVE_MYPORT SLAVE_MYPORT -eval CHANGE MASTER TO master_host = '127.0.0.1', master_port = $SLAVE_MYPORT; ---source include/start_slave.inc ---source include/sync_with_master_gtid.inc - -connection server_4; ---source include/stop_slave.inc ---replace_result $SERVER_MYPORT_3 SERVER_MYPORT_3 -eval CHANGE MASTER TO master_host = '127.0.0.1', master_port = $SERVER_MYPORT_3; ---source include/start_slave.inc - -connection server_1; -DROP TABLE t1,t2; ---source include/save_master_gtid.inc - ---echo *** A few more checks for BINLOG_GTID_POS function *** ---let $valid_binlog_name = query_get_value(SHOW BINARY LOGS,Log_name,1) ---error ER_WRONG_PARAMCOUNT_TO_NATIVE_FCT -SELECT BINLOG_GTID_POS(); ---error ER_WRONG_PARAMCOUNT_TO_NATIVE_FCT -SELECT BINLOG_GTID_POS('a'); ---error ER_WRONG_PARAMCOUNT_TO_NATIVE_FCT -SELECT BINLOG_GTID_POS('a',1,NULL); -SELECT BINLOG_GTID_POS(1,'a'); -SELECT BINLOG_GTID_POS(NULL,NULL); -SELECT BINLOG_GTID_POS('',1); -SELECT BINLOG_GTID_POS('a',1); -eval SELECT BINLOG_GTID_POS('$valid_binlog_name',-1); -eval SELECT BINLOG_GTID_POS('$valid_binlog_name',0); -eval SELECT BINLOG_GTID_POS('$valid_binlog_name',18446744073709551615); -eval SELECT BINLOG_GTID_POS('$valid_binlog_name',18446744073709551616); - - ---echo *** Some tests of @@GLOBAL.gtid_binlog_state *** ---connection server_2 ---source include/sync_with_master_gtid.inc ---source include/stop_slave.inc - ---connection server_1 -SET @old_state= @@GLOBAL.gtid_binlog_state; - ---error ER_BINLOG_MUST_BE_EMPTY -SET GLOBAL gtid_binlog_state = ''; -RESET MASTER; -SET GLOBAL gtid_binlog_state = ''; -FLUSH LOGS; ---source include/show_binary_logs.inc -SET GLOBAL gtid_binlog_state = '0-1-10,1-2-20,0-3-30'; ---source include/show_binary_logs.inc ---let $binlog_file= master-bin.000001 ---let $binlog_start= 4 ---source include/show_binlog_events.inc -#SELECT @@GLOBAL.gtid_binlog_pos; -#SELECT @@GLOBAL.gtid_binlog_state; ---error ER_BINLOG_MUST_BE_EMPTY -SET GLOBAL gtid_binlog_state = @old_state; -RESET MASTER; -SET GLOBAL gtid_binlog_state = @old_state; - -# Check that slave can reconnect again, despite the RESET MASTER, as we -# restored the state. - -CREATE TABLE t1 (a INT PRIMARY KEY); -SET gtid_seq_no=100; -INSERT INTO t1 VALUES (1); ---source include/save_master_gtid.inc - ---connection server_2 ---source include/start_slave.inc -# We cannot just use sync_with_master as we've done RESET MASTER, so -# slave old-style position is wrong. -# So sync on gtid position instead. ---source include/sync_with_master_gtid.inc - -SELECT * FROM t1; -# Check that the IO gtid position in SHOW SLAVE STATUS is also correct. ---let $status_items= Gtid_IO_Pos ---source include/show_slave_status.inc - ---echo *** Test @@LAST_GTID and MASTER_GTID_WAIT() *** - ---connection server_1 -DROP TABLE t1; -CREATE TABLE t1 (a INT PRIMARY KEY) ENGINE=InnoDB; ---save_master_pos - ---connection server_2 ---sync_with_master ---source include/stop_slave.inc - ---connect (m1,127.0.0.1,root,,test,$SERVER_MYPORT_1,) -SELECT @@last_gtid; -SET gtid_seq_no=110; -SELECT @@last_gtid; -BEGIN; -SELECT @@last_gtid; -INSERT INTO t1 VALUES (2); -SELECT @@last_gtid; -COMMIT; -SELECT @@last_gtid; ---let $pos= `SELECT @@gtid_binlog_pos` - ---connect (s1,127.0.0.1,root,,test,$SERVER_MYPORT_2,) -eval SET @pos= '$pos'; -# Check NULL argument. -SELECT master_gtid_wait(NULL); -# Check empty argument returns immediately. -SELECT master_gtid_wait('', NULL); -# Check this gets counted -SHOW STATUS LIKE 'Master_gtid_wait_count'; -SHOW STATUS LIKE 'Master_gtid_wait_timeouts'; -SHOW STATUS LIKE 'Master_gtid_wait_time'; -# Let's check that we get a timeout -SELECT master_gtid_wait(@pos, 0.5); -SELECT * FROM t1 ORDER BY a; -# Now actually wait until the slave reaches the position -send SELECT master_gtid_wait(@pos); - ---connection server_2 ---source include/start_slave.inc - ---connection s1 -reap; -SELECT * FROM t1 ORDER BY a; - -# Test waiting on a domain that does not exist yet. ---source include/stop_slave.inc - ---connection server_1 -SET gtid_domain_id= 1; -INSERT INTO t1 VALUES (3); ---let $pos= `SELECT @@gtid_binlog_pos` - ---connection s1 ---replace_result $pos POS -eval SET @pos= '$pos'; -SELECT master_gtid_wait(@pos, 0); -SELECT * FROM t1 WHERE a >= 3; -send SELECT master_gtid_wait(@pos, -1); - ---connection server_2 ---source include/start_slave.inc - ---connection s1 -reap; -SELECT * FROM t1 WHERE a >= 3; -# Waiting for only part of the position. -SELECT master_gtid_wait('1-1-1', 0); - -# Now test a lot of parallel master_gtid_wait() calls, completing in different -# order, and some of which time out or get killed on the way. - ---connection s1 -send SELECT master_gtid_wait('2-1-1,1-1-4,0-1-110'); - ---connect (s2,127.0.0.1,root,,test,$SERVER_MYPORT_2,) -# This will time out. No event 0-1-1000 exists -send SELECT master_gtid_wait('0-1-1000', 0.5); - ---connect (s3,127.0.0.1,root,,test,$SERVER_MYPORT_2,) -# This one we will kill ---let $kill1_id= `SELECT connection_id()` -send SELECT master_gtid_wait('0-1-2000'); - ---connect (s4,127.0.0.1,root,,test,$SERVER_MYPORT_2,) -send SELECT master_gtid_wait('2-1-10'); - ---connect (s5,127.0.0.1,root,,test,$SERVER_MYPORT_2,) -send SELECT master_gtid_wait('2-1-6', 1); - -# This one we will kill also. ---connect (s6,127.0.0.1,root,,test,$SERVER_MYPORT_2,) ---let $kill2_id= `SELECT connection_id()` -send SELECT master_gtid_wait('2-1-5'); - ---connect (s7,127.0.0.1,root,,test,$SERVER_MYPORT_2,) -send SELECT master_gtid_wait('2-1-10'); - ---connect (s8,127.0.0.1,root,,test,$SERVER_MYPORT_2,) -send SELECT master_gtid_wait('2-1-5,1-1-4,0-1-110'); - ---connect (s9,127.0.0.1,root,,test,$SERVER_MYPORT_2,) -send SELECT master_gtid_wait('2-1-2'); - ---connection server_2 -# This one completes immediately. -SHOW STATUS LIKE 'Master_gtid_wait_timeouts'; -SHOW STATUS LIKE 'Master_gtid_wait_count'; -SELECT master_gtid_wait('1-1-1'); -SHOW STATUS LIKE 'Master_gtid_wait_timeouts'; -SHOW STATUS LIKE 'Master_gtid_wait_count'; -let $wait_time = query_get_value(SHOW STATUS LIKE 'Master_gtid_wait_time', Value, 1); ---replace_result $wait_time MASTER_GTID_WAIT_TIME -eval SET @a= $wait_time; -SELECT IF(@a <= 100*1000*1000, "OK", CONCAT("Error: wait time ", @a, " is larger than expected")) - AS Master_gtid_wait_time_as_expected; - - ---connect (s10,127.0.0.1,root,,test,$SERVER_MYPORT_2,) -send SELECT master_gtid_wait('0-1-109'); - ---connection server_2 -# This one should time out. -SHOW STATUS LIKE 'Master_gtid_wait_timeouts'; -SHOW STATUS LIKE 'Master_gtid_wait_count'; -SELECT master_gtid_wait('2-1-2', 0.5); -SHOW STATUS LIKE 'Master_gtid_wait_timeouts'; -SHOW STATUS LIKE 'Master_gtid_wait_count'; -let $wait_time = query_get_value(SHOW STATUS LIKE 'Master_gtid_wait_time', Value, 1); ---replace_result $wait_time MASTER_GTID_WAIT_TIME -eval SET @a= $wait_time; -# We expect a wait time of just a bit over 0.5 seconds. But thread scheduling -# and timer inaccuracies could introduce significant jitter. So allow a -# generous interval. -SELECT IF(@a BETWEEN 0.4*1000*1000 AND 100*1000*1000, "OK", CONCAT("Error: wait time ", @a, " not as expected")) AS Master_gtid_wait_time_as_expected; - ---replace_result $kill1_id KILL_ID -eval KILL QUERY $kill1_id; ---connection s3 ---error ER_QUERY_INTERRUPTED -reap; - ---connection server_1 -SET gtid_domain_id=2; -SET gtid_seq_no=2; -INSERT INTO t1 VALUES (4); - ---connection s9 -reap; - ---connection server_2 ---replace_result $kill2_id KILL_ID -eval KILL CONNECTION $kill2_id; - ---connection s6 ---error 2013,ER_CONNECTION_KILLED -reap; - ---connection server_1 -SET gtid_domain_id=1; -SET gtid_seq_no=4; -INSERT INTO t1 VALUES (5); -SET gtid_domain_id=2; -SET gtid_seq_no=5; -INSERT INTO t1 VALUES (6); - ---connection s8 -reap; ---connection s1 -reap; ---connection s2 -reap; ---connection s5 -reap; ---connection s10 -reap; - ---connection server_1 -SET gtid_domain_id=2; -SET gtid_seq_no=10; -INSERT INTO t1 VALUES (7); - ---connection s4 -reap; ---connection s7 -reap; - - ---echo *** Test gtid_slave_pos when used with GTID *** - ---connection server_2 ---source include/stop_slave.inc - ---connection server_1 -SET gtid_domain_id=2; -SET gtid_seq_no=1000; -INSERT INTO t1 VALUES (10); -INSERT INTO t1 VALUES (11); ---save_master_pos - ---connection server_2 -SET sql_slave_skip_counter= 1; ---source include/start_slave.inc ---sync_with_master -SELECT * FROM t1 WHERE a >= 10 ORDER BY a; -SELECT IF(LOCATE("2-1-1001", @@GLOBAL.gtid_slave_pos)>0, "Ok", CONCAT("ERROR! expected GTID 2-1-1001 not found in gtid_slave_pos: ", @@GLOBAL.gtid_slave_pos)) AS status; - ---source include/stop_slave.inc - ---connection server_1 -SET gtid_domain_id=2; -SET gtid_seq_no=1010; -INSERT INTO t1 VALUES (12); -INSERT INTO t1 VALUES (13); ---save_master_pos - ---connection server_2 -SET sql_slave_skip_counter= 2; ---source include/start_slave.inc ---sync_with_master -SELECT * FROM t1 WHERE a >= 10 ORDER BY a; -SELECT IF(LOCATE("2-1-1011", @@GLOBAL.gtid_slave_pos)>0, "Ok", CONCAT("ERROR! expected GTID 2-1-1011 not found in gtid_slave_pos: ", @@GLOBAL.gtid_slave_pos)) AS status; - ---source include/stop_slave.inc - ---connection server_1 -SET gtid_domain_id=2; -SET gtid_seq_no=1020; -INSERT INTO t1 VALUES (14); -INSERT INTO t1 VALUES (15); -INSERT INTO t1 VALUES (16); ---save_master_pos - ---connection server_2 -SET sql_slave_skip_counter= 3; ---source include/start_slave.inc ---sync_with_master -SELECT * FROM t1 WHERE a >= 10 ORDER BY a; -SELECT IF(LOCATE("2-1-1022", @@GLOBAL.gtid_slave_pos)>0, "Ok", CONCAT("ERROR! expected GTID 2-1-1022 not found in gtid_slave_pos: ", @@GLOBAL.gtid_slave_pos)) AS status; - ---source include/stop_slave.inc - ---connection server_1 -SET gtid_domain_id=2; -SET gtid_seq_no=1030; -# Disable logging Annotate_rows events to preserve events count. -let $binlog_annotate_row_events_saved= `SELECT @@binlog_annotate_row_events`; -SET @@binlog_annotate_row_events= 0; -INSERT INTO t1 VALUES (17); -INSERT INTO t1 VALUES (18); -INSERT INTO t1 VALUES (19); -eval SET @@binlog_annotate_row_events= $binlog_annotate_row_events_saved; ---save_master_pos - ---connection server_2 -SET sql_slave_skip_counter= 5; ---source include/start_slave.inc ---sync_with_master -SELECT * FROM t1 WHERE a >= 10 ORDER BY a; -SELECT IF(LOCATE("2-1-1032", @@GLOBAL.gtid_slave_pos)>0, "Ok", CONCAT("ERROR! expected GTID 2-1-1032 not found in gtid_slave_pos: ", @@GLOBAL.gtid_slave_pos)) AS status; - - ---source include/stop_slave.inc - ---connection server_1 -SET gtid_domain_id=3; -SET gtid_seq_no=100; -CREATE TABLE t2 (a INT PRIMARY KEY); -DROP TABLE t2; -SET gtid_domain_id=2; -SET gtid_seq_no=1040; -INSERT INTO t1 VALUES (20); ---save_master_pos - ---connection server_2 -SET @saved_mode= @@GLOBAL.slave_ddl_exec_mode; -SET GLOBAL slave_ddl_exec_mode=STRICT; -SET sql_slave_skip_counter=1; -START SLAVE UNTIL master_gtid_pos="3-1-100"; ---let $master_pos=3-1-100 ---source include/sync_with_master_gtid.inc ---source include/wait_for_slave_to_stop.inc ---error ER_NO_SUCH_TABLE -SELECT * FROM t2; -SELECT IF(LOCATE("3-1-100", @@GLOBAL.gtid_slave_pos)>0, "Ok", CONCAT("ERROR! expected GTID 3-1-100 not found in gtid_slave_pos: ", @@GLOBAL.gtid_slave_pos)) AS status; - -# Start the slave again, it should fail on the DROP TABLE as the table is not there. -SET sql_log_bin=0; -CALL mtr.add_suppression("Slave: Unknown table 'test\\.t2' Error_code: 1051"); -SET sql_log_bin=1; -START SLAVE; ---let $slave_sql_errno=1051 ---source include/wait_for_slave_sql_error.inc -SELECT IF(LOCATE("3-1-100", @@GLOBAL.gtid_slave_pos)>0, "Ok", CONCAT("ERROR! expected GTID 3-1-100 not found in gtid_slave_pos: ", @@GLOBAL.gtid_slave_pos)) AS status; - -STOP SLAVE IO_THREAD; -SET sql_slave_skip_counter=2; ---source include/start_slave.inc ---sync_with_master - -SELECT * FROM t1 WHERE a >= 20 ORDER BY a; -SELECT IF(LOCATE("3-1-101", @@GLOBAL.gtid_slave_pos)>0, "Ok", CONCAT("ERROR! expected GTID 3-1-101 not found in gtid_slave_pos: ", @@GLOBAL.gtid_slave_pos)) AS status; -SELECT IF(LOCATE("2-1-1040", @@GLOBAL.gtid_slave_pos)>0, "Ok", CONCAT("ERROR! expected GTID 2-1-1040 not found in gtid_slave_pos: ", @@GLOBAL.gtid_slave_pos)) AS status; - -SET GLOBAL slave_ddl_exec_mode= @saved_mode; - - ---echo *** Test GTID-connecting to a master with out-of-order sequence numbers in the binlog. *** - -# Create an out-of-order binlog on server 2. -# Let server 3 replicate to an out-of-order point, stop it, restart it, -# and check that it replicates correctly despite the out-of-order. - ---connection server_1 -SET gtid_domain_id= @@GLOBAL.gtid_domain_id; -INSERT INTO t1 VALUES (31); ---save_master_pos - ---connection server_2 ---sync_with_master -SET gtid_domain_id= @@GLOBAL.gtid_domain_id; -INSERT INTO t1 VALUES (32); - ---connection server_1 -INSERT INTO t1 VALUES (33); ---save_master_pos - ---connection server_2 ---sync_with_master ---save_master_pos - ---connection server_3 ---sync_with_master ---source include/stop_slave.inc - ---connection server_1 -INSERT INTO t1 VALUES (34); ---save_master_pos - ---connection server_2 ---sync_with_master ---save_master_pos - ---connection server_3 ---source include/start_slave.inc ---sync_with_master -SELECT * FROM t1 WHERE a >= 30 ORDER BY a; ---save_master_pos - ---connection server_4 ---sync_with_master -SELECT * FROM t1 WHERE a >= 30 ORDER BY a; - - -# Clean up. ---connection server_1 -DROP TABLE t1; - - ---source include/rpl_end.inc diff --git a/mysql-test/suite/rpl/include/rpl_incident.inc b/mysql-test/suite/rpl/include/rpl_incident.inc deleted file mode 100644 index 75d28d6a6c6b0..0000000000000 --- a/mysql-test/suite/rpl/include/rpl_incident.inc +++ /dev/null @@ -1,61 +0,0 @@ -# -# This include file is used by more than one test suite -# (currently rpl and binlog_encryption). -# Please check all dependent tests after modifying it -# - ---source include/have_debug.inc ---source include/master-slave.inc - -SET @old_binlog_checksum=@@binlog_checksum; -SET GLOBAL BINLOG_CHECKSUM=none; -connection slave; -SET @old_binlog_checksum=@@binlog_checksum; -SET GLOBAL BINLOG_CHECKSUM=none; -connection master; - ---echo **** On Master **** -CREATE TABLE t1 (a INT); - -INSERT INTO t1 VALUES (1),(2),(3); -SELECT * FROM t1; - -set @saved_dbug = @@global.debug_dbug; -SET GLOBAL debug_dbug= '+d,incident_database_resync_on_replace,*'; - -# This will generate an incident log event and store it in the binary -# log before the replace statement. -REPLACE INTO t1 VALUES (4); ---save_master_pos -SELECT * FROM t1; - -set @@global.debug_dbug = @saved_dbug; - -connection slave; -# Wait until SQL thread stops with error LOST_EVENT on master -call mtr.add_suppression("Slave SQL.*The incident LOST_EVENTS occurred on the master.* 1590"); -let $slave_sql_errno= 1590; -let $show_slave_sql_error= 1; -source include/wait_for_slave_sql_error.inc; - -# The 4 should not be inserted into the table, since the incident log -# event should have stop the slave. ---echo **** On Slave **** -SELECT * FROM t1; - -SET GLOBAL SQL_SLAVE_SKIP_COUNTER=1; -START SLAVE; ---sync_with_master - -# Now, we should have inserted the row into the table and the slave -# should be running. We should also have rotated to a new binary log. - -SELECT * FROM t1; -source include/check_slave_is_running.inc; - -connection master; -SET GLOBAL BINLOG_CHECKSUM=@old_binlog_checksum; -DROP TABLE t1; ---sync_slave_with_master -SET GLOBAL BINLOG_CHECKSUM=@old_binlog_checksum; ---source include/rpl_end.inc diff --git a/mysql-test/suite/rpl/include/rpl_init_slave_errors.inc b/mysql-test/suite/rpl/include/rpl_init_slave_errors.inc deleted file mode 100644 index 46673ea47649f..0000000000000 --- a/mysql-test/suite/rpl/include/rpl_init_slave_errors.inc +++ /dev/null @@ -1,96 +0,0 @@ -# -# This include file is used by more than one test suite -# (currently rpl and binlog_encryption). -# Please check all dependent tests after modifying it -# - -###################################################################### -# Some errors that cause the slave SQL thread to stop are not shown in -# the Slave_SQL_Error column of "SHOW SLAVE STATUS". Instead, the error -# is only in the server's error log. -# -# Two failures and their respective reporting are verified: -# -# 1 - Failures during slave thread initialization -# 2 - Failures while processing queries passed through the init_slave -# option. -# -# In order to check the first type of failure, we inject a fault in the -# SQL/IO Threads through SET GLOBAL debug. -# -# To check the second type, we set @@global.init_slave to an invalid -# command thus preventing the initialization of the SQL Thread. -# -# Obs: -# 1 - Note that testing failures while initializing the relay log position -# is hard as the same function is called before the code reaches the point -# that we want to test. -# -# 2 - This test does not target failures that are reported while applying -# events such as duplicate keys, errors while reading the relay-log.bin*, -# etc. Such errors are already checked on other tests. -###################################################################### - -###################################################################### -# Configuring the Environment -###################################################################### -source include/have_debug.inc; -source include/have_log_bin.inc; -source include/master-slave.inc; - -connection slave; - ---disable_warnings -stop slave; ---enable_warnings -reset slave; - -###################################################################### -# Injecting faults in the threads' initialization -###################################################################### -connection slave; - -# Set debug flags on slave to force errors to occur -set @saved_dbug = @@global.debug_dbug; -SET GLOBAL debug_dbug= "d,simulate_io_slave_error_on_init,simulate_sql_slave_error_on_init"; - -start slave; - -# -# slave is going to stop because of emulated failures -# but there won't be any crashes nor asserts hit. -# -# 1593 = ER_SLAVE_FATAL_ERROR ---let $slave_sql_errno= 1593 ---let $show_slave_sql_error= 1 ---source include/wait_for_slave_sql_error.inc - -call mtr.add_suppression("Failed during slave.* thread initialization"); - -set @@global.debug_dbug = @saved_dbug; - -###################################################################### -# Injecting faults in the init_slave option -###################################################################### -connection slave; - -reset slave; - -SET GLOBAL init_slave= "garbage"; - -start slave; -# 1064 = ER_PARSE_ERROR ---let $slave_sql_errno= 1064 ---let $show_slave_sql_error= 1 ---source include/wait_for_slave_sql_error.inc - -###################################################################### -# Clean up -###################################################################### -SET GLOBAL init_slave= ""; - -# Clean up Last_SQL_Error ---source include/stop_slave_io.inc -RESET SLAVE; ---let $rpl_only_running_threads= 1 ---source include/rpl_end.inc diff --git a/mysql-test/suite/rpl/include/rpl_loadfile.inc b/mysql-test/suite/rpl/include/rpl_loadfile.inc deleted file mode 100644 index 9cd645306908c..0000000000000 --- a/mysql-test/suite/rpl/include/rpl_loadfile.inc +++ /dev/null @@ -1,120 +0,0 @@ -# -# This include file is used by more than one test suite -# (currently rpl and binlog_encryption). -# Please check all dependent tests after modifying it -# - -############################################################################# -# Original Author: JBM # -# Original Date: Aug/18/2005 # -############################################################################# -# TEST: To test the LOAD_FILE() in rbr # -############################################################################# -# Change Author: JBM -# Change Date: 2006-01-16 -########## - -# Includes --- source include/have_binlog_format_mixed_or_row.inc --- source include/master-slave.inc - --- source suite/rpl/include/rpl_loadfile.test - -# BUG#39701: Mixed binlog format does not switch to row mode on LOAD_FILE -# -# DESCRIPTION -# -# Problem: when using load_file string function and mixed binlogging format -# there was no switch to row based binlogging format. This leads -# to scenarios on which the slave replicates the statement and it -# will try to load the file from local file system, which in most -# likely it will not exist. -# -# Solution: -# Marking this function as unsafe for statement format, makes the -# statement using it to be logged in row based format. As such, data -# replicated from the master, becomes the content of the loaded file. -# Consequently, the slave receives the necessary data to complete -# the load_file instruction correctly. -# -# IMPLEMENTATION -# -# The test is implemented as follows: -# -# On Master, -# i) write to file the desired content. -# ii) create table and stored procedure with load_file -# iii) stop slave -# iii) execute load_file -# iv) remove file -# -# On Slave, -# v) start slave -# vi) sync it with master so that it gets the updates from binlog (which -# should have bin logged in row format). -# -# If the the binlog format does not change to row, then the assertion -# done in the following step fails. This happens because tables differ -# since the file does not exist anymore, meaning that when slave -# attempts to execute LOAD_FILE statement it inserts NULL on table -# instead of the same contents that the master loaded when it executed -# the procedure (which was executed when file existed). -# -# vii) assert that the contents of master and slave -# table are the same - ---source include/rpl_reset.inc - -connection master; -let $file= $MYSQLTEST_VARDIR/tmp/bug_39701.data; - ---replace_result $MYSQLTEST_VARDIR MYSQLTEST_VARDIR ---eval SELECT repeat('x',20) INTO OUTFILE '$file' - -disable_warnings; -DROP TABLE IF EXISTS t1; -enable_warnings; - -CREATE TABLE t1 (t text); -DELIMITER |; -CREATE PROCEDURE p(file varchar(4096)) - BEGIN - INSERT INTO t1 VALUES (LOAD_FILE(file)); - END| -DELIMITER ;| - -# stop slave before issuing the load_file on master -connection slave; -source include/stop_slave.inc; - -connection master; - -# test: check that logging falls back to rbr. ---replace_result $MYSQLTEST_VARDIR MYSQLTEST_VARDIR ---eval CALL p('$file') - -# test: remove the file from the filesystem and assert that slave still -# gets the loaded file -remove_file $file; - -# now that the file is removed it is safe (regarding what we want to test) -# to start slave -connection slave; -source include/start_slave.inc; - -connection master; -sync_slave_with_master; - -# assertion: assert that the slave got the updates even -# if the file was removed before the slave started, -# meaning that contents were indeed transfered -# through binlog (in row format) -let $diff_tables= master:t1, slave:t1; -source include/diff_tables.inc; - -# CLEAN UP ---connection master -DROP TABLE t1; -DROP PROCEDURE p; - ---source include/rpl_end.inc diff --git a/mysql-test/suite/rpl/include/rpl_packet.inc b/mysql-test/suite/rpl/include/rpl_packet.inc deleted file mode 100644 index cbde486bcbbda..0000000000000 --- a/mysql-test/suite/rpl/include/rpl_packet.inc +++ /dev/null @@ -1,184 +0,0 @@ -# -# This include file is used by more than one test suite -# (currently rpl and binlog_encryption). -# Please check all dependent tests after modifying it -# - -# ==== Purpose ==== -# -# Check replication protocol packet size handling -# -# ==== Related bugs ==== -# Bug#19402 SQL close to the size of the max_allowed_packet fails on slave -# BUG#23755: Replicated event larger that max_allowed_packet infinitely re-transmits -# BUG#42914: No LAST_IO_ERROR for max_allowed_packet errors -# BUG#55322: SHOW BINLOG EVENTS increases @@SESSION.MAX_ALLOWED_PACKET - -# max-out size db name -source include/have_binlog_format_row.inc; -source include/master-slave.inc; - -call mtr.add_suppression("Slave I/O: Got a packet bigger than 'slave_max_allowed_packet' bytes, .*error.* 1153"); -call mtr.add_suppression("Log entry on master is longer than slave_max_allowed_packet"); -let $db= DB_NAME_OF_MAX_LENGTH_AKA_NAME_LEN_64_BYTES_____________________; -disable_warnings; -eval drop database if exists $db; -enable_warnings; -eval create database $db; - -connection master; -let $old_max_allowed_packet= `SELECT @@global.max_allowed_packet`; -let $old_net_buffer_length= `SELECT @@global.net_buffer_length`; -let $old_slave_max_allowed_packet= `SELECT @@global.slave_max_allowed_packet`; -SET @@global.max_allowed_packet=1024; -SET @@global.net_buffer_length=1024; - -sync_slave_with_master; -# Restart slave for setting to take effect -source include/stop_slave.inc; -source include/start_slave.inc; - -# Reconnect to master for new setting to take effect -disconnect master; - -# alas, can't use eval here; if db name changed apply the change here -connect (master,localhost,root,,DB_NAME_OF_MAX_LENGTH_AKA_NAME_LEN_64_BYTES_____________________); - -connection master; -select @@net_buffer_length, @@max_allowed_packet; - -create table `t1` (`f1` LONGTEXT) ENGINE=MyISAM; - -INSERT INTO `t1`(`f1`) VALUES ('aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa1023'); -sync_slave_with_master; - -eval select count(*) from `$db`.`t1` /* must be 1 */; - -SHOW STATUS LIKE 'Slave_running'; -select * from information_schema.session_status where variable_name= 'SLAVE_RUNNING'; -connection master; -eval drop database $db; -sync_slave_with_master; - -# -# Bug #23755: Replicated event larger that max_allowed_packet infinitely re-transmits -# -# Check that a situation when the size of event on the master is greater than -# max_allowed_packet on the slave does not lead to infinite re-transmits. - -connection master; - -# Change the max packet size on master - -SET @@global.max_allowed_packet=4096; -SET @@global.net_buffer_length=4096; - -# Restart slave for new setting to take effect -connection slave; -source include/stop_slave.inc; -source include/start_slave.inc; - -# Reconnect to master for new setting to take effect -disconnect master; -connect (master, localhost, root); -connection master; - -CREATE TABLE `t1` (`f1` LONGTEXT) ENGINE=MyISAM; - -sync_slave_with_master; - -connection master; - -INSERT INTO `t1`(`f1`) VALUES ('aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa2048'); - - -# -# Bug#42914: The slave I/O thread must stop after trying to read the above -# event, However there is no Last_IO_Error report. -# - -# The slave I/O thread must stop after trying to read the above event -connection slave; -# 1153 = ER_NET_PACKET_TOO_LARGE ---let $slave_io_errno= 1153 ---let $show_slave_io_error= 1 ---source include/wait_for_slave_io_error.inc - -# TODO: this is needed because of BUG#55790. Remove once that is fixed. ---source include/stop_slave_sql.inc - -# -# Bug#42914: On the master, if a binary log event is larger than -# max_allowed_packet, the error message ER_MASTER_FATAL_ERROR_READING_BINLOG -# is sent to a slave when it requests a dump from the master, thus leading the -# I/O thread to stop. However, there is no Last_IO_Error reported. -# - ---let $rpl_only_running_threads= 1 ---source include/rpl_reset.inc ---connection master -DROP TABLE t1; ---sync_slave_with_master - - -connection master; -CREATE TABLE t1 (f1 int PRIMARY KEY, f2 LONGTEXT, f3 LONGTEXT) ENGINE=MyISAM; -sync_slave_with_master; - -connection master; -INSERT INTO t1(f1, f2, f3) VALUES(1, REPEAT('a', @@global.max_allowed_packet), REPEAT('b', @@global.max_allowed_packet)); - -connection slave; -# The slave I/O thread must stop after receiving -# 1153 = ER_NET_PACKET_TOO_LARGE ---let $slave_io_errno= 1153 ---let $show_slave_io_error= 1 ---source include/wait_for_slave_io_error.inc - -# Remove the bad binlog and clear error status on slave. -STOP SLAVE; -RESET SLAVE; ---connection master -RESET MASTER; - - -# -# BUG#55322: SHOW BINLOG EVENTS increases @@SESSION.MAX_ALLOWED_PACKET -# -# In BUG#55322, @@session.max_allowed_packet increased each time SHOW -# BINLOG EVENTS was issued. To verify that this bug is fixed, we -# execute SHOW BINLOG EVENTS twice and check that max_allowed_packet -# never changes. We turn off the result log because we don't care -# about the contents of the binlog. - ---disable_result_log -SET @max_allowed_packet_0= @@session.max_allowed_packet; -SHOW BINLOG EVENTS; -SET @max_allowed_packet_1= @@session.max_allowed_packet; -SHOW BINLOG EVENTS; -SET @max_allowed_packet_2= @@session.max_allowed_packet; ---enable_result_log -if (`SELECT NOT(@max_allowed_packet_0 = @max_allowed_packet_1 AND @max_allowed_packet_1 = @max_allowed_packet_2)`) -{ - --echo ERROR: max_allowed_packet changed after executing SHOW BINLOG EVENTS - --source include/show_rpl_debug_info.inc - SELECT @max_allowed_packet_0, @max_allowed_packet_1, @max_allowed_packet_2; - --die @max_allowed_packet changed after executing SHOW BINLOG EVENTS -} - - ---echo ==== clean up ==== -connection master; -DROP TABLE t1; -eval SET @@global.max_allowed_packet= $old_max_allowed_packet; -eval SET @@global.net_buffer_length= $old_net_buffer_length; -eval SET @@global.slave_max_allowed_packet= $old_slave_max_allowed_packet; -# slave is stopped -connection slave; -DROP TABLE t1; - -# Clear Last_IO_Error -RESET SLAVE; - ---source include/rpl_end.inc -# End of tests diff --git a/mysql-test/suite/rpl/include/rpl_parallel_ignored_errors.inc b/mysql-test/suite/rpl/include/rpl_parallel_ignored_errors.inc deleted file mode 100644 index 7a6a758a508dd..0000000000000 --- a/mysql-test/suite/rpl/include/rpl_parallel_ignored_errors.inc +++ /dev/null @@ -1,112 +0,0 @@ -# ==== Purpose ==== -# -# Test verifies that, in parallel replication, transaction failure notification -# is propagated to all the workers. Workers should abort the execution of -# transaction event groups, whose event positions are higher than the failing -# transaction group. -# -# ==== Implementation ==== -# -# Steps: -# 0 - Create a table t1 on master which has a primary key. Enable parallel -# replication on slave with slave_parallel_mode='optimistic' and -# slave_parallel_threads=3. -# 1 - On slave start a transaction and execute a local INSERT statement -# which will insert value 32. This is done to block the INSERT coming -# from master. -# 2 - On master execute an INSERT statement with value 32, so that it is -# blocked on slave. -# 3 - On slave enable a debug sync point such that it holds the worker thread -# execution as soon as work is scheduled to it. -# 4 - INSERT value 33 on master. It will be held on slave by other worker -# thread due to debug simulation. -# 5 - INSERT value 34 on master. -# 6 - On slave, enusre that INSERT 34 has reached a state where it waits for -# its prior transactions to commit. -# 7 - Commit the local INSERT 32 on slave server so that first worker will -# error out. -# 8 - Now send a continue signal to second worker processing 33. It should -# wakeup and propagate the error to INSERT 34. -# 9 - Upon slave stop due to error, check that no rows are found after the -# failed INSERT 32. -# -# ==== References ==== -# -# MDEV-20645: Replication consistency is broken as workers miss the error -# notification from an earlier failed group. -# - ---source include/have_innodb.inc ---source include/have_debug.inc ---source include/have_debug_sync.inc ---source include/have_binlog_format_statement.inc ---source include/master-slave.inc - ---enable_connect_log ---connection server_2 ---source include/stop_slave.inc -SET @old_parallel_threads=@@GLOBAL.slave_parallel_threads; -SET @old_parallel_mode=@@GLOBAL.slave_parallel_mode; -SET @old_debug= @@GLOBAL.debug_dbug; -SET GLOBAL slave_parallel_mode='optimistic'; -SET GLOBAL slave_parallel_threads= 3; -CHANGE MASTER TO master_use_gtid=slave_pos; -CALL mtr.add_suppression("Commit failed due to failure of an earlier commit on which this one depends"); ---source include/start_slave.inc - ---connection server_1 -ALTER TABLE mysql.gtid_slave_pos ENGINE=InnoDB; -CREATE TABLE t1 (a int PRIMARY KEY) ENGINE=InnoDB; ---source include/save_master_gtid.inc - ---connection server_2 ---source include/sync_with_master_gtid.inc - ---connect (con_temp2,127.0.0.1,root,,test,$SERVER_MYPORT_2,) -BEGIN; -INSERT INTO t1 VALUES (32); - ---connection server_1 -INSERT INTO t1 VALUES (32); - ---connection server_2 ---let $wait_condition= SELECT COUNT(*) = 1 FROM information_schema.processlist WHERE info like "INSERT INTO t1 VALUES (32)" ---source include/wait_condition.inc -SET GLOBAL debug_dbug="+d,hold_worker_on_schedule"; -SET debug_sync="debug_sync_action SIGNAL reached_pause WAIT_FOR continue_worker"; - ---connection server_1 -SET gtid_seq_no=100; -INSERT INTO t1 VALUES (33); - ---connection server_2 -SET debug_sync='now WAIT_FOR reached_pause'; - ---connection server_1 -INSERT INTO t1 VALUES (34); - ---connection server_2 ---let $wait_condition= SELECT COUNT(*) = 1 FROM information_schema.processlist WHERE state like "Waiting for prior transaction to commit" ---source include/wait_condition.inc ---connection con_temp2 -COMMIT; - -# Clean up. ---connection server_2 ---source include/stop_slave.inc ---let $assert_cond= COUNT(*) = 0 FROM t1 WHERE a>32 ---let $assert_text= table t1 should have zero rows where a>32 ---source include/assert.inc -SELECT * FROM t1 WHERE a>32; -DELETE FROM t1 WHERE a=32; - -SET GLOBAL slave_parallel_threads=@old_parallel_threads; -SET GLOBAL slave_parallel_mode=@old_parallel_mode; -SET GLOBAL debug_dbug=@old_debug; -SET DEBUG_SYNC= 'RESET'; ---source include/start_slave.inc - ---connection server_1 -DROP TABLE t1; ---disable_connect_log ---source include/rpl_end.inc diff --git a/mysql-test/suite/rpl/include/rpl_parallel_show_binlog_events_purge_logs.inc b/mysql-test/suite/rpl/include/rpl_parallel_show_binlog_events_purge_logs.inc deleted file mode 100644 index cddc9286bd28d..0000000000000 --- a/mysql-test/suite/rpl/include/rpl_parallel_show_binlog_events_purge_logs.inc +++ /dev/null @@ -1,38 +0,0 @@ -# -# This include file is used by more than one test suite -# (currently rpl and binlog_encryption). -# Please check all dependent tests after modifying it -# - -# BUG#13979418: SHOW BINLOG EVENTS MAY CRASH THE SERVER -# -# The function mysql_show_binlog_events has a local stack variable -# 'LOG_INFO linfo;', which is assigned to thd->current_linfo, however -# this variable goes out of scope and is destroyed before clean -# thd->current_linfo. -# -# This test case runs SHOW BINLOG EVENTS and FLUSH LOGS to make sure -# that with the fix local variable linfo is valid along all -# mysql_show_binlog_events function scope. -# ---source include/have_debug.inc ---source include/have_debug_sync.inc ---source include/master-slave.inc - ---connection slave -SET DEBUG_SYNC= 'after_show_binlog_events SIGNAL on_show_binlog_events WAIT_FOR end'; ---send SHOW BINLOG EVENTS - ---connection slave1 -SET DEBUG_SYNC= 'now WAIT_FOR on_show_binlog_events'; -FLUSH LOGS; -SET DEBUG_SYNC= 'now SIGNAL end'; - ---connection slave ---disable_result_log ---reap ---enable_result_log -SET DEBUG_SYNC= 'RESET'; - ---connection master ---source include/rpl_end.inc diff --git a/mysql-test/suite/rpl/include/rpl_relayrotate.inc b/mysql-test/suite/rpl/include/rpl_relayrotate.inc deleted file mode 100644 index 4de554d314359..0000000000000 --- a/mysql-test/suite/rpl/include/rpl_relayrotate.inc +++ /dev/null @@ -1,18 +0,0 @@ -# -# This include file is used by more than one test suite -# (currently rpl and binlog_encryption). -# Please check all dependent tests after modifying it -# - -####################################################### -# Wrapper for rpl_relayrotate.test to allow multi # -# Engines to reuse test code. By JBM 2006-02-15 # -####################################################### --- source include/have_innodb.inc -# Slow test, don't run during staging part --- source include/not_staging.inc --- source include/master-slave.inc - -let $engine_type=innodb; --- source suite/rpl/include/rpl_relayrotate.test ---source include/rpl_end.inc diff --git a/mysql-test/suite/rpl/include/rpl_semi_sync.inc b/mysql-test/suite/rpl/include/rpl_semi_sync.inc deleted file mode 100644 index c3cd918b5fc5f..0000000000000 --- a/mysql-test/suite/rpl/include/rpl_semi_sync.inc +++ /dev/null @@ -1,525 +0,0 @@ -# -# This include file is used by more than one test suite -# (currently rpl and binlog_encryption). -# Please check all dependent tests after modifying it -# - -source include/not_embedded.inc; -source include/have_innodb.inc; -source include/master-slave.inc; - -let $engine_type= InnoDB; - -# Suppress warnings that might be generated during the test -connection master; -call mtr.add_suppression("Timeout waiting for reply of binlog"); -call mtr.add_suppression("Read semi-sync reply"); -call mtr.add_suppression("Unsafe statement written to the binary log using statement format since BINLOG_FORMAT = STATEMENT."); -call mtr.add_suppression("mysqld: Got an error reading communication packets"); -connection slave; -call mtr.add_suppression("Master server does not support semi-sync"); -call mtr.add_suppression("Semi-sync slave .* reply"); -call mtr.add_suppression("Slave SQL.*Request to stop slave SQL Thread received while applying a group that has non-transactional changes; waiting for completion of the group"); -connection master; - -# wait for dying connections (if any) to disappear -let $wait_condition= select count(*) = 0 from information_schema.processlist where command='killed'; ---source include/wait_condition.inc - -# After fix of BUG#45848, semi-sync slave should not create any extra -# connections on master, save the count of connections before start -# semi-sync slave for comparison below. -let $_connections_normal_slave= query_get_value(SHOW STATUS LIKE 'Threads_connected', Value, 1); - ---echo # ---echo # Uninstall semi-sync plugins on master and slave ---echo # -connection slave; -source include/stop_slave.inc; -reset slave; -set global rpl_semi_sync_master_enabled= 0; -set global rpl_semi_sync_slave_enabled= 0; - -connection master; -reset master; -set global rpl_semi_sync_master_enabled= 0; -set global rpl_semi_sync_slave_enabled= 0; - ---echo # ---echo # Main test of semi-sync replication start here ---echo # - -connection master; - -set global rpl_semi_sync_master_timeout= 60000; # 60s - -echo [ default state of semi-sync on master should be OFF ]; -show variables like 'rpl_semi_sync_master_enabled'; - -echo [ enable semi-sync on master ]; -set global rpl_semi_sync_master_enabled = 1; -show variables like 'rpl_semi_sync_master_enabled'; - -echo [ status of semi-sync on master should be ON even without any semi-sync slaves ]; -show status like 'Rpl_semi_sync_master_clients'; -show status like 'Rpl_semi_sync_master_status'; -show status like 'Rpl_semi_sync_master_yes_tx'; - ---echo # ---echo # BUG#45672 Semisync repl: ActiveTranx:insert_tranx_node: transaction node allocation failed ---echo # BUG#45673 Semisynch reports correct operation even if no slave is connected ---echo # - -# BUG#45672 When semi-sync is enabled on master, it would allocate -# transaction node even without semi-sync slave connected, and would -# finally result in transaction node allocation error. -# -# Semi-sync master will pre-allocate 'max_connections' transaction -# nodes, so here we do more than that much transactions to check if it -# will fail or not. -# select @@global.max_connections + 1; -let $i= `select @@global.max_connections + 1`; -disable_query_log; -eval create table t1 (a int) engine=$engine_type; -while ($i) -{ - eval insert into t1 values ($i); - dec $i; -} -drop table t1; -enable_query_log; - -# BUG#45673 -echo [ status of semi-sync on master should be OFF ]; -show status like 'Rpl_semi_sync_master_clients'; -show status like 'Rpl_semi_sync_master_status'; -show status like 'Rpl_semi_sync_master_yes_tx'; - -# reset master to make sure the following test will start with a clean environment -reset master; - -connection slave; - -echo [ default state of semi-sync on slave should be OFF ]; -show variables like 'rpl_semi_sync_slave_enabled'; - -echo [ enable semi-sync on slave ]; -set global rpl_semi_sync_slave_enabled = 1; -show variables like 'rpl_semi_sync_slave_enabled'; -source include/start_slave.inc; - -connection master; - -# NOTE: Rpl_semi_sync_master_client will only be updated when -# semi-sync slave has started binlog dump request -let $status_var= Rpl_semi_sync_master_clients; -let $status_var_value= 1; -source include/wait_for_status_var.inc; - -echo [ initial master state after the semi-sync slave connected ]; -show status like 'Rpl_semi_sync_master_clients'; -show status like 'Rpl_semi_sync_master_status'; -show status like 'Rpl_semi_sync_master_no_tx'; -show status like 'Rpl_semi_sync_master_yes_tx'; - -replace_result $engine_type ENGINE_TYPE; -eval create table t1(a int) engine = $engine_type; - -echo [ master state after CREATE TABLE statement ]; -show status like 'Rpl_semi_sync_master_status'; -show status like 'Rpl_semi_sync_master_no_tx'; -show status like 'Rpl_semi_sync_master_yes_tx'; - -# After fix of BUG#45848, semi-sync slave should not create any extra -# connections on master. -let $_connections_semisync_slave= query_get_value(SHOW STATUS LIKE 'Threads_connected', Value, 1); -replace_result $_connections_normal_slave CONNECTIONS_NORMAL_SLAVE $_connections_semisync_slave CONNECTIONS_SEMISYNC_SLAVE; -eval select $_connections_semisync_slave - $_connections_normal_slave as 'Should be 0'; - -echo [ insert records to table ]; -insert t1 values (10); -insert t1 values (9); -insert t1 values (8); -insert t1 values (7); -insert t1 values (6); -insert t1 values (5); -insert t1 values (4); -insert t1 values (3); -insert t1 values (2); -insert t1 values (1); - -echo [ master status after inserts ]; -show status like 'Rpl_semi_sync_master_status'; -show status like 'Rpl_semi_sync_master_no_tx'; -show status like 'Rpl_semi_sync_master_yes_tx'; - -sync_slave_with_master; - -echo [ slave status after replicated inserts ]; -show status like 'Rpl_semi_sync_slave_status'; - -select count(distinct a) from t1; -select min(a) from t1; -select max(a) from t1; - ---echo ---echo # BUG#50157 ---echo # semi-sync replication crashes when replicating a transaction which ---echo # include 'CREATE TEMPORARY TABLE `MyISAM_t` SELECT * FROM `Innodb_t` ; - -connection master; -SET SESSION AUTOCOMMIT= 0; -CREATE TABLE t2(c1 INT) ENGINE=innodb; -sync_slave_with_master; - -connection master; -BEGIN; ---echo ---echo # Even though it is in a transaction, this statement is binlogged into binlog ---echo # file immediately. ---disable_warnings -CREATE TEMPORARY TABLE t3 SELECT c1 FROM t2 where 1=1; ---enable_warnings ---echo ---echo # These statements will not be binlogged until the transaction is committed -INSERT INTO t2 VALUES(11); -INSERT INTO t2 VALUES(22); -COMMIT; - -DROP TABLE t2, t3; -SET SESSION AUTOCOMMIT= 1; -sync_slave_with_master; - - ---echo # ---echo # Test semi-sync master will switch OFF after one transaction ---echo # timeout waiting for slave reply. ---echo # -connection slave; -source include/stop_slave.inc; - -connection master; ---source include/kill_binlog_dump_threads.inc -set global rpl_semi_sync_master_timeout= 5000; - -# The first semi-sync check should be on because after slave stop, -# there are no transactions on the master. -echo [ master status should be ON ]; - -let $status_var= Rpl_semi_sync_master_status; -let $status_var_value= ON; -source include/wait_for_status_var.inc; - -let $status_var= Rpl_semi_sync_master_clients; -let $status_var_value= 0; -source include/wait_for_status_var.inc; - -show status like 'Rpl_semi_sync_master_no_tx'; -show status like 'Rpl_semi_sync_master_yes_tx'; - -echo [ semi-sync replication of these transactions will fail ]; -insert into t1 values (500); - -# Wait for the semi-sync replication of this transaction to timeout -let $status_var= Rpl_semi_sync_master_status; -let $status_var_value= OFF; -source include/wait_for_status_var.inc; - -# The second semi-sync check should be off because one transaction -# times out during waiting. -echo [ master status should be OFF ]; -show status like 'Rpl_semi_sync_master_status'; -show status like 'Rpl_semi_sync_master_no_tx'; -show status like 'Rpl_semi_sync_master_yes_tx'; - -# Semi-sync status on master is now OFF, so all these transactions -# will be replicated asynchronously. -delete from t1 where a=10; -delete from t1 where a=9; -delete from t1 where a=8; -delete from t1 where a=7; -delete from t1 where a=6; -delete from t1 where a=5; -delete from t1 where a=4; -delete from t1 where a=3; -delete from t1 where a=2; -delete from t1 where a=1; - -insert into t1 values (100); - -echo [ master status should be OFF ]; -show status like 'Rpl_semi_sync_master_status'; -show status like 'Rpl_semi_sync_master_no_tx'; -show status like 'Rpl_semi_sync_master_yes_tx'; - ---echo # ---echo # Test semi-sync status on master will be ON again when slave catches up ---echo # - -# Save the master position for later use. -save_master_pos; - -connection slave; - -echo [ slave status should be OFF ]; -show status like 'Rpl_semi_sync_slave_status'; -source include/start_slave.inc; -sync_with_master; - -echo [ slave status should be ON ]; -show status like 'Rpl_semi_sync_slave_status'; - -select count(distinct a) from t1; -select min(a) from t1; -select max(a) from t1; - -connection master; - -# The master semi-sync status should be on again after slave catches up. -echo [ master status should be ON again after slave catches up ]; - -let $status_var= Rpl_semi_sync_master_status; -let $status_var_value= ON; -source include/wait_for_status_var.inc; -show status like 'Rpl_semi_sync_master_no_tx'; -show status like 'Rpl_semi_sync_master_yes_tx'; -show status like 'Rpl_semi_sync_master_clients'; - ---echo # ---echo # Test disable/enable master semi-sync on the fly. ---echo # - -drop table t1; -sync_slave_with_master; - -source include/stop_slave.inc; - ---echo # ---echo # Flush status ---echo # -connection master; -echo [ Semi-sync master status variables before FLUSH STATUS ]; -SHOW STATUS LIKE 'Rpl_semi_sync_master_no_tx'; -SHOW STATUS LIKE 'Rpl_semi_sync_master_yes_tx'; -# Do not write the FLUSH STATUS to binlog, to make sure we'll get a -# clean status after this. -FLUSH NO_WRITE_TO_BINLOG STATUS; -echo [ Semi-sync master status variables after FLUSH STATUS ]; -SHOW STATUS LIKE 'Rpl_semi_sync_master_no_tx'; -SHOW STATUS LIKE 'Rpl_semi_sync_master_yes_tx'; - -connection master; - -source include/show_master_logs.inc; -show variables like 'rpl_semi_sync_master_enabled'; - -echo [ disable semi-sync on the fly ]; -set global rpl_semi_sync_master_enabled=0; -show variables like 'rpl_semi_sync_master_enabled'; -show status like 'Rpl_semi_sync_master_status'; - -echo [ enable semi-sync on the fly ]; -set global rpl_semi_sync_master_enabled=1; -show variables like 'rpl_semi_sync_master_enabled'; -show status like 'Rpl_semi_sync_master_status'; - ---echo # ---echo # Test RESET MASTER/SLAVE ---echo # - -connection slave; - -source include/start_slave.inc; - -connection master; - -replace_result $engine_type ENGINE_TYPE; -eval create table t1 (a int) engine = $engine_type; -drop table t1; - -sync_slave_with_master; - -echo [ test reset master ]; -connection master; - -reset master; - -show status like 'Rpl_semi_sync_master_status'; -show status like 'Rpl_semi_sync_master_no_tx'; -show status like 'Rpl_semi_sync_master_yes_tx'; - -connection slave; - -source include/stop_slave.inc; -reset slave; - -# Kill the dump thread on master for previous slave connection and ---source include/kill_binlog_dump_threads.inc - -connection slave; -source include/start_slave.inc; - -connection master; - -# Wait for dump thread to start, Rpl_semi_sync_master_clients will be -# 1 after dump thread started. -let $status_var= Rpl_semi_sync_master_clients; -let $status_var_value= 1; -source include/wait_for_status_var.inc; - -replace_result $engine_type ENGINE_TYPE; -eval create table t1 (a int) engine = $engine_type; -insert into t1 values (1); -insert into t1 values (2), (3); - -sync_slave_with_master; - -select * from t1; - -connection master; - -echo [ master semi-sync status should be ON ]; -show status like 'Rpl_semi_sync_master_status'; -show status like 'Rpl_semi_sync_master_no_tx'; -show status like 'Rpl_semi_sync_master_yes_tx'; - ---echo # ---echo # Start semi-sync replication without SUPER privilege ---echo # -connection slave; -source include/stop_slave.inc; -reset slave; -connection master; -reset master; - -# Kill the dump thread on master for previous slave connection and wait for it to exit ---source include/kill_binlog_dump_threads.inc - -# Do not binlog the following statement because it will generate -# different events for ROW and STATEMENT format -set sql_log_bin=0; -grant replication slave on *.* to rpl@127.0.0.1 identified by 'rpl_password'; -flush privileges; -set sql_log_bin=1; -connection slave; -grant replication slave on *.* to rpl@127.0.0.1 identified by 'rpl_password'; -flush privileges; -change master to master_user='rpl',master_password='rpl_password'; -source include/start_slave.inc; -show status like 'Rpl_semi_sync_slave_status'; -connection master; - -# Wait for the semi-sync binlog dump thread to start -let $status_var= Rpl_semi_sync_master_clients; -let $status_var_value= 1; -source include/wait_for_status_var.inc; -echo [ master semi-sync should be ON ]; -show status like 'Rpl_semi_sync_master_clients'; -show status like 'Rpl_semi_sync_master_status'; -show status like 'Rpl_semi_sync_master_no_tx'; -show status like 'Rpl_semi_sync_master_yes_tx'; -insert into t1 values (4); -insert into t1 values (5); -echo [ master semi-sync should be ON ]; -show status like 'Rpl_semi_sync_master_clients'; -show status like 'Rpl_semi_sync_master_status'; -show status like 'Rpl_semi_sync_master_no_tx'; -show status like 'Rpl_semi_sync_master_yes_tx'; - ---echo # ---echo # Test semi-sync slave connect to non-semi-sync master ---echo # - -# Disable semi-sync on master -connection slave; -source include/stop_slave.inc; -SHOW STATUS LIKE 'Rpl_semi_sync_slave_status'; - -connection master; - -# Kill the dump thread on master for previous slave connection and wait for it to exit ---source include/kill_binlog_dump_threads.inc - -echo [ Semi-sync status on master should be ON ]; -let $status_var= Rpl_semi_sync_master_clients; -let $status_var_value= 0; -source include/wait_for_status_var.inc; -show status like 'Rpl_semi_sync_master_status'; -let $status_var= Rpl_semi_sync_master_status; -let $status_var_value= ON; -source include/wait_for_status_var.inc; -set global rpl_semi_sync_master_enabled= 0; - -connection slave; -SHOW VARIABLES LIKE 'rpl_semi_sync_slave_enabled'; -source include/start_slave.inc; -connection master; -insert into t1 values (8); -let $status_var= Rpl_semi_sync_master_clients; -let $status_var_value= 1; -source include/wait_for_status_var.inc; -echo [ master semi-sync clients should be 1, status should be OFF ]; -show status like 'Rpl_semi_sync_master_clients'; -show status like 'Rpl_semi_sync_master_status'; -sync_slave_with_master; -show status like 'Rpl_semi_sync_slave_status'; - -# Uninstall semi-sync plugin on master -connection slave; -source include/stop_slave.inc; -connection master; -set global rpl_semi_sync_master_enabled= 0; - -connection slave; -SHOW VARIABLES LIKE 'rpl_semi_sync_slave_enabled'; -source include/start_slave.inc; - -connection master; -insert into t1 values (10); -sync_slave_with_master; - ---echo # ---echo # Test non-semi-sync slave connect to semi-sync master ---echo # - -connection master; -set global rpl_semi_sync_master_timeout= 5000; # 5s -set global rpl_semi_sync_master_enabled= 1; - -connection slave; -source include/stop_slave.inc; -SHOW STATUS LIKE 'Rpl_semi_sync_slave_status'; - -echo [ uninstall semi-sync slave plugin ]; -set global rpl_semi_sync_slave_enabled= 0; - -echo [ reinstall semi-sync slave plugin and disable semi-sync ]; -SHOW VARIABLES LIKE 'rpl_semi_sync_slave_enabled'; -SHOW STATUS LIKE 'Rpl_semi_sync_slave_status'; -source include/start_slave.inc; -SHOW STATUS LIKE 'Rpl_semi_sync_slave_status'; - ---echo # ---echo # Clean up ---echo # - -connection slave; -source include/stop_slave.inc; -set global rpl_semi_sync_slave_enabled= 0; - -connection master; -set global rpl_semi_sync_master_enabled= 0; - -connection slave; -change master to master_user='root',master_password=''; -source include/start_slave.inc; - -connection master; -drop table t1; -sync_slave_with_master; - -connection master; -drop user rpl@127.0.0.1; -flush privileges; -set global rpl_semi_sync_master_timeout= default; ---source include/rpl_end.inc diff --git a/mysql-test/suite/rpl/include/rpl_skip_replication.inc b/mysql-test/suite/rpl/include/rpl_skip_replication.inc deleted file mode 100644 index 97fc961d43856..0000000000000 --- a/mysql-test/suite/rpl/include/rpl_skip_replication.inc +++ /dev/null @@ -1,402 +0,0 @@ -# -# This include file is used by more than one test suite -# (currently rpl and binlog_encryption). -# Please check all dependent tests after modifying it. -# -# Usage: -# -# --let $use_remote_mysqlbinlog= 1 # optional -# --source suite/rpl/include/rpl_skip_replication.inc -# -# The script uses MYSQLBINLOG to verify certain results. -# By default, it uses binary logs directly. If it is undesirable, -# this behavior can be overridden by setting $use_remote_binlog -# as shown above. -# The value will be unset after every execution of the script, -# so if it is needed, it should be set explicitly before each call. -# - ---source include/have_innodb.inc ---source include/master-slave.inc - -connection slave; -# Test that SUPER is required to change @@replicate_events_marked_for_skip. -CREATE USER 'nonsuperuser'@'127.0.0.1'; -GRANT ALTER,CREATE,DELETE,DROP,EVENT,INSERT,PROCESS,REPLICATION SLAVE, - SELECT,UPDATE ON *.* TO 'nonsuperuser'@'127.0.0.1'; -connect(nonpriv, 127.0.0.1, nonsuperuser,, test, $SLAVE_MYPORT,); -connection nonpriv; ---error ER_SPECIFIC_ACCESS_DENIED_ERROR -SET GLOBAL replicate_events_marked_for_skip=FILTER_ON_MASTER; -disconnect nonpriv; -connection slave; -DROP USER'nonsuperuser'@'127.0.0.1'; - -SELECT @@global.replicate_events_marked_for_skip; ---error ER_SLAVE_MUST_STOP -SET GLOBAL replicate_events_marked_for_skip=FILTER_ON_SLAVE; -SELECT @@global.replicate_events_marked_for_skip; -STOP SLAVE; ---error ER_GLOBAL_VARIABLE -SET SESSION replicate_events_marked_for_skip=FILTER_ON_MASTER; -SELECT @@global.replicate_events_marked_for_skip; -SET GLOBAL replicate_events_marked_for_skip=FILTER_ON_MASTER; -SELECT @@global.replicate_events_marked_for_skip; -START SLAVE; - -connection master; -SELECT @@skip_replication; ---error ER_LOCAL_VARIABLE -SET GLOBAL skip_replication=1; -SELECT @@skip_replication; - -CREATE TABLE t1 (a INT PRIMARY KEY, b INT) ENGINE=myisam; -CREATE TABLE t2 (a INT PRIMARY KEY, b INT) ENGINE=innodb; -INSERT INTO t1(a) VALUES (1); -INSERT INTO t2(a) VALUES (1); - - -# Test that master-side filtering works. -SET skip_replication=1; - -CREATE TABLE t3 (a INT PRIMARY KEY, b INT) ENGINE=myisam; -INSERT INTO t1(a) VALUES (2); -INSERT INTO t2(a) VALUES (2); - -# Inject a rotate event in the binlog stream sent to slave (otherwise we will -# fail sync_slave_with_master as the last event on the master is not present -# on the slave). -FLUSH NO_WRITE_TO_BINLOG LOGS; - -sync_slave_with_master; -connection slave; -SHOW TABLES; -SELECT * FROM t1; -SELECT * FROM t2; - -connection master; -DROP TABLE t3; - -FLUSH NO_WRITE_TO_BINLOG LOGS; -sync_slave_with_master; - - -# Test that slave-side filtering works. -connection slave; -STOP SLAVE; -SET GLOBAL replicate_events_marked_for_skip=FILTER_ON_SLAVE; -START SLAVE; - -connection master; -SET skip_replication=1; -CREATE TABLE t3 (a INT PRIMARY KEY, b INT) ENGINE=myisam; -INSERT INTO t1(a) VALUES (3); -INSERT INTO t2(a) VALUES (3); - -# Inject a rotate event in the binlog stream sent to slave (otherwise we will -# fail sync_slave_with_master as the last event on the master is not present -# on the slave). -FLUSH NO_WRITE_TO_BINLOG LOGS; - -sync_slave_with_master; -connection slave; -SHOW TABLES; -SELECT * FROM t1; -SELECT * FROM t2; - -connection master; -DROP TABLE t3; - -FLUSH NO_WRITE_TO_BINLOG LOGS; -sync_slave_with_master; -connection slave; -STOP SLAVE; -SET GLOBAL replicate_events_marked_for_skip=REPLICATE; -START SLAVE; - - -# Test that events with @@skip_replication=1 are not filtered when filtering is -# not set on slave. -connection master; -SET skip_replication=1; -CREATE TABLE t3 (a INT PRIMARY KEY, b INT) ENGINE=myisam; -INSERT INTO t3(a) VALUES(2); -sync_slave_with_master; -connection slave; -SELECT * FROM t3; -connection master; -DROP TABLE t3; - -# -# Test that the slave will preserve the @@skip_replication flag in its -# own binlog. -# - -TRUNCATE t1; -sync_slave_with_master; -connection slave; -RESET MASTER; - -connection master; -SET skip_replication=0; -INSERT INTO t1 VALUES (1,0); -SET skip_replication=1; -INSERT INTO t1 VALUES (2,0); -SET skip_replication=0; -INSERT INTO t1 VALUES (3,0); - -sync_slave_with_master; -connection slave; -# Since slave has @@replicate_events_marked_for_skip=REPLICATE, it should have -# applied all events. -SELECT * FROM t1 ORDER by a; - -STOP SLAVE; -SET GLOBAL replicate_events_marked_for_skip=FILTER_ON_MASTER; -let $SLAVE_DATADIR= `select @@datadir`; - -connection master; -TRUNCATE t1; - -# Now apply the slave binlog to the master, to check that both the slave -# and mysqlbinlog will preserve the @@skip_replication flag. - ---let $mysqlbinlog_args= $SLAVE_DATADIR/slave-bin.000001 -if ($use_remote_mysqlbinlog) -{ - --let $mysqlbinlog_args= --read-from-remote-server --protocol=tcp --host=127.0.0.1 --port=$SLAVE_MYPORT -uroot slave-bin.000001 - --let $use_remote_mysqlbinlog= 0 -} ---exec $MYSQL_BINLOG $mysqlbinlog_args > $MYSQLTEST_VARDIR/tmp/rpl_skip_replication.binlog ---exec $MYSQL test < $MYSQLTEST_VARDIR/tmp/rpl_skip_replication.binlog - -# The master should have all three events. -SELECT * FROM t1 ORDER by a; - -# The slave should be missing event 2, which is marked with the -# @@skip_replication flag. - -connection slave; -START SLAVE; - -connection master; -sync_slave_with_master; - -connection slave; -SELECT * FROM t1 ORDER by a; - -# -# Test that @@sql_slave_skip_counter does not count skipped @@skip_replication -# events. -# - -connection master; -TRUNCATE t1; - -sync_slave_with_master; -connection slave; -STOP SLAVE; -# We will skip two INSERTs (in addition to any skipped due to -# @@skip_replication). Since from 5.5 every statement is wrapped in -# BEGIN ... END, we need to skip 6 events for this. -SET GLOBAL sql_slave_skip_counter=6; -SET GLOBAL replicate_events_marked_for_skip=FILTER_ON_SLAVE; -START SLAVE; - -connection master; -# Need to fix @@binlog_format to get consistent event count. -SET @old_binlog_format= @@binlog_format; -SET binlog_format= statement; -SET skip_replication=0; -INSERT INTO t1 VALUES (1,5); -SET skip_replication=1; -INSERT INTO t1 VALUES (2,5); -SET skip_replication=0; -INSERT INTO t1 VALUES (3,5); -INSERT INTO t1 VALUES (4,5); -SET binlog_format= @old_binlog_format; - -sync_slave_with_master; -connection slave; - -# The slave should have skipped the first three inserts (number 1 and 3 due -# to @@sql_slave_skip_counter=2, number 2 due to -# @@replicate_events_marked_for_skip=FILTER_ON_SLAVE). So only number 4 -# should be left. -SELECT * FROM t1; - - -# -# Check that BINLOG statement preserves the @@skip_replication flag. -# -connection slave; -# Need row @@binlog_format for BINLOG statements containing row events. ---source include/stop_slave.inc -SET @old_slave_binlog_format= @@global.binlog_format; -SET GLOBAL binlog_format= row; ---source include/start_slave.inc - -connection master; -TRUNCATE t1; - -SET @old_binlog_format= @@binlog_format; -SET binlog_format= row; -# Format description log event. -BINLOG 'wlZOTw8BAAAA8QAAAPUAAAAAAAQANS41LjIxLU1hcmlhREItZGVidWctbG9nAAAAAAAAAAAAAAAA -AAAAAAAAAAAAAAAAAAAAAAAAEzgNAAgAEgAEBAQEEgAA2QAEGggAAAAICAgCAAAAAAAAAAAAAAAA -AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA -AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA -AAAAAAAAAAAA371saA=='; -# INSERT INTO t1 VALUES (1,8) # with @@skip_replication=1 -BINLOG 'wlZOTxMBAAAAKgAAAGMBAAAAgCkAAAAAAAEABHRlc3QAAnQxAAIDAwAC -wlZOTxcBAAAAJgAAAIkBAAAAgCkAAAAAAAEAAv/8AQAAAAgAAAA='; -# INSERT INTO t1 VALUES (2,8) # with @@skip_replication=0 -BINLOG 'wlZOTxMBAAAAKgAAADwCAAAAACkAAAAAAAEABHRlc3QAAnQxAAIDAwAC -wlZOTxcBAAAAJgAAAGICAAAAACkAAAAAAAEAAv/8AgAAAAgAAAA='; -SET binlog_format= @old_binlog_format; - -SELECT * FROM t1 ORDER BY a; -sync_slave_with_master; -connection slave; -# Slave should have only the second insert, the first should be ignored due to -# the @@skip_replication flag. -SELECT * FROM t1 ORDER by a; - ---source include/stop_slave.inc -SET GLOBAL binlog_format= @old_slave_binlog_format; ---source include/start_slave.inc - - -# Test that it is not possible to change @@skip_replication inside a -# transaction or statement, thereby replicating only parts of statements -# or transactions. -connection master; -SET skip_replication=0; - -BEGIN; ---error ER_INSIDE_TRANSACTION_PREVENTS_SWITCH_SKIP_REPLICATION -SET skip_replication=0; ---error ER_INSIDE_TRANSACTION_PREVENTS_SWITCH_SKIP_REPLICATION -SET skip_replication=1; -ROLLBACK; -SET skip_replication=1; -BEGIN; ---error ER_INSIDE_TRANSACTION_PREVENTS_SWITCH_SKIP_REPLICATION -SET skip_replication=0; ---error ER_INSIDE_TRANSACTION_PREVENTS_SWITCH_SKIP_REPLICATION -SET skip_replication=1; -COMMIT; -SET autocommit=0; -INSERT INTO t2(a) VALUES(100); ---error ER_INSIDE_TRANSACTION_PREVENTS_SWITCH_SKIP_REPLICATION -SET skip_replication=1; -ROLLBACK; -SET autocommit=1; - -SET skip_replication=1; ---delimiter | -CREATE FUNCTION foo (x INT) RETURNS INT BEGIN SET SESSION skip_replication=x; RETURN x; END| -CREATE PROCEDURE bar(x INT) BEGIN SET SESSION skip_replication=x; END| -CREATE FUNCTION baz (x INT) RETURNS INT BEGIN CALL bar(x); RETURN x; END| ---delimiter ; ---error ER_STORED_FUNCTION_PREVENTS_SWITCH_SKIP_REPLICATION -SELECT foo(0); ---error ER_STORED_FUNCTION_PREVENTS_SWITCH_SKIP_REPLICATION -SELECT baz(0); ---error ER_STORED_FUNCTION_PREVENTS_SWITCH_SKIP_REPLICATION -SET @a= foo(1); ---error ER_STORED_FUNCTION_PREVENTS_SWITCH_SKIP_REPLICATION -SET @a= baz(1); ---error ER_STORED_FUNCTION_PREVENTS_SWITCH_SKIP_REPLICATION -UPDATE t2 SET b=foo(0); ---error ER_STORED_FUNCTION_PREVENTS_SWITCH_SKIP_REPLICATION -UPDATE t2 SET b=baz(0); ---error ER_STORED_FUNCTION_PREVENTS_SWITCH_SKIP_REPLICATION -INSERT INTO t1 VALUES (101, foo(1)); ---error ER_STORED_FUNCTION_PREVENTS_SWITCH_SKIP_REPLICATION -INSERT INTO t1 VALUES (101, baz(0)); -SELECT @@skip_replication; -CALL bar(0); -SELECT @@skip_replication; -CALL bar(1); -SELECT @@skip_replication; -DROP FUNCTION foo; -DROP PROCEDURE bar; -DROP FUNCTION baz; - - -# Test that master-side filtering happens on the master side, and that -# slave-side filtering happens on the slave. - -# First test that events do not reach the slave when master-side filtering -# is configured. Do this by replicating first with only the IO thread running -# and master-side filtering; then change to no filtering and start the SQL -# thread. This should still skip the events, as master-side filtering -# means the events never reached the slave. -connection master; -SET skip_replication= 0; -TRUNCATE t1; -sync_slave_with_master; -connection slave; -STOP SLAVE; -SET GLOBAL replicate_events_marked_for_skip=FILTER_ON_MASTER; -START SLAVE IO_THREAD; -connection master; -SET skip_replication= 1; -INSERT INTO t1(a) VALUES (1); -SET skip_replication= 0; -INSERT INTO t1(a) VALUES (2); ---source include/save_master_pos.inc -connection slave; ---source include/sync_io_with_master.inc -STOP SLAVE IO_THREAD; -SET GLOBAL replicate_events_marked_for_skip=REPLICATE; -START SLAVE; -connection master; -sync_slave_with_master; -connection slave; -# Now only the second insert of (2) should be visible, as the first was -# filtered on the master, so even though the SQL thread ran without skipping -# events, it will never see the event in the first place. -SELECT * FROM t1; - -# Now tests that when slave-side filtering is configured, events _do_ reach -# the slave. -connection master; -SET skip_replication= 0; -TRUNCATE t1; -sync_slave_with_master; -connection slave; -STOP SLAVE; -SET GLOBAL replicate_events_marked_for_skip=FILTER_ON_SLAVE; -START SLAVE IO_THREAD; -connection master; -SET skip_replication= 1; -INSERT INTO t1(a) VALUES (1); -SET skip_replication= 0; -INSERT INTO t1(a) VALUES (2); ---source include/save_master_pos.inc -connection slave; ---source include/sync_io_with_master.inc -STOP SLAVE IO_THREAD; -SET GLOBAL replicate_events_marked_for_skip=REPLICATE; -START SLAVE; -connection master; -sync_slave_with_master; -connection slave; -# Now both inserts should be visible. Since filtering was configured to be -# slave-side, the event is in the relay log, and when the SQL thread ran we -# had disabled filtering again. -SELECT * FROM t1 ORDER BY a; - - -# Clean up. -connection master; -SET skip_replication=0; -DROP TABLE t1,t2; -connection slave; -STOP SLAVE; -SET GLOBAL replicate_events_marked_for_skip=REPLICATE; -START SLAVE; - ---source include/rpl_end.inc diff --git a/mysql-test/suite/rpl/include/rpl_special_charset.inc b/mysql-test/suite/rpl/include/rpl_special_charset.inc deleted file mode 100644 index 641aa483d32b7..0000000000000 --- a/mysql-test/suite/rpl/include/rpl_special_charset.inc +++ /dev/null @@ -1,32 +0,0 @@ -# -# This include file is used by more than one test suite -# (currently rpl and binlog_encryption). -# Please check all dependent tests after modifying it -# - -################################################################################ -# Bug#19855907 IO THREAD AUTHENTICATION ISSUE WITH SOME CHARACTER SETS -# Problem: IO thread fails to connect to master if servers are configured with -# special character sets like utf16, utf32, ucs2. -# -# Analysis: MySQL server does not support few special character sets like -# utf16,utf32 and ucs2 as "client's character set"(eg: utf16,utf32, ucs2). -# When IO thread is trying to connect to Master, it sets server's character -# set as client's character set. When Slave server is started with these -# special character sets, IO thread (a connection to Master) fails because -# of the above said reason. -# -# Fix: If server's character set is not supported as client's character set, -# then set default's client character set(latin1) as client's character set. -############################################################################### ---source include/master-slave.inc -call mtr.add_suppression("'utf16' can not be used as client character set"); -CREATE TABLE t1(i VARCHAR(20)); -INSERT INTO t1 VALUES (0xFFFF); ---sync_slave_with_master ---let diff_tables=master:t1, slave:t1 ---source include/diff_tables.inc -# Cleanup ---connection master -DROP TABLE t1; ---source include/rpl_end.inc diff --git a/mysql-test/suite/rpl/include/rpl_sporadic_master.inc b/mysql-test/suite/rpl/include/rpl_sporadic_master.inc deleted file mode 100644 index ad4c44cbf7409..0000000000000 --- a/mysql-test/suite/rpl/include/rpl_sporadic_master.inc +++ /dev/null @@ -1,32 +0,0 @@ -# -# This include file is used by more than one test suite -# (currently rpl and binlog_encryption). -# Please check all dependent tests after modifying it -# - -# test to see if replication can continue when master sporadically fails on -# COM_BINLOG_DUMP and additionally limits the number of events per dump - -source include/master-slave.inc; - -create table t2(n int); -create table t1(n int not null auto_increment primary key); -insert into t1 values (NULL),(NULL); -truncate table t1; -# We have to use 4 in the following to make this test work with all table types -insert into t1 values (4),(NULL); -sync_slave_with_master; ---source include/stop_slave.inc ---source include/start_slave.inc -connection master; -insert into t1 values (NULL),(NULL); -flush logs; -truncate table t1; -insert into t1 values (10),(NULL),(NULL),(NULL),(NULL),(NULL); -sync_slave_with_master; -select * from t1 ORDER BY n; -connection master; -drop table t1,t2; -sync_slave_with_master; - ---source include/rpl_end.inc diff --git a/mysql-test/suite/rpl/include/rpl_ssl.inc b/mysql-test/suite/rpl/include/rpl_ssl.inc deleted file mode 100644 index 59a2af9f137c0..0000000000000 --- a/mysql-test/suite/rpl/include/rpl_ssl.inc +++ /dev/null @@ -1,116 +0,0 @@ -# -# This include file is used by more than one test suite -# (currently rpl and binlog_encryption). -# Please check all dependent tests after modifying it -# - -source include/have_ssl_communication.inc; -source include/master-slave.inc; -source include/no_valgrind_without_big.inc; - -# create a user for replication that requires ssl encryption -connection master; -create user replssl@localhost; -grant replication slave on *.* to replssl@localhost require ssl; -create table t1 (t int auto_increment, KEY(t)); - -sync_slave_with_master; - -# Set slave to use SSL for connection to master -stop slave; ---replace_result $MYSQL_TEST_DIR MYSQL_TEST_DIR -eval change master to - master_user='replssl', - master_password='', - master_ssl=1, - master_ssl_ca ='$MYSQL_TEST_DIR/std_data/cacert.pem', - master_ssl_cert='$MYSQL_TEST_DIR/std_data/client-cert.pem', - master_ssl_key='$MYSQL_TEST_DIR/std_data/client-key.pem'; -start slave; - -# Switch to master and insert one record, then sync it to slave -connection master; -insert into t1 values(1); -sync_slave_with_master; - -# The record should now be on slave -select * from t1; - -# The slave is synced and waiting/reading from master -# SHOW SLAVE STATUS will show "Waiting for master to send event" -let $status_items= Master_SSL_Allowed, Master_SSL_CA_Path, Master_SSL_CA_File, Master_SSL_Crl, Master_SSL_Crlpath, Master_SSL_Cert, Master_SSL_Key; -source include/show_slave_status.inc; -source include/check_slave_is_running.inc; - -# Stop the slave, as reported in bug#21871 it would hang -STOP SLAVE; - -select * from t1; - -# Do the same thing a number of times -disable_query_log; -disable_result_log; -# 2007-11-27 mats Bug #32756 Starting and stopping the slave in a loop can lose rows -# After discussions with Engineering, I'm disabling this part of the test to avoid it causing -# red trees. -disable_parsing; -let $i= 100; -while ($i) -{ - start slave; - connection master; - insert into t1 values (NULL); - select * from t1; # Some variance - connection slave; - select * from t1; # Some variance - stop slave; - dec $i; -} -enable_parsing; -START SLAVE; -enable_query_log; -enable_result_log; -connection master; -# INSERT one more record to make sure -# the sync has something to do -insert into t1 values (NULL); -let $master_count= `select count(*) from t1`; - -sync_slave_with_master; ---source include/wait_for_slave_to_start.inc -source include/show_slave_status.inc; -source include/check_slave_is_running.inc; - -let $slave_count= `select count(*) from t1`; - -if ($slave_count != $master_count) -{ - echo master and slave differed in number of rows; - echo master: $master_count; - echo slave: $slave_count; - - connection master; - select count(*) t1; - select * from t1; - connection slave; - select count(*) t1; - select * from t1; - query_vertical show slave status; -} - -connection master; -drop user replssl@localhost; -drop table t1; -sync_slave_with_master; - ---source include/stop_slave.inc -CHANGE MASTER TO - master_user = 'root', - master_ssl = 0, - master_ssl_ca = '', - master_ssl_cert = '', - master_ssl_key = ''; - ---echo End of 5.0 tests ---let $rpl_only_running_threads= 1 ---source include/rpl_end.inc diff --git a/mysql-test/suite/rpl/include/rpl_stm_relay_ign_space.inc b/mysql-test/suite/rpl/include/rpl_stm_relay_ign_space.inc deleted file mode 100644 index 41339f539f804..0000000000000 --- a/mysql-test/suite/rpl/include/rpl_stm_relay_ign_space.inc +++ /dev/null @@ -1,107 +0,0 @@ -# -# This include file is used by more than one test suite -# (currently rpl and binlog_encryption). -# Please check all dependent tests after modifying it -# - -# -# BUG#12400313 / BUG#64503 test case -# -# -# Description -# ----------- -# -# This test case starts the slave server with: -# --relay-log-space-limit=8192 --relay-log-purge --max-relay-log-size=4096 -# -# Then it issues some queries that will cause the slave to reach -# relay-log-space-limit. We lock the table so that the SQL thread is -# not able to purge the log and then we issue some more statements. -# -# The purpose is to show that the IO thread will honor the limits -# while the SQL thread is not able to purge the relay logs, which did -# not happen before this patch. In addition we assert that while -# ignoring the limit (SQL thread needs to rotate before purging), the -# IO thread does not do it in an uncontrolled manner. - ---source include/have_binlog_format_statement.inc ---source include/have_innodb.inc ---source include/master-slave.inc - ---disable_query_log -CREATE TABLE t1 (c1 TEXT) engine=InnoDB; - -INSERT INTO t1 VALUES ('xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx'); -INSERT INTO t1 VALUES ('xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx'); -INSERT INTO t1 VALUES ('xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx'); -INSERT INTO t1 VALUES ('xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx'); - ---sync_slave_with_master - -# wait for the SQL thread to sleep ---let $show_statement= SHOW PROCESSLIST ---let $field= State ---let $condition= = 'Slave has read all relay log; waiting for the slave I/O thread to update it' ---source include/wait_show_condition.inc - -# now the io thread has set rli->ignore_space_limit -# lets lock the table so that once the SQL thread awakes -# it blocks there and does not set rli->ignore_space_limit -# back to zero -LOCK TABLE t1 WRITE; - -# now issue more statements that will overflow the -# rli->log_space_limit (in this case ~10K) ---connection master - -INSERT INTO t1 VALUES ('xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx'); -INSERT INTO t1 VALUES ('xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx'); -INSERT INTO t1 VALUES ('xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx'); -INSERT INTO t1 VALUES ('xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx'); -INSERT INTO t1 VALUES ('xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx'); -INSERT INTO t1 VALUES ('xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx'); -INSERT INTO t1 VALUES ('xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx'); -INSERT INTO t1 VALUES ('xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx'); -INSERT INTO t1 VALUES ('xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx'); -INSERT INTO t1 VALUES ('xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx'); - ---connection slave - -# ASSERT that the IO thread waits for the SQL thread to release some -# space before continuing ---let $show_statement= SHOW PROCESSLIST ---let $field= State ---let $condition= LIKE 'Waiting for %' -# before the patch (IO would have transfered everything) -#--let $condition= = 'Waiting for master to send event' -# after the patch (now it waits for space to be freed) -#--let $condition= = 'Waiting for the slave SQL thread to free enough relay log space' ---source include/wait_show_condition.inc - -# without the patch we can uncomment the following two lines and -# watch the IO thread synchronize with the master, thus writing -# relay logs way over the space limit -#--connection master -#--source include/sync_slave_io_with_master.inc - -## ASSERT that the IO thread has honored the limit+few bytes required to be able to purge ---let $relay_log_space_while_sql_is_executing = query_get_value(SHOW SLAVE STATUS, Relay_Log_Space, 1) ---let $relay_log_space_limit = query_get_value(SHOW VARIABLES LIKE "relay_log_space_limit", Value, 1) ---let $assert_text= Assert that relay log space is close to the limit ---let $assert_cond= $relay_log_space_while_sql_is_executing <= $relay_log_space_limit * 1.15 ---source include/assert.inc - -# unlock the table and let SQL thread continue applying events -UNLOCK TABLES; - ---connection master ---sync_slave_with_master ---let $diff_tables=master:test.t1,slave:test.t1 ---source include/diff_tables.inc - ---connection master -DROP TABLE t1; ---enable_query_log ---sync_slave_with_master - ---source include/rpl_end.inc diff --git a/mysql-test/suite/rpl/include/rpl_switch_stm_row_mixed.inc b/mysql-test/suite/rpl/include/rpl_switch_stm_row_mixed.inc deleted file mode 100644 index 31b80732c607e..0000000000000 --- a/mysql-test/suite/rpl/include/rpl_switch_stm_row_mixed.inc +++ /dev/null @@ -1,633 +0,0 @@ -# -# This include file is used by more than one test suite -# (currently rpl and binlog_encryption). -# Please check all dependent tests after modifying it -# - -# -# rpl_switch_stm_row_mixed tests covers -# -# - Master is switching explicitly between STATEMENT, ROW, and MIXED -# binlog format showing when it is possible and when not. -# - Master switching from MIXED to RBR implicitly listing all use -# cases, e.g a query invokes UUID(), thereafter to serve as the -# definition of MIXED binlog format -# - correctness of execution - - --- source include/have_binlog_format_mixed_or_row.inc --- source include/master-slave.inc - -# Since this test generates row-based events in the binary log, the -# slave SQL thread cannot be in STATEMENT mode to execute this test, -# so we only execute it for MIXED and ROW as default value of -# BINLOG_FORMAT. - -connection slave; - -connection master; ---disable_warnings -drop database if exists mysqltest1; -create database mysqltest1; ---enable_warnings -use mysqltest1; - -# Save binlog format -set @my_binlog_format= @@global.binlog_format; - -# play with switching -set session binlog_format=mixed; -show session variables like "binlog_format%"; -set session binlog_format=statement; -show session variables like "binlog_format%"; -set session binlog_format=row; -show session variables like "binlog_format%"; - -set global binlog_format=DEFAULT; -show global variables like "binlog_format%"; -set global binlog_format=MIXED; -show global variables like "binlog_format%"; -set global binlog_format=STATEMENT; -show global variables like "binlog_format%"; -set global binlog_format=ROW; -show global variables like "binlog_format%"; -show session variables like "binlog_format%"; -select @@global.binlog_format, @@session.binlog_format; - -CREATE TABLE t1 (a varchar(100)); - -prepare stmt1 from 'insert into t1 select concat(UUID(),?)'; -set @string="emergency_1_"; -insert into t1 values("work_2_"); -execute stmt1 using @string; -deallocate prepare stmt1; - -prepare stmt1 from 'insert into t1 select ?'; -insert into t1 values(concat(UUID(),"work_3_")); -execute stmt1 using @string; -deallocate prepare stmt1; - -insert into t1 values(concat("for_4_",UUID())); -insert into t1 select "yesterday_5_"; - -# verify that temp tables prevent a switch to SBR -create temporary table tmp(a char(100)); -insert into tmp values("see_6_"); ---error ER_TEMP_TABLE_PREVENTS_SWITCH_OUT_OF_RBR -set binlog_format=statement; -insert into t1 select * from tmp; -drop temporary table tmp; - -# Now we go to SBR -set binlog_format=statement; -show global variables like "binlog_format%"; -show session variables like "binlog_format%"; -select @@global.binlog_format, @@session.binlog_format; -set global binlog_format=statement; -show global variables like "binlog_format%"; -show session variables like "binlog_format%"; -select @@global.binlog_format, @@session.binlog_format; - -prepare stmt1 from 'insert into t1 select ?'; -set @string="emergency_7_"; -insert into t1 values("work_8_"); -execute stmt1 using @string; -deallocate prepare stmt1; - -prepare stmt1 from 'insert into t1 select ?'; -insert into t1 values("work_9_"); -execute stmt1 using @string; -deallocate prepare stmt1; - -insert into t1 values("for_10_"); -insert into t1 select "yesterday_11_"; - -# test statement (is not default after wl#3368) -set binlog_format=statement; -select @@global.binlog_format, @@session.binlog_format; -set global binlog_format=statement; -select @@global.binlog_format, @@session.binlog_format; - -prepare stmt1 from 'insert into t1 select ?'; -set @string="emergency_12_"; -insert into t1 values("work_13_"); -execute stmt1 using @string; -deallocate prepare stmt1; - -prepare stmt1 from 'insert into t1 select ?'; -insert into t1 values("work_14_"); -execute stmt1 using @string; -deallocate prepare stmt1; - -insert into t1 values("for_15_"); -insert into t1 select "yesterday_16_"; - -# and now the mixed mode - -set global binlog_format=mixed; -select @@global.binlog_format, @@session.binlog_format; -set binlog_format=default; -select @@global.binlog_format, @@session.binlog_format; - -prepare stmt1 from 'insert into t1 select concat(UUID(),?)'; -set @string="emergency_17_"; -insert into t1 values("work_18_"); -execute stmt1 using @string; -deallocate prepare stmt1; - -prepare stmt1 from 'insert into t1 select ?'; -insert into t1 values(concat(UUID(),"work_19_")); -execute stmt1 using @string; -deallocate prepare stmt1; - -insert into t1 values(concat("for_20_",UUID())); -insert into t1 select "yesterday_21_"; - -prepare stmt1 from 'insert into t1 select ?'; -insert into t1 values(concat(UUID(),"work_22_")); -execute stmt1 using @string; -deallocate prepare stmt1; - -insert into t1 values(concat("for_23_",UUID())); -insert into t1 select "yesterday_24_"; - -# Test of CREATE TABLE SELECT - -create table t2 ENGINE=MyISAM select rpad(UUID(),100,' '); -create table t3 select 1 union select UUID(); ---disable_warnings -SET STATEMENT sql_mode = 'NO_ENGINE_SUBSTITUTION' FOR -create table t4 select * from t1 where 3 in (select 1 union select 2 union select UUID() union select 3); ---enable_warnings -SET STATEMENT sql_mode = 'NO_ENGINE_SUBSTITUTION' FOR -create table t5 select * from t1 where 3 in (select 1 union select 2 union select curdate() union select 3); -# what if UUID() is first: ---disable_warnings -insert ignore into t5 select UUID() from t1 where 3 in (select 1 union select 2 union select 3 union select * from t4); ---enable_warnings - -# inside a stored procedure - -delimiter |; -create procedure foo() -begin -insert into t1 values("work_25_"); -insert into t1 values(concat("for_26_",UUID())); -insert into t1 select "yesterday_27_"; -end| -create procedure foo2() -begin -insert into t1 values(concat("emergency_28_",UUID())); -insert into t1 values("work_29_"); -insert into t1 values(concat("for_30_",UUID())); -set session binlog_format=row; # accepted for stored procs -insert into t1 values("more work_31_"); -set session binlog_format=mixed; -end| -create function foo3() returns bigint unsigned -begin - set session binlog_format=row; # rejected for stored funcs - insert into t1 values("alarm"); - return 100; -end| -create procedure foo4(x varchar(100)) -begin -insert into t1 values(concat("work_250_",x)); -insert into t1 select "yesterday_270_"; -end| -delimiter ;| -call foo(); -call foo2(); -call foo4("hello"); -call foo4(UUID()); -call foo4("world"); - -# test that can't SET in a stored function ---error ER_STORED_FUNCTION_PREVENTS_SWITCH_BINLOG_FORMAT -select foo3(); -select * from t1 where a="alarm"; - -# Tests of stored functions/triggers/views for BUG#20930 "Mixed -# binlogging mode does not work with stored functions, triggers, -# views" - -# Function which calls procedure -drop function foo3; -delimiter |; -create function foo3() returns bigint unsigned -begin - insert into t1 values("foo3_32_"); - call foo(); - return 100; -end| -delimiter ;| -insert into t2 select foo3(); - -prepare stmt1 from 'insert into t2 select foo3()'; -execute stmt1; -execute stmt1; -deallocate prepare stmt1; - -# Test if stored function calls stored function which calls procedure -# which requires row-based. - -delimiter |; -create function foo4() returns bigint unsigned -begin - insert into t2 select foo3(); - return 100; -end| -delimiter ;| -select foo4(); - -prepare stmt1 from 'select foo4()'; -execute stmt1; -execute stmt1; -deallocate prepare stmt1; - -# A simple stored function -delimiter |; -create function foo5() returns bigint unsigned -begin - insert into t2 select UUID(); - return 100; -end| -delimiter ;| -select foo5(); - -prepare stmt1 from 'select foo5()'; -execute stmt1; -execute stmt1; -deallocate prepare stmt1; - -# A simple stored function where UUID() is in the argument -delimiter |; -create function foo6(x varchar(100)) returns bigint unsigned -begin - insert into t2 select x; - return 100; -end| -delimiter ;| -select foo6("foo6_1_"); -select foo6(concat("foo6_2_",UUID())); - -prepare stmt1 from 'select foo6(concat("foo6_3_",UUID()))'; -execute stmt1; -execute stmt1; -deallocate prepare stmt1; - - -# Test of views using UUID() - -create view v1 as select uuid(); -create table t11 (data varchar(255)); -insert into t11 select * from v1; -# Test of querying INFORMATION_SCHEMA which parses the view's body, -# to verify that it binlogs statement-based (is not polluted by -# the parsing of the view's body). -insert into t11 select TABLE_NAME from INFORMATION_SCHEMA.TABLES where TABLE_SCHEMA='mysqltest1' and TABLE_NAME IN ('v1','t11'); -prepare stmt1 from "insert into t11 select TABLE_NAME from INFORMATION_SCHEMA.TABLES where TABLE_SCHEMA='mysqltest1' and TABLE_NAME IN ('v1','t11')"; -execute stmt1; -execute stmt1; -deallocate prepare stmt1; - -# Test of triggers with UUID() -delimiter |; -create trigger t11_bi before insert on t11 for each row -begin - set NEW.data = concat(NEW.data,UUID()); -end| -delimiter ;| -insert into t11 values("try_560_"); - -# Test that INSERT DELAYED works in mixed mode (BUG#20649) -insert delayed into t2 values("delay_1_"); -insert delayed into t2 values(concat("delay_2_",UUID())); -insert delayed into t2 values("delay_6_"); - -# Test for BUG#20633 (INSERT DELAYED RAND()/user_variable does not -# replicate fine in statement-based ; we test that in mixed mode it -# works). -insert delayed into t2 values(rand()); -set @a=2.345; -insert delayed into t2 values(@a); - -# With INSERT DELAYED, rows are written to the binlog after they are -# written to the table. Therefore, it is not enough to wait until the -# rows make it to t2 on the master (the rows may not be in the binlog -# at that time, and may still not be in the binlog when -# sync_slave_with_master is later called). Instead, we wait until the -# rows make it to t2 on the slave. We first call -# sync_slave_with_master, so that we are sure that t2 has been created -# on the slave. -sync_slave_with_master; -let $wait_condition= SELECT COUNT(*) = 19 FROM mysqltest1.t2; ---source include/wait_condition.inc -connection master; - -# If you want to do manual testing of the mixed mode regarding UDFs (not -# testable automatically as quite platform- and compiler-dependent), -# you just need to set the variable below to 1, and to -# "make udf_example.so" in sql/, and to copy sql/udf_example.so to -# MYSQL_TEST_DIR/lib/mysql. -let $you_want_to_test_UDF=0; -if ($you_want_to_test_UDF) -{ - CREATE FUNCTION metaphon RETURNS STRING SONAME 'udf_example.so'; - prepare stmt1 from 'insert into t1 select metaphon(?)'; - set @string="emergency_133_"; - insert into t1 values("work_134_"); - execute stmt1 using @string; - deallocate prepare stmt1; - prepare stmt1 from 'insert into t1 select ?'; - insert into t1 values(metaphon("work_135_")); - execute stmt1 using @string; - deallocate prepare stmt1; - insert into t1 values(metaphon("for_136_")); - insert into t1 select "yesterday_137_"; - create table t6 select metaphon("for_138_"); - create table t7 select 1 union select metaphon("for_139_"); - create table t8 select * from t1 where 3 in (select 1 union select 2 union select metaphon("for_140_") union select 3); - create table t9 select * from t1 where 3 in (select 1 union select 2 union select curdate() union select 3); -} - -create table t20 select * from t1; # save for comparing later -create table t21 select * from t2; -create table t22 select * from t3; -drop table t1,t2,t3; - -# This tests the fix to -# BUG#19630 stored function inserting into two auto_increment breaks statement-based binlog -# We verify that under the mixed binlog mode, a stored function -# modifying at least two tables having an auto_increment column, -# is binlogged row-based. Indeed in statement-based binlogging, -# only the auto_increment value generated for the first table -# is recorded in the binlog, the value generated for the 2nd table -# lacking. - -create table t1 (a int primary key auto_increment, b varchar(100)); -create table t2 (a int primary key auto_increment, b varchar(100)); -create table t3 (b varchar(100)); -delimiter |; -create function f (x varchar(100)) returns int deterministic -begin - insert into t1 values(null,x); - insert into t2 values(null,x); - return 1; -end| -delimiter ;| -select f("try_41_"); -# Two operations which compensate each other except that their net -# effect is that they advance the auto_increment counter of t2 on slave: -sync_slave_with_master; -use mysqltest1; -insert into t2 values(2,null),(3,null),(4,null); -delete from t2 where a>=2; - -connection master; -# this is the call which didn't replicate well -select f("try_42_"); -sync_slave_with_master; - -# now use prepared statement and test again, just to see that the RBB -# mode isn't set at PREPARE but at EXECUTE. - -insert into t2 values(3,null),(4,null); -delete from t2 where a>=3; - -connection master; -prepare stmt1 from 'select f(?)'; -set @string="try_43_"; -insert into t1 values(null,"try_44_"); # should be SBB -execute stmt1 using @string; # should be RBB -deallocate prepare stmt1; -sync_slave_with_master; - -# verify that if only one table has auto_inc, it does not trigger RBB -# (we'll check in binlog further below) - -connection master; -create table t12 select * from t1; # save for comparing later -drop table t1; -create table t1 (a int, b varchar(100), key(a)); -select f("try_45_"); - -# restore table's key -create table t13 select * from t1; -drop table t1; -create table t1 (a int primary key auto_increment, b varchar(100)); - -# now test if it's two functions, each of them inserts in one table - -drop function f; -# we need a unique key to have sorting of rows by mysqldump -create table t14 (unique (a)) select * from t2; -truncate table t2; -delimiter |; -create function f1 (x varchar(100)) returns int deterministic -begin - insert into t1 values(null,x); - return 1; -end| -create function f2 (x varchar(100)) returns int deterministic -begin - insert into t2 values(null,x); - return 1; -end| -delimiter ;| -select f1("try_46_"),f2("try_47_"); - -sync_slave_with_master; -insert into t2 values(2,null),(3,null),(4,null); -delete from t2 where a>=2; - -connection master; -# Test with SELECT and INSERT -select f1("try_48_"),f2("try_49_"); -insert into t3 values(concat("try_50_",f1("try_51_"),f2("try_52_"))); -sync_slave_with_master; - -# verify that if f2 does only read on an auto_inc table, this does not -# switch to RBB -connection master; -drop function f2; -delimiter |; -create function f2 (x varchar(100)) returns int deterministic -begin - declare y int; - insert into t1 values(null,x); - set y = (select count(*) from t2); - return y; -end| -delimiter ;| -select f1("try_53_"),f2("try_54_"); -sync_slave_with_master; - -# And now, a normal statement with a trigger (no stored functions) - -connection master; -drop function f2; -delimiter |; -create trigger t1_bi before insert on t1 for each row -begin - insert into t2 values(null,"try_55_"); -end| -delimiter ;| -insert into t1 values(null,"try_56_"); -# and now remove one auto_increment and verify SBB -alter table t1 modify a int, drop primary key; -insert into t1 values(null,"try_57_"); -sync_slave_with_master; - -# Test for BUG#20499 "mixed mode with temporary table breaks binlog" -# Slave used to have only 2 rows instead of 3. -connection master; -CREATE TEMPORARY TABLE t15 SELECT UUID(); -create table t16 like t15; -INSERT INTO t16 SELECT * FROM t15; -# we'll verify that this one is done RBB -insert into t16 values("try_65_"); -drop table t15; -# we'll verify that this one is done SBB -insert into t16 values("try_66_"); -sync_slave_with_master; - -# and now compare: - -connection master; - -# first check that data on master is sensible -select count(*) from t1; -select count(*) from t2; -select count(*) from t3; -select count(*) from t4; -select count(*) from t5; -select count(*) from t11; -select count(*) from t20; -select count(*) from t21; -select count(*) from t22; -select count(*) from t12; -select count(*) from t13; -select count(*) from t14; -select count(*) from t16; -if ($you_want_to_test_UDF) -{ - select count(*) from t6; - select count(*) from t7; - select count(*) from t8; - select count(*) from t9; -} - -sync_slave_with_master; - -# -# Bug#20863 If binlog format is changed between update and unlock of -# tables, wrong binlog -# - -connection master; -DROP TABLE IF EXISTS t11; -SET SESSION BINLOG_FORMAT=STATEMENT; -CREATE TABLE t11 (song VARCHAR(255)); -LOCK TABLES t11 WRITE; -SET SESSION BINLOG_FORMAT=ROW; -INSERT INTO t11 VALUES('Several Species of Small Furry Animals Gathered Together in a Cave and Grooving With a Pict'); -SET SESSION BINLOG_FORMAT=STATEMENT; -INSERT INTO t11 VALUES('Careful With That Axe, Eugene'); -UNLOCK TABLES; - ---query_vertical SELECT * FROM t11 -sync_slave_with_master; -USE mysqltest1; ---query_vertical SELECT * FROM t11 - -connection master; -DROP TABLE IF EXISTS t12; -SET SESSION BINLOG_FORMAT=MIXED; -CREATE TABLE t12 (data LONG); -LOCK TABLES t12 WRITE; -INSERT INTO t12 VALUES(UUID()); -UNLOCK TABLES; -sync_slave_with_master; - -# -# BUG#28086: SBR of USER() becomes corrupted on slave -# - -connection master; - -# Just to get something that is non-trivial, albeit still simple, we -# stuff the result of USER() and CURRENT_USER() into a variable. ---delimiter $$ -CREATE FUNCTION my_user() - RETURNS CHAR(64) -BEGIN - DECLARE user CHAR(64); - SELECT USER() INTO user; - RETURN user; -END $$ ---delimiter ; - ---delimiter $$ -CREATE FUNCTION my_current_user() - RETURNS CHAR(64) -BEGIN - DECLARE user CHAR(64); - SELECT CURRENT_USER() INTO user; - RETURN user; -END $$ ---delimiter ; - -DROP TABLE IF EXISTS t13; -CREATE TABLE t13 (data CHAR(64)); -INSERT INTO t13 VALUES (USER()); -INSERT INTO t13 VALUES (my_user()); -INSERT INTO t13 VALUES (CURRENT_USER()); -INSERT INTO t13 VALUES (my_current_user()); - -sync_slave_with_master; - -# as we're using UUID we don't SELECT but use "diff" like in rpl_row_UUID ---exec $MYSQL_DUMP --compact --order-by-primary --skip-extended-insert --no-create-info mysqltest1 > $MYSQLTEST_VARDIR/tmp/rpl_switch_stm_row_mixed_master.sql ---exec $MYSQL_DUMP_SLAVE --compact --order-by-primary --skip-extended-insert --no-create-info mysqltest1 > $MYSQLTEST_VARDIR/tmp/rpl_switch_stm_row_mixed_slave.sql - -# Let's compare. Note: If they match test will pass, if they do not match -# the test will show that the diff statement failed and not reject file -# will be created. You will need to go to the mysql-test dir and diff -# the files your self to see what is not matching - -diff_files $MYSQLTEST_VARDIR/tmp/rpl_switch_stm_row_mixed_master.sql $MYSQLTEST_VARDIR/tmp/rpl_switch_stm_row_mixed_slave.sql; - -connection master; - -# Now test that mysqlbinlog works fine on a binlog generated by the -# mixed mode - -# BUG#11312 "DELIMITER is not written to the binary log that causes -# syntax error" makes that mysqlbinlog will fail if we pass it the -# text of queries; this forces us to use --base64-output here. - -# BUG#20929 "BINLOG command causes invalid free plus assertion -# failure" makes mysqld segfault when receiving --base64-output - -# So I can't enable this piece of test -# SIGH - -if ($enable_when_11312_or_20929_fixed) -{ ---exec $MYSQL_BINLOG --base64-output $MYSQLTEST_VARDIR/log/master-bin.000001 > $MYSQLTEST_VARDIR/tmp/mysqlbinlog_mixed.sql -drop database mysqltest1; ---exec $MYSQL < $MYSQLTEST_VARDIR/tmp/mysqlbinlog_mixed.sql ---exec $MYSQL_DUMP --compact --order-by-primary --skip-extended-insert --no-create-info mysqltest1 > $MYSQLTEST_VARDIR/tmp/rpl_switch_stm_row_mixed_master.sql -# the old mysqldump output on slave is the same as what it was on -# master before restoring on master. -diff_files $MYSQLTEST_VARDIR/tmp/rpl_switch_stm_row_mixed_master.sql $MYSQLTEST_VARDIR/tmp/rpl_switch_stm_row_mixed_slave.sql; -} - -drop database mysqltest1; -sync_slave_with_master; - -connection master; -# Restore binlog format setting -set global binlog_format =@my_binlog_format; ---source include/rpl_end.inc diff --git a/mysql-test/suite/rpl/include/rpl_sync_test.inc b/mysql-test/suite/rpl/include/rpl_sync_test.inc deleted file mode 100644 index 1e2ec2ca83b85..0000000000000 --- a/mysql-test/suite/rpl/include/rpl_sync_test.inc +++ /dev/null @@ -1,159 +0,0 @@ -# -# This include file is used by more than one test suite -# (currently rpl and binlog_encryption). -# Please check all dependent tests after modifying it -# - -######################################################################################## -# This test verifies the options --sync-relay-log-info and --relay-log-recovery by -# crashing the slave in two different situations: -# (case-1) - Corrupt the relay log with changes which were not processed by -# the SQL Thread and crashes it. -# (case-2) - Corrupt the master.info with wrong coordinates and crashes it. -# -# Case 1: -# 1 - Stops the SQL Thread -# 2 - Inserts new records into the master. -# 3 - Corrupts the relay-log.bin* which most likely has such changes. -# 4 - Crashes the slave -# 5 - Verifies if the slave is sync with the master which means that the information -# loss was circumvented by the recovery process. -# -# Case 2: -# 1 - Stops the SQL/IO Threads -# 2 - Inserts new records into the master. -# 3 - Corrupts the master.info with wrong coordinates. -# 4 - Crashes the slave -# 5 - Verifies if the slave is sync with the master which means that the information -# loss was circumvented by the recovery process. -######################################################################################## - -######################################################################################## -# Configuring the environment -######################################################################################## ---echo =====Configuring the enviroment=======; ---source include/not_embedded.inc ---source include/not_valgrind.inc ---source include/have_debug.inc ---source include/have_innodb.inc ---source include/not_crashrep.inc ---source include/master-slave.inc - -call mtr.add_suppression('Attempting backtrace'); -call mtr.add_suppression("Recovery from master pos .* and file master-bin.000001"); -# Use innodb so we do not get "table should be repaired" issues. -ALTER TABLE mysql.gtid_slave_pos ENGINE=InnoDB; -flush tables; -CREATE TABLE t1(a INT, PRIMARY KEY(a)) engine=innodb; - -insert into t1(a) values(1); -insert into t1(a) values(2); -insert into t1(a) values(3); - -######################################################################################## -# Case 1: Corrupt a relay-log.bin* -######################################################################################## ---echo =====Inserting data on the master but without the SQL Thread being running=======; -sync_slave_with_master; - -connection slave; -let $MYSQLD_SLAVE_DATADIR= `select @@datadir`; ---replace_result $MYSQLD_SLAVE_DATADIR MYSQLD_SLAVE_DATADIR ---copy_file $MYSQLD_SLAVE_DATADIR/master.info $MYSQLD_SLAVE_DATADIR/master.backup ---source include/stop_slave_sql.inc - -connection master; -insert into t1(a) values(4); -insert into t1(a) values(5); -insert into t1(a) values(6); - ---echo =====Removing relay log files and crashing/recoverying the slave=======; -connection slave; ---source include/stop_slave_io.inc - -let $file= query_get_value("SHOW SLAVE STATUS", Relay_Log_File, 1); - ---let FILE_TO_CORRUPT= $MYSQLD_SLAVE_DATADIR/$file -perl; -$file= $ENV{'FILE_TO_CORRUPT'}; -open(FILE, ">$file") || die "Unable to open $file."; -truncate(FILE,0); -print FILE "failure"; -close ($file); -EOF - ---exec echo "restart" > $MYSQLTEST_VARDIR/tmp/mysqld.2.expect -SET SESSION debug_dbug="d,crash_before_rotate_relaylog"; ---error 2013 -FLUSH LOGS; - ---let $rpl_server_number= 2 ---source include/rpl_reconnect.inc - ---echo =====Dumping and comparing tables=======; ---source include/start_slave.inc - -connection master; -sync_slave_with_master; - -let $diff_tables=master:t1,slave:t1; -source include/diff_tables.inc; - -######################################################################################## -# Case 2: Corrupt a master.info -######################################################################################## ---echo =====Corrupting the master.info=======; -connection slave; ---source include/stop_slave.inc - -connection master; -FLUSH LOGS; - -insert into t1(a) values(7); -insert into t1(a) values(8); -insert into t1(a) values(9); - -connection slave; -let MYSQLD_SLAVE_DATADIR=`select @@datadir`; - ---perl -use strict; -use warnings; -my $src= "$ENV{'MYSQLD_SLAVE_DATADIR'}/master.backup"; -my $dst= "$ENV{'MYSQLD_SLAVE_DATADIR'}/master.info"; -open(FILE, "<", $src) or die; -my @content= ; -close FILE; -open(FILE, ">", $dst) or die; -binmode FILE; -print FILE @content; -close FILE; -EOF - ---exec echo "restart" > $MYSQLTEST_VARDIR/tmp/mysqld.2.expect -SET SESSION debug_dbug="d,crash_before_rotate_relaylog"; ---error 2013 -FLUSH LOGS; - ---let $rpl_server_number= 2 ---source include/rpl_reconnect.inc - ---echo =====Dumping and comparing tables=======; ---source include/start_slave.inc - -connection master; -sync_slave_with_master; - -let $diff_tables=master:t1,slave:t1; -source include/diff_tables.inc; - -######################################################################################## -# Clean up -######################################################################################## ---echo =====Clean up=======; -connection master; -drop table t1; - ---remove_file $MYSQLD_SLAVE_DATADIR/master.backup ---source include/rpl_end.inc - diff --git a/mysql-test/suite/rpl/include/rpl_temporal_format_default_to_default.inc b/mysql-test/suite/rpl/include/rpl_temporal_format_default_to_default.inc deleted file mode 100644 index 6728ff55d6f5e..0000000000000 --- a/mysql-test/suite/rpl/include/rpl_temporal_format_default_to_default.inc +++ /dev/null @@ -1,82 +0,0 @@ -# -# This include file is used by more than one test suite -# (currently rpl and binlog_encryption). -# Please check all dependent tests after modifying it -# - ---source include/master-slave.inc - -if ($force_master_mysql56_temporal_format) -{ - connection master; - eval SET @@global.mysql56_temporal_format=$force_master_mysql56_temporal_format; -} - -if ($force_slave_mysql56_temporal_format) -{ - connection slave; - eval SET @@global.mysql56_temporal_format=$force_slave_mysql56_temporal_format; -} - -connection master; -SELECT @@global.mysql56_temporal_format AS on_master; -connection slave; -SELECT @@global.mysql56_temporal_format AS on_slave; -connection master; - -CREATE TABLE t1 -( - c0 TIME(0), - c1 TIME(1), - c2 TIME(2), - c3 TIME(3), - c4 TIME(4), - c5 TIME(5), - c6 TIME(6) -); -CREATE TABLE t2 -( - c0 TIMESTAMP(0), - c1 TIMESTAMP(1), - c2 TIMESTAMP(2), - c3 TIMESTAMP(3), - c4 TIMESTAMP(4), - c5 TIMESTAMP(5), - c6 TIMESTAMP(6) -); - -CREATE TABLE t3 -( - c0 DATETIME(0), - c1 DATETIME(1), - c2 DATETIME(2), - c3 DATETIME(3), - c4 DATETIME(4), - c5 DATETIME(5), - c6 DATETIME(6) -); -INSERT INTO t1 VALUES ('01:01:01','01:01:01.1','01:01:01.11','01:01:01.111','01:01:01.1111','01:01:01.11111','01:01:01.111111'); -INSERT INTO t2 VALUES ('2001-01-01 01:01:01','2001-01-01 01:01:01.1','2001-01-01 01:01:01.11','2001-01-01 01:01:01.111','2001-01-01 01:01:01.1111','2001-01-01 01:01:01.11111','2001-01-01 01:01:01.111111'); -INSERT INTO t3 VALUES ('2001-01-01 01:01:01','2001-01-01 01:01:01.1','2001-01-01 01:01:01.11','2001-01-01 01:01:01.111','2001-01-01 01:01:01.1111','2001-01-01 01:01:01.11111','2001-01-01 01:01:01.111111'); -SELECT TABLE_NAME, TABLE_ROWS, AVG_ROW_LENGTH,DATA_LENGTH FROM INFORMATION_SCHEMA.TABLES -WHERE TABLE_NAME RLIKE 't[1-3]' ORDER BY TABLE_NAME; -sync_slave_with_master; - -connection slave; ---query_vertical SELECT * FROM t1; ---query_vertical SELECT * FROM t2; ---query_vertical SELECT * FROM t3; -SELECT TABLE_NAME, TABLE_ROWS, AVG_ROW_LENGTH,DATA_LENGTH FROM INFORMATION_SCHEMA.TABLES -WHERE TABLE_NAME RLIKE 't[1-3]' ORDER BY TABLE_NAME; - -connection master; -DROP TABLE t1; -DROP TABLE t2; -DROP TABLE t3; - -connection slave; -SET @@global.mysql56_temporal_format=DEFAULT; -connection master; -SET @@global.mysql56_temporal_format=DEFAULT; - ---source include/rpl_end.inc diff --git a/mysql-test/suite/rpl/include/rpl_typeconv.inc b/mysql-test/suite/rpl/include/rpl_typeconv.inc deleted file mode 100644 index 9e5662588827e..0000000000000 --- a/mysql-test/suite/rpl/include/rpl_typeconv.inc +++ /dev/null @@ -1,78 +0,0 @@ -# -# This include file is used by more than one test suite -# (currently rpl and binlog_encryption suite). -# Please check all dependent tests after modifying it -# - ---source include/have_binlog_format_row.inc ---source include/master-slave.inc - -connection slave; -set @saved_slave_type_conversions = @@global.slave_type_conversions; -CREATE TABLE type_conversions ( - TestNo INT AUTO_INCREMENT PRIMARY KEY, - Source TEXT, - Target TEXT, - Flags TEXT, - On_Master LONGTEXT, - On_Slave LONGTEXT, - Expected LONGTEXT, - Compare INT, - Error TEXT); - -SELECT @@global.slave_type_conversions; -SET GLOBAL SLAVE_TYPE_CONVERSIONS=''; -SELECT @@global.slave_type_conversions; -SET GLOBAL SLAVE_TYPE_CONVERSIONS='ALL_NON_LOSSY'; -SELECT @@global.slave_type_conversions; -SET GLOBAL SLAVE_TYPE_CONVERSIONS='ALL_LOSSY'; -SELECT @@global.slave_type_conversions; -SET GLOBAL SLAVE_TYPE_CONVERSIONS='ALL_LOSSY,ALL_NON_LOSSY'; -SELECT @@global.slave_type_conversions; ---error ER_WRONG_VALUE_FOR_VAR -SET GLOBAL SLAVE_TYPE_CONVERSIONS='ALL_LOSSY,ALL_NON_LOSSY,NONEXISTING_BIT'; -SELECT @@global.slave_type_conversions; - -# Checking strict interpretation of type conversions -connection slave; -SET GLOBAL SLAVE_TYPE_CONVERSIONS=''; -source suite/rpl/include/type_conversions.test; - -# Checking lossy integer type conversions -connection slave; -SET GLOBAL SLAVE_TYPE_CONVERSIONS='ALL_NON_LOSSY'; -source suite/rpl/include/type_conversions.test; - -# Checking non-lossy integer type conversions -connection slave; -SET GLOBAL SLAVE_TYPE_CONVERSIONS='ALL_LOSSY'; -source suite/rpl/include/type_conversions.test; - -# Checking all type conversions -connection slave; -SET GLOBAL SLAVE_TYPE_CONVERSIONS='ALL_LOSSY,ALL_NON_LOSSY'; -source suite/rpl/include/type_conversions.test; - -connection slave; ---echo **** Result of conversions **** -disable_query_log; -SELECT RPAD(Source, 15, ' ') AS Source_Type, - RPAD(Target, 15, ' ') AS Target_Type, - RPAD(Flags, 25, ' ') AS All_Type_Conversion_Flags, - IF(Compare IS NULL AND Error IS NOT NULL, '', - IF(Compare, '', - CONCAT("'", On_Slave, "' != '", Expected, "'"))) - AS Value_On_Slave - FROM type_conversions; -enable_query_log; -DROP TABLE type_conversions; - -call mtr.add_suppression("Slave SQL.*Column 1 of table .test.t1. cannot be converted from type.* error.* 1677"); - -connection master; -DROP TABLE t1; -sync_slave_with_master; - -set global slave_type_conversions = @saved_slave_type_conversions; - ---source include/rpl_end.inc diff --git a/mysql-test/suite/rpl/t/rpl_binlog_errors.test b/mysql-test/suite/rpl/t/rpl_binlog_errors.test index 30faaf7961308..bf92736a2afbc 100644 --- a/mysql-test/suite/rpl/t/rpl_binlog_errors.test +++ b/mysql-test/suite/rpl/t/rpl_binlog_errors.test @@ -1 +1,438 @@ ---source include/rpl_binlog_errors.inc +# +# This include file is used by more than one test suite +# (currently rpl and binlog_encryption). +# Please check all dependent tests after modifying it +# +# Usage: +# --let $binlog_limit= X[,Y] # optional +# +# Semantics of the value is the same as in include/show_binlog_events.inc +# which the script calls as a part of the test flow. +# The goal is to print the event demonstrating the triggered error, +# so normally Y should be 1 (print the exact event only); +# however, depending on test-specific server options, the offset X +# can be different. +# + +# BUG#46166: MYSQL_BIN_LOG::new_file_impl is not propagating error +# when generating new name. +# +# WHY +# === +# +# We want to check whether error is reported or not when +# new_file_impl fails (this may happen when rotation is not +# possible because there is some problem finding an +# unique filename). +# +# HOW +# === +# +# Test cases are documented inline. + +-- source include/have_innodb.inc +-- source include/have_debug.inc +-- source include/master-slave.inc + +-- echo ####################################################################### +-- echo ####################### PART 1: MASTER TESTS ########################## +-- echo ####################################################################### + + +### ACTION: stopping slave as it is not needed for the first part of +### the test + +-- connection slave +-- source include/stop_slave.inc +-- connection master + +call mtr.add_suppression("Can't generate a unique log-filename"); +call mtr.add_suppression("Writing one row to the row-based binary log failed.*"); +call mtr.add_suppression("Error writing file .*"); +call mtr.add_suppression("Could not use master-bin for logging"); + +SET @old_debug= @@global.debug_dbug; + +### ACTION: create a large file (> 4096 bytes) that will be later used +### in LOAD DATA INFILE to check binlog errors in its vacinity +-- let $load_file= $MYSQLTEST_VARDIR/tmp/bug_46166.data +-- let $MYSQLD_DATADIR= `select @@datadir` +-- replace_result $MYSQLTEST_VARDIR MYSQLTEST_VARDIR +-- eval SELECT repeat('x',8192) INTO OUTFILE '$load_file' + +### ACTION: create a small file (< 4096 bytes) that will be later used +### in LOAD DATA INFILE to check for absence of binlog errors +### when file loading this file does not force flushing and +### rotating the binary log +-- let $load_file2= $MYSQLTEST_VARDIR/tmp/bug_46166-2.data +-- let $MYSQLD_DATADIR= `select @@datadir` +-- replace_result $MYSQLTEST_VARDIR MYSQLTEST_VARDIR +-- eval SELECT repeat('x',10) INTO OUTFILE '$load_file2' + +RESET MASTER; + +-- echo ###################### TEST #1 + +### ASSERTION: no problem flushing logs (should show two binlogs) +FLUSH LOGS; +-- echo # assert: must show two binlogs +-- source include/show_binary_logs.inc + +-- echo ###################### TEST #2 + +### ASSERTION: check that FLUSH LOGS actually fails and reports +### failure back to the user if find_uniq_filename fails +### (should show just one binlog) + +RESET MASTER; +SET @@global.debug_dbug="d,error_unique_log_filename"; +-- error ER_NO_UNIQUE_LOGFILE +FLUSH LOGS; +-- echo # assert: must show one binlog +-- source include/show_binary_logs.inc + +### ACTION: clean up and move to next test +SET @@global.debug_dbug=@old_debug; +RESET MASTER; + +-- echo ###################### TEST #3 + +### ACTION: create some tables (t1, t2, t4) and insert some values in +### table t1 +CREATE TABLE t1 (a INT); +CREATE TABLE t2 (a VARCHAR(16384)) Engine=InnoDB; +CREATE TABLE t4 (a VARCHAR(16384)); +INSERT INTO t1 VALUES (1); +RESET MASTER; + +### ASSERTION: we force rotation of the binary log because it exceeds +### the max_binlog_size option (should show two binary +### logs) + +-- replace_result $MYSQLTEST_VARDIR MYSQLTEST_VARDIR +-- eval LOAD DATA INFILE '$load_file' INTO TABLE t2 + +# shows two binary logs +-- echo # assert: must show two binlog +-- source include/show_binary_logs.inc + +# clean up the table and the binlog to be used in next part of test +SET @@global.debug_dbug=@old_debug; +DELETE FROM t2; +RESET MASTER; + +-- echo ###################### TEST #4 + +### ASSERTION: load the big file into a transactional table and check +### that it reports error. The table will contain the +### changes performed despite the fact that it reported an +### error. + +SET @@global.debug_dbug="d,error_unique_log_filename"; +-- replace_result $MYSQLTEST_VARDIR MYSQLTEST_VARDIR +-- error ER_NO_UNIQUE_LOGFILE +-- eval LOAD DATA INFILE '$load_file' INTO TABLE t2 + +# show table +-- echo # assert: must show one entry +SELECT count(*) FROM t2; + +# clean up the table and the binlog to be used in next part of test +SET @@global.debug_dbug=@old_debug; +DELETE FROM t2; +RESET MASTER; + +-- echo ###################### TEST #5 + +### ASSERTION: load the small file into a transactional table and +### check that it succeeds + +SET @@global.debug_dbug="d,error_unique_log_filename"; +-- replace_result $MYSQLTEST_VARDIR MYSQLTEST_VARDIR +-- eval LOAD DATA INFILE '$load_file2' INTO TABLE t2 + +# show table +-- echo # assert: must show one entry +SELECT count(*) FROM t2; + +# clean up the table and the binlog to be used in next part of test +SET @@global.debug_dbug=@old_debug; +DELETE FROM t2; +RESET MASTER; + +-- echo ###################### TEST #6 + +### ASSERTION: check that even if one is using a transactional table +### and explicit transactions (no autocommit) if rotation +### fails we get the error. Transaction is not rolledback +### because rotation happens after the commit. + +SET @@global.debug_dbug="d,error_unique_log_filename"; +SET AUTOCOMMIT=0; +INSERT INTO t2 VALUES ('muse'); +-- replace_result $MYSQLTEST_VARDIR MYSQLTEST_VARDIR +-- eval LOAD DATA INFILE '$load_file' INTO TABLE t2 +INSERT INTO t2 VALUES ('muse'); +-- error ER_NO_UNIQUE_LOGFILE +COMMIT; + +### ACTION: Show the contents of the table after the test +-- echo # assert: must show three entries +SELECT count(*) FROM t2; + +### ACTION: clean up and move to the next test +SET AUTOCOMMIT= 1; +SET @@global.debug_dbug=@old_debug; +DELETE FROM t2; +RESET MASTER; + +-- echo ###################### TEST #7 + +### ASSERTION: check that on a non-transactional table, if rotation +### fails then an error is reported and an incident event +### is written to the current binary log. + +SET @@global.debug_dbug="d,error_unique_log_filename"; + +# Disable logging Annotate_rows events to preserve events count. +let $binlog_annotate_row_events_saved= `SELECT @@binlog_annotate_row_events`; +SET @@binlog_annotate_row_events= 0; + +SELECT count(*) FROM t4; +-- replace_result $MYSQLTEST_VARDIR MYSQLTEST_VARDIR +-- error ER_NO_UNIQUE_LOGFILE +-- eval LOAD DATA INFILE '$load_file' INTO TABLE t4 + +-- echo # assert: must show 1 entry +SELECT count(*) FROM t4; + +-- echo ### check that the incident event is written to the current log +SET @@global.debug_dbug=@old_debug; +if (!$binlog_limit) +{ + -- let $binlog_limit= 4,1 +} +-- source include/show_binlog_events.inc + +# clean up and move to next test +DELETE FROM t4; + +--disable_query_log +eval SET @@binlog_annotate_row_events= $binlog_annotate_row_events_saved; +--enable_query_log + +RESET MASTER; + +-- echo ###################### TEST #8 + +### ASSERTION: check that statements end up in error but they succeed +### on changing the data. + +SET @@global.debug_dbug="d,error_unique_log_filename"; +-- echo # must show 0 entries +SELECT count(*) FROM t4; +SELECT count(*) FROM t2; + +-- replace_result $MYSQLTEST_VARDIR MYSQLTEST_VARDIR +-- error ER_NO_UNIQUE_LOGFILE +-- eval LOAD DATA INFILE '$load_file' INTO TABLE t4 +-- replace_result $MYSQLTEST_VARDIR MYSQLTEST_VARDIR +-- error ER_NO_UNIQUE_LOGFILE +-- eval LOAD DATA INFILE '$load_file' INTO TABLE t2 +-- error ER_NO_UNIQUE_LOGFILE +INSERT INTO t2 VALUES ('aaa'), ('bbb'), ('ccc'); + +-- echo # INFO: Count(*) Before Offending DELETEs +-- echo # assert: must show 1 entry +SELECT count(*) FROM t4; +-- echo # assert: must show 4 entries +SELECT count(*) FROM t2; + +-- error ER_NO_UNIQUE_LOGFILE +DELETE FROM t4; +-- error ER_NO_UNIQUE_LOGFILE +DELETE FROM t2; + +-- echo # INFO: Count(*) After Offending DELETEs +-- echo # assert: must show zero entries +SELECT count(*) FROM t4; +SELECT count(*) FROM t2; + +# remove fault injection +SET @@global.debug_dbug=@old_debug; + +-- echo ###################### TEST #9 + +### ASSERTION: check that if we disable binlogging, then statements +### succeed. +SET @@global.debug_dbug="d,error_unique_log_filename"; +SET SQL_LOG_BIN=0; +INSERT INTO t2 VALUES ('aaa'), ('bbb'), ('ccc'), ('ddd'); +INSERT INTO t4 VALUES ('eee'), ('fff'), ('ggg'), ('hhh'); +-- echo # assert: must show four entries +SELECT count(*) FROM t2; +SELECT count(*) FROM t4; +DELETE FROM t2; +DELETE FROM t4; +-- echo # assert: must show zero entries +SELECT count(*) FROM t2; +SELECT count(*) FROM t4; +SET SQL_LOG_BIN=1; +SET @@global.debug_dbug=@old_debug; + +-- echo ###################### TEST #10 + +### ASSERTION: check that error is reported if there is a failure +### while registering the index file and the binary log +### file or failure to write the rotate event. + +call mtr.add_suppression("MYSQL_BIN_LOG::open failed to sync the index file."); +call mtr.add_suppression("Could not use .*"); + +RESET MASTER; +SHOW WARNINGS; + +# +d,fault_injection_registering_index => injects fault on MYSQL_BIN_LOG::open +SET @@global.debug_dbug="d,fault_injection_registering_index"; +-- replace_regex /\.[\\\/]master/master/ +-- error ER_CANT_OPEN_FILE +FLUSH LOGS; +SET @@global.debug_dbug=@old_debug; + +-- error ER_NO_BINARY_LOGGING +SHOW BINARY LOGS; + +# issue some statements and check that they don't fail +CREATE TABLE t5 (a INT); +INSERT INTO t4 VALUES ('bbbbb'); +INSERT INTO t2 VALUES ('aaaaa'); +DELETE FROM t4; +DELETE FROM t2; +DROP TABLE t5; +flush tables; + +-- echo ###################### TEST #11 + +### ASSERTION: check that error is reported if there is a failure +### while opening the index file and the binary log file or +### failure to write the rotate event. + +# restart the server so that we have binlog again +--let $rpl_server_number= 1 +--source include/rpl_restart_server.inc + +# +d,fault_injection_openning_index => injects fault on MYSQL_BIN_LOG::open_index_file +SET @@global.debug_dbug="d,fault_injection_openning_index"; +-- replace_regex /\.[\\\/]master/master/ +-- error ER_CANT_OPEN_FILE +FLUSH LOGS; +SET @@global.debug_dbug=@old_debug; + +-- error ER_FLUSH_MASTER_BINLOG_CLOSED +RESET MASTER; + +# issue some statements and check that they don't fail +CREATE TABLE t5 (a INT); +INSERT INTO t4 VALUES ('bbbbb'); +INSERT INTO t2 VALUES ('aaaaa'); +DELETE FROM t4; +DELETE FROM t2; +DROP TABLE t5; +flush tables; + +# restart the server so that we have binlog again +--let $rpl_server_number= 1 +--source include/rpl_restart_server.inc + +-- echo ###################### TEST #12 + +### ASSERTION: check that error is reported if there is a failure +### while writing the rotate event when creating a new log +### file. + +# +d,fault_injection_new_file_rotate_event => injects fault on MYSQL_BIN_LOG::MYSQL_BIN_LOG::new_file_impl +SET @@global.debug_dbug="d,fault_injection_new_file_rotate_event"; +-- error ER_ERROR_ON_WRITE +FLUSH LOGS; +SET @@global.debug_dbug=@old_debug; + +-- error ER_FLUSH_MASTER_BINLOG_CLOSED +RESET MASTER; + +# issue some statements and check that they don't fail +CREATE TABLE t5 (a INT); +INSERT INTO t4 VALUES ('bbbbb'); +INSERT INTO t2 VALUES ('aaaaa'); +DELETE FROM t4; +DELETE FROM t2; +DROP TABLE t5; +flush tables; + +# restart the server so that we have binlog again +--let $rpl_server_number= 1 +--source include/rpl_restart_server.inc + +## clean up +DROP TABLE t1, t2, t4; +RESET MASTER; + +# restart slave again +-- connection slave +-- source include/start_slave.inc +-- connection master + +-- echo ####################################################################### +-- echo ####################### PART 2: SLAVE TESTS ########################### +-- echo ####################################################################### + +### setup +--source include/rpl_reset.inc +-- connection slave + +# slave suppressions + +call mtr.add_suppression("Slave I/O: Relay log write failure: could not queue event from master.*"); +call mtr.add_suppression("Error writing file .*"); +call mtr.add_suppression("Could not use .*"); +call mtr.add_suppression("MYSQL_BIN_LOG::open failed to sync the index file."); +call mtr.add_suppression("Can't generate a unique log-filename .*"); +-- echo ###################### TEST #13 + +#### ASSERTION: check against unique log filename error +-- let $io_thd_injection_fault_flag= error_unique_log_filename +-- let $slave_io_errno= 1595 +-- let $show_slave_io_error= 1 +-- source include/io_thd_fault_injection.inc + +-- echo ###################### TEST #14 + +#### ASSERTION: check against rotate failing +-- let $io_thd_injection_fault_flag= fault_injection_new_file_rotate_event +-- let $slave_io_errno= 1595 +-- let $show_slave_io_error= 1 +-- source include/io_thd_fault_injection.inc + +-- echo ###################### TEST #15 + +#### ASSERTION: check against relay log open failure +-- let $io_thd_injection_fault_flag= fault_injection_registering_index +-- let $slave_io_errno= 1595 +-- let $show_slave_io_error= 1 +-- source include/io_thd_fault_injection.inc + +-- echo ###################### TEST #16 + +#### ASSERTION: check against relay log index open failure +-- let $io_thd_injection_fault_flag= fault_injection_openning_index +-- let $slave_io_errno= 1595 +-- let $show_slave_io_error= 1 +-- source include/io_thd_fault_injection.inc + +### clean up +-- source include/stop_slave_sql.inc +RESET SLAVE; +RESET MASTER; +--remove_file $load_file +--remove_file $load_file2 +--let $rpl_only_running_threads= 1 +--source include/rpl_end.inc diff --git a/mysql-test/suite/rpl/t/rpl_cant_read_event_incident.test b/mysql-test/suite/rpl/t/rpl_cant_read_event_incident.test index 573c1d111fc49..7dfef023947a9 100644 --- a/mysql-test/suite/rpl/t/rpl_cant_read_event_incident.test +++ b/mysql-test/suite/rpl/t/rpl_cant_read_event_incident.test @@ -1 +1,83 @@ ---source include/rpl_cant_read_event_incident.inc +# +# This include file is used by more than one test suite +# (currently rpl and binlog_encryption). +# Please check all dependent tests after modifying it +# + +# +# Bug#11747416 : 32228 A disk full makes binary log corrupt. +# +# +# The test demonstrates reading from binlog error propagation to slave +# and reporting there. +# Conditions for the bug include a crash at time of the last event to +# the binlog was written partly. With the fixes the event is not sent out +# any longer, but rather the dump thread sends out a sound error message. +# +# Crash is not simulated. A binlog with partly written event in its end is installed +# and replication is started from it. +# + +--source include/have_binlog_format_mixed.inc +--source include/master-slave.inc + +--connection slave +# Make sure the slave is stopped while we are messing with master. +# Otherwise we get occasional failures as the slave manages to re-connect +# to the newly started master and we get extra events applied, causing +# conflicts. +--source include/stop_slave.inc + +--connection master +call mtr.add_suppression("Error in Log_event::read_log_event()"); +--let $datadir= `SELECT @@datadir` + +--let $rpl_server_number= 1 +--source include/rpl_stop_server.inc + +--remove_file $datadir/master-bin.000001 +--copy_file $MYSQL_TEST_DIR/std_data/bug11747416_32228_binlog.000001 $datadir/master-bin.000001 + +--let $rpl_server_number= 1 +--source include/rpl_start_server.inc + +--source include/wait_until_connected_again.inc + +# evidence of the partial binlog +--error ER_ERROR_WHEN_EXECUTING_COMMAND +show binlog events; + +--connection slave +call mtr.add_suppression("Slave I/O: Got fatal error 1236 from master when reading data from binary log"); +reset slave; +start slave; + +# ER_MASTER_FATAL_ERROR_READING_BINLOG 1236 +--let $slave_param=Last_IO_Errno +--let $slave_param_value=1236 +--source include/wait_for_slave_param.inc + +--let $slave_field_result_replace= / at [0-9]*/ at XXX/ +--let $status_items= Last_IO_Errno, Last_IO_Error +--source include/show_slave_status.inc + +# +# Cleanup +# + +--connection master +reset master; + +--connection slave +stop slave; +reset slave; +# Table was created from binlog, it may not be created if SQL thread is running +# slowly and IO thread reaches incident before SQL thread applies it. +--disable_warnings +drop table if exists t; +--enable_warnings +reset master; + +--echo End of the tests +--let $rpl_only_running_threads= 1 +--source include/rpl_end.inc diff --git a/mysql-test/suite/rpl/t/rpl_checksum.test b/mysql-test/suite/rpl/t/rpl_checksum.test index 0edf8fda7f329..17a986dc30801 100644 --- a/mysql-test/suite/rpl/t/rpl_checksum.test +++ b/mysql-test/suite/rpl/t/rpl_checksum.test @@ -1 +1,335 @@ ---source include/rpl_checksum.inc +# +# This include file is used by more than one test suite +# (currently rpl and binlog_encryption). +# Please check all dependent tests after modifying it +# + +# WL2540 replication events checksum +# Testing configuration parameters + +--source include/have_debug.inc +--source include/have_binlog_format_mixed.inc +--source include/master-slave.inc + +call mtr.add_suppression('Slave can not handle replication events with the checksum that master is configured to log'); +call mtr.add_suppression('Replication event checksum verification failed'); +# due to C failure simulation +call mtr.add_suppression('Relay log write failure: could not queue event from master'); +call mtr.add_suppression('Master is configured to log replication events with checksum, but will not send such events to slaves that cannot process them'); + +# A. read/write access to the global vars: +# binlog_checksum master_verify_checksum slave_sql_verify_checksum + +connection master; + +set @master_save_binlog_checksum= @@global.binlog_checksum; +set @save_master_verify_checksum = @@global.master_verify_checksum; + +select @@global.binlog_checksum as 'must be CRC32 because of the command line option'; +--error ER_INCORRECT_GLOBAL_LOCAL_VAR +select @@session.binlog_checksum as 'no session var'; + +select @@global.master_verify_checksum as 'must be zero because of default'; +--error ER_INCORRECT_GLOBAL_LOCAL_VAR +select @@session.master_verify_checksum as 'no session var'; + +connection slave; + +set @slave_save_binlog_checksum= @@global.binlog_checksum; +set @save_slave_sql_verify_checksum = @@global.slave_sql_verify_checksum; + +select @@global.slave_sql_verify_checksum as 'must be one because of default'; +--error ER_INCORRECT_GLOBAL_LOCAL_VAR +select @@session.slave_sql_verify_checksum as 'no session var'; + +connection master; + +source include/show_binary_logs.inc; +set @@global.binlog_checksum = NONE; +select @@global.binlog_checksum; +--echo *** must be rotations seen *** +source include/show_binary_logs.inc; + +set @@global.binlog_checksum = default; +select @@global.binlog_checksum; + +# testing lack of side-effects in non-effective update of binlog_checksum: +set @@global.binlog_checksum = CRC32; +select @@global.binlog_checksum; +set @@global.binlog_checksum = CRC32; + +set @@global.master_verify_checksum = 0; +set @@global.master_verify_checksum = default; + +--error ER_WRONG_VALUE_FOR_VAR +set @@global.binlog_checksum = ADLER32; +--error ER_WRONG_VALUE_FOR_VAR +set @@global.master_verify_checksum = 2; # the var is of bool type + +connection slave; + +set @@global.slave_sql_verify_checksum = 0; +set @@global.slave_sql_verify_checksum = default; +--error ER_WRONG_VALUE_FOR_VAR +set @@global.slave_sql_verify_checksum = 2; # the var is of bool type + +# +# B. Old Slave to New master conditions +# +# while master does not send a checksum-ed binlog the Old Slave can +# work with the New Master + +connection master; + +set @@global.binlog_checksum = NONE; +create table t1 (a int); + +# testing that binlog rotation preserves opt_binlog_checksum value +flush logs; +flush logs; +-- source include/wait_for_binlog_checkpoint.inc +flush logs; + +sync_slave_with_master; +#connection slave; +# checking that rotation on the slave side leaves slave stable +flush logs; +flush logs; +flush logs; +select count(*) as zero from t1; + +source include/stop_slave.inc; + +connection master; +set @@global.binlog_checksum = CRC32; +-- source include/wait_for_binlog_checkpoint.inc +insert into t1 values (1) /* will not be applied on slave due to simulation */; + +# instruction to the dump thread + +connection slave; +set @saved_dbug = @@global.debug_dbug; +set @@global.debug_dbug='d,simulate_slave_unaware_checksum'; +start slave; +--let $slave_io_errno= 1236 +--let $show_slave_io_error= 1 +source include/wait_for_slave_io_error.inc; + +select count(*) as zero from t1; + +set @@global.debug_dbug = @saved_dbug; + +connection slave; +source include/start_slave.inc; + +# +# C. checksum failure simulations +# + +# C1. Failure by a client thread +connection master; +set @@global.master_verify_checksum = 1; +set @save_dbug = @@session.debug_dbug; +set @@session.debug_dbug='d,simulate_checksum_test_failure'; +--error ER_ERROR_WHEN_EXECUTING_COMMAND +show binlog events; +SET debug_dbug= @save_dbug; +set @@global.master_verify_checksum = default; + +#connection master; +sync_slave_with_master; + +connection slave; +source include/stop_slave.inc; + +connection master; +create table t2 (a int); +let $pos_master= query_get_value(SHOW MASTER STATUS, Position, 1); + +connection slave; + +# C2. Failure by IO thread +# instruction to io thread +set @saved_dbug = @@global.debug_dbug; +set @@global.debug_dbug='d,simulate_checksum_test_failure'; +start slave io_thread; +# When the checksum error is detected, the slave sets error code 1913 +# (ER_NETWORK_READ_EVENT_CHECKSUM_FAILURE) in queue_event(), then immediately +# sets error 1595 (ER_SLAVE_RELAY_LOG_WRITE_FAILURE) in handle_slave_io(). +# So we usually get 1595, but it is occasionally possible to get 1913. +--let $slave_io_errno= 1595,1913 +--let $show_slave_io_error= 0 +source include/wait_for_slave_io_error.inc; +set @@global.debug_dbug = @saved_dbug; + +# to make IO thread re-read it again w/o the failure +start slave io_thread; +let $slave_param= Read_Master_Log_Pos; +let $slave_param_value= $pos_master; +source include/wait_for_slave_param.inc; + +# C3. Failure by SQL thread +# instruction to sql thread; +set @@global.slave_sql_verify_checksum = 1; + +set @@global.debug_dbug='d,simulate_checksum_test_failure'; + +start slave sql_thread; +--let $slave_sql_errno= 1593 +--let $show_slave_sql_error= 1 +source include/wait_for_slave_sql_error.inc; + +# resuming SQL thread to parse out the event w/o the failure + +set @@global.debug_dbug = @saved_dbug; +source include/start_slave.inc; + +connection master; +sync_slave_with_master; + +#connection slave; +select count(*) as 'must be zero' from t2; + +# +# D. Reset slave, Change-Master, Binlog & Relay-log rotations with +# random value on binlog_checksum on both master and slave +# +connection slave; +stop slave; +reset slave; + +# randomize slave server's own checksum policy +set @@global.binlog_checksum= IF(floor((rand()*1000)%2), "CRC32", "NONE"); +flush logs; + +connection master; +set @@global.binlog_checksum= CRC32; +reset master; +flush logs; +create table t3 (a int, b char(5)); + +connection slave; +source include/start_slave.inc; + +connection master; +sync_slave_with_master; + +#connection slave; +select count(*) as 'must be zero' from t3; +source include/stop_slave.inc; +--replace_result $MASTER_MYPORT MASTER_PORT +eval change master to master_host='127.0.0.1',master_port=$MASTER_MYPORT, master_user='root'; + +connection master; +flush logs; +reset master; +insert into t3 value (1, @@global.binlog_checksum); + +connection slave; +source include/start_slave.inc; +flush logs; + +connection master; +sync_slave_with_master; + +#connection slave; +select count(*) as 'must be one' from t3; + +connection master; +set @@global.binlog_checksum= IF(floor((rand()*1000)%2), "CRC32", "NONE"); +insert into t3 value (1, @@global.binlog_checksum); +sync_slave_with_master; + +#connection slave; + +#clean-up + +connection master; +drop table t1, t2, t3; +set @@global.binlog_checksum = @master_save_binlog_checksum; +set @@global.master_verify_checksum = @save_master_verify_checksum; + +# +# BUG#58564: flush_read_lock fails in mysql-trunk-bugfixing after merging with WL#2540 +# +# Sanity check that verifies that no assertions are triggered because +# of old FD events (generated by versions prior to server released with +# checksums feature) +# +# There is no need for query log, if something wrong this should trigger +# an assertion + +--disable_query_log + +BINLOG ' +MfmqTA8BAAAAZwAAAGsAAAABAAQANS41LjctbTMtZGVidWctbG9nAAAAAAAAAAAAAAAAAAAAAAAA +AAAAAAAAAAAAAAAAAAAx+apMEzgNAAgAEgAEBAQEEgAAVAAEGggAAAAICAgCAA== +'; + +--enable_query_log + +#connection slave; +sync_slave_with_master; + + +--echo *** Bug#59123 / MDEV-5799: INCIDENT_EVENT checksum written to error log as garbage characters *** + +--connection master + +--source include/wait_for_binlog_checkpoint.inc +CREATE TABLE t4 (a INT PRIMARY KEY); +INSERT INTO t4 VALUES (1); + +SET sql_log_bin=0; +CALL mtr.add_suppression("\\[ERROR\\] Can't generate a unique log-filename"); +SET sql_log_bin=1; +SET @old_dbug= @@GLOBAL.debug_dbug; +SET debug_dbug= '+d,binlog_inject_new_name_error'; +--error ER_NO_UNIQUE_LOGFILE +FLUSH LOGS; +SET debug_dbug= @old_dbug; + +INSERT INTO t4 VALUES (2); + +--connection slave +--let $slave_sql_errno= 1590 +--source include/wait_for_slave_sql_error.inc + +# Search the error log for the error message. +# The bug was that 4 garbage bytes were output in the middle of the error +# message; by searching for a pattern that spans that location, we can +# catch the error. +let $log_error_= `SELECT @@GLOBAL.log_error`; +if(!$log_error_) +{ + # MySQL Server on windows is started with --console and thus + # does not know the location of its .err log, use default location + let $log_error_ = $MYSQLTEST_VARDIR/log/mysqld.2.err; +} +--let SEARCH_FILE= $log_error_ +--let SEARCH_PATTERN= Slave SQL: The incident LOST_EVENTS occurred on the master\. Message: error writing to the binary log, Internal MariaDB error code: 1590 +--source include/search_pattern_in_file.inc + +SELECT * FROM t4 ORDER BY a; +STOP SLAVE IO_THREAD; +SET sql_slave_skip_counter= 1; +--source include/start_slave.inc + +--connection master +--save_master_pos + +--connection slave +--sync_with_master +SELECT * FROM t4 ORDER BY a; + + +--connection slave +set @@global.binlog_checksum = @slave_save_binlog_checksum; +set @@global.slave_sql_verify_checksum = @save_slave_sql_verify_checksum; + +--echo End of tests + +--connection master +DROP TABLE t4; + +--source include/rpl_end.inc diff --git a/mysql-test/suite/rpl/t/rpl_checksum_cache.test b/mysql-test/suite/rpl/t/rpl_checksum_cache.test index 59b338d25562f..e04f618b81ea1 100644 --- a/mysql-test/suite/rpl/t/rpl_checksum_cache.test +++ b/mysql-test/suite/rpl/t/rpl_checksum_cache.test @@ -1 +1,261 @@ ---source include/rpl_checksum_cache.inc +# +# This include file is used by more than one test suite +# (currently rpl and binlog_encryption). +# Please check all dependent tests after modifying it +# + +-- source include/have_innodb.inc +-- source include/master-slave.inc + +--disable_warnings +call mtr.add_suppression("Unsafe statement written to the binary log using statement format since BINLOG_FORMAT = STATEMENT. .*Statement: insert into t2 set data=repeat.*'a', @act_size.*"); +call mtr.add_suppression("Unsafe statement written to the binary log using statement format since BINLOG_FORMAT = STATEMENT. .*Statement: insert into t1 values.* NAME_CONST.*'n',.*, @data .*"); +--enable_warnings + +connection master; +set @save_binlog_cache_size = @@global.binlog_cache_size; +set @save_binlog_checksum = @@global.binlog_checksum; +set @save_master_verify_checksum = @@global.master_verify_checksum; +set @@global.binlog_cache_size = 4096; +set @@global.binlog_checksum = CRC32; +set @@global.master_verify_checksum = 1; + +# restart slave to force the dump thread to verify events (on master side) +connection slave; +source include/stop_slave.inc; +source include/start_slave.inc; + +connection master; + +# +# Testing a critical part of checksum handling dealing with transaction cache. +# The cache's buffer size is set to be less than the transaction's footprint +# in binlog. +# +# To verify combined buffer-by-buffer read out of the file and fixing crc per event +# there are the following parts: +# +# 1. the event size is much less than the cache's buffer +# 2. the event size is bigger than the cache's buffer +# 3. the event size if approximately the same as the cache's buffer +# 4. all in above + +# +# 1. the event size is much less than the cache's buffer +# + +flush status; +show status like "binlog_cache_use"; +show status like "binlog_cache_disk_use"; +--disable_warnings +drop table if exists t1; +--enable_warnings + +# +# parameter to ensure the test slightly varies binlog content +# between different invocations +# +let $deviation_size=32; +eval create table t1 (a int PRIMARY KEY, b CHAR($deviation_size)) engine=innodb; + +# Now we are going to create transaction which is long enough so its +# transaction binlog will be flushed to disk... + +delimiter |; +create procedure test.p_init (n int, size int) +begin + while n > 0 do + select round(RAND() * size) into @act_size; + set @data = repeat('a', @act_size); + insert into t1 values(n, @data ); + set n= n-1; + end while; +end| + +delimiter ;| + +let $1 = 4000; # PB2 can run it slow to time out on following sync_slave_with_master:s + +begin; +--disable_warnings +# todo: check if it is really so. +#+Note 1592 Unsafe statement binlogged in statement format since BINLOG_FORMAT = STATEMENT. Reason for unsafeness: Statement uses a system function whose value may differ on slave. +eval call test.p_init($1, $deviation_size); +--enable_warnings +commit; + +show status like "binlog_cache_use"; +--echo *** binlog_cache_disk_use must be non-zero *** +show status like "binlog_cache_disk_use"; + +sync_slave_with_master; + +let $diff_tables=master:test.t1, slave:test.t1; +source include/diff_tables.inc; + +# undoing changes with verifying the above once again +connection master; + +begin; +delete from t1; +commit; + +sync_slave_with_master; + + +# +# 2. the event size is bigger than the cache's buffer +# +connection master; + +flush status; +let $t2_data_size= `select 3 * @@global.binlog_cache_size`; +let $t2_aver_size= `select 2 * @@global.binlog_cache_size`; +let $t2_max_rand= `select 1 * @@global.binlog_cache_size`; + +eval create table t2(a int auto_increment primary key, data VARCHAR($t2_data_size)) ENGINE=Innodb; +let $1=100; +--disable_query_log +begin; +while ($1) +{ + eval select round($t2_aver_size + RAND() * $t2_max_rand) into @act_size; + set @data = repeat('a', @act_size); + insert into t2 set data = @data; + dec $1; +} +commit; +--enable_query_log +show status like "binlog_cache_use"; +--echo *** binlog_cache_disk_use must be non-zero *** +show status like "binlog_cache_disk_use"; + +sync_slave_with_master; + +let $diff_tables=master:test.t2, slave:test.t2; +source include/diff_tables.inc; + +# undoing changes with verifying the above once again +connection master; + +begin; +delete from t2; +commit; + +sync_slave_with_master; + +# +# 3. the event size if approximately the same as the cache's buffer +# + +connection master; + +flush status; +let $t3_data_size= `select 2 * @@global.binlog_cache_size`; +let $t3_aver_size= `select (9 * @@global.binlog_cache_size) / 10`; +let $t3_max_rand= `select (2 * @@global.binlog_cache_size) / 10`; + +eval create table t3(a int auto_increment primary key, data VARCHAR($t3_data_size)) engine=innodb; + +let $1= 300; +--disable_query_log +begin; +while ($1) +{ + eval select round($t3_aver_size + RAND() * $t3_max_rand) into @act_size; + insert into t3 set data= repeat('a', @act_size); + dec $1; +} +commit; +--enable_query_log +show status like "binlog_cache_use"; +--echo *** binlog_cache_disk_use must be non-zero *** +show status like "binlog_cache_disk_use"; + +sync_slave_with_master; + +let $diff_tables=master:test.t3, slave:test.t3; +source include/diff_tables.inc; + +# undoing changes with verifying the above once again +connection master; + +begin; +delete from t3; +commit; + +sync_slave_with_master; + + +# +# 4. all in above +# + +connection master; +flush status; + +delimiter |; +eval create procedure test.p1 (n int) +begin + while n > 0 do + case (select (round(rand()*100) % 3) + 1) + when 1 then + select round(RAND() * $deviation_size) into @act_size; + set @data = repeat('a', @act_size); + insert into t1 values(n, @data); + when 2 then + begin + select round($t2_aver_size + RAND() * $t2_max_rand) into @act_size; + insert into t2 set data=repeat('a', @act_size); + end; + when 3 then + begin + select round($t3_aver_size + RAND() * $t3_max_rand) into @act_size; + insert into t3 set data= repeat('a', @act_size); + end; + end case; + set n= n-1; + end while; +end| +delimiter ;| + +let $1= 1000; +set autocommit= 0; +begin; +--disable_warnings +eval call test.p1($1); +--enable_warnings +commit; + +show status like "binlog_cache_use"; +--echo *** binlog_cache_disk_use must be non-zero *** +show status like "binlog_cache_disk_use"; + +sync_slave_with_master; + +let $diff_tables=master:test.t1, slave:test.t1; +source include/diff_tables.inc; + +let $diff_tables=master:test.t2, slave:test.t2; +source include/diff_tables.inc; + +let $diff_tables=master:test.t3, slave:test.t3; +source include/diff_tables.inc; + + +connection master; + +begin; +delete from t1; +delete from t2; +delete from t3; +commit; + +drop table t1, t2, t3; +set @@global.binlog_cache_size = @save_binlog_cache_size; +set @@global.binlog_checksum = @save_binlog_checksum; +set @@global.master_verify_checksum = @save_master_verify_checksum; +drop procedure test.p_init; +drop procedure test.p1; + +--source include/rpl_end.inc diff --git a/mysql-test/suite/rpl/t/rpl_corruption.test b/mysql-test/suite/rpl/t/rpl_corruption.test index e51d1c65e9503..c7a913af9d7f2 100644 --- a/mysql-test/suite/rpl/t/rpl_corruption.test +++ b/mysql-test/suite/rpl/t/rpl_corruption.test @@ -1 +1,175 @@ ---source include/rpl_corruption.inc +# +# This include file is used by more than one test suite +# (currently rpl and binlog_encryption). +# Please check all dependent tests after modifying it +# + +############################################################ +# Purpose: WL#5064 Testing with corrupted events. +# The test emulates the corruption at the vary stages +# of replication: +# - in binlog file +# - in network +# - in relay log +############################################################ + +# +# The tests intensively utilize @@global.debug. Note, +# Bug#11765758 - 58754, +# @@global.debug is read by the slave threads through dbug-interface. +# Hence, before a client thread set @@global.debug we have to ensure that: +# (a) the slave threads are stopped, or (b) the slave threads are in +# sync and waiting. + +--source include/have_debug.inc +--source include/master-slave.inc + +# Block legal errors for MTR +call mtr.add_suppression('Found invalid event in binary log'); +call mtr.add_suppression('Slave I/O: Relay log write failure: could not queue event from master'); +call mtr.add_suppression('event read from binlog did not pass crc check'); +call mtr.add_suppression('Replication event checksum verification failed'); +call mtr.add_suppression('Event crc check failed! Most likely there is event corruption'); +call mtr.add_suppression('Slave SQL: Error initializing relay log position: I/O error reading event at position .*, error.* 1593'); + +SET @old_master_verify_checksum = @@master_verify_checksum; + +# Creating test table/data and set corruption position for testing +--echo # 1. Creating test table/data and set corruption position for testing +--connection master +--echo * insert/update/delete rows in table t1 * +# Corruption algorithm modifies only the first event and +# then will be reset. To avoid checking always the first event +# from binlog (usually it is FD) we randomly execute different +# statements and set position for corruption inside events. + +CREATE TABLE t1 (a INT NOT NULL PRIMARY KEY, b VARCHAR(10), c VARCHAR(100)); +--disable_query_log +let $i=`SELECT 3+CEILING(10*RAND())`; +let $j=1; +let $pos=0; +while ($i) { + eval INSERT INTO t1 VALUES ($j, 'a', NULL); + if (`SELECT RAND() > 0.7`) + { + eval UPDATE t1 SET c = REPEAT('a', 20) WHERE a = $j; + } + if (`SELECT RAND() > 0.8`) + { + eval DELETE FROM t1 WHERE a = $j; + } + if (!$pos) { + let $pos= query_get_value(SHOW MASTER STATUS, Position, 1); + --sync_slave_with_master + --source include/stop_slave.inc + --disable_query_log + --connection master + } + dec $i; + inc $j; +} +--enable_query_log + + +# Emulate corruption in binlog file when SHOW BINLOG EVENTS is executing +--echo # 2. Corruption in master binlog and SHOW BINLOG EVENTS +SET @saved_dbug = @@global.debug_dbug; +SET @@global.debug_dbug="d,corrupt_read_log_event_char"; +--echo SHOW BINLOG EVENTS; +--disable_query_log +send_eval SHOW BINLOG EVENTS FROM $pos; +--enable_query_log +--error ER_ERROR_WHEN_EXECUTING_COMMAND +reap; + +SET @@global.debug_dbug=@saved_dbug; + +# Emulate corruption on master with crc checking on master +--echo # 3. Master read a corrupted event from binlog and send the error to slave + +# We have a rare but nasty potential race here: if the dump thread on +# the master for the _old_ slave connection has not yet discovered +# that the slave has disconnected, we will inject the corrupt event on +# the wrong connection, and the test will fail +# (+d,corrupt_read_log_event2 corrupts only one event). +# So kill any lingering dump thread (we need to kill; otherwise dump thread +# could manage to send all events down the socket before seeing it close, and +# hang forever waiting for new binlog events to be created). +let $id= `select id from information_schema.processlist where command = "Binlog Dump"`; +if ($id) +{ + --disable_query_log + --error 0,1094 + eval kill $id; + --enable_query_log +} +let $wait_condition= + SELECT COUNT(*)=0 FROM INFORMATION_SCHEMA.PROCESSLIST WHERE command = 'Binlog Dump'; +--source include/wait_condition.inc + +SET @@global.debug_dbug="d,corrupt_read_log_event2_set"; +--connection slave +START SLAVE IO_THREAD; +let $slave_io_errno= 1236; +--let $slave_timeout= 10 +--source include/wait_for_slave_io_error.inc +--connection master +SET @@global.debug_dbug=@saved_dbug; + +# Emulate corruption on master without crc checking on master +--echo # 4. Master read a corrupted event from binlog and send it to slave +--connection master +SET GLOBAL master_verify_checksum=0; +SET @@global.debug_dbug="d,corrupt_read_log_event2_set"; +--connection slave +START SLAVE IO_THREAD; +# When the checksum error is detected, the slave sets error code 1743 +# (ER_NETWORK_READ_EVENT_CHECKSUM_FAILURE) in queue_event(), then immediately +# sets error 1595 (ER_SLAVE_RELAY_LOG_WRITE_FAILURE) in handle_slave_io(). +# So we usually get 1595, but it is occasionally possible to get 1743. +let $slave_io_errno= 1595,1743; # ER_SLAVE_RELAY_LOG_WRITE_FAILURE, ER_NETWORK_READ_EVENT_CHECKSUM_FAILURE +--source include/wait_for_slave_io_error.inc +--connection master +SET @@global.debug_dbug=@saved_dbug; +SET GLOBAL master_verify_checksum=1; + +# Emulate corruption in network +--echo # 5. Slave. Corruption in network +--connection slave +SET @saved_dbug_slave = @@GLOBAL.debug_dbug; +SET @@global.debug_dbug="d,corrupt_queue_event"; +START SLAVE IO_THREAD; +let $slave_io_errno= 1595,1743; # ER_SLAVE_RELAY_LOG_WRITE_FAILURE, ER_NETWORK_READ_EVENT_CHECKSUM_FAILURE +--source include/wait_for_slave_io_error.inc +SET @@global.debug_dbug=@saved_dbug_slave; + +# Emulate corruption in relay log +--echo # 6. Slave. Corruption in relay log + +SET @@global.debug_dbug="d,corrupt_read_log_event_char"; + +START SLAVE SQL_THREAD; +let $slave_sql_errno= 1593; +--source include/wait_for_slave_sql_error.inc + +SET @@global.debug_dbug=@saved_dbug_slave; + +# Start normal replication and compare same table on master +# and slave +--echo # 7. Seek diff for tables on master and slave +--connection slave +--source include/start_slave.inc +--connection master +--sync_slave_with_master +let $diff_tables= master:test.t1, slave:test.t1; +--source include/diff_tables.inc + +# Clean up +--echo # 8. Clean up +--connection master +set @@global.debug_dbug = @saved_dbug; +SET GLOBAL master_verify_checksum = @old_master_verify_checksum; +DROP TABLE t1; +--sync_slave_with_master + +--source include/rpl_end.inc diff --git a/mysql-test/suite/rpl/t/rpl_gtid_basic.test b/mysql-test/suite/rpl/t/rpl_gtid_basic.test index 004003ea52488..5975c6f03c3e3 100644 --- a/mysql-test/suite/rpl/t/rpl_gtid_basic.test +++ b/mysql-test/suite/rpl/t/rpl_gtid_basic.test @@ -1,4 +1,575 @@ ---source include/rpl_gtid_basic.inc +# +# This include file is used by more than one test suite +# (currently rpl and binlog_encryption). +# Please check all dependent tests after modifying it +# + +--source include/have_innodb.inc +--let $rpl_topology=1->2->3->4 +--source include/rpl_init.inc + +# Set up a 4-deep replication topology, then test various fail-overs +# using GTID. +# +# A -> B -> C -> D + +connection server_1; +--source include/wait_for_binlog_checkpoint.inc +--let $binlog_file = query_get_value(SHOW MASTER STATUS,File,1) +--let $binlog_pos = query_get_value(SHOW MASTER STATUS,Position,1) +--echo *** GTID position should be empty here *** +--replace_result $binlog_file $binlog_pos +eval SELECT BINLOG_GTID_POS('$binlog_file',$binlog_pos); + +CREATE TABLE t1 (a INT PRIMARY KEY, b VARCHAR(10)) ENGINE=MyISAM; +CREATE TABLE t2 (a INT PRIMARY KEY, b VARCHAR(10)) ENGINE=InnoDB; +INSERT INTO t1 VALUES (1, "m1"); +INSERT INTO t1 VALUES (2, "m2"), (3, "m3"), (4, "m4"); +INSERT INTO t2 VALUES (1, "i1"); +BEGIN; +INSERT INTO t2 VALUES (2, "i2"), (3, "i3"); +INSERT INTO t2 VALUES (4, "i4"); +COMMIT; +save_master_pos; +source include/wait_for_binlog_checkpoint.inc; +--let $binlog_file = query_get_value(SHOW MASTER STATUS,File,1) +--let $binlog_pos = query_get_value(SHOW MASTER STATUS,Position,1) +--let $gtid_pos_server_1 = `SELECT @@gtid_binlog_pos` +--echo *** GTID position should be non-empty here *** +--replace_result $binlog_file $binlog_pos $gtid_pos_server_1 +eval SELECT BINLOG_GTID_POS('$binlog_file',$binlog_pos); + +connection server_2; +sync_with_master; +source include/wait_for_binlog_checkpoint.inc; +--let $binlog_file = query_get_value(SHOW MASTER STATUS,File,1) +--let $binlog_pos = query_get_value(SHOW MASTER STATUS,Position,1) +--echo *** GTID position should be the same as on server_1 *** +--replace_result $binlog_file $binlog_pos $gtid_pos_server_1 +eval SELECT BINLOG_GTID_POS('$binlog_file',$binlog_pos); +SELECT * FROM t1 ORDER BY a; +SELECT * FROM t2 ORDER BY a; +save_master_pos; + +connection server_3; +sync_with_master; +SELECT * FROM t1 ORDER BY a; +SELECT * FROM t2 ORDER BY a; +save_master_pos; + +connection server_4; +sync_with_master; +SELECT * FROM t1 ORDER BY a; +SELECT * FROM t2 ORDER BY a; + + +--echo *** Now take out D, let it fall behind a bit, and then test re-attaching it to A *** +connection server_4; +--source include/stop_slave.inc + +connection server_1; +INSERT INTO t1 VALUES (5, "m1a"); +INSERT INTO t2 VALUES (5, "i1a"); +save_master_pos; + +connection server_4; +--replace_result $MASTER_MYPORT MASTER_PORT +eval CHANGE MASTER TO master_host = '127.0.0.1', master_port = $MASTER_MYPORT, + MASTER_USE_GTID=CURRENT_POS; +--source include/start_slave.inc +sync_with_master; +SELECT * FROM t1 ORDER BY a; +SELECT * FROM t2 ORDER BY a; + +--echo *** Now move B to D (C is still replicating from B) *** +connection server_2; +--source include/stop_slave.inc +--replace_result $SERVER_MYPORT_4 SERVER_MYPORT_4 +eval CHANGE MASTER TO master_host = '127.0.0.1', master_port = $SERVER_MYPORT_4, + MASTER_USE_GTID=CURRENT_POS; +--source include/start_slave.inc + +connection server_4; +UPDATE t2 SET b="j1a" WHERE a=5; +save_master_pos; + +connection server_2; +sync_with_master; +SELECT * FROM t1 ORDER BY a; +SELECT * FROM t2 ORDER BY a; + +--echo *** Now move C to D, after letting it fall a little behind *** +connection server_3; +--source include/stop_slave.inc + +connection server_1; +INSERT INTO t2 VALUES (6, "i6b"); +INSERT INTO t2 VALUES (7, "i7b"); +--source include/save_master_gtid.inc + +connection server_3; +--replace_result $SERVER_MYPORT_4 SERVER_MYPORT_4 +eval CHANGE MASTER TO master_host = '127.0.0.1', master_port = $SERVER_MYPORT_4, + MASTER_USE_GTID=CURRENT_POS; +--source include/start_slave.inc +--source include/sync_with_master_gtid.inc +SELECT * FROM t2 ORDER BY a; + +--echo *** Now change everything back to what it was, to make rpl_end.inc happy +# Also check that MASTER_USE_GTID=CURRENT_POS is still enabled. +connection server_2; +# We need to sync up server_2 before switching. If it happened to have reached +# the point 'UPDATE t2 SET b="j1a" WHERE a=5' it will fail to connect to +# server_1, which is (deliberately) missing that transaction. +--source include/sync_with_master_gtid.inc +--source include/stop_slave.inc +--replace_result $MASTER_MYPORT MASTER_MYPORT +eval CHANGE MASTER TO master_host = '127.0.0.1', master_port = $MASTER_MYPORT; +--source include/start_slave.inc +--source include/wait_for_slave_to_start.inc + +connection server_3; +--source include/stop_slave.inc +--replace_result $SLAVE_MYPORT SLAVE_MYPORT +eval CHANGE MASTER TO master_host = '127.0.0.1', master_port = $SLAVE_MYPORT; +--source include/start_slave.inc +--source include/sync_with_master_gtid.inc + +connection server_4; +--source include/stop_slave.inc +--replace_result $SERVER_MYPORT_3 SERVER_MYPORT_3 +eval CHANGE MASTER TO master_host = '127.0.0.1', master_port = $SERVER_MYPORT_3; +--source include/start_slave.inc + +connection server_1; +DROP TABLE t1,t2; +--source include/save_master_gtid.inc + +--echo *** A few more checks for BINLOG_GTID_POS function *** +--let $valid_binlog_name = query_get_value(SHOW BINARY LOGS,Log_name,1) +--error ER_WRONG_PARAMCOUNT_TO_NATIVE_FCT +SELECT BINLOG_GTID_POS(); +--error ER_WRONG_PARAMCOUNT_TO_NATIVE_FCT +SELECT BINLOG_GTID_POS('a'); +--error ER_WRONG_PARAMCOUNT_TO_NATIVE_FCT +SELECT BINLOG_GTID_POS('a',1,NULL); +SELECT BINLOG_GTID_POS(1,'a'); +SELECT BINLOG_GTID_POS(NULL,NULL); +SELECT BINLOG_GTID_POS('',1); +SELECT BINLOG_GTID_POS('a',1); +eval SELECT BINLOG_GTID_POS('$valid_binlog_name',-1); +eval SELECT BINLOG_GTID_POS('$valid_binlog_name',0); +eval SELECT BINLOG_GTID_POS('$valid_binlog_name',18446744073709551615); +eval SELECT BINLOG_GTID_POS('$valid_binlog_name',18446744073709551616); + + +--echo *** Some tests of @@GLOBAL.gtid_binlog_state *** +--connection server_2 +--source include/sync_with_master_gtid.inc +--source include/stop_slave.inc + +--connection server_1 +SET @old_state= @@GLOBAL.gtid_binlog_state; + +--error ER_BINLOG_MUST_BE_EMPTY +SET GLOBAL gtid_binlog_state = ''; +RESET MASTER; +SET GLOBAL gtid_binlog_state = ''; +FLUSH LOGS; +--source include/show_binary_logs.inc +SET GLOBAL gtid_binlog_state = '0-1-10,1-2-20,0-3-30'; +--source include/show_binary_logs.inc +--let $binlog_file= master-bin.000001 +--let $binlog_start= 4 +--source include/show_binlog_events.inc +#SELECT @@GLOBAL.gtid_binlog_pos; +#SELECT @@GLOBAL.gtid_binlog_state; +--error ER_BINLOG_MUST_BE_EMPTY +SET GLOBAL gtid_binlog_state = @old_state; +RESET MASTER; +SET GLOBAL gtid_binlog_state = @old_state; + +# Check that slave can reconnect again, despite the RESET MASTER, as we +# restored the state. + +CREATE TABLE t1 (a INT PRIMARY KEY); +SET gtid_seq_no=100; +INSERT INTO t1 VALUES (1); +--source include/save_master_gtid.inc + +--connection server_2 +--source include/start_slave.inc +# We cannot just use sync_with_master as we've done RESET MASTER, so +# slave old-style position is wrong. +# So sync on gtid position instead. +--source include/sync_with_master_gtid.inc + +SELECT * FROM t1; +# Check that the IO gtid position in SHOW SLAVE STATUS is also correct. +--let $status_items= Gtid_IO_Pos +--source include/show_slave_status.inc + +--echo *** Test @@LAST_GTID and MASTER_GTID_WAIT() *** + +--connection server_1 +DROP TABLE t1; +CREATE TABLE t1 (a INT PRIMARY KEY) ENGINE=InnoDB; +--save_master_pos + +--connection server_2 +--sync_with_master +--source include/stop_slave.inc + +--connect (m1,127.0.0.1,root,,test,$SERVER_MYPORT_1,) +SELECT @@last_gtid; +SET gtid_seq_no=110; +SELECT @@last_gtid; +BEGIN; +SELECT @@last_gtid; +INSERT INTO t1 VALUES (2); +SELECT @@last_gtid; +COMMIT; +SELECT @@last_gtid; +--let $pos= `SELECT @@gtid_binlog_pos` + +--connect (s1,127.0.0.1,root,,test,$SERVER_MYPORT_2,) +eval SET @pos= '$pos'; +# Check NULL argument. +SELECT master_gtid_wait(NULL); +# Check empty argument returns immediately. +SELECT master_gtid_wait('', NULL); +# Check this gets counted +SHOW STATUS LIKE 'Master_gtid_wait_count'; +SHOW STATUS LIKE 'Master_gtid_wait_timeouts'; +SHOW STATUS LIKE 'Master_gtid_wait_time'; +# Let's check that we get a timeout +SELECT master_gtid_wait(@pos, 0.5); +SELECT * FROM t1 ORDER BY a; +# Now actually wait until the slave reaches the position +send SELECT master_gtid_wait(@pos); + +--connection server_2 +--source include/start_slave.inc + +--connection s1 +reap; +SELECT * FROM t1 ORDER BY a; + +# Test waiting on a domain that does not exist yet. +--source include/stop_slave.inc + +--connection server_1 +SET gtid_domain_id= 1; +INSERT INTO t1 VALUES (3); +--let $pos= `SELECT @@gtid_binlog_pos` + +--connection s1 +--replace_result $pos POS +eval SET @pos= '$pos'; +SELECT master_gtid_wait(@pos, 0); +SELECT * FROM t1 WHERE a >= 3; +send SELECT master_gtid_wait(@pos, -1); + +--connection server_2 +--source include/start_slave.inc + +--connection s1 +reap; +SELECT * FROM t1 WHERE a >= 3; +# Waiting for only part of the position. +SELECT master_gtid_wait('1-1-1', 0); + +# Now test a lot of parallel master_gtid_wait() calls, completing in different +# order, and some of which time out or get killed on the way. + +--connection s1 +send SELECT master_gtid_wait('2-1-1,1-1-4,0-1-110'); + +--connect (s2,127.0.0.1,root,,test,$SERVER_MYPORT_2,) +# This will time out. No event 0-1-1000 exists +send SELECT master_gtid_wait('0-1-1000', 0.5); + +--connect (s3,127.0.0.1,root,,test,$SERVER_MYPORT_2,) +# This one we will kill +--let $kill1_id= `SELECT connection_id()` +send SELECT master_gtid_wait('0-1-2000'); + +--connect (s4,127.0.0.1,root,,test,$SERVER_MYPORT_2,) +send SELECT master_gtid_wait('2-1-10'); + +--connect (s5,127.0.0.1,root,,test,$SERVER_MYPORT_2,) +send SELECT master_gtid_wait('2-1-6', 1); + +# This one we will kill also. +--connect (s6,127.0.0.1,root,,test,$SERVER_MYPORT_2,) +--let $kill2_id= `SELECT connection_id()` +send SELECT master_gtid_wait('2-1-5'); + +--connect (s7,127.0.0.1,root,,test,$SERVER_MYPORT_2,) +send SELECT master_gtid_wait('2-1-10'); + +--connect (s8,127.0.0.1,root,,test,$SERVER_MYPORT_2,) +send SELECT master_gtid_wait('2-1-5,1-1-4,0-1-110'); + +--connect (s9,127.0.0.1,root,,test,$SERVER_MYPORT_2,) +send SELECT master_gtid_wait('2-1-2'); + +--connection server_2 +# This one completes immediately. +SHOW STATUS LIKE 'Master_gtid_wait_timeouts'; +SHOW STATUS LIKE 'Master_gtid_wait_count'; +SELECT master_gtid_wait('1-1-1'); +SHOW STATUS LIKE 'Master_gtid_wait_timeouts'; +SHOW STATUS LIKE 'Master_gtid_wait_count'; +let $wait_time = query_get_value(SHOW STATUS LIKE 'Master_gtid_wait_time', Value, 1); +--replace_result $wait_time MASTER_GTID_WAIT_TIME +eval SET @a= $wait_time; +SELECT IF(@a <= 100*1000*1000, "OK", CONCAT("Error: wait time ", @a, " is larger than expected")) + AS Master_gtid_wait_time_as_expected; + + +--connect (s10,127.0.0.1,root,,test,$SERVER_MYPORT_2,) +send SELECT master_gtid_wait('0-1-109'); + +--connection server_2 +# This one should time out. +SHOW STATUS LIKE 'Master_gtid_wait_timeouts'; +SHOW STATUS LIKE 'Master_gtid_wait_count'; +SELECT master_gtid_wait('2-1-2', 0.5); +SHOW STATUS LIKE 'Master_gtid_wait_timeouts'; +SHOW STATUS LIKE 'Master_gtid_wait_count'; +let $wait_time = query_get_value(SHOW STATUS LIKE 'Master_gtid_wait_time', Value, 1); +--replace_result $wait_time MASTER_GTID_WAIT_TIME +eval SET @a= $wait_time; +# We expect a wait time of just a bit over 0.5 seconds. But thread scheduling +# and timer inaccuracies could introduce significant jitter. So allow a +# generous interval. +SELECT IF(@a BETWEEN 0.4*1000*1000 AND 100*1000*1000, "OK", CONCAT("Error: wait time ", @a, " not as expected")) AS Master_gtid_wait_time_as_expected; + +--replace_result $kill1_id KILL_ID +eval KILL QUERY $kill1_id; +--connection s3 +--error ER_QUERY_INTERRUPTED +reap; + +--connection server_1 +SET gtid_domain_id=2; +SET gtid_seq_no=2; +INSERT INTO t1 VALUES (4); + +--connection s9 +reap; + +--connection server_2 +--replace_result $kill2_id KILL_ID +eval KILL CONNECTION $kill2_id; + +--connection s6 +--error 2013,ER_CONNECTION_KILLED +reap; + +--connection server_1 +SET gtid_domain_id=1; +SET gtid_seq_no=4; +INSERT INTO t1 VALUES (5); +SET gtid_domain_id=2; +SET gtid_seq_no=5; +INSERT INTO t1 VALUES (6); + +--connection s8 +reap; +--connection s1 +reap; +--connection s2 +reap; +--connection s5 +reap; +--connection s10 +reap; + +--connection server_1 +SET gtid_domain_id=2; +SET gtid_seq_no=10; +INSERT INTO t1 VALUES (7); + +--connection s4 +reap; +--connection s7 +reap; + + +--echo *** Test gtid_slave_pos when used with GTID *** + +--connection server_2 +--source include/stop_slave.inc + +--connection server_1 +SET gtid_domain_id=2; +SET gtid_seq_no=1000; +INSERT INTO t1 VALUES (10); +INSERT INTO t1 VALUES (11); +--save_master_pos + +--connection server_2 +SET sql_slave_skip_counter= 1; +--source include/start_slave.inc +--sync_with_master +SELECT * FROM t1 WHERE a >= 10 ORDER BY a; +SELECT IF(LOCATE("2-1-1001", @@GLOBAL.gtid_slave_pos)>0, "Ok", CONCAT("ERROR! expected GTID 2-1-1001 not found in gtid_slave_pos: ", @@GLOBAL.gtid_slave_pos)) AS status; + +--source include/stop_slave.inc + +--connection server_1 +SET gtid_domain_id=2; +SET gtid_seq_no=1010; +INSERT INTO t1 VALUES (12); +INSERT INTO t1 VALUES (13); +--save_master_pos + +--connection server_2 +SET sql_slave_skip_counter= 2; +--source include/start_slave.inc +--sync_with_master +SELECT * FROM t1 WHERE a >= 10 ORDER BY a; +SELECT IF(LOCATE("2-1-1011", @@GLOBAL.gtid_slave_pos)>0, "Ok", CONCAT("ERROR! expected GTID 2-1-1011 not found in gtid_slave_pos: ", @@GLOBAL.gtid_slave_pos)) AS status; + +--source include/stop_slave.inc + +--connection server_1 +SET gtid_domain_id=2; +SET gtid_seq_no=1020; +INSERT INTO t1 VALUES (14); +INSERT INTO t1 VALUES (15); +INSERT INTO t1 VALUES (16); +--save_master_pos + +--connection server_2 +SET sql_slave_skip_counter= 3; +--source include/start_slave.inc +--sync_with_master +SELECT * FROM t1 WHERE a >= 10 ORDER BY a; +SELECT IF(LOCATE("2-1-1022", @@GLOBAL.gtid_slave_pos)>0, "Ok", CONCAT("ERROR! expected GTID 2-1-1022 not found in gtid_slave_pos: ", @@GLOBAL.gtid_slave_pos)) AS status; + +--source include/stop_slave.inc + +--connection server_1 +SET gtid_domain_id=2; +SET gtid_seq_no=1030; +# Disable logging Annotate_rows events to preserve events count. +let $binlog_annotate_row_events_saved= `SELECT @@binlog_annotate_row_events`; +SET @@binlog_annotate_row_events= 0; +INSERT INTO t1 VALUES (17); +INSERT INTO t1 VALUES (18); +INSERT INTO t1 VALUES (19); +eval SET @@binlog_annotate_row_events= $binlog_annotate_row_events_saved; +--save_master_pos + +--connection server_2 +SET sql_slave_skip_counter= 5; +--source include/start_slave.inc +--sync_with_master +SELECT * FROM t1 WHERE a >= 10 ORDER BY a; +SELECT IF(LOCATE("2-1-1032", @@GLOBAL.gtid_slave_pos)>0, "Ok", CONCAT("ERROR! expected GTID 2-1-1032 not found in gtid_slave_pos: ", @@GLOBAL.gtid_slave_pos)) AS status; + + +--source include/stop_slave.inc + +--connection server_1 +SET gtid_domain_id=3; +SET gtid_seq_no=100; +CREATE TABLE t2 (a INT PRIMARY KEY); +DROP TABLE t2; +SET gtid_domain_id=2; +SET gtid_seq_no=1040; +INSERT INTO t1 VALUES (20); +--save_master_pos + +--connection server_2 +SET @saved_mode= @@GLOBAL.slave_ddl_exec_mode; +SET GLOBAL slave_ddl_exec_mode=STRICT; +SET sql_slave_skip_counter=1; +START SLAVE UNTIL master_gtid_pos="3-1-100"; +--let $master_pos=3-1-100 +--source include/sync_with_master_gtid.inc +--source include/wait_for_slave_to_stop.inc +--error ER_NO_SUCH_TABLE +SELECT * FROM t2; +SELECT IF(LOCATE("3-1-100", @@GLOBAL.gtid_slave_pos)>0, "Ok", CONCAT("ERROR! expected GTID 3-1-100 not found in gtid_slave_pos: ", @@GLOBAL.gtid_slave_pos)) AS status; + +# Start the slave again, it should fail on the DROP TABLE as the table is not there. +SET sql_log_bin=0; +CALL mtr.add_suppression("Slave: Unknown table 'test\\.t2' Error_code: 1051"); +SET sql_log_bin=1; +START SLAVE; +--let $slave_sql_errno=1051 +--source include/wait_for_slave_sql_error.inc +SELECT IF(LOCATE("3-1-100", @@GLOBAL.gtid_slave_pos)>0, "Ok", CONCAT("ERROR! expected GTID 3-1-100 not found in gtid_slave_pos: ", @@GLOBAL.gtid_slave_pos)) AS status; + +STOP SLAVE IO_THREAD; +SET sql_slave_skip_counter=2; +--source include/start_slave.inc +--sync_with_master + +SELECT * FROM t1 WHERE a >= 20 ORDER BY a; +SELECT IF(LOCATE("3-1-101", @@GLOBAL.gtid_slave_pos)>0, "Ok", CONCAT("ERROR! expected GTID 3-1-101 not found in gtid_slave_pos: ", @@GLOBAL.gtid_slave_pos)) AS status; +SELECT IF(LOCATE("2-1-1040", @@GLOBAL.gtid_slave_pos)>0, "Ok", CONCAT("ERROR! expected GTID 2-1-1040 not found in gtid_slave_pos: ", @@GLOBAL.gtid_slave_pos)) AS status; + +SET GLOBAL slave_ddl_exec_mode= @saved_mode; + + +--echo *** Test GTID-connecting to a master with out-of-order sequence numbers in the binlog. *** + +# Create an out-of-order binlog on server 2. +# Let server 3 replicate to an out-of-order point, stop it, restart it, +# and check that it replicates correctly despite the out-of-order. + +--connection server_1 +SET gtid_domain_id= @@GLOBAL.gtid_domain_id; +INSERT INTO t1 VALUES (31); +--save_master_pos + +--connection server_2 +--sync_with_master +SET gtid_domain_id= @@GLOBAL.gtid_domain_id; +INSERT INTO t1 VALUES (32); + +--connection server_1 +INSERT INTO t1 VALUES (33); +--save_master_pos + +--connection server_2 +--sync_with_master +--save_master_pos + +--connection server_3 +--sync_with_master +--source include/stop_slave.inc + +--connection server_1 +INSERT INTO t1 VALUES (34); +--save_master_pos + +--connection server_2 +--sync_with_master +--save_master_pos + +--connection server_3 +--source include/start_slave.inc +--sync_with_master +SELECT * FROM t1 WHERE a >= 30 ORDER BY a; +--save_master_pos + +--connection server_4 +--sync_with_master +SELECT * FROM t1 WHERE a >= 30 ORDER BY a; + + +# Clean up. +--connection server_1 +DROP TABLE t1; + + +--source include/rpl_end.inc --echo # --echo # Start of 10.2 tests diff --git a/mysql-test/suite/rpl/t/rpl_incident.test b/mysql-test/suite/rpl/t/rpl_incident.test index 4bb6477ca986d..75d28d6a6c6b0 100644 --- a/mysql-test/suite/rpl/t/rpl_incident.test +++ b/mysql-test/suite/rpl/t/rpl_incident.test @@ -1 +1,61 @@ ---source include/rpl_incident.inc +# +# This include file is used by more than one test suite +# (currently rpl and binlog_encryption). +# Please check all dependent tests after modifying it +# + +--source include/have_debug.inc +--source include/master-slave.inc + +SET @old_binlog_checksum=@@binlog_checksum; +SET GLOBAL BINLOG_CHECKSUM=none; +connection slave; +SET @old_binlog_checksum=@@binlog_checksum; +SET GLOBAL BINLOG_CHECKSUM=none; +connection master; + +--echo **** On Master **** +CREATE TABLE t1 (a INT); + +INSERT INTO t1 VALUES (1),(2),(3); +SELECT * FROM t1; + +set @saved_dbug = @@global.debug_dbug; +SET GLOBAL debug_dbug= '+d,incident_database_resync_on_replace,*'; + +# This will generate an incident log event and store it in the binary +# log before the replace statement. +REPLACE INTO t1 VALUES (4); +--save_master_pos +SELECT * FROM t1; + +set @@global.debug_dbug = @saved_dbug; + +connection slave; +# Wait until SQL thread stops with error LOST_EVENT on master +call mtr.add_suppression("Slave SQL.*The incident LOST_EVENTS occurred on the master.* 1590"); +let $slave_sql_errno= 1590; +let $show_slave_sql_error= 1; +source include/wait_for_slave_sql_error.inc; + +# The 4 should not be inserted into the table, since the incident log +# event should have stop the slave. +--echo **** On Slave **** +SELECT * FROM t1; + +SET GLOBAL SQL_SLAVE_SKIP_COUNTER=1; +START SLAVE; +--sync_with_master + +# Now, we should have inserted the row into the table and the slave +# should be running. We should also have rotated to a new binary log. + +SELECT * FROM t1; +source include/check_slave_is_running.inc; + +connection master; +SET GLOBAL BINLOG_CHECKSUM=@old_binlog_checksum; +DROP TABLE t1; +--sync_slave_with_master +SET GLOBAL BINLOG_CHECKSUM=@old_binlog_checksum; +--source include/rpl_end.inc diff --git a/mysql-test/suite/rpl/t/rpl_init_slave_errors.test b/mysql-test/suite/rpl/t/rpl_init_slave_errors.test index 6f6ab7e8d7c9a..46673ea47649f 100644 --- a/mysql-test/suite/rpl/t/rpl_init_slave_errors.test +++ b/mysql-test/suite/rpl/t/rpl_init_slave_errors.test @@ -1 +1,96 @@ ---source include/rpl_init_slave_errors.inc +# +# This include file is used by more than one test suite +# (currently rpl and binlog_encryption). +# Please check all dependent tests after modifying it +# + +###################################################################### +# Some errors that cause the slave SQL thread to stop are not shown in +# the Slave_SQL_Error column of "SHOW SLAVE STATUS". Instead, the error +# is only in the server's error log. +# +# Two failures and their respective reporting are verified: +# +# 1 - Failures during slave thread initialization +# 2 - Failures while processing queries passed through the init_slave +# option. +# +# In order to check the first type of failure, we inject a fault in the +# SQL/IO Threads through SET GLOBAL debug. +# +# To check the second type, we set @@global.init_slave to an invalid +# command thus preventing the initialization of the SQL Thread. +# +# Obs: +# 1 - Note that testing failures while initializing the relay log position +# is hard as the same function is called before the code reaches the point +# that we want to test. +# +# 2 - This test does not target failures that are reported while applying +# events such as duplicate keys, errors while reading the relay-log.bin*, +# etc. Such errors are already checked on other tests. +###################################################################### + +###################################################################### +# Configuring the Environment +###################################################################### +source include/have_debug.inc; +source include/have_log_bin.inc; +source include/master-slave.inc; + +connection slave; + +--disable_warnings +stop slave; +--enable_warnings +reset slave; + +###################################################################### +# Injecting faults in the threads' initialization +###################################################################### +connection slave; + +# Set debug flags on slave to force errors to occur +set @saved_dbug = @@global.debug_dbug; +SET GLOBAL debug_dbug= "d,simulate_io_slave_error_on_init,simulate_sql_slave_error_on_init"; + +start slave; + +# +# slave is going to stop because of emulated failures +# but there won't be any crashes nor asserts hit. +# +# 1593 = ER_SLAVE_FATAL_ERROR +--let $slave_sql_errno= 1593 +--let $show_slave_sql_error= 1 +--source include/wait_for_slave_sql_error.inc + +call mtr.add_suppression("Failed during slave.* thread initialization"); + +set @@global.debug_dbug = @saved_dbug; + +###################################################################### +# Injecting faults in the init_slave option +###################################################################### +connection slave; + +reset slave; + +SET GLOBAL init_slave= "garbage"; + +start slave; +# 1064 = ER_PARSE_ERROR +--let $slave_sql_errno= 1064 +--let $show_slave_sql_error= 1 +--source include/wait_for_slave_sql_error.inc + +###################################################################### +# Clean up +###################################################################### +SET GLOBAL init_slave= ""; + +# Clean up Last_SQL_Error +--source include/stop_slave_io.inc +RESET SLAVE; +--let $rpl_only_running_threads= 1 +--source include/rpl_end.inc diff --git a/mysql-test/suite/rpl/include/rpl_loaddata_local.inc b/mysql-test/suite/rpl/t/rpl_loaddata_local.test similarity index 100% rename from mysql-test/suite/rpl/include/rpl_loaddata_local.inc rename to mysql-test/suite/rpl/t/rpl_loaddata_local.test diff --git a/mysql-test/suite/rpl/t/rpl_loaddatalocal.test b/mysql-test/suite/rpl/t/rpl_loaddatalocal.test deleted file mode 100644 index 712041467ab1c..0000000000000 --- a/mysql-test/suite/rpl/t/rpl_loaddatalocal.test +++ /dev/null @@ -1 +0,0 @@ ---source include/rpl_loaddata_local.inc diff --git a/mysql-test/suite/rpl/t/rpl_loadfile.test b/mysql-test/suite/rpl/t/rpl_loadfile.test index 10fecf1f65354..9cd645306908c 100644 --- a/mysql-test/suite/rpl/t/rpl_loadfile.test +++ b/mysql-test/suite/rpl/t/rpl_loadfile.test @@ -1 +1,120 @@ ---source include/rpl_loadfile.inc +# +# This include file is used by more than one test suite +# (currently rpl and binlog_encryption). +# Please check all dependent tests after modifying it +# + +############################################################################# +# Original Author: JBM # +# Original Date: Aug/18/2005 # +############################################################################# +# TEST: To test the LOAD_FILE() in rbr # +############################################################################# +# Change Author: JBM +# Change Date: 2006-01-16 +########## + +# Includes +-- source include/have_binlog_format_mixed_or_row.inc +-- source include/master-slave.inc + +-- source suite/rpl/include/rpl_loadfile.test + +# BUG#39701: Mixed binlog format does not switch to row mode on LOAD_FILE +# +# DESCRIPTION +# +# Problem: when using load_file string function and mixed binlogging format +# there was no switch to row based binlogging format. This leads +# to scenarios on which the slave replicates the statement and it +# will try to load the file from local file system, which in most +# likely it will not exist. +# +# Solution: +# Marking this function as unsafe for statement format, makes the +# statement using it to be logged in row based format. As such, data +# replicated from the master, becomes the content of the loaded file. +# Consequently, the slave receives the necessary data to complete +# the load_file instruction correctly. +# +# IMPLEMENTATION +# +# The test is implemented as follows: +# +# On Master, +# i) write to file the desired content. +# ii) create table and stored procedure with load_file +# iii) stop slave +# iii) execute load_file +# iv) remove file +# +# On Slave, +# v) start slave +# vi) sync it with master so that it gets the updates from binlog (which +# should have bin logged in row format). +# +# If the the binlog format does not change to row, then the assertion +# done in the following step fails. This happens because tables differ +# since the file does not exist anymore, meaning that when slave +# attempts to execute LOAD_FILE statement it inserts NULL on table +# instead of the same contents that the master loaded when it executed +# the procedure (which was executed when file existed). +# +# vii) assert that the contents of master and slave +# table are the same + +--source include/rpl_reset.inc + +connection master; +let $file= $MYSQLTEST_VARDIR/tmp/bug_39701.data; + +--replace_result $MYSQLTEST_VARDIR MYSQLTEST_VARDIR +--eval SELECT repeat('x',20) INTO OUTFILE '$file' + +disable_warnings; +DROP TABLE IF EXISTS t1; +enable_warnings; + +CREATE TABLE t1 (t text); +DELIMITER |; +CREATE PROCEDURE p(file varchar(4096)) + BEGIN + INSERT INTO t1 VALUES (LOAD_FILE(file)); + END| +DELIMITER ;| + +# stop slave before issuing the load_file on master +connection slave; +source include/stop_slave.inc; + +connection master; + +# test: check that logging falls back to rbr. +--replace_result $MYSQLTEST_VARDIR MYSQLTEST_VARDIR +--eval CALL p('$file') + +# test: remove the file from the filesystem and assert that slave still +# gets the loaded file +remove_file $file; + +# now that the file is removed it is safe (regarding what we want to test) +# to start slave +connection slave; +source include/start_slave.inc; + +connection master; +sync_slave_with_master; + +# assertion: assert that the slave got the updates even +# if the file was removed before the slave started, +# meaning that contents were indeed transfered +# through binlog (in row format) +let $diff_tables= master:t1, slave:t1; +source include/diff_tables.inc; + +# CLEAN UP +--connection master +DROP TABLE t1; +DROP PROCEDURE p; + +--source include/rpl_end.inc diff --git a/mysql-test/suite/rpl/t/rpl_packet.test b/mysql-test/suite/rpl/t/rpl_packet.test index 1bf99c2366b65..cbde486bcbbda 100644 --- a/mysql-test/suite/rpl/t/rpl_packet.test +++ b/mysql-test/suite/rpl/t/rpl_packet.test @@ -1 +1,184 @@ ---source include/rpl_packet.inc +# +# This include file is used by more than one test suite +# (currently rpl and binlog_encryption). +# Please check all dependent tests after modifying it +# + +# ==== Purpose ==== +# +# Check replication protocol packet size handling +# +# ==== Related bugs ==== +# Bug#19402 SQL close to the size of the max_allowed_packet fails on slave +# BUG#23755: Replicated event larger that max_allowed_packet infinitely re-transmits +# BUG#42914: No LAST_IO_ERROR for max_allowed_packet errors +# BUG#55322: SHOW BINLOG EVENTS increases @@SESSION.MAX_ALLOWED_PACKET + +# max-out size db name +source include/have_binlog_format_row.inc; +source include/master-slave.inc; + +call mtr.add_suppression("Slave I/O: Got a packet bigger than 'slave_max_allowed_packet' bytes, .*error.* 1153"); +call mtr.add_suppression("Log entry on master is longer than slave_max_allowed_packet"); +let $db= DB_NAME_OF_MAX_LENGTH_AKA_NAME_LEN_64_BYTES_____________________; +disable_warnings; +eval drop database if exists $db; +enable_warnings; +eval create database $db; + +connection master; +let $old_max_allowed_packet= `SELECT @@global.max_allowed_packet`; +let $old_net_buffer_length= `SELECT @@global.net_buffer_length`; +let $old_slave_max_allowed_packet= `SELECT @@global.slave_max_allowed_packet`; +SET @@global.max_allowed_packet=1024; +SET @@global.net_buffer_length=1024; + +sync_slave_with_master; +# Restart slave for setting to take effect +source include/stop_slave.inc; +source include/start_slave.inc; + +# Reconnect to master for new setting to take effect +disconnect master; + +# alas, can't use eval here; if db name changed apply the change here +connect (master,localhost,root,,DB_NAME_OF_MAX_LENGTH_AKA_NAME_LEN_64_BYTES_____________________); + +connection master; +select @@net_buffer_length, @@max_allowed_packet; + +create table `t1` (`f1` LONGTEXT) ENGINE=MyISAM; + +INSERT INTO `t1`(`f1`) VALUES ('aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa1023'); +sync_slave_with_master; + +eval select count(*) from `$db`.`t1` /* must be 1 */; + +SHOW STATUS LIKE 'Slave_running'; +select * from information_schema.session_status where variable_name= 'SLAVE_RUNNING'; +connection master; +eval drop database $db; +sync_slave_with_master; + +# +# Bug #23755: Replicated event larger that max_allowed_packet infinitely re-transmits +# +# Check that a situation when the size of event on the master is greater than +# max_allowed_packet on the slave does not lead to infinite re-transmits. + +connection master; + +# Change the max packet size on master + +SET @@global.max_allowed_packet=4096; +SET @@global.net_buffer_length=4096; + +# Restart slave for new setting to take effect +connection slave; +source include/stop_slave.inc; +source include/start_slave.inc; + +# Reconnect to master for new setting to take effect +disconnect master; +connect (master, localhost, root); +connection master; + +CREATE TABLE `t1` (`f1` LONGTEXT) ENGINE=MyISAM; + +sync_slave_with_master; + +connection master; + +INSERT INTO `t1`(`f1`) VALUES ('aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa2048'); + + +# +# Bug#42914: The slave I/O thread must stop after trying to read the above +# event, However there is no Last_IO_Error report. +# + +# The slave I/O thread must stop after trying to read the above event +connection slave; +# 1153 = ER_NET_PACKET_TOO_LARGE +--let $slave_io_errno= 1153 +--let $show_slave_io_error= 1 +--source include/wait_for_slave_io_error.inc + +# TODO: this is needed because of BUG#55790. Remove once that is fixed. +--source include/stop_slave_sql.inc + +# +# Bug#42914: On the master, if a binary log event is larger than +# max_allowed_packet, the error message ER_MASTER_FATAL_ERROR_READING_BINLOG +# is sent to a slave when it requests a dump from the master, thus leading the +# I/O thread to stop. However, there is no Last_IO_Error reported. +# + +--let $rpl_only_running_threads= 1 +--source include/rpl_reset.inc +--connection master +DROP TABLE t1; +--sync_slave_with_master + + +connection master; +CREATE TABLE t1 (f1 int PRIMARY KEY, f2 LONGTEXT, f3 LONGTEXT) ENGINE=MyISAM; +sync_slave_with_master; + +connection master; +INSERT INTO t1(f1, f2, f3) VALUES(1, REPEAT('a', @@global.max_allowed_packet), REPEAT('b', @@global.max_allowed_packet)); + +connection slave; +# The slave I/O thread must stop after receiving +# 1153 = ER_NET_PACKET_TOO_LARGE +--let $slave_io_errno= 1153 +--let $show_slave_io_error= 1 +--source include/wait_for_slave_io_error.inc + +# Remove the bad binlog and clear error status on slave. +STOP SLAVE; +RESET SLAVE; +--connection master +RESET MASTER; + + +# +# BUG#55322: SHOW BINLOG EVENTS increases @@SESSION.MAX_ALLOWED_PACKET +# +# In BUG#55322, @@session.max_allowed_packet increased each time SHOW +# BINLOG EVENTS was issued. To verify that this bug is fixed, we +# execute SHOW BINLOG EVENTS twice and check that max_allowed_packet +# never changes. We turn off the result log because we don't care +# about the contents of the binlog. + +--disable_result_log +SET @max_allowed_packet_0= @@session.max_allowed_packet; +SHOW BINLOG EVENTS; +SET @max_allowed_packet_1= @@session.max_allowed_packet; +SHOW BINLOG EVENTS; +SET @max_allowed_packet_2= @@session.max_allowed_packet; +--enable_result_log +if (`SELECT NOT(@max_allowed_packet_0 = @max_allowed_packet_1 AND @max_allowed_packet_1 = @max_allowed_packet_2)`) +{ + --echo ERROR: max_allowed_packet changed after executing SHOW BINLOG EVENTS + --source include/show_rpl_debug_info.inc + SELECT @max_allowed_packet_0, @max_allowed_packet_1, @max_allowed_packet_2; + --die @max_allowed_packet changed after executing SHOW BINLOG EVENTS +} + + +--echo ==== clean up ==== +connection master; +DROP TABLE t1; +eval SET @@global.max_allowed_packet= $old_max_allowed_packet; +eval SET @@global.net_buffer_length= $old_net_buffer_length; +eval SET @@global.slave_max_allowed_packet= $old_slave_max_allowed_packet; +# slave is stopped +connection slave; +DROP TABLE t1; + +# Clear Last_IO_Error +RESET SLAVE; + +--source include/rpl_end.inc +# End of tests diff --git a/mysql-test/suite/rpl/t/rpl_parallel_ignored_errors.test b/mysql-test/suite/rpl/t/rpl_parallel_ignored_errors.test index 90f09a76546db..7a6a758a508dd 100644 --- a/mysql-test/suite/rpl/t/rpl_parallel_ignored_errors.test +++ b/mysql-test/suite/rpl/t/rpl_parallel_ignored_errors.test @@ -1 +1,112 @@ ---source include/rpl_parallel_ignored_errors.inc +# ==== Purpose ==== +# +# Test verifies that, in parallel replication, transaction failure notification +# is propagated to all the workers. Workers should abort the execution of +# transaction event groups, whose event positions are higher than the failing +# transaction group. +# +# ==== Implementation ==== +# +# Steps: +# 0 - Create a table t1 on master which has a primary key. Enable parallel +# replication on slave with slave_parallel_mode='optimistic' and +# slave_parallel_threads=3. +# 1 - On slave start a transaction and execute a local INSERT statement +# which will insert value 32. This is done to block the INSERT coming +# from master. +# 2 - On master execute an INSERT statement with value 32, so that it is +# blocked on slave. +# 3 - On slave enable a debug sync point such that it holds the worker thread +# execution as soon as work is scheduled to it. +# 4 - INSERT value 33 on master. It will be held on slave by other worker +# thread due to debug simulation. +# 5 - INSERT value 34 on master. +# 6 - On slave, enusre that INSERT 34 has reached a state where it waits for +# its prior transactions to commit. +# 7 - Commit the local INSERT 32 on slave server so that first worker will +# error out. +# 8 - Now send a continue signal to second worker processing 33. It should +# wakeup and propagate the error to INSERT 34. +# 9 - Upon slave stop due to error, check that no rows are found after the +# failed INSERT 32. +# +# ==== References ==== +# +# MDEV-20645: Replication consistency is broken as workers miss the error +# notification from an earlier failed group. +# + +--source include/have_innodb.inc +--source include/have_debug.inc +--source include/have_debug_sync.inc +--source include/have_binlog_format_statement.inc +--source include/master-slave.inc + +--enable_connect_log +--connection server_2 +--source include/stop_slave.inc +SET @old_parallel_threads=@@GLOBAL.slave_parallel_threads; +SET @old_parallel_mode=@@GLOBAL.slave_parallel_mode; +SET @old_debug= @@GLOBAL.debug_dbug; +SET GLOBAL slave_parallel_mode='optimistic'; +SET GLOBAL slave_parallel_threads= 3; +CHANGE MASTER TO master_use_gtid=slave_pos; +CALL mtr.add_suppression("Commit failed due to failure of an earlier commit on which this one depends"); +--source include/start_slave.inc + +--connection server_1 +ALTER TABLE mysql.gtid_slave_pos ENGINE=InnoDB; +CREATE TABLE t1 (a int PRIMARY KEY) ENGINE=InnoDB; +--source include/save_master_gtid.inc + +--connection server_2 +--source include/sync_with_master_gtid.inc + +--connect (con_temp2,127.0.0.1,root,,test,$SERVER_MYPORT_2,) +BEGIN; +INSERT INTO t1 VALUES (32); + +--connection server_1 +INSERT INTO t1 VALUES (32); + +--connection server_2 +--let $wait_condition= SELECT COUNT(*) = 1 FROM information_schema.processlist WHERE info like "INSERT INTO t1 VALUES (32)" +--source include/wait_condition.inc +SET GLOBAL debug_dbug="+d,hold_worker_on_schedule"; +SET debug_sync="debug_sync_action SIGNAL reached_pause WAIT_FOR continue_worker"; + +--connection server_1 +SET gtid_seq_no=100; +INSERT INTO t1 VALUES (33); + +--connection server_2 +SET debug_sync='now WAIT_FOR reached_pause'; + +--connection server_1 +INSERT INTO t1 VALUES (34); + +--connection server_2 +--let $wait_condition= SELECT COUNT(*) = 1 FROM information_schema.processlist WHERE state like "Waiting for prior transaction to commit" +--source include/wait_condition.inc +--connection con_temp2 +COMMIT; + +# Clean up. +--connection server_2 +--source include/stop_slave.inc +--let $assert_cond= COUNT(*) = 0 FROM t1 WHERE a>32 +--let $assert_text= table t1 should have zero rows where a>32 +--source include/assert.inc +SELECT * FROM t1 WHERE a>32; +DELETE FROM t1 WHERE a=32; + +SET GLOBAL slave_parallel_threads=@old_parallel_threads; +SET GLOBAL slave_parallel_mode=@old_parallel_mode; +SET GLOBAL debug_dbug=@old_debug; +SET DEBUG_SYNC= 'RESET'; +--source include/start_slave.inc + +--connection server_1 +DROP TABLE t1; +--disable_connect_log +--source include/rpl_end.inc diff --git a/mysql-test/suite/rpl/t/rpl_parallel_show_binlog_events_purge_logs.test b/mysql-test/suite/rpl/t/rpl_parallel_show_binlog_events_purge_logs.test index 8c8892d53707f..cddc9286bd28d 100644 --- a/mysql-test/suite/rpl/t/rpl_parallel_show_binlog_events_purge_logs.test +++ b/mysql-test/suite/rpl/t/rpl_parallel_show_binlog_events_purge_logs.test @@ -1 +1,38 @@ ---source include/rpl_parallel_show_binlog_events_purge_logs.inc +# +# This include file is used by more than one test suite +# (currently rpl and binlog_encryption). +# Please check all dependent tests after modifying it +# + +# BUG#13979418: SHOW BINLOG EVENTS MAY CRASH THE SERVER +# +# The function mysql_show_binlog_events has a local stack variable +# 'LOG_INFO linfo;', which is assigned to thd->current_linfo, however +# this variable goes out of scope and is destroyed before clean +# thd->current_linfo. +# +# This test case runs SHOW BINLOG EVENTS and FLUSH LOGS to make sure +# that with the fix local variable linfo is valid along all +# mysql_show_binlog_events function scope. +# +--source include/have_debug.inc +--source include/have_debug_sync.inc +--source include/master-slave.inc + +--connection slave +SET DEBUG_SYNC= 'after_show_binlog_events SIGNAL on_show_binlog_events WAIT_FOR end'; +--send SHOW BINLOG EVENTS + +--connection slave1 +SET DEBUG_SYNC= 'now WAIT_FOR on_show_binlog_events'; +FLUSH LOGS; +SET DEBUG_SYNC= 'now SIGNAL end'; + +--connection slave +--disable_result_log +--reap +--enable_result_log +SET DEBUG_SYNC= 'RESET'; + +--connection master +--source include/rpl_end.inc diff --git a/mysql-test/suite/rpl/t/rpl_relayrotate.test b/mysql-test/suite/rpl/t/rpl_relayrotate.test index 720739e14c079..4de554d314359 100644 --- a/mysql-test/suite/rpl/t/rpl_relayrotate.test +++ b/mysql-test/suite/rpl/t/rpl_relayrotate.test @@ -1 +1,18 @@ ---source include/rpl_relayrotate.inc +# +# This include file is used by more than one test suite +# (currently rpl and binlog_encryption). +# Please check all dependent tests after modifying it +# + +####################################################### +# Wrapper for rpl_relayrotate.test to allow multi # +# Engines to reuse test code. By JBM 2006-02-15 # +####################################################### +-- source include/have_innodb.inc +# Slow test, don't run during staging part +-- source include/not_staging.inc +-- source include/master-slave.inc + +let $engine_type=innodb; +-- source suite/rpl/include/rpl_relayrotate.test +--source include/rpl_end.inc diff --git a/mysql-test/suite/rpl/t/rpl_semi_sync.test b/mysql-test/suite/rpl/t/rpl_semi_sync.test index 5c17bcb2344d1..c3cd918b5fc5f 100644 --- a/mysql-test/suite/rpl/t/rpl_semi_sync.test +++ b/mysql-test/suite/rpl/t/rpl_semi_sync.test @@ -1 +1,525 @@ ---source include/rpl_semi_sync.inc +# +# This include file is used by more than one test suite +# (currently rpl and binlog_encryption). +# Please check all dependent tests after modifying it +# + +source include/not_embedded.inc; +source include/have_innodb.inc; +source include/master-slave.inc; + +let $engine_type= InnoDB; + +# Suppress warnings that might be generated during the test +connection master; +call mtr.add_suppression("Timeout waiting for reply of binlog"); +call mtr.add_suppression("Read semi-sync reply"); +call mtr.add_suppression("Unsafe statement written to the binary log using statement format since BINLOG_FORMAT = STATEMENT."); +call mtr.add_suppression("mysqld: Got an error reading communication packets"); +connection slave; +call mtr.add_suppression("Master server does not support semi-sync"); +call mtr.add_suppression("Semi-sync slave .* reply"); +call mtr.add_suppression("Slave SQL.*Request to stop slave SQL Thread received while applying a group that has non-transactional changes; waiting for completion of the group"); +connection master; + +# wait for dying connections (if any) to disappear +let $wait_condition= select count(*) = 0 from information_schema.processlist where command='killed'; +--source include/wait_condition.inc + +# After fix of BUG#45848, semi-sync slave should not create any extra +# connections on master, save the count of connections before start +# semi-sync slave for comparison below. +let $_connections_normal_slave= query_get_value(SHOW STATUS LIKE 'Threads_connected', Value, 1); + +--echo # +--echo # Uninstall semi-sync plugins on master and slave +--echo # +connection slave; +source include/stop_slave.inc; +reset slave; +set global rpl_semi_sync_master_enabled= 0; +set global rpl_semi_sync_slave_enabled= 0; + +connection master; +reset master; +set global rpl_semi_sync_master_enabled= 0; +set global rpl_semi_sync_slave_enabled= 0; + +--echo # +--echo # Main test of semi-sync replication start here +--echo # + +connection master; + +set global rpl_semi_sync_master_timeout= 60000; # 60s + +echo [ default state of semi-sync on master should be OFF ]; +show variables like 'rpl_semi_sync_master_enabled'; + +echo [ enable semi-sync on master ]; +set global rpl_semi_sync_master_enabled = 1; +show variables like 'rpl_semi_sync_master_enabled'; + +echo [ status of semi-sync on master should be ON even without any semi-sync slaves ]; +show status like 'Rpl_semi_sync_master_clients'; +show status like 'Rpl_semi_sync_master_status'; +show status like 'Rpl_semi_sync_master_yes_tx'; + +--echo # +--echo # BUG#45672 Semisync repl: ActiveTranx:insert_tranx_node: transaction node allocation failed +--echo # BUG#45673 Semisynch reports correct operation even if no slave is connected +--echo # + +# BUG#45672 When semi-sync is enabled on master, it would allocate +# transaction node even without semi-sync slave connected, and would +# finally result in transaction node allocation error. +# +# Semi-sync master will pre-allocate 'max_connections' transaction +# nodes, so here we do more than that much transactions to check if it +# will fail or not. +# select @@global.max_connections + 1; +let $i= `select @@global.max_connections + 1`; +disable_query_log; +eval create table t1 (a int) engine=$engine_type; +while ($i) +{ + eval insert into t1 values ($i); + dec $i; +} +drop table t1; +enable_query_log; + +# BUG#45673 +echo [ status of semi-sync on master should be OFF ]; +show status like 'Rpl_semi_sync_master_clients'; +show status like 'Rpl_semi_sync_master_status'; +show status like 'Rpl_semi_sync_master_yes_tx'; + +# reset master to make sure the following test will start with a clean environment +reset master; + +connection slave; + +echo [ default state of semi-sync on slave should be OFF ]; +show variables like 'rpl_semi_sync_slave_enabled'; + +echo [ enable semi-sync on slave ]; +set global rpl_semi_sync_slave_enabled = 1; +show variables like 'rpl_semi_sync_slave_enabled'; +source include/start_slave.inc; + +connection master; + +# NOTE: Rpl_semi_sync_master_client will only be updated when +# semi-sync slave has started binlog dump request +let $status_var= Rpl_semi_sync_master_clients; +let $status_var_value= 1; +source include/wait_for_status_var.inc; + +echo [ initial master state after the semi-sync slave connected ]; +show status like 'Rpl_semi_sync_master_clients'; +show status like 'Rpl_semi_sync_master_status'; +show status like 'Rpl_semi_sync_master_no_tx'; +show status like 'Rpl_semi_sync_master_yes_tx'; + +replace_result $engine_type ENGINE_TYPE; +eval create table t1(a int) engine = $engine_type; + +echo [ master state after CREATE TABLE statement ]; +show status like 'Rpl_semi_sync_master_status'; +show status like 'Rpl_semi_sync_master_no_tx'; +show status like 'Rpl_semi_sync_master_yes_tx'; + +# After fix of BUG#45848, semi-sync slave should not create any extra +# connections on master. +let $_connections_semisync_slave= query_get_value(SHOW STATUS LIKE 'Threads_connected', Value, 1); +replace_result $_connections_normal_slave CONNECTIONS_NORMAL_SLAVE $_connections_semisync_slave CONNECTIONS_SEMISYNC_SLAVE; +eval select $_connections_semisync_slave - $_connections_normal_slave as 'Should be 0'; + +echo [ insert records to table ]; +insert t1 values (10); +insert t1 values (9); +insert t1 values (8); +insert t1 values (7); +insert t1 values (6); +insert t1 values (5); +insert t1 values (4); +insert t1 values (3); +insert t1 values (2); +insert t1 values (1); + +echo [ master status after inserts ]; +show status like 'Rpl_semi_sync_master_status'; +show status like 'Rpl_semi_sync_master_no_tx'; +show status like 'Rpl_semi_sync_master_yes_tx'; + +sync_slave_with_master; + +echo [ slave status after replicated inserts ]; +show status like 'Rpl_semi_sync_slave_status'; + +select count(distinct a) from t1; +select min(a) from t1; +select max(a) from t1; + +--echo +--echo # BUG#50157 +--echo # semi-sync replication crashes when replicating a transaction which +--echo # include 'CREATE TEMPORARY TABLE `MyISAM_t` SELECT * FROM `Innodb_t` ; + +connection master; +SET SESSION AUTOCOMMIT= 0; +CREATE TABLE t2(c1 INT) ENGINE=innodb; +sync_slave_with_master; + +connection master; +BEGIN; +--echo +--echo # Even though it is in a transaction, this statement is binlogged into binlog +--echo # file immediately. +--disable_warnings +CREATE TEMPORARY TABLE t3 SELECT c1 FROM t2 where 1=1; +--enable_warnings +--echo +--echo # These statements will not be binlogged until the transaction is committed +INSERT INTO t2 VALUES(11); +INSERT INTO t2 VALUES(22); +COMMIT; + +DROP TABLE t2, t3; +SET SESSION AUTOCOMMIT= 1; +sync_slave_with_master; + + +--echo # +--echo # Test semi-sync master will switch OFF after one transaction +--echo # timeout waiting for slave reply. +--echo # +connection slave; +source include/stop_slave.inc; + +connection master; +--source include/kill_binlog_dump_threads.inc +set global rpl_semi_sync_master_timeout= 5000; + +# The first semi-sync check should be on because after slave stop, +# there are no transactions on the master. +echo [ master status should be ON ]; + +let $status_var= Rpl_semi_sync_master_status; +let $status_var_value= ON; +source include/wait_for_status_var.inc; + +let $status_var= Rpl_semi_sync_master_clients; +let $status_var_value= 0; +source include/wait_for_status_var.inc; + +show status like 'Rpl_semi_sync_master_no_tx'; +show status like 'Rpl_semi_sync_master_yes_tx'; + +echo [ semi-sync replication of these transactions will fail ]; +insert into t1 values (500); + +# Wait for the semi-sync replication of this transaction to timeout +let $status_var= Rpl_semi_sync_master_status; +let $status_var_value= OFF; +source include/wait_for_status_var.inc; + +# The second semi-sync check should be off because one transaction +# times out during waiting. +echo [ master status should be OFF ]; +show status like 'Rpl_semi_sync_master_status'; +show status like 'Rpl_semi_sync_master_no_tx'; +show status like 'Rpl_semi_sync_master_yes_tx'; + +# Semi-sync status on master is now OFF, so all these transactions +# will be replicated asynchronously. +delete from t1 where a=10; +delete from t1 where a=9; +delete from t1 where a=8; +delete from t1 where a=7; +delete from t1 where a=6; +delete from t1 where a=5; +delete from t1 where a=4; +delete from t1 where a=3; +delete from t1 where a=2; +delete from t1 where a=1; + +insert into t1 values (100); + +echo [ master status should be OFF ]; +show status like 'Rpl_semi_sync_master_status'; +show status like 'Rpl_semi_sync_master_no_tx'; +show status like 'Rpl_semi_sync_master_yes_tx'; + +--echo # +--echo # Test semi-sync status on master will be ON again when slave catches up +--echo # + +# Save the master position for later use. +save_master_pos; + +connection slave; + +echo [ slave status should be OFF ]; +show status like 'Rpl_semi_sync_slave_status'; +source include/start_slave.inc; +sync_with_master; + +echo [ slave status should be ON ]; +show status like 'Rpl_semi_sync_slave_status'; + +select count(distinct a) from t1; +select min(a) from t1; +select max(a) from t1; + +connection master; + +# The master semi-sync status should be on again after slave catches up. +echo [ master status should be ON again after slave catches up ]; + +let $status_var= Rpl_semi_sync_master_status; +let $status_var_value= ON; +source include/wait_for_status_var.inc; +show status like 'Rpl_semi_sync_master_no_tx'; +show status like 'Rpl_semi_sync_master_yes_tx'; +show status like 'Rpl_semi_sync_master_clients'; + +--echo # +--echo # Test disable/enable master semi-sync on the fly. +--echo # + +drop table t1; +sync_slave_with_master; + +source include/stop_slave.inc; + +--echo # +--echo # Flush status +--echo # +connection master; +echo [ Semi-sync master status variables before FLUSH STATUS ]; +SHOW STATUS LIKE 'Rpl_semi_sync_master_no_tx'; +SHOW STATUS LIKE 'Rpl_semi_sync_master_yes_tx'; +# Do not write the FLUSH STATUS to binlog, to make sure we'll get a +# clean status after this. +FLUSH NO_WRITE_TO_BINLOG STATUS; +echo [ Semi-sync master status variables after FLUSH STATUS ]; +SHOW STATUS LIKE 'Rpl_semi_sync_master_no_tx'; +SHOW STATUS LIKE 'Rpl_semi_sync_master_yes_tx'; + +connection master; + +source include/show_master_logs.inc; +show variables like 'rpl_semi_sync_master_enabled'; + +echo [ disable semi-sync on the fly ]; +set global rpl_semi_sync_master_enabled=0; +show variables like 'rpl_semi_sync_master_enabled'; +show status like 'Rpl_semi_sync_master_status'; + +echo [ enable semi-sync on the fly ]; +set global rpl_semi_sync_master_enabled=1; +show variables like 'rpl_semi_sync_master_enabled'; +show status like 'Rpl_semi_sync_master_status'; + +--echo # +--echo # Test RESET MASTER/SLAVE +--echo # + +connection slave; + +source include/start_slave.inc; + +connection master; + +replace_result $engine_type ENGINE_TYPE; +eval create table t1 (a int) engine = $engine_type; +drop table t1; + +sync_slave_with_master; + +echo [ test reset master ]; +connection master; + +reset master; + +show status like 'Rpl_semi_sync_master_status'; +show status like 'Rpl_semi_sync_master_no_tx'; +show status like 'Rpl_semi_sync_master_yes_tx'; + +connection slave; + +source include/stop_slave.inc; +reset slave; + +# Kill the dump thread on master for previous slave connection and +--source include/kill_binlog_dump_threads.inc + +connection slave; +source include/start_slave.inc; + +connection master; + +# Wait for dump thread to start, Rpl_semi_sync_master_clients will be +# 1 after dump thread started. +let $status_var= Rpl_semi_sync_master_clients; +let $status_var_value= 1; +source include/wait_for_status_var.inc; + +replace_result $engine_type ENGINE_TYPE; +eval create table t1 (a int) engine = $engine_type; +insert into t1 values (1); +insert into t1 values (2), (3); + +sync_slave_with_master; + +select * from t1; + +connection master; + +echo [ master semi-sync status should be ON ]; +show status like 'Rpl_semi_sync_master_status'; +show status like 'Rpl_semi_sync_master_no_tx'; +show status like 'Rpl_semi_sync_master_yes_tx'; + +--echo # +--echo # Start semi-sync replication without SUPER privilege +--echo # +connection slave; +source include/stop_slave.inc; +reset slave; +connection master; +reset master; + +# Kill the dump thread on master for previous slave connection and wait for it to exit +--source include/kill_binlog_dump_threads.inc + +# Do not binlog the following statement because it will generate +# different events for ROW and STATEMENT format +set sql_log_bin=0; +grant replication slave on *.* to rpl@127.0.0.1 identified by 'rpl_password'; +flush privileges; +set sql_log_bin=1; +connection slave; +grant replication slave on *.* to rpl@127.0.0.1 identified by 'rpl_password'; +flush privileges; +change master to master_user='rpl',master_password='rpl_password'; +source include/start_slave.inc; +show status like 'Rpl_semi_sync_slave_status'; +connection master; + +# Wait for the semi-sync binlog dump thread to start +let $status_var= Rpl_semi_sync_master_clients; +let $status_var_value= 1; +source include/wait_for_status_var.inc; +echo [ master semi-sync should be ON ]; +show status like 'Rpl_semi_sync_master_clients'; +show status like 'Rpl_semi_sync_master_status'; +show status like 'Rpl_semi_sync_master_no_tx'; +show status like 'Rpl_semi_sync_master_yes_tx'; +insert into t1 values (4); +insert into t1 values (5); +echo [ master semi-sync should be ON ]; +show status like 'Rpl_semi_sync_master_clients'; +show status like 'Rpl_semi_sync_master_status'; +show status like 'Rpl_semi_sync_master_no_tx'; +show status like 'Rpl_semi_sync_master_yes_tx'; + +--echo # +--echo # Test semi-sync slave connect to non-semi-sync master +--echo # + +# Disable semi-sync on master +connection slave; +source include/stop_slave.inc; +SHOW STATUS LIKE 'Rpl_semi_sync_slave_status'; + +connection master; + +# Kill the dump thread on master for previous slave connection and wait for it to exit +--source include/kill_binlog_dump_threads.inc + +echo [ Semi-sync status on master should be ON ]; +let $status_var= Rpl_semi_sync_master_clients; +let $status_var_value= 0; +source include/wait_for_status_var.inc; +show status like 'Rpl_semi_sync_master_status'; +let $status_var= Rpl_semi_sync_master_status; +let $status_var_value= ON; +source include/wait_for_status_var.inc; +set global rpl_semi_sync_master_enabled= 0; + +connection slave; +SHOW VARIABLES LIKE 'rpl_semi_sync_slave_enabled'; +source include/start_slave.inc; +connection master; +insert into t1 values (8); +let $status_var= Rpl_semi_sync_master_clients; +let $status_var_value= 1; +source include/wait_for_status_var.inc; +echo [ master semi-sync clients should be 1, status should be OFF ]; +show status like 'Rpl_semi_sync_master_clients'; +show status like 'Rpl_semi_sync_master_status'; +sync_slave_with_master; +show status like 'Rpl_semi_sync_slave_status'; + +# Uninstall semi-sync plugin on master +connection slave; +source include/stop_slave.inc; +connection master; +set global rpl_semi_sync_master_enabled= 0; + +connection slave; +SHOW VARIABLES LIKE 'rpl_semi_sync_slave_enabled'; +source include/start_slave.inc; + +connection master; +insert into t1 values (10); +sync_slave_with_master; + +--echo # +--echo # Test non-semi-sync slave connect to semi-sync master +--echo # + +connection master; +set global rpl_semi_sync_master_timeout= 5000; # 5s +set global rpl_semi_sync_master_enabled= 1; + +connection slave; +source include/stop_slave.inc; +SHOW STATUS LIKE 'Rpl_semi_sync_slave_status'; + +echo [ uninstall semi-sync slave plugin ]; +set global rpl_semi_sync_slave_enabled= 0; + +echo [ reinstall semi-sync slave plugin and disable semi-sync ]; +SHOW VARIABLES LIKE 'rpl_semi_sync_slave_enabled'; +SHOW STATUS LIKE 'Rpl_semi_sync_slave_status'; +source include/start_slave.inc; +SHOW STATUS LIKE 'Rpl_semi_sync_slave_status'; + +--echo # +--echo # Clean up +--echo # + +connection slave; +source include/stop_slave.inc; +set global rpl_semi_sync_slave_enabled= 0; + +connection master; +set global rpl_semi_sync_master_enabled= 0; + +connection slave; +change master to master_user='root',master_password=''; +source include/start_slave.inc; + +connection master; +drop table t1; +sync_slave_with_master; + +connection master; +drop user rpl@127.0.0.1; +flush privileges; +set global rpl_semi_sync_master_timeout= default; +--source include/rpl_end.inc diff --git a/mysql-test/suite/rpl/t/rpl_skip_replication.test b/mysql-test/suite/rpl/t/rpl_skip_replication.test index 66fdbb8915a34..97fc961d43856 100644 --- a/mysql-test/suite/rpl/t/rpl_skip_replication.test +++ b/mysql-test/suite/rpl/t/rpl_skip_replication.test @@ -1 +1,402 @@ ---source include/rpl_skip_replication.inc +# +# This include file is used by more than one test suite +# (currently rpl and binlog_encryption). +# Please check all dependent tests after modifying it. +# +# Usage: +# +# --let $use_remote_mysqlbinlog= 1 # optional +# --source suite/rpl/include/rpl_skip_replication.inc +# +# The script uses MYSQLBINLOG to verify certain results. +# By default, it uses binary logs directly. If it is undesirable, +# this behavior can be overridden by setting $use_remote_binlog +# as shown above. +# The value will be unset after every execution of the script, +# so if it is needed, it should be set explicitly before each call. +# + +--source include/have_innodb.inc +--source include/master-slave.inc + +connection slave; +# Test that SUPER is required to change @@replicate_events_marked_for_skip. +CREATE USER 'nonsuperuser'@'127.0.0.1'; +GRANT ALTER,CREATE,DELETE,DROP,EVENT,INSERT,PROCESS,REPLICATION SLAVE, + SELECT,UPDATE ON *.* TO 'nonsuperuser'@'127.0.0.1'; +connect(nonpriv, 127.0.0.1, nonsuperuser,, test, $SLAVE_MYPORT,); +connection nonpriv; +--error ER_SPECIFIC_ACCESS_DENIED_ERROR +SET GLOBAL replicate_events_marked_for_skip=FILTER_ON_MASTER; +disconnect nonpriv; +connection slave; +DROP USER'nonsuperuser'@'127.0.0.1'; + +SELECT @@global.replicate_events_marked_for_skip; +--error ER_SLAVE_MUST_STOP +SET GLOBAL replicate_events_marked_for_skip=FILTER_ON_SLAVE; +SELECT @@global.replicate_events_marked_for_skip; +STOP SLAVE; +--error ER_GLOBAL_VARIABLE +SET SESSION replicate_events_marked_for_skip=FILTER_ON_MASTER; +SELECT @@global.replicate_events_marked_for_skip; +SET GLOBAL replicate_events_marked_for_skip=FILTER_ON_MASTER; +SELECT @@global.replicate_events_marked_for_skip; +START SLAVE; + +connection master; +SELECT @@skip_replication; +--error ER_LOCAL_VARIABLE +SET GLOBAL skip_replication=1; +SELECT @@skip_replication; + +CREATE TABLE t1 (a INT PRIMARY KEY, b INT) ENGINE=myisam; +CREATE TABLE t2 (a INT PRIMARY KEY, b INT) ENGINE=innodb; +INSERT INTO t1(a) VALUES (1); +INSERT INTO t2(a) VALUES (1); + + +# Test that master-side filtering works. +SET skip_replication=1; + +CREATE TABLE t3 (a INT PRIMARY KEY, b INT) ENGINE=myisam; +INSERT INTO t1(a) VALUES (2); +INSERT INTO t2(a) VALUES (2); + +# Inject a rotate event in the binlog stream sent to slave (otherwise we will +# fail sync_slave_with_master as the last event on the master is not present +# on the slave). +FLUSH NO_WRITE_TO_BINLOG LOGS; + +sync_slave_with_master; +connection slave; +SHOW TABLES; +SELECT * FROM t1; +SELECT * FROM t2; + +connection master; +DROP TABLE t3; + +FLUSH NO_WRITE_TO_BINLOG LOGS; +sync_slave_with_master; + + +# Test that slave-side filtering works. +connection slave; +STOP SLAVE; +SET GLOBAL replicate_events_marked_for_skip=FILTER_ON_SLAVE; +START SLAVE; + +connection master; +SET skip_replication=1; +CREATE TABLE t3 (a INT PRIMARY KEY, b INT) ENGINE=myisam; +INSERT INTO t1(a) VALUES (3); +INSERT INTO t2(a) VALUES (3); + +# Inject a rotate event in the binlog stream sent to slave (otherwise we will +# fail sync_slave_with_master as the last event on the master is not present +# on the slave). +FLUSH NO_WRITE_TO_BINLOG LOGS; + +sync_slave_with_master; +connection slave; +SHOW TABLES; +SELECT * FROM t1; +SELECT * FROM t2; + +connection master; +DROP TABLE t3; + +FLUSH NO_WRITE_TO_BINLOG LOGS; +sync_slave_with_master; +connection slave; +STOP SLAVE; +SET GLOBAL replicate_events_marked_for_skip=REPLICATE; +START SLAVE; + + +# Test that events with @@skip_replication=1 are not filtered when filtering is +# not set on slave. +connection master; +SET skip_replication=1; +CREATE TABLE t3 (a INT PRIMARY KEY, b INT) ENGINE=myisam; +INSERT INTO t3(a) VALUES(2); +sync_slave_with_master; +connection slave; +SELECT * FROM t3; +connection master; +DROP TABLE t3; + +# +# Test that the slave will preserve the @@skip_replication flag in its +# own binlog. +# + +TRUNCATE t1; +sync_slave_with_master; +connection slave; +RESET MASTER; + +connection master; +SET skip_replication=0; +INSERT INTO t1 VALUES (1,0); +SET skip_replication=1; +INSERT INTO t1 VALUES (2,0); +SET skip_replication=0; +INSERT INTO t1 VALUES (3,0); + +sync_slave_with_master; +connection slave; +# Since slave has @@replicate_events_marked_for_skip=REPLICATE, it should have +# applied all events. +SELECT * FROM t1 ORDER by a; + +STOP SLAVE; +SET GLOBAL replicate_events_marked_for_skip=FILTER_ON_MASTER; +let $SLAVE_DATADIR= `select @@datadir`; + +connection master; +TRUNCATE t1; + +# Now apply the slave binlog to the master, to check that both the slave +# and mysqlbinlog will preserve the @@skip_replication flag. + +--let $mysqlbinlog_args= $SLAVE_DATADIR/slave-bin.000001 +if ($use_remote_mysqlbinlog) +{ + --let $mysqlbinlog_args= --read-from-remote-server --protocol=tcp --host=127.0.0.1 --port=$SLAVE_MYPORT -uroot slave-bin.000001 + --let $use_remote_mysqlbinlog= 0 +} +--exec $MYSQL_BINLOG $mysqlbinlog_args > $MYSQLTEST_VARDIR/tmp/rpl_skip_replication.binlog +--exec $MYSQL test < $MYSQLTEST_VARDIR/tmp/rpl_skip_replication.binlog + +# The master should have all three events. +SELECT * FROM t1 ORDER by a; + +# The slave should be missing event 2, which is marked with the +# @@skip_replication flag. + +connection slave; +START SLAVE; + +connection master; +sync_slave_with_master; + +connection slave; +SELECT * FROM t1 ORDER by a; + +# +# Test that @@sql_slave_skip_counter does not count skipped @@skip_replication +# events. +# + +connection master; +TRUNCATE t1; + +sync_slave_with_master; +connection slave; +STOP SLAVE; +# We will skip two INSERTs (in addition to any skipped due to +# @@skip_replication). Since from 5.5 every statement is wrapped in +# BEGIN ... END, we need to skip 6 events for this. +SET GLOBAL sql_slave_skip_counter=6; +SET GLOBAL replicate_events_marked_for_skip=FILTER_ON_SLAVE; +START SLAVE; + +connection master; +# Need to fix @@binlog_format to get consistent event count. +SET @old_binlog_format= @@binlog_format; +SET binlog_format= statement; +SET skip_replication=0; +INSERT INTO t1 VALUES (1,5); +SET skip_replication=1; +INSERT INTO t1 VALUES (2,5); +SET skip_replication=0; +INSERT INTO t1 VALUES (3,5); +INSERT INTO t1 VALUES (4,5); +SET binlog_format= @old_binlog_format; + +sync_slave_with_master; +connection slave; + +# The slave should have skipped the first three inserts (number 1 and 3 due +# to @@sql_slave_skip_counter=2, number 2 due to +# @@replicate_events_marked_for_skip=FILTER_ON_SLAVE). So only number 4 +# should be left. +SELECT * FROM t1; + + +# +# Check that BINLOG statement preserves the @@skip_replication flag. +# +connection slave; +# Need row @@binlog_format for BINLOG statements containing row events. +--source include/stop_slave.inc +SET @old_slave_binlog_format= @@global.binlog_format; +SET GLOBAL binlog_format= row; +--source include/start_slave.inc + +connection master; +TRUNCATE t1; + +SET @old_binlog_format= @@binlog_format; +SET binlog_format= row; +# Format description log event. +BINLOG 'wlZOTw8BAAAA8QAAAPUAAAAAAAQANS41LjIxLU1hcmlhREItZGVidWctbG9nAAAAAAAAAAAAAAAA +AAAAAAAAAAAAAAAAAAAAAAAAEzgNAAgAEgAEBAQEEgAA2QAEGggAAAAICAgCAAAAAAAAAAAAAAAA +AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA +AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA +AAAAAAAAAAAA371saA=='; +# INSERT INTO t1 VALUES (1,8) # with @@skip_replication=1 +BINLOG 'wlZOTxMBAAAAKgAAAGMBAAAAgCkAAAAAAAEABHRlc3QAAnQxAAIDAwAC +wlZOTxcBAAAAJgAAAIkBAAAAgCkAAAAAAAEAAv/8AQAAAAgAAAA='; +# INSERT INTO t1 VALUES (2,8) # with @@skip_replication=0 +BINLOG 'wlZOTxMBAAAAKgAAADwCAAAAACkAAAAAAAEABHRlc3QAAnQxAAIDAwAC +wlZOTxcBAAAAJgAAAGICAAAAACkAAAAAAAEAAv/8AgAAAAgAAAA='; +SET binlog_format= @old_binlog_format; + +SELECT * FROM t1 ORDER BY a; +sync_slave_with_master; +connection slave; +# Slave should have only the second insert, the first should be ignored due to +# the @@skip_replication flag. +SELECT * FROM t1 ORDER by a; + +--source include/stop_slave.inc +SET GLOBAL binlog_format= @old_slave_binlog_format; +--source include/start_slave.inc + + +# Test that it is not possible to change @@skip_replication inside a +# transaction or statement, thereby replicating only parts of statements +# or transactions. +connection master; +SET skip_replication=0; + +BEGIN; +--error ER_INSIDE_TRANSACTION_PREVENTS_SWITCH_SKIP_REPLICATION +SET skip_replication=0; +--error ER_INSIDE_TRANSACTION_PREVENTS_SWITCH_SKIP_REPLICATION +SET skip_replication=1; +ROLLBACK; +SET skip_replication=1; +BEGIN; +--error ER_INSIDE_TRANSACTION_PREVENTS_SWITCH_SKIP_REPLICATION +SET skip_replication=0; +--error ER_INSIDE_TRANSACTION_PREVENTS_SWITCH_SKIP_REPLICATION +SET skip_replication=1; +COMMIT; +SET autocommit=0; +INSERT INTO t2(a) VALUES(100); +--error ER_INSIDE_TRANSACTION_PREVENTS_SWITCH_SKIP_REPLICATION +SET skip_replication=1; +ROLLBACK; +SET autocommit=1; + +SET skip_replication=1; +--delimiter | +CREATE FUNCTION foo (x INT) RETURNS INT BEGIN SET SESSION skip_replication=x; RETURN x; END| +CREATE PROCEDURE bar(x INT) BEGIN SET SESSION skip_replication=x; END| +CREATE FUNCTION baz (x INT) RETURNS INT BEGIN CALL bar(x); RETURN x; END| +--delimiter ; +--error ER_STORED_FUNCTION_PREVENTS_SWITCH_SKIP_REPLICATION +SELECT foo(0); +--error ER_STORED_FUNCTION_PREVENTS_SWITCH_SKIP_REPLICATION +SELECT baz(0); +--error ER_STORED_FUNCTION_PREVENTS_SWITCH_SKIP_REPLICATION +SET @a= foo(1); +--error ER_STORED_FUNCTION_PREVENTS_SWITCH_SKIP_REPLICATION +SET @a= baz(1); +--error ER_STORED_FUNCTION_PREVENTS_SWITCH_SKIP_REPLICATION +UPDATE t2 SET b=foo(0); +--error ER_STORED_FUNCTION_PREVENTS_SWITCH_SKIP_REPLICATION +UPDATE t2 SET b=baz(0); +--error ER_STORED_FUNCTION_PREVENTS_SWITCH_SKIP_REPLICATION +INSERT INTO t1 VALUES (101, foo(1)); +--error ER_STORED_FUNCTION_PREVENTS_SWITCH_SKIP_REPLICATION +INSERT INTO t1 VALUES (101, baz(0)); +SELECT @@skip_replication; +CALL bar(0); +SELECT @@skip_replication; +CALL bar(1); +SELECT @@skip_replication; +DROP FUNCTION foo; +DROP PROCEDURE bar; +DROP FUNCTION baz; + + +# Test that master-side filtering happens on the master side, and that +# slave-side filtering happens on the slave. + +# First test that events do not reach the slave when master-side filtering +# is configured. Do this by replicating first with only the IO thread running +# and master-side filtering; then change to no filtering and start the SQL +# thread. This should still skip the events, as master-side filtering +# means the events never reached the slave. +connection master; +SET skip_replication= 0; +TRUNCATE t1; +sync_slave_with_master; +connection slave; +STOP SLAVE; +SET GLOBAL replicate_events_marked_for_skip=FILTER_ON_MASTER; +START SLAVE IO_THREAD; +connection master; +SET skip_replication= 1; +INSERT INTO t1(a) VALUES (1); +SET skip_replication= 0; +INSERT INTO t1(a) VALUES (2); +--source include/save_master_pos.inc +connection slave; +--source include/sync_io_with_master.inc +STOP SLAVE IO_THREAD; +SET GLOBAL replicate_events_marked_for_skip=REPLICATE; +START SLAVE; +connection master; +sync_slave_with_master; +connection slave; +# Now only the second insert of (2) should be visible, as the first was +# filtered on the master, so even though the SQL thread ran without skipping +# events, it will never see the event in the first place. +SELECT * FROM t1; + +# Now tests that when slave-side filtering is configured, events _do_ reach +# the slave. +connection master; +SET skip_replication= 0; +TRUNCATE t1; +sync_slave_with_master; +connection slave; +STOP SLAVE; +SET GLOBAL replicate_events_marked_for_skip=FILTER_ON_SLAVE; +START SLAVE IO_THREAD; +connection master; +SET skip_replication= 1; +INSERT INTO t1(a) VALUES (1); +SET skip_replication= 0; +INSERT INTO t1(a) VALUES (2); +--source include/save_master_pos.inc +connection slave; +--source include/sync_io_with_master.inc +STOP SLAVE IO_THREAD; +SET GLOBAL replicate_events_marked_for_skip=REPLICATE; +START SLAVE; +connection master; +sync_slave_with_master; +connection slave; +# Now both inserts should be visible. Since filtering was configured to be +# slave-side, the event is in the relay log, and when the SQL thread ran we +# had disabled filtering again. +SELECT * FROM t1 ORDER BY a; + + +# Clean up. +connection master; +SET skip_replication=0; +DROP TABLE t1,t2; +connection slave; +STOP SLAVE; +SET GLOBAL replicate_events_marked_for_skip=REPLICATE; +START SLAVE; + +--source include/rpl_end.inc diff --git a/mysql-test/suite/rpl/t/rpl_special_charset.test b/mysql-test/suite/rpl/t/rpl_special_charset.test index fa19a17b1e4f2..641aa483d32b7 100644 --- a/mysql-test/suite/rpl/t/rpl_special_charset.test +++ b/mysql-test/suite/rpl/t/rpl_special_charset.test @@ -1 +1,32 @@ ---source include/rpl_special_charset.inc +# +# This include file is used by more than one test suite +# (currently rpl and binlog_encryption). +# Please check all dependent tests after modifying it +# + +################################################################################ +# Bug#19855907 IO THREAD AUTHENTICATION ISSUE WITH SOME CHARACTER SETS +# Problem: IO thread fails to connect to master if servers are configured with +# special character sets like utf16, utf32, ucs2. +# +# Analysis: MySQL server does not support few special character sets like +# utf16,utf32 and ucs2 as "client's character set"(eg: utf16,utf32, ucs2). +# When IO thread is trying to connect to Master, it sets server's character +# set as client's character set. When Slave server is started with these +# special character sets, IO thread (a connection to Master) fails because +# of the above said reason. +# +# Fix: If server's character set is not supported as client's character set, +# then set default's client character set(latin1) as client's character set. +############################################################################### +--source include/master-slave.inc +call mtr.add_suppression("'utf16' can not be used as client character set"); +CREATE TABLE t1(i VARCHAR(20)); +INSERT INTO t1 VALUES (0xFFFF); +--sync_slave_with_master +--let diff_tables=master:t1, slave:t1 +--source include/diff_tables.inc +# Cleanup +--connection master +DROP TABLE t1; +--source include/rpl_end.inc diff --git a/mysql-test/suite/rpl/t/rpl_sporadic_master.test b/mysql-test/suite/rpl/t/rpl_sporadic_master.test index 397756af3965d..ad4c44cbf7409 100644 --- a/mysql-test/suite/rpl/t/rpl_sporadic_master.test +++ b/mysql-test/suite/rpl/t/rpl_sporadic_master.test @@ -1 +1,32 @@ ---source include/rpl_sporadic_master.inc +# +# This include file is used by more than one test suite +# (currently rpl and binlog_encryption). +# Please check all dependent tests after modifying it +# + +# test to see if replication can continue when master sporadically fails on +# COM_BINLOG_DUMP and additionally limits the number of events per dump + +source include/master-slave.inc; + +create table t2(n int); +create table t1(n int not null auto_increment primary key); +insert into t1 values (NULL),(NULL); +truncate table t1; +# We have to use 4 in the following to make this test work with all table types +insert into t1 values (4),(NULL); +sync_slave_with_master; +--source include/stop_slave.inc +--source include/start_slave.inc +connection master; +insert into t1 values (NULL),(NULL); +flush logs; +truncate table t1; +insert into t1 values (10),(NULL),(NULL),(NULL),(NULL),(NULL); +sync_slave_with_master; +select * from t1 ORDER BY n; +connection master; +drop table t1,t2; +sync_slave_with_master; + +--source include/rpl_end.inc diff --git a/mysql-test/suite/rpl/t/rpl_ssl.test b/mysql-test/suite/rpl/t/rpl_ssl.test index c4a534b929495..59a2af9f137c0 100644 --- a/mysql-test/suite/rpl/t/rpl_ssl.test +++ b/mysql-test/suite/rpl/t/rpl_ssl.test @@ -1 +1,116 @@ ---source include/rpl_ssl.inc +# +# This include file is used by more than one test suite +# (currently rpl and binlog_encryption). +# Please check all dependent tests after modifying it +# + +source include/have_ssl_communication.inc; +source include/master-slave.inc; +source include/no_valgrind_without_big.inc; + +# create a user for replication that requires ssl encryption +connection master; +create user replssl@localhost; +grant replication slave on *.* to replssl@localhost require ssl; +create table t1 (t int auto_increment, KEY(t)); + +sync_slave_with_master; + +# Set slave to use SSL for connection to master +stop slave; +--replace_result $MYSQL_TEST_DIR MYSQL_TEST_DIR +eval change master to + master_user='replssl', + master_password='', + master_ssl=1, + master_ssl_ca ='$MYSQL_TEST_DIR/std_data/cacert.pem', + master_ssl_cert='$MYSQL_TEST_DIR/std_data/client-cert.pem', + master_ssl_key='$MYSQL_TEST_DIR/std_data/client-key.pem'; +start slave; + +# Switch to master and insert one record, then sync it to slave +connection master; +insert into t1 values(1); +sync_slave_with_master; + +# The record should now be on slave +select * from t1; + +# The slave is synced and waiting/reading from master +# SHOW SLAVE STATUS will show "Waiting for master to send event" +let $status_items= Master_SSL_Allowed, Master_SSL_CA_Path, Master_SSL_CA_File, Master_SSL_Crl, Master_SSL_Crlpath, Master_SSL_Cert, Master_SSL_Key; +source include/show_slave_status.inc; +source include/check_slave_is_running.inc; + +# Stop the slave, as reported in bug#21871 it would hang +STOP SLAVE; + +select * from t1; + +# Do the same thing a number of times +disable_query_log; +disable_result_log; +# 2007-11-27 mats Bug #32756 Starting and stopping the slave in a loop can lose rows +# After discussions with Engineering, I'm disabling this part of the test to avoid it causing +# red trees. +disable_parsing; +let $i= 100; +while ($i) +{ + start slave; + connection master; + insert into t1 values (NULL); + select * from t1; # Some variance + connection slave; + select * from t1; # Some variance + stop slave; + dec $i; +} +enable_parsing; +START SLAVE; +enable_query_log; +enable_result_log; +connection master; +# INSERT one more record to make sure +# the sync has something to do +insert into t1 values (NULL); +let $master_count= `select count(*) from t1`; + +sync_slave_with_master; +--source include/wait_for_slave_to_start.inc +source include/show_slave_status.inc; +source include/check_slave_is_running.inc; + +let $slave_count= `select count(*) from t1`; + +if ($slave_count != $master_count) +{ + echo master and slave differed in number of rows; + echo master: $master_count; + echo slave: $slave_count; + + connection master; + select count(*) t1; + select * from t1; + connection slave; + select count(*) t1; + select * from t1; + query_vertical show slave status; +} + +connection master; +drop user replssl@localhost; +drop table t1; +sync_slave_with_master; + +--source include/stop_slave.inc +CHANGE MASTER TO + master_user = 'root', + master_ssl = 0, + master_ssl_ca = '', + master_ssl_cert = '', + master_ssl_key = ''; + +--echo End of 5.0 tests +--let $rpl_only_running_threads= 1 +--source include/rpl_end.inc diff --git a/mysql-test/suite/rpl/t/rpl_stm_relay_ign_space.test b/mysql-test/suite/rpl/t/rpl_stm_relay_ign_space.test index b4e5335871268..41339f539f804 100644 --- a/mysql-test/suite/rpl/t/rpl_stm_relay_ign_space.test +++ b/mysql-test/suite/rpl/t/rpl_stm_relay_ign_space.test @@ -1 +1,107 @@ ---source include/rpl_stm_relay_ign_space.inc +# +# This include file is used by more than one test suite +# (currently rpl and binlog_encryption). +# Please check all dependent tests after modifying it +# + +# +# BUG#12400313 / BUG#64503 test case +# +# +# Description +# ----------- +# +# This test case starts the slave server with: +# --relay-log-space-limit=8192 --relay-log-purge --max-relay-log-size=4096 +# +# Then it issues some queries that will cause the slave to reach +# relay-log-space-limit. We lock the table so that the SQL thread is +# not able to purge the log and then we issue some more statements. +# +# The purpose is to show that the IO thread will honor the limits +# while the SQL thread is not able to purge the relay logs, which did +# not happen before this patch. In addition we assert that while +# ignoring the limit (SQL thread needs to rotate before purging), the +# IO thread does not do it in an uncontrolled manner. + +--source include/have_binlog_format_statement.inc +--source include/have_innodb.inc +--source include/master-slave.inc + +--disable_query_log +CREATE TABLE t1 (c1 TEXT) engine=InnoDB; + +INSERT INTO t1 VALUES ('xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx'); +INSERT INTO t1 VALUES ('xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx'); +INSERT INTO t1 VALUES ('xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx'); +INSERT INTO t1 VALUES ('xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx'); + +--sync_slave_with_master + +# wait for the SQL thread to sleep +--let $show_statement= SHOW PROCESSLIST +--let $field= State +--let $condition= = 'Slave has read all relay log; waiting for the slave I/O thread to update it' +--source include/wait_show_condition.inc + +# now the io thread has set rli->ignore_space_limit +# lets lock the table so that once the SQL thread awakes +# it blocks there and does not set rli->ignore_space_limit +# back to zero +LOCK TABLE t1 WRITE; + +# now issue more statements that will overflow the +# rli->log_space_limit (in this case ~10K) +--connection master + +INSERT INTO t1 VALUES ('xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx'); +INSERT INTO t1 VALUES ('xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx'); +INSERT INTO t1 VALUES ('xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx'); +INSERT INTO t1 VALUES ('xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx'); +INSERT INTO t1 VALUES ('xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx'); +INSERT INTO t1 VALUES ('xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx'); +INSERT INTO t1 VALUES ('xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx'); +INSERT INTO t1 VALUES ('xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx'); +INSERT INTO t1 VALUES ('xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx'); +INSERT INTO t1 VALUES ('xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx'); + +--connection slave + +# ASSERT that the IO thread waits for the SQL thread to release some +# space before continuing +--let $show_statement= SHOW PROCESSLIST +--let $field= State +--let $condition= LIKE 'Waiting for %' +# before the patch (IO would have transfered everything) +#--let $condition= = 'Waiting for master to send event' +# after the patch (now it waits for space to be freed) +#--let $condition= = 'Waiting for the slave SQL thread to free enough relay log space' +--source include/wait_show_condition.inc + +# without the patch we can uncomment the following two lines and +# watch the IO thread synchronize with the master, thus writing +# relay logs way over the space limit +#--connection master +#--source include/sync_slave_io_with_master.inc + +## ASSERT that the IO thread has honored the limit+few bytes required to be able to purge +--let $relay_log_space_while_sql_is_executing = query_get_value(SHOW SLAVE STATUS, Relay_Log_Space, 1) +--let $relay_log_space_limit = query_get_value(SHOW VARIABLES LIKE "relay_log_space_limit", Value, 1) +--let $assert_text= Assert that relay log space is close to the limit +--let $assert_cond= $relay_log_space_while_sql_is_executing <= $relay_log_space_limit * 1.15 +--source include/assert.inc + +# unlock the table and let SQL thread continue applying events +UNLOCK TABLES; + +--connection master +--sync_slave_with_master +--let $diff_tables=master:test.t1,slave:test.t1 +--source include/diff_tables.inc + +--connection master +DROP TABLE t1; +--enable_query_log +--sync_slave_with_master + +--source include/rpl_end.inc diff --git a/mysql-test/suite/rpl/t/rpl_switch_stm_row_mixed.test b/mysql-test/suite/rpl/t/rpl_switch_stm_row_mixed.test index 2625508515b90..31b80732c607e 100644 --- a/mysql-test/suite/rpl/t/rpl_switch_stm_row_mixed.test +++ b/mysql-test/suite/rpl/t/rpl_switch_stm_row_mixed.test @@ -1 +1,633 @@ ---source include/rpl_switch_stm_row_mixed.inc +# +# This include file is used by more than one test suite +# (currently rpl and binlog_encryption). +# Please check all dependent tests after modifying it +# + +# +# rpl_switch_stm_row_mixed tests covers +# +# - Master is switching explicitly between STATEMENT, ROW, and MIXED +# binlog format showing when it is possible and when not. +# - Master switching from MIXED to RBR implicitly listing all use +# cases, e.g a query invokes UUID(), thereafter to serve as the +# definition of MIXED binlog format +# - correctness of execution + + +-- source include/have_binlog_format_mixed_or_row.inc +-- source include/master-slave.inc + +# Since this test generates row-based events in the binary log, the +# slave SQL thread cannot be in STATEMENT mode to execute this test, +# so we only execute it for MIXED and ROW as default value of +# BINLOG_FORMAT. + +connection slave; + +connection master; +--disable_warnings +drop database if exists mysqltest1; +create database mysqltest1; +--enable_warnings +use mysqltest1; + +# Save binlog format +set @my_binlog_format= @@global.binlog_format; + +# play with switching +set session binlog_format=mixed; +show session variables like "binlog_format%"; +set session binlog_format=statement; +show session variables like "binlog_format%"; +set session binlog_format=row; +show session variables like "binlog_format%"; + +set global binlog_format=DEFAULT; +show global variables like "binlog_format%"; +set global binlog_format=MIXED; +show global variables like "binlog_format%"; +set global binlog_format=STATEMENT; +show global variables like "binlog_format%"; +set global binlog_format=ROW; +show global variables like "binlog_format%"; +show session variables like "binlog_format%"; +select @@global.binlog_format, @@session.binlog_format; + +CREATE TABLE t1 (a varchar(100)); + +prepare stmt1 from 'insert into t1 select concat(UUID(),?)'; +set @string="emergency_1_"; +insert into t1 values("work_2_"); +execute stmt1 using @string; +deallocate prepare stmt1; + +prepare stmt1 from 'insert into t1 select ?'; +insert into t1 values(concat(UUID(),"work_3_")); +execute stmt1 using @string; +deallocate prepare stmt1; + +insert into t1 values(concat("for_4_",UUID())); +insert into t1 select "yesterday_5_"; + +# verify that temp tables prevent a switch to SBR +create temporary table tmp(a char(100)); +insert into tmp values("see_6_"); +--error ER_TEMP_TABLE_PREVENTS_SWITCH_OUT_OF_RBR +set binlog_format=statement; +insert into t1 select * from tmp; +drop temporary table tmp; + +# Now we go to SBR +set binlog_format=statement; +show global variables like "binlog_format%"; +show session variables like "binlog_format%"; +select @@global.binlog_format, @@session.binlog_format; +set global binlog_format=statement; +show global variables like "binlog_format%"; +show session variables like "binlog_format%"; +select @@global.binlog_format, @@session.binlog_format; + +prepare stmt1 from 'insert into t1 select ?'; +set @string="emergency_7_"; +insert into t1 values("work_8_"); +execute stmt1 using @string; +deallocate prepare stmt1; + +prepare stmt1 from 'insert into t1 select ?'; +insert into t1 values("work_9_"); +execute stmt1 using @string; +deallocate prepare stmt1; + +insert into t1 values("for_10_"); +insert into t1 select "yesterday_11_"; + +# test statement (is not default after wl#3368) +set binlog_format=statement; +select @@global.binlog_format, @@session.binlog_format; +set global binlog_format=statement; +select @@global.binlog_format, @@session.binlog_format; + +prepare stmt1 from 'insert into t1 select ?'; +set @string="emergency_12_"; +insert into t1 values("work_13_"); +execute stmt1 using @string; +deallocate prepare stmt1; + +prepare stmt1 from 'insert into t1 select ?'; +insert into t1 values("work_14_"); +execute stmt1 using @string; +deallocate prepare stmt1; + +insert into t1 values("for_15_"); +insert into t1 select "yesterday_16_"; + +# and now the mixed mode + +set global binlog_format=mixed; +select @@global.binlog_format, @@session.binlog_format; +set binlog_format=default; +select @@global.binlog_format, @@session.binlog_format; + +prepare stmt1 from 'insert into t1 select concat(UUID(),?)'; +set @string="emergency_17_"; +insert into t1 values("work_18_"); +execute stmt1 using @string; +deallocate prepare stmt1; + +prepare stmt1 from 'insert into t1 select ?'; +insert into t1 values(concat(UUID(),"work_19_")); +execute stmt1 using @string; +deallocate prepare stmt1; + +insert into t1 values(concat("for_20_",UUID())); +insert into t1 select "yesterday_21_"; + +prepare stmt1 from 'insert into t1 select ?'; +insert into t1 values(concat(UUID(),"work_22_")); +execute stmt1 using @string; +deallocate prepare stmt1; + +insert into t1 values(concat("for_23_",UUID())); +insert into t1 select "yesterday_24_"; + +# Test of CREATE TABLE SELECT + +create table t2 ENGINE=MyISAM select rpad(UUID(),100,' '); +create table t3 select 1 union select UUID(); +--disable_warnings +SET STATEMENT sql_mode = 'NO_ENGINE_SUBSTITUTION' FOR +create table t4 select * from t1 where 3 in (select 1 union select 2 union select UUID() union select 3); +--enable_warnings +SET STATEMENT sql_mode = 'NO_ENGINE_SUBSTITUTION' FOR +create table t5 select * from t1 where 3 in (select 1 union select 2 union select curdate() union select 3); +# what if UUID() is first: +--disable_warnings +insert ignore into t5 select UUID() from t1 where 3 in (select 1 union select 2 union select 3 union select * from t4); +--enable_warnings + +# inside a stored procedure + +delimiter |; +create procedure foo() +begin +insert into t1 values("work_25_"); +insert into t1 values(concat("for_26_",UUID())); +insert into t1 select "yesterday_27_"; +end| +create procedure foo2() +begin +insert into t1 values(concat("emergency_28_",UUID())); +insert into t1 values("work_29_"); +insert into t1 values(concat("for_30_",UUID())); +set session binlog_format=row; # accepted for stored procs +insert into t1 values("more work_31_"); +set session binlog_format=mixed; +end| +create function foo3() returns bigint unsigned +begin + set session binlog_format=row; # rejected for stored funcs + insert into t1 values("alarm"); + return 100; +end| +create procedure foo4(x varchar(100)) +begin +insert into t1 values(concat("work_250_",x)); +insert into t1 select "yesterday_270_"; +end| +delimiter ;| +call foo(); +call foo2(); +call foo4("hello"); +call foo4(UUID()); +call foo4("world"); + +# test that can't SET in a stored function +--error ER_STORED_FUNCTION_PREVENTS_SWITCH_BINLOG_FORMAT +select foo3(); +select * from t1 where a="alarm"; + +# Tests of stored functions/triggers/views for BUG#20930 "Mixed +# binlogging mode does not work with stored functions, triggers, +# views" + +# Function which calls procedure +drop function foo3; +delimiter |; +create function foo3() returns bigint unsigned +begin + insert into t1 values("foo3_32_"); + call foo(); + return 100; +end| +delimiter ;| +insert into t2 select foo3(); + +prepare stmt1 from 'insert into t2 select foo3()'; +execute stmt1; +execute stmt1; +deallocate prepare stmt1; + +# Test if stored function calls stored function which calls procedure +# which requires row-based. + +delimiter |; +create function foo4() returns bigint unsigned +begin + insert into t2 select foo3(); + return 100; +end| +delimiter ;| +select foo4(); + +prepare stmt1 from 'select foo4()'; +execute stmt1; +execute stmt1; +deallocate prepare stmt1; + +# A simple stored function +delimiter |; +create function foo5() returns bigint unsigned +begin + insert into t2 select UUID(); + return 100; +end| +delimiter ;| +select foo5(); + +prepare stmt1 from 'select foo5()'; +execute stmt1; +execute stmt1; +deallocate prepare stmt1; + +# A simple stored function where UUID() is in the argument +delimiter |; +create function foo6(x varchar(100)) returns bigint unsigned +begin + insert into t2 select x; + return 100; +end| +delimiter ;| +select foo6("foo6_1_"); +select foo6(concat("foo6_2_",UUID())); + +prepare stmt1 from 'select foo6(concat("foo6_3_",UUID()))'; +execute stmt1; +execute stmt1; +deallocate prepare stmt1; + + +# Test of views using UUID() + +create view v1 as select uuid(); +create table t11 (data varchar(255)); +insert into t11 select * from v1; +# Test of querying INFORMATION_SCHEMA which parses the view's body, +# to verify that it binlogs statement-based (is not polluted by +# the parsing of the view's body). +insert into t11 select TABLE_NAME from INFORMATION_SCHEMA.TABLES where TABLE_SCHEMA='mysqltest1' and TABLE_NAME IN ('v1','t11'); +prepare stmt1 from "insert into t11 select TABLE_NAME from INFORMATION_SCHEMA.TABLES where TABLE_SCHEMA='mysqltest1' and TABLE_NAME IN ('v1','t11')"; +execute stmt1; +execute stmt1; +deallocate prepare stmt1; + +# Test of triggers with UUID() +delimiter |; +create trigger t11_bi before insert on t11 for each row +begin + set NEW.data = concat(NEW.data,UUID()); +end| +delimiter ;| +insert into t11 values("try_560_"); + +# Test that INSERT DELAYED works in mixed mode (BUG#20649) +insert delayed into t2 values("delay_1_"); +insert delayed into t2 values(concat("delay_2_",UUID())); +insert delayed into t2 values("delay_6_"); + +# Test for BUG#20633 (INSERT DELAYED RAND()/user_variable does not +# replicate fine in statement-based ; we test that in mixed mode it +# works). +insert delayed into t2 values(rand()); +set @a=2.345; +insert delayed into t2 values(@a); + +# With INSERT DELAYED, rows are written to the binlog after they are +# written to the table. Therefore, it is not enough to wait until the +# rows make it to t2 on the master (the rows may not be in the binlog +# at that time, and may still not be in the binlog when +# sync_slave_with_master is later called). Instead, we wait until the +# rows make it to t2 on the slave. We first call +# sync_slave_with_master, so that we are sure that t2 has been created +# on the slave. +sync_slave_with_master; +let $wait_condition= SELECT COUNT(*) = 19 FROM mysqltest1.t2; +--source include/wait_condition.inc +connection master; + +# If you want to do manual testing of the mixed mode regarding UDFs (not +# testable automatically as quite platform- and compiler-dependent), +# you just need to set the variable below to 1, and to +# "make udf_example.so" in sql/, and to copy sql/udf_example.so to +# MYSQL_TEST_DIR/lib/mysql. +let $you_want_to_test_UDF=0; +if ($you_want_to_test_UDF) +{ + CREATE FUNCTION metaphon RETURNS STRING SONAME 'udf_example.so'; + prepare stmt1 from 'insert into t1 select metaphon(?)'; + set @string="emergency_133_"; + insert into t1 values("work_134_"); + execute stmt1 using @string; + deallocate prepare stmt1; + prepare stmt1 from 'insert into t1 select ?'; + insert into t1 values(metaphon("work_135_")); + execute stmt1 using @string; + deallocate prepare stmt1; + insert into t1 values(metaphon("for_136_")); + insert into t1 select "yesterday_137_"; + create table t6 select metaphon("for_138_"); + create table t7 select 1 union select metaphon("for_139_"); + create table t8 select * from t1 where 3 in (select 1 union select 2 union select metaphon("for_140_") union select 3); + create table t9 select * from t1 where 3 in (select 1 union select 2 union select curdate() union select 3); +} + +create table t20 select * from t1; # save for comparing later +create table t21 select * from t2; +create table t22 select * from t3; +drop table t1,t2,t3; + +# This tests the fix to +# BUG#19630 stored function inserting into two auto_increment breaks statement-based binlog +# We verify that under the mixed binlog mode, a stored function +# modifying at least two tables having an auto_increment column, +# is binlogged row-based. Indeed in statement-based binlogging, +# only the auto_increment value generated for the first table +# is recorded in the binlog, the value generated for the 2nd table +# lacking. + +create table t1 (a int primary key auto_increment, b varchar(100)); +create table t2 (a int primary key auto_increment, b varchar(100)); +create table t3 (b varchar(100)); +delimiter |; +create function f (x varchar(100)) returns int deterministic +begin + insert into t1 values(null,x); + insert into t2 values(null,x); + return 1; +end| +delimiter ;| +select f("try_41_"); +# Two operations which compensate each other except that their net +# effect is that they advance the auto_increment counter of t2 on slave: +sync_slave_with_master; +use mysqltest1; +insert into t2 values(2,null),(3,null),(4,null); +delete from t2 where a>=2; + +connection master; +# this is the call which didn't replicate well +select f("try_42_"); +sync_slave_with_master; + +# now use prepared statement and test again, just to see that the RBB +# mode isn't set at PREPARE but at EXECUTE. + +insert into t2 values(3,null),(4,null); +delete from t2 where a>=3; + +connection master; +prepare stmt1 from 'select f(?)'; +set @string="try_43_"; +insert into t1 values(null,"try_44_"); # should be SBB +execute stmt1 using @string; # should be RBB +deallocate prepare stmt1; +sync_slave_with_master; + +# verify that if only one table has auto_inc, it does not trigger RBB +# (we'll check in binlog further below) + +connection master; +create table t12 select * from t1; # save for comparing later +drop table t1; +create table t1 (a int, b varchar(100), key(a)); +select f("try_45_"); + +# restore table's key +create table t13 select * from t1; +drop table t1; +create table t1 (a int primary key auto_increment, b varchar(100)); + +# now test if it's two functions, each of them inserts in one table + +drop function f; +# we need a unique key to have sorting of rows by mysqldump +create table t14 (unique (a)) select * from t2; +truncate table t2; +delimiter |; +create function f1 (x varchar(100)) returns int deterministic +begin + insert into t1 values(null,x); + return 1; +end| +create function f2 (x varchar(100)) returns int deterministic +begin + insert into t2 values(null,x); + return 1; +end| +delimiter ;| +select f1("try_46_"),f2("try_47_"); + +sync_slave_with_master; +insert into t2 values(2,null),(3,null),(4,null); +delete from t2 where a>=2; + +connection master; +# Test with SELECT and INSERT +select f1("try_48_"),f2("try_49_"); +insert into t3 values(concat("try_50_",f1("try_51_"),f2("try_52_"))); +sync_slave_with_master; + +# verify that if f2 does only read on an auto_inc table, this does not +# switch to RBB +connection master; +drop function f2; +delimiter |; +create function f2 (x varchar(100)) returns int deterministic +begin + declare y int; + insert into t1 values(null,x); + set y = (select count(*) from t2); + return y; +end| +delimiter ;| +select f1("try_53_"),f2("try_54_"); +sync_slave_with_master; + +# And now, a normal statement with a trigger (no stored functions) + +connection master; +drop function f2; +delimiter |; +create trigger t1_bi before insert on t1 for each row +begin + insert into t2 values(null,"try_55_"); +end| +delimiter ;| +insert into t1 values(null,"try_56_"); +# and now remove one auto_increment and verify SBB +alter table t1 modify a int, drop primary key; +insert into t1 values(null,"try_57_"); +sync_slave_with_master; + +# Test for BUG#20499 "mixed mode with temporary table breaks binlog" +# Slave used to have only 2 rows instead of 3. +connection master; +CREATE TEMPORARY TABLE t15 SELECT UUID(); +create table t16 like t15; +INSERT INTO t16 SELECT * FROM t15; +# we'll verify that this one is done RBB +insert into t16 values("try_65_"); +drop table t15; +# we'll verify that this one is done SBB +insert into t16 values("try_66_"); +sync_slave_with_master; + +# and now compare: + +connection master; + +# first check that data on master is sensible +select count(*) from t1; +select count(*) from t2; +select count(*) from t3; +select count(*) from t4; +select count(*) from t5; +select count(*) from t11; +select count(*) from t20; +select count(*) from t21; +select count(*) from t22; +select count(*) from t12; +select count(*) from t13; +select count(*) from t14; +select count(*) from t16; +if ($you_want_to_test_UDF) +{ + select count(*) from t6; + select count(*) from t7; + select count(*) from t8; + select count(*) from t9; +} + +sync_slave_with_master; + +# +# Bug#20863 If binlog format is changed between update and unlock of +# tables, wrong binlog +# + +connection master; +DROP TABLE IF EXISTS t11; +SET SESSION BINLOG_FORMAT=STATEMENT; +CREATE TABLE t11 (song VARCHAR(255)); +LOCK TABLES t11 WRITE; +SET SESSION BINLOG_FORMAT=ROW; +INSERT INTO t11 VALUES('Several Species of Small Furry Animals Gathered Together in a Cave and Grooving With a Pict'); +SET SESSION BINLOG_FORMAT=STATEMENT; +INSERT INTO t11 VALUES('Careful With That Axe, Eugene'); +UNLOCK TABLES; + +--query_vertical SELECT * FROM t11 +sync_slave_with_master; +USE mysqltest1; +--query_vertical SELECT * FROM t11 + +connection master; +DROP TABLE IF EXISTS t12; +SET SESSION BINLOG_FORMAT=MIXED; +CREATE TABLE t12 (data LONG); +LOCK TABLES t12 WRITE; +INSERT INTO t12 VALUES(UUID()); +UNLOCK TABLES; +sync_slave_with_master; + +# +# BUG#28086: SBR of USER() becomes corrupted on slave +# + +connection master; + +# Just to get something that is non-trivial, albeit still simple, we +# stuff the result of USER() and CURRENT_USER() into a variable. +--delimiter $$ +CREATE FUNCTION my_user() + RETURNS CHAR(64) +BEGIN + DECLARE user CHAR(64); + SELECT USER() INTO user; + RETURN user; +END $$ +--delimiter ; + +--delimiter $$ +CREATE FUNCTION my_current_user() + RETURNS CHAR(64) +BEGIN + DECLARE user CHAR(64); + SELECT CURRENT_USER() INTO user; + RETURN user; +END $$ +--delimiter ; + +DROP TABLE IF EXISTS t13; +CREATE TABLE t13 (data CHAR(64)); +INSERT INTO t13 VALUES (USER()); +INSERT INTO t13 VALUES (my_user()); +INSERT INTO t13 VALUES (CURRENT_USER()); +INSERT INTO t13 VALUES (my_current_user()); + +sync_slave_with_master; + +# as we're using UUID we don't SELECT but use "diff" like in rpl_row_UUID +--exec $MYSQL_DUMP --compact --order-by-primary --skip-extended-insert --no-create-info mysqltest1 > $MYSQLTEST_VARDIR/tmp/rpl_switch_stm_row_mixed_master.sql +--exec $MYSQL_DUMP_SLAVE --compact --order-by-primary --skip-extended-insert --no-create-info mysqltest1 > $MYSQLTEST_VARDIR/tmp/rpl_switch_stm_row_mixed_slave.sql + +# Let's compare. Note: If they match test will pass, if they do not match +# the test will show that the diff statement failed and not reject file +# will be created. You will need to go to the mysql-test dir and diff +# the files your self to see what is not matching + +diff_files $MYSQLTEST_VARDIR/tmp/rpl_switch_stm_row_mixed_master.sql $MYSQLTEST_VARDIR/tmp/rpl_switch_stm_row_mixed_slave.sql; + +connection master; + +# Now test that mysqlbinlog works fine on a binlog generated by the +# mixed mode + +# BUG#11312 "DELIMITER is not written to the binary log that causes +# syntax error" makes that mysqlbinlog will fail if we pass it the +# text of queries; this forces us to use --base64-output here. + +# BUG#20929 "BINLOG command causes invalid free plus assertion +# failure" makes mysqld segfault when receiving --base64-output + +# So I can't enable this piece of test +# SIGH + +if ($enable_when_11312_or_20929_fixed) +{ +--exec $MYSQL_BINLOG --base64-output $MYSQLTEST_VARDIR/log/master-bin.000001 > $MYSQLTEST_VARDIR/tmp/mysqlbinlog_mixed.sql +drop database mysqltest1; +--exec $MYSQL < $MYSQLTEST_VARDIR/tmp/mysqlbinlog_mixed.sql +--exec $MYSQL_DUMP --compact --order-by-primary --skip-extended-insert --no-create-info mysqltest1 > $MYSQLTEST_VARDIR/tmp/rpl_switch_stm_row_mixed_master.sql +# the old mysqldump output on slave is the same as what it was on +# master before restoring on master. +diff_files $MYSQLTEST_VARDIR/tmp/rpl_switch_stm_row_mixed_master.sql $MYSQLTEST_VARDIR/tmp/rpl_switch_stm_row_mixed_slave.sql; +} + +drop database mysqltest1; +sync_slave_with_master; + +connection master; +# Restore binlog format setting +set global binlog_format =@my_binlog_format; +--source include/rpl_end.inc diff --git a/mysql-test/suite/rpl/t/rpl_sync.test b/mysql-test/suite/rpl/t/rpl_sync.test index bdb0d8ec4ccd8..1e2ec2ca83b85 100644 --- a/mysql-test/suite/rpl/t/rpl_sync.test +++ b/mysql-test/suite/rpl/t/rpl_sync.test @@ -1,2 +1,159 @@ ---source include/rpl_sync_test.inc +# +# This include file is used by more than one test suite +# (currently rpl and binlog_encryption). +# Please check all dependent tests after modifying it +# + +######################################################################################## +# This test verifies the options --sync-relay-log-info and --relay-log-recovery by +# crashing the slave in two different situations: +# (case-1) - Corrupt the relay log with changes which were not processed by +# the SQL Thread and crashes it. +# (case-2) - Corrupt the master.info with wrong coordinates and crashes it. +# +# Case 1: +# 1 - Stops the SQL Thread +# 2 - Inserts new records into the master. +# 3 - Corrupts the relay-log.bin* which most likely has such changes. +# 4 - Crashes the slave +# 5 - Verifies if the slave is sync with the master which means that the information +# loss was circumvented by the recovery process. +# +# Case 2: +# 1 - Stops the SQL/IO Threads +# 2 - Inserts new records into the master. +# 3 - Corrupts the master.info with wrong coordinates. +# 4 - Crashes the slave +# 5 - Verifies if the slave is sync with the master which means that the information +# loss was circumvented by the recovery process. +######################################################################################## + +######################################################################################## +# Configuring the environment +######################################################################################## +--echo =====Configuring the enviroment=======; +--source include/not_embedded.inc +--source include/not_valgrind.inc +--source include/have_debug.inc +--source include/have_innodb.inc +--source include/not_crashrep.inc +--source include/master-slave.inc + +call mtr.add_suppression('Attempting backtrace'); +call mtr.add_suppression("Recovery from master pos .* and file master-bin.000001"); +# Use innodb so we do not get "table should be repaired" issues. +ALTER TABLE mysql.gtid_slave_pos ENGINE=InnoDB; +flush tables; +CREATE TABLE t1(a INT, PRIMARY KEY(a)) engine=innodb; + +insert into t1(a) values(1); +insert into t1(a) values(2); +insert into t1(a) values(3); + +######################################################################################## +# Case 1: Corrupt a relay-log.bin* +######################################################################################## +--echo =====Inserting data on the master but without the SQL Thread being running=======; +sync_slave_with_master; + +connection slave; +let $MYSQLD_SLAVE_DATADIR= `select @@datadir`; +--replace_result $MYSQLD_SLAVE_DATADIR MYSQLD_SLAVE_DATADIR +--copy_file $MYSQLD_SLAVE_DATADIR/master.info $MYSQLD_SLAVE_DATADIR/master.backup +--source include/stop_slave_sql.inc + +connection master; +insert into t1(a) values(4); +insert into t1(a) values(5); +insert into t1(a) values(6); + +--echo =====Removing relay log files and crashing/recoverying the slave=======; +connection slave; +--source include/stop_slave_io.inc + +let $file= query_get_value("SHOW SLAVE STATUS", Relay_Log_File, 1); + +--let FILE_TO_CORRUPT= $MYSQLD_SLAVE_DATADIR/$file +perl; +$file= $ENV{'FILE_TO_CORRUPT'}; +open(FILE, ">$file") || die "Unable to open $file."; +truncate(FILE,0); +print FILE "failure"; +close ($file); +EOF + +--exec echo "restart" > $MYSQLTEST_VARDIR/tmp/mysqld.2.expect +SET SESSION debug_dbug="d,crash_before_rotate_relaylog"; +--error 2013 +FLUSH LOGS; + +--let $rpl_server_number= 2 +--source include/rpl_reconnect.inc + +--echo =====Dumping and comparing tables=======; +--source include/start_slave.inc + +connection master; +sync_slave_with_master; + +let $diff_tables=master:t1,slave:t1; +source include/diff_tables.inc; + +######################################################################################## +# Case 2: Corrupt a master.info +######################################################################################## +--echo =====Corrupting the master.info=======; +connection slave; +--source include/stop_slave.inc + +connection master; +FLUSH LOGS; + +insert into t1(a) values(7); +insert into t1(a) values(8); +insert into t1(a) values(9); + +connection slave; +let MYSQLD_SLAVE_DATADIR=`select @@datadir`; + +--perl +use strict; +use warnings; +my $src= "$ENV{'MYSQLD_SLAVE_DATADIR'}/master.backup"; +my $dst= "$ENV{'MYSQLD_SLAVE_DATADIR'}/master.info"; +open(FILE, "<", $src) or die; +my @content= ; +close FILE; +open(FILE, ">", $dst) or die; +binmode FILE; +print FILE @content; +close FILE; +EOF + +--exec echo "restart" > $MYSQLTEST_VARDIR/tmp/mysqld.2.expect +SET SESSION debug_dbug="d,crash_before_rotate_relaylog"; +--error 2013 +FLUSH LOGS; + +--let $rpl_server_number= 2 +--source include/rpl_reconnect.inc + +--echo =====Dumping and comparing tables=======; +--source include/start_slave.inc + +connection master; +sync_slave_with_master; + +let $diff_tables=master:t1,slave:t1; +source include/diff_tables.inc; + +######################################################################################## +# Clean up +######################################################################################## +--echo =====Clean up=======; +connection master; +drop table t1; + +--remove_file $MYSQLD_SLAVE_DATADIR/master.backup +--source include/rpl_end.inc diff --git a/mysql-test/suite/rpl/t/rpl_temporal_format_default_to_default.test b/mysql-test/suite/rpl/t/rpl_temporal_format_default_to_default.test index d976ae3757bab..6728ff55d6f5e 100644 --- a/mysql-test/suite/rpl/t/rpl_temporal_format_default_to_default.test +++ b/mysql-test/suite/rpl/t/rpl_temporal_format_default_to_default.test @@ -1 +1,82 @@ ---source include/rpl_temporal_format_default_to_default.inc +# +# This include file is used by more than one test suite +# (currently rpl and binlog_encryption). +# Please check all dependent tests after modifying it +# + +--source include/master-slave.inc + +if ($force_master_mysql56_temporal_format) +{ + connection master; + eval SET @@global.mysql56_temporal_format=$force_master_mysql56_temporal_format; +} + +if ($force_slave_mysql56_temporal_format) +{ + connection slave; + eval SET @@global.mysql56_temporal_format=$force_slave_mysql56_temporal_format; +} + +connection master; +SELECT @@global.mysql56_temporal_format AS on_master; +connection slave; +SELECT @@global.mysql56_temporal_format AS on_slave; +connection master; + +CREATE TABLE t1 +( + c0 TIME(0), + c1 TIME(1), + c2 TIME(2), + c3 TIME(3), + c4 TIME(4), + c5 TIME(5), + c6 TIME(6) +); +CREATE TABLE t2 +( + c0 TIMESTAMP(0), + c1 TIMESTAMP(1), + c2 TIMESTAMP(2), + c3 TIMESTAMP(3), + c4 TIMESTAMP(4), + c5 TIMESTAMP(5), + c6 TIMESTAMP(6) +); + +CREATE TABLE t3 +( + c0 DATETIME(0), + c1 DATETIME(1), + c2 DATETIME(2), + c3 DATETIME(3), + c4 DATETIME(4), + c5 DATETIME(5), + c6 DATETIME(6) +); +INSERT INTO t1 VALUES ('01:01:01','01:01:01.1','01:01:01.11','01:01:01.111','01:01:01.1111','01:01:01.11111','01:01:01.111111'); +INSERT INTO t2 VALUES ('2001-01-01 01:01:01','2001-01-01 01:01:01.1','2001-01-01 01:01:01.11','2001-01-01 01:01:01.111','2001-01-01 01:01:01.1111','2001-01-01 01:01:01.11111','2001-01-01 01:01:01.111111'); +INSERT INTO t3 VALUES ('2001-01-01 01:01:01','2001-01-01 01:01:01.1','2001-01-01 01:01:01.11','2001-01-01 01:01:01.111','2001-01-01 01:01:01.1111','2001-01-01 01:01:01.11111','2001-01-01 01:01:01.111111'); +SELECT TABLE_NAME, TABLE_ROWS, AVG_ROW_LENGTH,DATA_LENGTH FROM INFORMATION_SCHEMA.TABLES +WHERE TABLE_NAME RLIKE 't[1-3]' ORDER BY TABLE_NAME; +sync_slave_with_master; + +connection slave; +--query_vertical SELECT * FROM t1; +--query_vertical SELECT * FROM t2; +--query_vertical SELECT * FROM t3; +SELECT TABLE_NAME, TABLE_ROWS, AVG_ROW_LENGTH,DATA_LENGTH FROM INFORMATION_SCHEMA.TABLES +WHERE TABLE_NAME RLIKE 't[1-3]' ORDER BY TABLE_NAME; + +connection master; +DROP TABLE t1; +DROP TABLE t2; +DROP TABLE t3; + +connection slave; +SET @@global.mysql56_temporal_format=DEFAULT; +connection master; +SET @@global.mysql56_temporal_format=DEFAULT; + +--source include/rpl_end.inc diff --git a/mysql-test/suite/rpl/t/rpl_typeconv.test b/mysql-test/suite/rpl/t/rpl_typeconv.test index c251708625827..9e5662588827e 100644 --- a/mysql-test/suite/rpl/t/rpl_typeconv.test +++ b/mysql-test/suite/rpl/t/rpl_typeconv.test @@ -1 +1,78 @@ ---source include/rpl_typeconv.inc +# +# This include file is used by more than one test suite +# (currently rpl and binlog_encryption suite). +# Please check all dependent tests after modifying it +# + +--source include/have_binlog_format_row.inc +--source include/master-slave.inc + +connection slave; +set @saved_slave_type_conversions = @@global.slave_type_conversions; +CREATE TABLE type_conversions ( + TestNo INT AUTO_INCREMENT PRIMARY KEY, + Source TEXT, + Target TEXT, + Flags TEXT, + On_Master LONGTEXT, + On_Slave LONGTEXT, + Expected LONGTEXT, + Compare INT, + Error TEXT); + +SELECT @@global.slave_type_conversions; +SET GLOBAL SLAVE_TYPE_CONVERSIONS=''; +SELECT @@global.slave_type_conversions; +SET GLOBAL SLAVE_TYPE_CONVERSIONS='ALL_NON_LOSSY'; +SELECT @@global.slave_type_conversions; +SET GLOBAL SLAVE_TYPE_CONVERSIONS='ALL_LOSSY'; +SELECT @@global.slave_type_conversions; +SET GLOBAL SLAVE_TYPE_CONVERSIONS='ALL_LOSSY,ALL_NON_LOSSY'; +SELECT @@global.slave_type_conversions; +--error ER_WRONG_VALUE_FOR_VAR +SET GLOBAL SLAVE_TYPE_CONVERSIONS='ALL_LOSSY,ALL_NON_LOSSY,NONEXISTING_BIT'; +SELECT @@global.slave_type_conversions; + +# Checking strict interpretation of type conversions +connection slave; +SET GLOBAL SLAVE_TYPE_CONVERSIONS=''; +source suite/rpl/include/type_conversions.test; + +# Checking lossy integer type conversions +connection slave; +SET GLOBAL SLAVE_TYPE_CONVERSIONS='ALL_NON_LOSSY'; +source suite/rpl/include/type_conversions.test; + +# Checking non-lossy integer type conversions +connection slave; +SET GLOBAL SLAVE_TYPE_CONVERSIONS='ALL_LOSSY'; +source suite/rpl/include/type_conversions.test; + +# Checking all type conversions +connection slave; +SET GLOBAL SLAVE_TYPE_CONVERSIONS='ALL_LOSSY,ALL_NON_LOSSY'; +source suite/rpl/include/type_conversions.test; + +connection slave; +--echo **** Result of conversions **** +disable_query_log; +SELECT RPAD(Source, 15, ' ') AS Source_Type, + RPAD(Target, 15, ' ') AS Target_Type, + RPAD(Flags, 25, ' ') AS All_Type_Conversion_Flags, + IF(Compare IS NULL AND Error IS NOT NULL, '', + IF(Compare, '', + CONCAT("'", On_Slave, "' != '", Expected, "'"))) + AS Value_On_Slave + FROM type_conversions; +enable_query_log; +DROP TABLE type_conversions; + +call mtr.add_suppression("Slave SQL.*Column 1 of table .test.t1. cannot be converted from type.* error.* 1677"); + +connection master; +DROP TABLE t1; +sync_slave_with_master; + +set global slave_type_conversions = @saved_slave_type_conversions; + +--source include/rpl_end.inc From 011261f4e95890b63bac83d7842ff93ced6d3ec8 Mon Sep 17 00:00:00 2001 From: Daniel Black Date: Fri, 24 Mar 2023 08:52:28 +1100 Subject: [PATCH 56/92] sql_class: sprintf -> snprintf This was failing to compile with AppleClang 14.0.0.14000029. Thanks to Arunesh Choudhary for noticing. --- sql/sql_class.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/sql/sql_class.h b/sql/sql_class.h index 6fa8d696b5361..d0c3e0244e789 100644 --- a/sql/sql_class.h +++ b/sql/sql_class.h @@ -1749,7 +1749,7 @@ show_system_thread(enum_thread_type thread) RETURN_NAME_AS_STRING(SYSTEM_THREAD_SLAVE_BACKGROUND); RETURN_NAME_AS_STRING(SYSTEM_THREAD_SEMISYNC_MASTER_BACKGROUND); default: - sprintf(buf, "", thread); + snprintf(buf, sizeof(buf), "", thread); return buf; } #undef RETURN_NAME_AS_STRING @@ -6996,7 +6996,7 @@ class Database_qualified_name if (unlikely(!(dst->str= tmp= (char*) alloc_root(mem_root, dst->length + 1)))) return true; - sprintf(tmp, "%.*s%.*s%.*s", + snprintf(tmp, dst->length + 1, "%.*s%.*s%.*s", (int) m_db.length, (m_db.length ? m_db.str : ""), dot, ".", (int) m_name.length, m_name.str); From f33fc2fae5c3f3e80c4d24348609f3ce5246ca9c Mon Sep 17 00:00:00 2001 From: Igor Babaev Date: Wed, 22 Mar 2023 21:59:18 -0700 Subject: [PATCH 57/92] MDEV-30539 EXPLAIN EXTENDED: no message with queries for DML statements EXPLAIN EXTENDED for an UPDATE/DELETE/INSERT/REPLACE statement did not produce the warning containing the text representation of the query obtained after the optimization phase. Such warning was produced for SELECT statements, but not for DML statements. The patch fixes this defect of EXPLAIN EXTENDED for DML statements. --- mysql-test/include/explain_non_select.inc | 16 + mysql-test/main/explain_non_select.result | 4 + mysql-test/main/multi_update.result | 2 +- mysql-test/main/multi_update.test | 2 +- .../main/myisam_explain_non_select_all.result | 193 +++++++++++ mysql-test/main/opt_trace.result | 2 +- mysql-test/main/ps.result | 4 + .../suite/versioning/r/delete_history.result | 2 + sql/sql_delete.cc | 2 + sql/sql_explain.cc | 19 +- sql/sql_explain.h | 2 +- sql/sql_insert.cc | 6 +- sql/sql_lex.cc | 2 + sql/sql_lex.h | 6 + sql/sql_parse.cc | 20 +- sql/sql_select.cc | 326 +++++++++++++++--- sql/sql_update.cc | 10 +- sql/table.h | 2 + 18 files changed, 563 insertions(+), 57 deletions(-) diff --git a/mysql-test/include/explain_non_select.inc b/mysql-test/include/explain_non_select.inc index d22310c98133c..bd0962d387640 100644 --- a/mysql-test/include/explain_non_select.inc +++ b/mysql-test/include/explain_non_select.inc @@ -788,6 +788,22 @@ INSERT INTO t1 VALUES (1), (2), (3), (4), (5); DROP TABLE t1; +--echo #75 + +CREATE TABLE t1 (id INT PRIMARY KEY, i INT); +--let $query = INSERT INTO t1 VALUES (3,10), (7,11), (3,11) ON DUPLICATE KEY UPDATE id=LAST_INSERT_ID(id); +--source include/explain_utils.inc +DROP TABLE t1; + +--echo #76 + +CREATE TABLE t1 (id INT PRIMARY KEY, i INT); +CREATE TABLE t2 (a INT, b INT); +INSERT INTO t2 VALUES (1,10), (3,10), (7,11), (3,11); +--let $query = INSERT INTO t1 SELECT * FROM t2 ON DUPLICATE KEY UPDATE id=LAST_INSERT_ID(id); +--source include/explain_utils.inc +DROP TABLE t1,t2; + --echo # --echo # Bug #12949629: CLIENT LOSES CONNECTION AFTER EXECUTING A PROCEDURE WITH --echo # EXPLAIN UPDATE/DEL/INS diff --git a/mysql-test/main/explain_non_select.result b/mysql-test/main/explain_non_select.result index 111b4c8ae500d..d60f10f85c887 100644 --- a/mysql-test/main/explain_non_select.result +++ b/mysql-test/main/explain_non_select.result @@ -157,9 +157,13 @@ id select_type table partitions type possible_keys key key_len ref rows Extra explain extended update t2 set b=3 where a in (3,4); id select_type table type possible_keys key key_len ref rows filtered Extra 1 SIMPLE t2 ALL NULL NULL NULL NULL 2 100.00 Using where +Warnings: +Note 1003 update `test`.`t2` set `test`.`t2`.`b` = 3 where `test`.`t2`.`a` in (3,4) explain extended delete from t2 where a in (3,4); id select_type table type possible_keys key key_len ref rows filtered Extra 1 SIMPLE t2 ALL NULL NULL NULL NULL 2 100.00 Using where +Warnings: +Note 1003 delete from `test`.`t2` where `test`.`t2`.`a` in (3,4) drop table t1,t2; # # Check the special case where partition pruning removed all partitions diff --git a/mysql-test/main/multi_update.result b/mysql-test/main/multi_update.result index d6cf9ba685f12..222c592cbcecb 100644 --- a/mysql-test/main/multi_update.result +++ b/mysql-test/main/multi_update.result @@ -1253,7 +1253,7 @@ EXPLAIN DROP TABLES t1, t2; # End of 10.3 tests # -# MDEV-28538: multi-table UPDATE/DELETE with possible exists-to-in +# MDEV-30538: multi-table UPDATE/DELETE with possible exists-to-in # create table t1 (c1 int, c2 int, c3 int, index idx(c2)); insert into t1 values diff --git a/mysql-test/main/multi_update.test b/mysql-test/main/multi_update.test index 48e6250393bcc..329394e8468d9 100644 --- a/mysql-test/main/multi_update.test +++ b/mysql-test/main/multi_update.test @@ -1134,7 +1134,7 @@ DROP TABLES t1, t2; --echo # End of 10.3 tests --echo # ---echo # MDEV-28538: multi-table UPDATE/DELETE with possible exists-to-in +--echo # MDEV-30538: multi-table UPDATE/DELETE with possible exists-to-in --echo # create table t1 (c1 int, c2 int, c3 int, index idx(c2)); diff --git a/mysql-test/main/myisam_explain_non_select_all.result b/mysql-test/main/myisam_explain_non_select_all.result index 7f24cb4896dfa..3ca9629d02773 100644 --- a/mysql-test/main/myisam_explain_non_select_all.result +++ b/mysql-test/main/myisam_explain_non_select_all.result @@ -17,6 +17,8 @@ FLUSH TABLES; EXPLAIN EXTENDED UPDATE t1 SET a = 10 WHERE a < 10; id select_type table type possible_keys key key_len ref rows filtered Extra 1 SIMPLE t1 ALL NULL NULL NULL NULL 3 100.00 Using where +Warnings: +Note 1003 update `test`.`t1` set `test`.`t1`.`a` = 10 where `test`.`t1`.`a` < 10 # Status of EXPLAIN EXTENDED query Variable_name Value Handler_read_key 2 @@ -60,6 +62,8 @@ FLUSH TABLES; EXPLAIN EXTENDED DELETE FROM t1 WHERE a < 10; id select_type table type possible_keys key key_len ref rows filtered Extra 1 SIMPLE t1 ALL NULL NULL NULL NULL 3 100.00 Using where +Warnings: +Note 1003 delete from `test`.`t1` where `test`.`t1`.`a` < 10 # Status of EXPLAIN EXTENDED query Variable_name Value Handler_read_key 2 @@ -103,6 +107,8 @@ FLUSH TABLES; EXPLAIN EXTENDED DELETE FROM t1 USING t1 WHERE a = 1; id select_type table type possible_keys key key_len ref rows filtered Extra 1 SIMPLE t1 ALL NULL NULL NULL NULL 3 100.00 Using where +Warnings: +Note 1003 delete from `test`.`t1` using `test`.`t1` where `test`.`t1`.`a` = 1 # Status of EXPLAIN EXTENDED query Variable_name Value Handler_read_key 2 @@ -150,6 +156,8 @@ EXPLAIN EXTENDED UPDATE t1, t2 SET t1.a = 10 WHERE t1.a = 1; id select_type table type possible_keys key key_len ref rows filtered Extra 1 SIMPLE t1 ALL NULL NULL NULL NULL 3 100.00 Using where 1 SIMPLE t2 ALL NULL NULL NULL NULL 3 100.00 +Warnings: +Note 1003 update `test`.`t1` join `test`.`t2` set `test`.`t1`.`a` = 10 where `test`.`t1`.`a` = 1 # Status of EXPLAIN EXTENDED query Variable_name Value Handler_read_key 4 @@ -200,6 +208,8 @@ id select_type table type possible_keys key key_len ref rows filtered Extra 1 PRIMARY t11 ALL NULL NULL NULL NULL 3 100.00 Using where 1 PRIMARY ALL NULL NULL NULL NULL 3 100.00 2 DERIVED t2 ALL NULL NULL NULL NULL 3 100.00 +Warnings: +Note 1003 /* select#1 */ update `test`.`t1` `t11` join (/* select#2 */ select `test`.`t2`.`b` AS `b` from `test`.`t2`) `t12` set `test`.`t11`.`a` = 10 where `test`.`t11`.`a` = 1 # Status of EXPLAIN EXTENDED query Variable_name Value Handler_read_key 4 @@ -248,6 +258,8 @@ EXPLAIN EXTENDED UPDATE t1 SET a = 10 WHERE 1 IN (SELECT 1 FROM t2 WHERE id select_type table type possible_keys key key_len ref rows filtered Extra 1 PRIMARY t1 ALL NULL NULL NULL NULL 3 100.00 2 SUBQUERY t2 ALL NULL NULL NULL NULL 3 100.00 Using where +Warnings: +Note 1003 /* select#1 */ update `test`.`t1` set `test`.`t1`.`a` = 10 where (1,(/* select#2 */ select 1 from `test`.`t2` where `test`.`t2`.`b` < 3 and 1)) # Status of EXPLAIN EXTENDED query Variable_name Value Handler_read_key 4 @@ -300,6 +312,7 @@ id select_type table type possible_keys key key_len ref rows filtered Extra 2 DEPENDENT SUBQUERY t2 ALL NULL NULL NULL NULL 3 100.00 Using where Warnings: Note 1276 Field or reference 'test.t1.a' of SELECT #2 was resolved in SELECT #1 +Note 1003 /* select#1 */ update `test`.`t1` set `test`.`t1`.`a` = 10 where (`test`.`t1`.`a`,(/* select#2 */ select `test`.`t2`.`b` from `test`.`t2` where `test`.`t1`.`a` < 3 and (`test`.`t1`.`a`) = `test`.`t2`.`b`)) # Status of EXPLAIN EXTENDED query Variable_name Value Handler_read_key 4 @@ -353,6 +366,8 @@ id select_type table type possible_keys key key_len ref rows filtered Extra 1 PRIMARY eq_ref distinct_key distinct_key 4 func 1 100.00 1 PRIMARY t2 ALL NULL NULL NULL NULL 3 100.00 2 MATERIALIZED t2 ALL NULL NULL NULL NULL 3 100.00 Using where +Warnings: +Note 1003 update `test`.`t1` semi join (`test`.`t2`) join `test`.`t2` set `test`.`t1`.`a` = 10 where `test`.`t2`.`b` < 3 # Status of EXPLAIN EXTENDED query Variable_name Value Handler_read_key 4 @@ -405,6 +420,8 @@ id select_type table type possible_keys key key_len ref rows filtered Extra 1 PRIMARY t11 ALL NULL NULL NULL NULL 3 100.00 1 PRIMARY ALL NULL NULL NULL NULL 3 100.00 2 DERIVED t2 ALL NULL NULL NULL NULL 3 100.00 +Warnings: +Note 1003 /* select#1 */ update `test`.`t1` `t11` join (/* select#2 */ select `test`.`t2`.`b` AS `b` from `test`.`t2`) `t12` set `test`.`t11`.`a` = `test`.`t11`.`a` + 10 # Status of EXPLAIN EXTENDED query Variable_name Value Handler_read_key 4 @@ -457,6 +474,8 @@ id select_type table type possible_keys key key_len ref rows filtered Extra 1 PRIMARY system NULL NULL NULL NULL 1 100.00 1 PRIMARY t11 ALL NULL NULL NULL NULL 3 100.00 2 DERIVED NULL NULL NULL NULL NULL NULL NULL NULL No tables used +Warnings: +Note 1003 /* select#1 */ update `test`.`t1` `t11` set `test`.`t11`.`a` = `test`.`t11`.`a` + 10 # Status of EXPLAIN EXTENDED query Variable_name Value Handler_read_key 2 @@ -511,6 +530,8 @@ id select_type table type possible_keys key key_len ref rows filtered Extra 1 PRIMARY t11 ALL NULL NULL NULL NULL 3 100.00 Using where 1 PRIMARY ALL NULL NULL NULL NULL 3 100.00 2 DERIVED t2 ALL NULL NULL NULL NULL 3 100.00 +Warnings: +Note 1003 /* select#1 */ update `test`.`t1` `t11` join (/* select#2 */ select `test`.`t2`.`b` AS `b` from `test`.`t2`) `t12` set `test`.`t11`.`a` = 10 where `test`.`t11`.`a` > 1 # Status of EXPLAIN EXTENDED query Variable_name Value Handler_read_key 4 @@ -555,6 +576,8 @@ FLUSH TABLES; EXPLAIN EXTENDED DELETE FROM t1 WHERE a > 1 LIMIT 1; id select_type table type possible_keys key key_len ref rows filtered Extra 1 SIMPLE t1 ALL NULL NULL NULL NULL 3 100.00 Using where +Warnings: +Note 1003 delete from `test`.`t1` where `test`.`t1`.`a` > 1 limit 1 # Status of EXPLAIN EXTENDED query Variable_name Value Handler_read_key 2 @@ -598,6 +621,8 @@ FLUSH TABLES; EXPLAIN EXTENDED DELETE FROM t1 WHERE 0; id select_type table type possible_keys key key_len ref rows filtered Extra 1 SIMPLE NULL NULL NULL NULL NULL NULL NULL NULL Impossible WHERE +Warnings: +Note 1003 delete from `test`.`t1` where 0 # Status of EXPLAIN EXTENDED query Variable_name Value Handler_read_key 2 @@ -638,6 +663,8 @@ FLUSH TABLES; EXPLAIN EXTENDED DELETE FROM t1 USING t1 WHERE 0; id select_type table type possible_keys key key_len ref rows filtered Extra 1 SIMPLE NULL NULL NULL NULL NULL NULL NULL NULL Impossible WHERE +Warnings: +Note 1003 delete from `test`.`t1` using `test`.`t1` where 0 # Status of EXPLAIN EXTENDED query Variable_name Value Handler_read_key 2 @@ -678,6 +705,8 @@ FLUSH TABLES; EXPLAIN EXTENDED DELETE FROM t1 WHERE a = 3; id select_type table type possible_keys key key_len ref rows filtered Extra 1 SIMPLE t1 range a a 5 NULL 1 100.00 Using where +Warnings: +Note 1003 delete from `test`.`t1` where `test`.`t1`.`a` = 3 # Status of EXPLAIN EXTENDED query Variable_name Value Handler_read_key 5 @@ -719,6 +748,8 @@ FLUSH TABLES; EXPLAIN EXTENDED DELETE FROM t1 WHERE a < 3; id select_type table type possible_keys key key_len ref rows filtered Extra 1 SIMPLE t1 range a a 5 NULL 1 100.00 Using where +Warnings: +Note 1003 delete from `test`.`t1` where `test`.`t1`.`a` < 3 # Status of EXPLAIN EXTENDED query Variable_name Value Handler_read_key 5 @@ -758,6 +789,8 @@ FLUSH TABLES; EXPLAIN EXTENDED DELETE FROM t1 WHERE t1.a > 0 ORDER BY t1.a; id select_type table type possible_keys key key_len ref rows filtered Extra 1 SIMPLE NULL NULL NULL NULL NULL NULL NULL NULL Impossible WHERE +Warnings: +Note 1003 delete from `test`.`t1` where `test`.`t1`.`a` > 0 order by `test`.`t1`.`a` # Status of EXPLAIN EXTENDED query Variable_name Value Handler_read_key 3 @@ -797,6 +830,8 @@ FLUSH TABLES; EXPLAIN EXTENDED DELETE FROM t1 WHERE t1.a > 0 ORDER BY t1.a; id select_type table type possible_keys key key_len ref rows filtered Extra 1 SIMPLE t1 range PRIMARY PRIMARY 4 NULL 3 100.00 Using where +Warnings: +Note 1003 delete from `test`.`t1` where `test`.`t1`.`a` > 0 order by `test`.`t1`.`a` # Status of EXPLAIN EXTENDED query Variable_name Value Handler_read_key 3 @@ -840,6 +875,8 @@ FLUSH TABLES; EXPLAIN EXTENDED DELETE FROM t1 WHERE (@a:= a) ORDER BY a LIMIT 1; id select_type table type possible_keys key key_len ref rows filtered Extra 1 SIMPLE t1 index NULL PRIMARY 4 NULL 1 100.00 Using where +Warnings: +Note 1003 delete from `test`.`t1` where @a:=`test`.`t1`.`a` order by `test`.`t1`.`a` limit 1 # Status of EXPLAIN EXTENDED query Variable_name Value Handler_read_key 3 @@ -884,6 +921,8 @@ FLUSH TABLES; EXPLAIN EXTENDED DELETE FROM t1 ORDER BY a ASC, b ASC LIMIT 1; id select_type table type possible_keys key key_len ref rows filtered Extra 1 SIMPLE t1 ALL NULL NULL NULL NULL 10 100.00 Using filesort +Warnings: +Note 1003 delete from `test`.`t1` order by `test`.`t1`.`a`,`test`.`t1`.`b` limit 1 # Status of EXPLAIN EXTENDED query Variable_name Value Handler_read_key 7 @@ -941,6 +980,8 @@ id select_type table type possible_keys key key_len ref rows filtered Extra 1 SIMPLE t1 ALL NULL NULL NULL NULL 3 100.00 1 SIMPLE t2 ref PRIMARY PRIMARY 4 test.t1.a1 1 100.00 1 SIMPLE t3 eq_ref PRIMARY PRIMARY 8 test.t2.b2,test.t1.b1 1 100.00 +Warnings: +Note 1003 delete from `test`.`t1`,`test`.`t2`,`test`.`t3` using `test`.`t1` join `test`.`t2` join `test`.`t3` where `test`.`t2`.`a2` = `test`.`t1`.`a1` and `test`.`t3`.`a3` = `test`.`t2`.`b2` and `test`.`t3`.`b3` = `test`.`t1`.`b1` # Status of EXPLAIN EXTENDED query Variable_name Value Handler_read_key 13 @@ -993,6 +1034,8 @@ EXPLAIN EXTENDED UPDATE t1 SET a = 10 WHERE a IN (SELECT a FROM t2); id select_type table type possible_keys key key_len ref rows filtered Extra 1 PRIMARY t1 ALL NULL NULL NULL NULL 3 100.00 Using where 2 DEPENDENT SUBQUERY t2 ALL NULL NULL NULL NULL 3 100.00 Using where +Warnings: +Note 1003 /* select#1 */ update `test`.`t1` set `test`.`t1`.`a` = 10 where (`test`.`t1`.`a`,(/* select#2 */ select `test`.`t2`.`a` from `test`.`t2` where (`test`.`t1`.`a`) = `test`.`t2`.`a`)) # Status of EXPLAIN EXTENDED query Variable_name Value Handler_read_key 4 @@ -1043,6 +1086,8 @@ EXPLAIN EXTENDED DELETE FROM t1 WHERE a1 IN (SELECT a2 FROM t2 WHERE a2 > 2); id select_type table type possible_keys key key_len ref rows filtered Extra 1 PRIMARY t1 ALL NULL NULL NULL NULL 5 100.00 Using where 2 DEPENDENT SUBQUERY t2 ALL NULL NULL NULL NULL 5 100.00 Using where +Warnings: +Note 1003 /* select#1 */ delete from `test`.`t1` where (`test`.`t1`.`a1`,(/* select#2 */ select `test`.`t2`.`a2` from `test`.`t2` where `test`.`t2`.`a2` > 2 and (`test`.`t1`.`a1`) = `test`.`t2`.`a2`)) # Status of EXPLAIN EXTENDED query Variable_name Value Handler_read_key 4 @@ -1088,6 +1133,8 @@ EXPLAIN EXTENDED DELETE FROM t1 WHERE a1 IN (SELECT a2 FROM t2 WHERE a2 > 2); id select_type table type possible_keys key key_len ref rows filtered Extra 1 PRIMARY t1 ALL NULL NULL NULL NULL 5 100.00 Using where 2 DEPENDENT SUBQUERY t2 ALL NULL NULL NULL NULL 5 100.00 Using where +Warnings: +Note 1003 /* select#1 */ delete from `test`.`t1` where (`test`.`t1`.`a1`,(/* select#2 */ select `test`.`t2`.`a2` from `test`.`t2` where `test`.`t2`.`a2` > 2 and (`test`.`t1`.`a1`) = `test`.`t2`.`a2`)) # Status of EXPLAIN EXTENDED query Variable_name Value Handler_read_key 4 @@ -1132,6 +1179,8 @@ FLUSH TABLES; EXPLAIN EXTENDED UPDATE t1 SET i = 10; id select_type table type possible_keys key key_len ref rows filtered Extra 1 SIMPLE t1 ALL NULL NULL NULL NULL 5 100.00 +Warnings: +Note 1003 update `test`.`t1` set `test`.`t1`.`i` = 10 # Status of EXPLAIN EXTENDED query Variable_name Value Handler_read_key 3 @@ -1175,6 +1224,8 @@ FLUSH TABLES; EXPLAIN EXTENDED DELETE FROM t1; id select_type table type possible_keys key key_len ref rows filtered Extra 1 SIMPLE NULL NULL NULL NULL NULL NULL 5 NULL Deleting all rows +Warnings: +Note 1003 delete from `test`.`t1` # Status of EXPLAIN EXTENDED query Variable_name Value Handler_read_key 3 @@ -1221,6 +1272,8 @@ FLUSH TABLES; EXPLAIN EXTENDED DELETE FROM t2 WHERE b = 10 ORDER BY a, c LIMIT 5; id select_type table type possible_keys key key_len ref rows filtered Extra 1 SIMPLE t2 index NULL a 15 NULL 5 100.00 Using where +Warnings: +Note 1003 delete from `test`.`t2` where `test`.`t2`.`b` = 10 order by `test`.`t2`.`a`,`test`.`t2`.`c` limit 5 # Status of EXPLAIN EXTENDED query Variable_name Value Handler_read_key 8 @@ -1267,6 +1320,8 @@ FLUSH TABLES; EXPLAIN EXTENDED INSERT INTO t2 SELECT * FROM t1; id select_type table type possible_keys key key_len ref rows filtered Extra 1 SIMPLE t1 ALL NULL NULL NULL NULL 3 100.00 +Warnings: +Note 1003 insert into `test`.`t2` select `test`.`t1`.`i` AS `i` from `test`.`t1` # Status of EXPLAIN EXTENDED query Variable_name Value Handler_read_key 4 @@ -1311,6 +1366,8 @@ FLUSH TABLES; EXPLAIN EXTENDED REPLACE INTO t2 SELECT * FROM t1; id select_type table type possible_keys key key_len ref rows filtered Extra 1 SIMPLE t1 ALL NULL NULL NULL NULL 3 100.00 +Warnings: +Note 1003 replace into `test`.`t2` select `test`.`t1`.`i` AS `i` from `test`.`t1` # Status of EXPLAIN EXTENDED query Variable_name Value Handler_read_key 4 @@ -1351,6 +1408,8 @@ FLUSH TABLES; EXPLAIN EXTENDED INSERT INTO t1 SET i = 10; id select_type table type possible_keys key key_len ref rows filtered Extra 1 INSERT t1 ALL NULL NULL NULL NULL NULL 100.00 NULL +Warnings: +Note 1003 insert into `test`.`t1`(i) values (10) # Status of EXPLAIN EXTENDED query Variable_name Value Handler_read_key 2 @@ -1374,6 +1433,8 @@ FLUSH TABLES; EXPLAIN EXTENDED REPLACE INTO t1 SET i = 10; id select_type table type possible_keys key key_len ref rows filtered Extra 1 INSERT t1 ALL NULL NULL NULL NULL NULL 100.00 NULL +Warnings: +Note 1003 replace into `test`.`t1`(i) values (10) # Status of EXPLAIN EXTENDED query Variable_name Value Handler_read_key 2 @@ -1402,6 +1463,8 @@ FLUSH TABLES; EXPLAIN EXTENDED DELETE FROM t1 WHERE i > 10 AND i <= 18 ORDER BY i LIMIT 5; id select_type table type possible_keys key key_len ref rows filtered Extra 1 SIMPLE t1 range PRIMARY PRIMARY 4 NULL 5 100.00 Using where +Warnings: +Note 1003 delete from `test`.`t1` where `test`.`t1`.`i` > 10 and `test`.`t1`.`i` <= 18 order by `test`.`t1`.`i` limit 5 # Status of EXPLAIN EXTENDED query Variable_name Value Handler_read_key 4 @@ -1447,6 +1510,8 @@ FLUSH TABLES; EXPLAIN EXTENDED DELETE FROM t1 WHERE i > 10 AND i <= 18 ORDER BY i LIMIT 5; id select_type table type possible_keys key key_len ref rows filtered Extra 1 SIMPLE t1 ALL NULL NULL NULL NULL 26 100.00 Using where; Using filesort +Warnings: +Note 1003 delete from `test`.`t1` where `test`.`t1`.`i` > 10 and `test`.`t1`.`i` <= 18 order by `test`.`t1`.`i` limit 5 # Status of EXPLAIN EXTENDED query Variable_name Value Handler_read_key 4 @@ -1500,6 +1565,8 @@ FLUSH TABLES; EXPLAIN EXTENDED DELETE FROM t2 WHERE b = 10 ORDER BY a, c LIMIT 5; id select_type table type possible_keys key key_len ref rows filtered Extra 1 SIMPLE t2 ALL NULL NULL NULL NULL 26 100.00 Using where; Using filesort +Warnings: +Note 1003 delete from `test`.`t2` where `test`.`t2`.`b` = 10 order by `test`.`t2`.`a`,`test`.`t2`.`c` limit 5 # Status of EXPLAIN EXTENDED query Variable_name Value Handler_read_key 8 @@ -1554,6 +1621,8 @@ FLUSH TABLES; EXPLAIN EXTENDED DELETE FROM t2 WHERE b = 10 ORDER BY a, c LIMIT 5; id select_type table type possible_keys key key_len ref rows filtered Extra 1 SIMPLE t2 index NULL a 15 NULL 5 100.00 Using where +Warnings: +Note 1003 delete from `test`.`t2` where `test`.`t2`.`b` = 10 order by `test`.`t2`.`a`,`test`.`t2`.`c` limit 5 # Status of EXPLAIN EXTENDED query Variable_name Value Handler_read_key 8 @@ -1603,6 +1672,8 @@ FLUSH TABLES; EXPLAIN EXTENDED DELETE FROM t2 WHERE b = 10 ORDER BY a, c LIMIT 5; id select_type table type possible_keys key key_len ref rows filtered Extra 1 SIMPLE t2 ALL NULL NULL NULL NULL 26 100.00 Using where; Using filesort +Warnings: +Note 1003 delete from `test`.`t2` where `test`.`t2`.`b` = 10 order by `test`.`t2`.`a`,`test`.`t2`.`c` limit 5 # Status of EXPLAIN EXTENDED query Variable_name Value Handler_read_key 8 @@ -1657,6 +1728,8 @@ FLUSH TABLES; EXPLAIN EXTENDED DELETE FROM t2 WHERE b = 10 ORDER BY a, c LIMIT 5; id select_type table type possible_keys key key_len ref rows filtered Extra 1 SIMPLE t2 ALL NULL NULL NULL NULL 26 100.00 Using where; Using filesort +Warnings: +Note 1003 delete from `test`.`t2` where `test`.`t2`.`b` = 10 order by `test`.`t2`.`a`,`test`.`t2`.`c` limit 5 # Status of EXPLAIN EXTENDED query Variable_name Value Handler_read_key 8 @@ -1712,6 +1785,8 @@ FLUSH TABLES; EXPLAIN EXTENDED DELETE FROM t2 WHERE key1 < 13 or key2 < 14 ORDER BY key1; id select_type table type possible_keys key key_len ref rows filtered Extra 1 SIMPLE t2 index_merge key1,key2 key1,key2 5,5 NULL 7 100.00 Using sort_union(key1,key2); Using where; Using filesort +Warnings: +Note 1003 delete from `test`.`t2` where `test`.`t2`.`key1` < 13 or `test`.`t2`.`key2` < 14 order by `test`.`t2`.`key1` # Status of EXPLAIN EXTENDED query Variable_name Value Handler_read_key 6 @@ -1765,6 +1840,8 @@ FLUSH TABLES; EXPLAIN EXTENDED DELETE FROM t2 WHERE i > 10 AND i <= 18 ORDER BY i DESC LIMIT 5; id select_type table type possible_keys key key_len ref rows filtered Extra 1 SIMPLE t2 range PRIMARY PRIMARY 4 NULL 5 100.00 Using where +Warnings: +Note 1003 delete from `test`.`t2` where `test`.`t2`.`i` > 10 and `test`.`t2`.`i` <= 18 order by `test`.`t2`.`i` desc limit 5 # Status of EXPLAIN EXTENDED query Variable_name Value Handler_read_key 4 @@ -1812,6 +1889,8 @@ FLUSH TABLES; EXPLAIN EXTENDED DELETE FROM t2 ORDER BY a, b DESC LIMIT 5; id select_type table type possible_keys key key_len ref rows filtered Extra 1 SIMPLE t2 ALL NULL NULL NULL NULL 26 100.00 Using filesort +Warnings: +Note 1003 delete from `test`.`t2` order by `test`.`t2`.`a`,`test`.`t2`.`b` desc limit 5 # Status of EXPLAIN EXTENDED query Variable_name Value Handler_read_key 6 @@ -1866,6 +1945,8 @@ FLUSH TABLES; EXPLAIN EXTENDED DELETE FROM t2 ORDER BY a DESC, b DESC LIMIT 5; id select_type table type possible_keys key key_len ref rows filtered Extra 1 SIMPLE t2 index NULL a 6 NULL 5 100.00 +Warnings: +Note 1003 delete from `test`.`t2` order by `test`.`t2`.`a` desc,`test`.`t2`.`b` desc limit 5 # Status of EXPLAIN EXTENDED query Variable_name Value Handler_read_key 6 @@ -1915,6 +1996,8 @@ FLUSH TABLES; EXPLAIN EXTENDED UPDATE t2 SET a = 10 WHERE i > 10 AND i <= 18 ORDER BY i LIMIT 5; id select_type table type possible_keys key key_len ref rows filtered Extra 1 SIMPLE t2 range PRIMARY PRIMARY 4 NULL 5 100.00 Using where; Using buffer +Warnings: +Note 1003 update `test`.`t2` set `test`.`t2`.`a` = 10 where `test`.`t2`.`i` > 10 and `test`.`t2`.`i` <= 18 order by `test`.`t2`.`i` limit 5 # Status of EXPLAIN EXTENDED query Variable_name Value Handler_read_key 4 @@ -1963,6 +2046,8 @@ FLUSH TABLES; EXPLAIN EXTENDED UPDATE t2 SET a = 10 WHERE i > 10 AND i <= 18 ORDER BY i LIMIT 5; id select_type table type possible_keys key key_len ref rows filtered Extra 1 SIMPLE t2 ALL NULL NULL NULL NULL 26 100.00 Using where; Using filesort +Warnings: +Note 1003 update `test`.`t2` set `test`.`t2`.`a` = 10 where `test`.`t2`.`i` > 10 and `test`.`t2`.`i` <= 18 order by `test`.`t2`.`i` limit 5 # Status of EXPLAIN EXTENDED query Variable_name Value Handler_read_key 4 @@ -2017,6 +2102,8 @@ FLUSH TABLES; EXPLAIN EXTENDED UPDATE t2 SET d = 10 WHERE b = 10 ORDER BY a, c LIMIT 5; id select_type table type possible_keys key key_len ref rows filtered Extra 1 SIMPLE t2 ALL NULL NULL NULL NULL 26 100.00 Using where; Using filesort +Warnings: +Note 1003 update `test`.`t2` set `test`.`t2`.`d` = 10 where `test`.`t2`.`b` = 10 order by `test`.`t2`.`a`,`test`.`t2`.`c` limit 5 # Status of EXPLAIN EXTENDED query Variable_name Value Handler_read_key 8 @@ -2072,6 +2159,8 @@ FLUSH TABLES; EXPLAIN EXTENDED UPDATE t2 SET d = 10 WHERE b = 10 ORDER BY a, c LIMIT 5; id select_type table type possible_keys key key_len ref rows filtered Extra 1 SIMPLE t2 index NULL a 15 NULL 5 100.00 Using where; Using buffer +Warnings: +Note 1003 update `test`.`t2` set `test`.`t2`.`d` = 10 where `test`.`t2`.`b` = 10 order by `test`.`t2`.`a`,`test`.`t2`.`c` limit 5 # Status of EXPLAIN EXTENDED query Variable_name Value Handler_read_key 8 @@ -2122,6 +2211,8 @@ FLUSH TABLES; EXPLAIN EXTENDED UPDATE t2 SET d = 10 WHERE b = 10 ORDER BY a, c LIMIT 5; id select_type table type possible_keys key key_len ref rows filtered Extra 1 SIMPLE t2 ALL NULL NULL NULL NULL 26 100.00 Using where; Using filesort +Warnings: +Note 1003 update `test`.`t2` set `test`.`t2`.`d` = 10 where `test`.`t2`.`b` = 10 order by `test`.`t2`.`a`,`test`.`t2`.`c` limit 5 # Status of EXPLAIN EXTENDED query Variable_name Value Handler_read_key 8 @@ -2176,6 +2267,8 @@ FLUSH TABLES; EXPLAIN EXTENDED UPDATE t2 SET d = 10 WHERE b = 10 ORDER BY a, c LIMIT 5; id select_type table type possible_keys key key_len ref rows filtered Extra 1 SIMPLE t2 ALL NULL NULL NULL NULL 26 100.00 Using where; Using filesort +Warnings: +Note 1003 update `test`.`t2` set `test`.`t2`.`d` = 10 where `test`.`t2`.`b` = 10 order by `test`.`t2`.`a`,`test`.`t2`.`c` limit 5 # Status of EXPLAIN EXTENDED query Variable_name Value Handler_read_key 8 @@ -2231,6 +2324,8 @@ FLUSH TABLES; EXPLAIN EXTENDED UPDATE t2 SET i = 123 WHERE key1 < 13 or key2 < 14 ORDER BY key1; id select_type table type possible_keys key key_len ref rows filtered Extra 1 SIMPLE t2 index_merge key1,key2 key1,key2 5,5 NULL 7 100.00 Using sort_union(key1,key2); Using where; Using filesort +Warnings: +Note 1003 update `test`.`t2` set `test`.`t2`.`i` = 123 where `test`.`t2`.`key1` < 13 or `test`.`t2`.`key2` < 14 order by `test`.`t2`.`key1` # Status of EXPLAIN EXTENDED query Variable_name Value Handler_read_key 6 @@ -2284,6 +2379,8 @@ FLUSH TABLES; EXPLAIN EXTENDED UPDATE t2 SET a = 10 WHERE i > 10 AND i <= 18 ORDER BY i DESC LIMIT 5; id select_type table type possible_keys key key_len ref rows filtered Extra 1 SIMPLE t2 range PRIMARY PRIMARY 4 NULL 5 100.00 Using where; Using buffer +Warnings: +Note 1003 update `test`.`t2` set `test`.`t2`.`a` = 10 where `test`.`t2`.`i` > 10 and `test`.`t2`.`i` <= 18 order by `test`.`t2`.`i` desc limit 5 # Status of EXPLAIN EXTENDED query Variable_name Value Handler_read_key 4 @@ -2332,6 +2429,8 @@ FLUSH TABLES; EXPLAIN EXTENDED UPDATE t2 SET c = 10 ORDER BY a, b DESC LIMIT 5; id select_type table type possible_keys key key_len ref rows filtered Extra 1 SIMPLE t2 ALL NULL NULL NULL NULL 26 100.00 Using filesort +Warnings: +Note 1003 update `test`.`t2` set `test`.`t2`.`c` = 10 order by `test`.`t2`.`a`,`test`.`t2`.`b` desc limit 5 # Status of EXPLAIN EXTENDED query Variable_name Value Handler_read_key 6 @@ -2387,6 +2486,8 @@ FLUSH TABLES; EXPLAIN EXTENDED UPDATE t2 SET c = 10 ORDER BY a DESC, b DESC LIMIT 5; id select_type table type possible_keys key key_len ref rows filtered Extra 1 SIMPLE t2 index NULL a 6 NULL 5 100.00 Using buffer +Warnings: +Note 1003 update `test`.`t2` set `test`.`t2`.`c` = 10 order by `test`.`t2`.`a` desc,`test`.`t2`.`b` desc limit 5 # Status of EXPLAIN EXTENDED query Variable_name Value Handler_read_key 6 @@ -2439,6 +2540,8 @@ FLUSH TABLES; EXPLAIN EXTENDED UPDATE t1 SET c2 = 0 WHERE c1_idx = 'y' ORDER BY pk DESC LIMIT 2; id select_type table type possible_keys key key_len ref rows filtered Extra 1 SIMPLE t1 range c1_idx c1_idx 2 NULL 2 100.00 Using where; Using filesort +Warnings: +Note 1003 update `test`.`t1` set `test`.`t1`.`c2` = 0 where `test`.`t1`.`c1_idx` = 'y' order by `test`.`t1`.`pk` desc limit 2 # Status of EXPLAIN EXTENDED query Variable_name Value Handler_read_key 6 @@ -2485,6 +2588,8 @@ FLUSH TABLES; EXPLAIN EXTENDED DELETE FROM t1 WHERE c1_idx = 'y' ORDER BY pk DESC LIMIT 2; id select_type table type possible_keys key key_len ref rows filtered Extra 1 SIMPLE t1 range c1_idx c1_idx 2 NULL 2 100.00 Using where; Using filesort +Warnings: +Note 1003 delete from `test`.`t1` where `test`.`t1`.`c1_idx` = 'y' order by `test`.`t1`.`pk` desc limit 2 # Status of EXPLAIN EXTENDED query Variable_name Value Handler_read_key 6 @@ -2534,6 +2639,8 @@ FLUSH TABLES; EXPLAIN EXTENDED UPDATE t1 SET a=a+10 WHERE a > 34; id select_type table type possible_keys key key_len ref rows filtered Extra 1 SIMPLE t1 range PRIMARY PRIMARY 4 NULL 2 100.00 Using where; Using buffer +Warnings: +Note 1003 update `test`.`t1` set `test`.`t1`.`a` = `test`.`t1`.`a` + 10 where `test`.`t1`.`a` > 34 # Status of EXPLAIN EXTENDED query Variable_name Value Handler_read_key 3 @@ -2581,6 +2688,8 @@ EXPLAIN EXTENDED UPDATE t1 LEFT JOIN t2 ON t1.c1 = t2.c1 SET t2.c2 = 10; id select_type table type possible_keys key key_len ref rows filtered Extra 1 SIMPLE t2 system NULL NULL NULL NULL 0 0.00 Const row not found 1 SIMPLE t1 ALL NULL NULL NULL NULL 2 100.00 +Warnings: +Note 1003 update `test`.`t1` set NULL = 10 # Status of EXPLAIN EXTENDED query Variable_name Value Handler_read_key 7 @@ -2624,6 +2733,8 @@ EXPLAIN EXTENDED UPDATE t1 LEFT JOIN t2 ON t1.c1 = t2.c1 SET t2.c2 = 10 W id select_type table type possible_keys key key_len ref rows filtered Extra 1 SIMPLE t2 system NULL NULL NULL NULL 0 0.00 Const row not found 1 SIMPLE t1 ALL NULL NULL NULL NULL 2 100.00 Using where +Warnings: +Note 1003 update `test`.`t1` set NULL = 10 where `test`.`t1`.`c3` = 10 # Status of EXPLAIN EXTENDED query Variable_name Value Handler_read_key 7 @@ -2676,6 +2787,7 @@ id select_type table type possible_keys key key_len ref rows filtered Extra 2 DEPENDENT SUBQUERY t2 ALL IDX NULL NULL NULL 2 100.00 Using where Warnings: Note 1276 Field or reference 'test.t1.f1' of SELECT #2 was resolved in SELECT #1 +Note 1003 /* select#1 */ update `test`.`t1` set `test`.`t1`.`f2` = (/* select#2 */ select max(`test`.`t2`.`f4`) from `test`.`t2` where `test`.`t2`.`f3` = `test`.`t1`.`f1`) # Status of EXPLAIN EXTENDED query Variable_name Value Handler_read_key 7 @@ -2747,6 +2859,8 @@ EXPLAIN EXTENDED UPDATE v1 SET a = 1 WHERE a > 0; id select_type table type possible_keys key key_len ref rows filtered Extra 1 SIMPLE t11 ALL NULL NULL NULL NULL 2 100.00 Using where 1 SIMPLE t12 ALL NULL NULL NULL NULL 2 100.00 +Warnings: +Note 1003 update `test`.`t1` `t11` join `test`.`t1` `t12` set `test`.`t11`.`a` = 1 where `test`.`t11`.`a` > 0 # Status of EXPLAIN EXTENDED query Variable_name Value Handler_read_key 2 @@ -2792,6 +2906,8 @@ id select_type table type possible_keys key key_len ref rows filtered Extra 1 SIMPLE t1 ALL NULL NULL NULL NULL 2 100.00 1 SIMPLE t11 ALL NULL NULL NULL NULL 2 100.00 Using where 1 SIMPLE t12 ALL NULL NULL NULL NULL 2 100.00 +Warnings: +Note 1003 update `test`.`t1` join `test`.`t1` `t11` join `test`.`t1` `t12` set `test`.`t11`.`a` = 1 where `test`.`t11`.`a` = `test`.`t1`.`a` # Status of EXPLAIN EXTENDED query Variable_name Value Handler_read_key 2 @@ -2841,6 +2957,8 @@ FLUSH TABLES; EXPLAIN EXTENDED DELETE FROM v1 WHERE a < 4; id select_type table type possible_keys key key_len ref rows filtered Extra 1 SIMPLE t1 range PRIMARY PRIMARY 4 NULL 3 100.00 Using where +Warnings: +Note 1003 /* select#1 */ delete from `test`.`t1` where `test`.`t1`.`a` < 4 # Status of EXPLAIN EXTENDED query Variable_name Value Handler_read_key 3 @@ -2892,6 +3010,8 @@ EXPLAIN EXTENDED DELETE v1 FROM t2, v1 WHERE t2.x = v1.a; id select_type table type possible_keys key key_len ref rows filtered Extra 1 SIMPLE t2 ALL NULL NULL NULL NULL 4 100.00 Using where 1 SIMPLE t1 eq_ref PRIMARY PRIMARY 4 test.t2.x 1 100.00 +Warnings: +Note 1003 delete from `test`.`t1` using `test`.`t2` join `test`.`t1` where `test`.`t1`.`a` = `test`.`t2`.`x` # Status of EXPLAIN EXTENDED query Variable_name Value Handler_read_key 6 @@ -2943,6 +3063,8 @@ EXPLAIN EXTENDED DELETE v1 FROM t2, v1 WHERE t2.x = v1.a; id select_type table type possible_keys key key_len ref rows filtered Extra 1 SIMPLE t2 ALL NULL NULL NULL NULL 4 100.00 Using where 1 SIMPLE t1 eq_ref PRIMARY PRIMARY 4 test.t2.x 1 100.00 +Warnings: +Note 1003 delete from `test`.`t1` using `test`.`t2` join `test`.`t1` where `test`.`t1`.`a` = `test`.`t2`.`x` # Status of EXPLAIN EXTENDED query Variable_name Value Handler_read_key 6 @@ -2987,6 +3109,8 @@ FLUSH TABLES; EXPLAIN EXTENDED INSERT INTO v1 VALUES (10); id select_type table type possible_keys key key_len ref rows filtered Extra 1 INSERT t1 ALL NULL NULL NULL NULL NULL 100.00 NULL +Warnings: +Note 1003 insert into `test`.`t1`(x) values (10) # Status of EXPLAIN EXTENDED query Variable_name Value Handler_read_key 2 @@ -3027,6 +3151,8 @@ FLUSH TABLES; EXPLAIN EXTENDED INSERT INTO v1 SELECT * FROM t1; id select_type table type possible_keys key key_len ref rows filtered Extra 1 SIMPLE t1 system NULL NULL NULL NULL 0 0.00 Const row not found +Warnings: +Note 1003 insert into `test`.`t2`(x) /* select#1 */ select NULL AS `a` from `test`.`t1` # Status of EXPLAIN EXTENDED query Variable_name Value Handler_read_key 4 @@ -3084,6 +3210,8 @@ id select_type table type possible_keys key key_len ref rows filtered Extra 1 PRIMARY t1 ALL NULL NULL NULL NULL 3 100.00 Using where 2 DEPENDENT SUBQUERY index_subquery key0 key0 5 func 2 100.00 3 DERIVED t2 ALL NULL NULL NULL NULL 3 100.00 Using filesort +Warnings: +Note 1003 /* select#1 */ update `test`.`t1` set `test`.`t1`.`a` = 10 where (`test`.`t1`.`a`,(((`test`.`t1`.`a`) in (temporary) on key0))) # Status of EXPLAIN EXTENDED query Variable_name Value Handler_read_key 4 @@ -3140,6 +3268,8 @@ id select_type table type possible_keys key key_len ref rows filtered Extra 1 PRIMARY t2 ALL NULL NULL NULL NULL 3 100.00 2 MATERIALIZED ALL NULL NULL NULL NULL 3 100.00 3 DERIVED t2 ALL NULL NULL NULL NULL 3 100.00 Using filesort +Warnings: +Note 1003 /* select#1 */ update `test`.`t1` semi join ((/* select#3 */ select `test`.`t2`.`b` AS `b` from `test`.`t2` order by `test`.`t2`.`b` limit 2,2) `x`) join `test`.`t2` set `test`.`t1`.`a` = 10 where 1 # Status of EXPLAIN EXTENDED query Variable_name Value Handler_read_key 4 @@ -3198,6 +3328,8 @@ id select_type table type possible_keys key key_len ref rows filtered Extra 3 MATERIALIZED ALL NULL NULL NULL NULL 3 100.00 4 DERIVED t2 ALL NULL NULL NULL NULL 3 100.00 Using filesort 2 DERIVED t2 ALL NULL NULL NULL NULL 3 100.00 +Warnings: +Note 1003 /* select#1 */ update `test`.`t1` semi join ((/* select#4 */ select `test`.`t2`.`b` AS `b` from `test`.`t2` order by `test`.`t2`.`b` limit 2,2) `x`) join (/* select#2 */ select `test`.`t2`.`b` AS `b` from `test`.`t2`) `y` set `test`.`t1`.`a` = 10 where 1 # Status of EXPLAIN EXTENDED query Variable_name Value Handler_read_key 4 @@ -3248,6 +3380,8 @@ JOIN t1 AS a12 ON a12.c1 = a11.c1 id select_type table type possible_keys key key_len ref rows filtered Extra 1 PRIMARY t3 ALL NULL NULL NULL NULL 0 100.00 2 SUBQUERY NULL NULL NULL NULL NULL NULL NULL NULL Impossible WHERE noticed after reading const tables +Warnings: +Note 1003 /* select#1 */ update `test`.`t3` set `test`.`t3`.`c3` = (/* select#2 */ select count(NULL) from `test`.`t1` `a11` straight_join `test`.`t2` `a21` join `test`.`t1` `a12` where 0) DROP TABLE t1, t2, t3; #73 CREATE TABLE t1 (id INT); @@ -3276,6 +3410,8 @@ FLUSH TABLES; EXPLAIN EXTENDED UPDATE t1 SET a=a+1 WHERE a>10; id select_type table type possible_keys key key_len ref rows filtered Extra 1 SIMPLE t1 range PRIMARY PRIMARY 4 NULL 1 100.00 Using where; Using buffer +Warnings: +Note 1003 update `test`.`t1` set `test`.`t1`.`a` = `test`.`t1`.`a` + 1 where `test`.`t1`.`a` > 10 # Status of EXPLAIN EXTENDED query Variable_name Value Handler_read_key 3 @@ -3315,6 +3451,8 @@ FLUSH TABLES; EXPLAIN EXTENDED UPDATE t1 SET a=a+1 WHERE a>10 ORDER BY a+20; id select_type table type possible_keys key key_len ref rows filtered Extra 1 SIMPLE t1 range PRIMARY PRIMARY 4 NULL 1 100.00 Using where; Using filesort +Warnings: +Note 1003 update `test`.`t1` set `test`.`t1`.`a` = `test`.`t1`.`a` + 1 where `test`.`t1`.`a` > 10 order by `test`.`t1`.`a` + 20 # Status of EXPLAIN EXTENDED query Variable_name Value Handler_read_key 3 @@ -3341,6 +3479,61 @@ Handler_read_key 4 Sort_range 1 DROP TABLE t1; +#75 +CREATE TABLE t1 (id INT PRIMARY KEY, i INT); +# +# query: INSERT INTO t1 VALUES (3,10), (7,11), (3,11) ON DUPLICATE KEY UPDATE id=LAST_INSERT_ID(id); +# select: +# +EXPLAIN INSERT INTO t1 VALUES (3,10), (7,11), (3,11) ON DUPLICATE KEY UPDATE id=LAST_INSERT_ID(id);; +id select_type table type possible_keys key key_len ref rows Extra +1 INSERT t1 ALL NULL NULL NULL NULL NULL NULL +FLUSH STATUS; +FLUSH TABLES; +EXPLAIN EXTENDED INSERT INTO t1 VALUES (3,10), (7,11), (3,11) ON DUPLICATE KEY UPDATE id=LAST_INSERT_ID(id);; +id select_type table type possible_keys key key_len ref rows filtered Extra +1 INSERT t1 ALL NULL NULL NULL NULL NULL 100.00 NULL +Warnings: +Note 1003 insert into `test`.`t1` values (3,10),(7,11),(3,11) on duplicate key update `test`.`t1`.`id` = last_insert_id(`test`.`t1`.`id`) +# Status of EXPLAIN EXTENDED query +Variable_name Value +Handler_read_key 4 +# Status of testing query execution: +Variable_name Value +Handler_read_key 4 +Handler_read_rnd 1 +Handler_write 3 + +DROP TABLE t1; +#76 +CREATE TABLE t1 (id INT PRIMARY KEY, i INT); +CREATE TABLE t2 (a INT, b INT); +INSERT INTO t2 VALUES (1,10), (3,10), (7,11), (3,11); +# +# query: INSERT INTO t1 SELECT * FROM t2 ON DUPLICATE KEY UPDATE id=LAST_INSERT_ID(id); +# select: +# +EXPLAIN INSERT INTO t1 SELECT * FROM t2 ON DUPLICATE KEY UPDATE id=LAST_INSERT_ID(id);; +id select_type table type possible_keys key key_len ref rows Extra +1 SIMPLE t2 ALL NULL NULL NULL NULL 4 +FLUSH STATUS; +FLUSH TABLES; +EXPLAIN EXTENDED INSERT INTO t1 SELECT * FROM t2 ON DUPLICATE KEY UPDATE id=LAST_INSERT_ID(id);; +id select_type table type possible_keys key key_len ref rows filtered Extra +1 SIMPLE t2 ALL NULL NULL NULL NULL 4 100.00 +Warnings: +Note 1003 insert into `test`.`t1` select `test`.`t2`.`a` AS `a`,`test`.`t2`.`b` AS `b` from `test`.`t2` on duplicate key update `test`.`t1`.`id` = last_insert_id(`test`.`t1`.`id`) +# Status of EXPLAIN EXTENDED query +Variable_name Value +Handler_read_key 7 +# Status of testing query execution: +Variable_name Value +Handler_read_key 7 +Handler_read_rnd 1 +Handler_read_rnd_next 5 +Handler_write 4 + +DROP TABLE t1,t2; # # Bug #12949629: CLIENT LOSES CONNECTION AFTER EXECUTING A PROCEDURE WITH # EXPLAIN UPDATE/DEL/INS diff --git a/mysql-test/main/opt_trace.result b/mysql-test/main/opt_trace.result index a343d5941f189..a8b391ffbe8b5 100644 --- a/mysql-test/main/opt_trace.result +++ b/mysql-test/main/opt_trace.result @@ -3766,7 +3766,7 @@ explain delete t0,t1 from t0, t1 where t0.a=t1.a and t1.a<3 { "select_id": 1, "steps": [ { - "expanded_query": "select NULL AS `NULL` from t0 join t1 where t0.a = t1.a and t1.a < 3" + "expanded_query": "delete from t0,t1 using t0 join t1 where t0.a = t1.a and t1.a < 3" } ] } diff --git a/mysql-test/main/ps.result b/mysql-test/main/ps.result index 673b18cb3b057..408b1ec26667d 100644 --- a/mysql-test/main/ps.result +++ b/mysql-test/main/ps.result @@ -5566,11 +5566,15 @@ EXPLAIN EXTENDED UPDATE t3 SET c3 = ( SELECT COUNT(d1.c1) FROM ( SELECT a11.c1 F id select_type table type possible_keys key key_len ref rows filtered Extra 1 PRIMARY t3 ALL NULL NULL NULL NULL 0 100.00 2 SUBQUERY NULL NULL NULL NULL NULL NULL NULL NULL Impossible WHERE noticed after reading const tables +Warnings: +Note 1003 /* select#1 */ update `test`.`t3` set `test`.`t3`.`c3` = (/* select#2 */ select count(NULL) from `test`.`t1` `a11` straight_join `test`.`t2` `a21` join `test`.`t1` `a12` where 0) PREPARE stmt FROM "EXPLAIN EXTENDED UPDATE t3 SET c3 = ( SELECT COUNT(d1.c1) FROM ( SELECT a11.c1 FROM t1 AS a11 STRAIGHT_JOIN t2 AS a21 ON a21.c2 = a11.c1 JOIN t1 AS a12 ON a12.c1 = a11.c1 ) d1 )"; EXECUTE stmt; id select_type table type possible_keys key key_len ref rows filtered Extra 1 PRIMARY t3 ALL NULL NULL NULL NULL 0 100.00 2 SUBQUERY NULL NULL NULL NULL NULL NULL NULL NULL Impossible WHERE noticed after reading const tables +Warnings: +Note 1003 /* select#1 */ update `test`.`t3` set `test`.`t3`.`c3` = (/* select#2 */ select count(NULL) from `test`.`t1` `a11` straight_join `test`.`t2` `a21` join `test`.`t1` `a12` where 0) DEALLOCATE PREPARE stmt; DROP TABLE t1, t2, t3; # diff --git a/mysql-test/suite/versioning/r/delete_history.result b/mysql-test/suite/versioning/r/delete_history.result index 8efe75a1ffd54..7bb81111aa877 100644 --- a/mysql-test/suite/versioning/r/delete_history.result +++ b/mysql-test/suite/versioning/r/delete_history.result @@ -171,6 +171,8 @@ x explain extended delete history from t1 before system_time '2039-01-01 23:00'; id select_type table type possible_keys key key_len ref rows filtered Extra 1 SIMPLE t1 ALL NULL NULL NULL NULL 1 100.00 Using where +Warnings: +Note 1003 delete from `test`.`t1` FOR SYSTEM_TIME BEFORE TIMESTAMP '2039-01-01 23:00' where `test`.`t1`.`row_end` < '2039-01-01 23:00' and is_history(`test`.`t1`.`row_end`) create or replace procedure p() delete history from t1 before system_time '2039-01-01 23:00'; call p; select * from t1; diff --git a/sql/sql_delete.cc b/sql/sql_delete.cc index 1b3fa3087e74d..776dfffe11309 100644 --- a/sql/sql_delete.cc +++ b/sql/sql_delete.cc @@ -1084,6 +1084,8 @@ int mysql_prepare_delete(THD *thd, TABLE_LIST *table_list, DBUG_RETURN(TRUE); select_lex->fix_prepare_information(thd, conds, &fake_conds); + if (!thd->lex->upd_del_where) + thd->lex->upd_del_where= *conds; DBUG_RETURN(FALSE); } diff --git a/sql/sql_explain.cc b/sql/sql_explain.cc index 70e300997f95b..6b76db8139e98 100644 --- a/sql/sql_explain.cc +++ b/sql/sql_explain.cc @@ -161,7 +161,7 @@ void Explain_query::query_plan_ready() Send EXPLAIN output to the client. */ -int Explain_query::send_explain(THD *thd) +int Explain_query::send_explain(THD *thd, bool extended) { select_result *result; LEX *lex= thd->lex; @@ -174,8 +174,22 @@ int Explain_query::send_explain(THD *thd) if (thd->lex->explain_json) print_explain_json(result, thd->lex->analyze_stmt); else + { res= print_explain(result, lex->describe, thd->lex->analyze_stmt); - + if (extended) + { + char buff[1024]; + String str(buff,(uint32) sizeof(buff), system_charset_info); + str.length(0); + /* + The warnings system requires input in utf8, @see + mysqld_show_warnings(). + */ + lex->unit.print(&str, QT_EXPLAIN_EXTENDED); + push_warning(thd, Sql_condition::WARN_LEVEL_NOTE, + ER_YES, str.c_ptr_safe()); + } + } if (res) result->abort_result_set(); else @@ -185,6 +199,7 @@ int Explain_query::send_explain(THD *thd) } + /* The main entry point to print EXPLAIN of the entire query */ diff --git a/sql/sql_explain.h b/sql/sql_explain.h index 7b5042b9ccf1f..3add40419cfd3 100644 --- a/sql/sql_explain.h +++ b/sql/sql_explain.h @@ -474,7 +474,7 @@ class Explain_query : public Sql_alloc bool is_analyze); /* Send tabular EXPLAIN to the client */ - int send_explain(THD *thd); + int send_explain(THD *thd, bool extended); /* Return tabular EXPLAIN output as a text string */ bool print_explain_str(THD *thd, String *out_str, bool is_analyze); diff --git a/sql/sql_insert.cc b/sql/sql_insert.cc index f31c9eab4286b..9a760614f6a35 100644 --- a/sql/sql_insert.cc +++ b/sql/sql_insert.cc @@ -827,7 +827,8 @@ bool mysql_insert(THD *thd,TABLE_LIST *table_list, save_insert_query_plan(thd, table_list); if (thd->lex->describe) { - retval= thd->lex->explain->send_explain(thd); + bool extended= thd->lex->describe & DESCRIBE_EXTENDED; + retval= thd->lex->explain->send_explain(thd, extended); goto abort; } @@ -1250,7 +1251,8 @@ bool mysql_insert(THD *thd,TABLE_LIST *table_list, goto abort; if (thd->lex->analyze_stmt) { - retval= thd->lex->explain->send_explain(thd); + bool extended= thd->lex->describe & DESCRIBE_EXTENDED; + retval= thd->lex->explain->send_explain(thd, extended); goto abort; } DBUG_PRINT("info", ("touched: %llu copied: %llu updated: %llu deleted: %llu", diff --git a/sql/sql_lex.cc b/sql/sql_lex.cc index e14d9f7a7406f..e7689a99c2263 100644 --- a/sql/sql_lex.cc +++ b/sql/sql_lex.cc @@ -780,6 +780,8 @@ void LEX::start(THD *thd_arg) frame_bottom_bound= NULL; win_spec= NULL; + upd_del_where= NULL; + vers_conditions.empty(); period_conditions.empty(); diff --git a/sql/sql_lex.h b/sql/sql_lex.h index 769b17508cf64..6170637ad779b 100644 --- a/sql/sql_lex.h +++ b/sql/sql_lex.h @@ -1417,6 +1417,10 @@ class st_select_lex: public st_select_lex_node } bool setup_ref_array(THD *thd, uint order_group_num); void print(THD *thd, String *str, enum_query_type query_type); + void print_item_list(THD *thd, String *str, enum_query_type query_type); + void print_set_clause(THD *thd, String *str, enum_query_type query_type); + void print_on_duplicate_key_clause(THD *thd, String *str, + enum_query_type query_type); static void print_order(String *str, ORDER *order, enum_query_type query_type); @@ -3493,6 +3497,8 @@ struct LEX: public Query_tables_list Window_frame_bound *frame_bottom_bound; Window_spec *win_spec; + Item *upd_del_where; + /* System Versioning */ vers_select_conds_t vers_conditions; vers_select_conds_t period_conditions; diff --git a/sql/sql_parse.cc b/sql/sql_parse.cc index 1f1962a5d44bd..c495ae2d6c4a6 100644 --- a/sql/sql_parse.cc +++ b/sql/sql_parse.cc @@ -4744,7 +4744,10 @@ mysql_execute_command(THD *thd) } if (!res && (explain || lex->analyze_stmt)) - res= thd->lex->explain->send_explain(thd); + { + bool extended= thd->lex->describe & DESCRIBE_EXTENDED; + res= thd->lex->explain->send_explain(thd, extended); + } /* revert changes for SP */ MYSQL_INSERT_SELECT_DONE(res, (ulong) thd->get_row_count_func()); @@ -4813,7 +4816,10 @@ mysql_execute_command(THD *thd) if (thd->lex->analyze_stmt || thd->lex->describe) { if (!res) - res= thd->lex->explain->send_explain(thd); + { + bool extended= thd->lex->describe & DESCRIBE_EXTENDED; + res= thd->lex->explain->send_explain(thd, extended); + } } delete sel_result; @@ -4875,7 +4881,10 @@ mysql_execute_command(THD *thd) else { if (lex->describe || lex->analyze_stmt) - res= thd->lex->explain->send_explain(thd); + { + bool extended= thd->lex->describe & DESCRIBE_EXTENDED; + res= thd->lex->explain->send_explain(thd, extended); + } } multi_delete_error: delete result; @@ -6463,7 +6472,10 @@ static bool execute_sqlcom_select(THD *thd, TABLE_LIST *all_tables) thd->protocol= save_protocol; } if (!res) - res= thd->lex->explain->send_explain(thd); + { + bool extended= thd->lex->describe & DESCRIBE_EXTENDED; + res= thd->lex->explain->send_explain(thd, extended); + } } } } diff --git a/sql/sql_select.cc b/sql/sql_select.cc index 2c12d1c4c6500..c4fc2d191561d 100644 --- a/sql/sql_select.cc +++ b/sql/sql_select.cc @@ -305,6 +305,9 @@ static Item **get_sargable_cond(JOIN *join, TABLE *table); bool is_eq_cond_injected_for_split_opt(Item_func_eq *eq_item); +void print_list_item(String *str, List_item *list, + enum_query_type query_type); + #ifndef DBUG_OFF /* @@ -27981,6 +27984,162 @@ void TABLE_LIST::print(THD *thd, table_map eliminated_tables, String *str, } } +enum explainable_cmd_type +{ + SELECT_CMD, INSERT_CMD, REPLACE_CMD, UPDATE_CMD, DELETE_CMD, NO_CMD +}; + +static +const char * const explainable_cmd_name []= +{ + "select ", + "insert ", + "replace ", + "update ", + "delete ", +}; + +static +char const *get_explainable_cmd_name(enum explainable_cmd_type cmd) +{ + return explainable_cmd_name[cmd]; +} + +static +enum explainable_cmd_type get_explainable_cmd_type(THD *thd) +{ + switch (thd->lex->sql_command) { + case SQLCOM_SELECT: + return SELECT_CMD; + case SQLCOM_INSERT: + case SQLCOM_INSERT_SELECT: + return INSERT_CMD; + case SQLCOM_REPLACE: + case SQLCOM_REPLACE_SELECT: + return REPLACE_CMD; + case SQLCOM_UPDATE: + case SQLCOM_UPDATE_MULTI: + return UPDATE_CMD; + case SQLCOM_DELETE: + case SQLCOM_DELETE_MULTI: + return DELETE_CMD; + default: + return SELECT_CMD; + } +} + + +void TABLE_LIST::print_leaf_tables(THD *thd, String *str, + enum_query_type query_type) +{ + if (merge_underlying_list) + { + for (TABLE_LIST *tbl= merge_underlying_list; tbl; tbl= tbl->next_local) + tbl->print_leaf_tables(thd, str, query_type); + } + else + print(thd, 0, str, query_type); +} + + +void st_select_lex::print_item_list(THD *thd, String *str, + enum_query_type query_type) +{ + bool first= 1; + /* + outer_select() can not be used here because it is for name resolution + and will return NULL at any end of name resolution chain (view/derived) + */ + bool top_level= (get_master()->get_master() == 0); + List_iterator_fast it(item_list); + Item *item; + while ((item= it++)) + { + if (first) + first= 0; + else + str->append(','); + + if ((is_subquery_function() && item->is_autogenerated_name) || + !item->name.str) + { + /* + Do not print auto-generated aliases in subqueries. It has no purpose + in a view definition or other contexts where the query is printed. + */ + item->print(str, query_type); + } + else + { + /* + Do not print illegal names (if it is not top level SELECT). + Top level view checked (and correct name are assigned), + other cases of top level SELECT are not important, because + it is not "table field". + */ + if (top_level || + !item->is_autogenerated_name || + !check_column_name(item->name.str)) + item->print_item_w_name(str, query_type); + else + item->print(str, query_type); + } + } +} + + +void st_select_lex::print_set_clause(THD *thd, String *str, + enum_query_type query_type) +{ + bool first= 1; + /* + outer_select() can not be used here because it is for name resolution + and will return NULL at any end of name resolution chain (view/derived) + */ + List_iterator_fast it(item_list); + List_iterator_fast vt(thd->lex->value_list); + Item *item; + Item *val; + while ((item= it++, val= vt++ )) + { + if (first) + { + str->append(STRING_WITH_LEN(" set ")); + first= 0; + } + else + str->append(','); + + item->print(str, query_type); + str->append(STRING_WITH_LEN(" = ")); + val->print(str, query_type); + } +} + + +void st_select_lex::print_on_duplicate_key_clause(THD *thd, String *str, + enum_query_type query_type) +{ + bool first= 1; + List_iterator_fast it(thd->lex->update_list); + List_iterator_fast vt(thd->lex->value_list); + Item *item; + Item *val; + while ((item= it++, val= vt++ )) + { + if (first) + { + str->append(STRING_WITH_LEN(" on duplicate key update ")); + first= 0; + } + else + str->append(','); + + item->print(str, query_type); + str->append(STRING_WITH_LEN(" = ")); + val->print(str, query_type); + } +} void st_select_lex::print(THD *thd, String *str, enum_query_type query_type) { @@ -27998,6 +28157,61 @@ void st_select_lex::print(THD *thd, String *str, enum_query_type query_type) return; } + bool top_level= (get_master()->get_master() == 0); + enum explainable_cmd_type sel_type= SELECT_CMD; + if (top_level) + sel_type= get_explainable_cmd_type(thd); + + if (sel_type == INSERT_CMD || sel_type == REPLACE_CMD) + { + str->append(get_explainable_cmd_name(sel_type)); + str->append(STRING_WITH_LEN("into ")); + TABLE_LIST *tbl= thd->lex->query_tables; + while (tbl->merge_underlying_list) + tbl= tbl->merge_underlying_list; + tbl->print(thd, 0, str, query_type); + if (thd->lex->field_list.elements) + { + str->append ('('); + List_iterator_fast it(thd->lex->field_list); + Item *item; + bool first= true; + while ((item= it++)) + { + if (first) + first= false; + else + str->append(','); + str->append(item->name); + } + str->append(')'); + } + + str->append(' '); + + if (thd->lex->sql_command == SQLCOM_INSERT || + thd->lex->sql_command == SQLCOM_REPLACE) + { + str->append(STRING_WITH_LEN("values ")); + bool is_first_elem= true; + List_iterator_fast li(thd->lex->many_values); + List_item *list; + + while ((list= li++)) + { + if (is_first_elem) + is_first_elem= false; + else + str->append(','); + + print_list_item(str, list, query_type); + } + if (thd->lex->update_list.elements) + print_on_duplicate_key_clause(thd, str, query_type); + return; + } + } + if ((query_type & QT_SHOW_SELECT_NUMBER) && thd->lex->all_selects_list && thd->lex->all_selects_list->link_next && @@ -28021,7 +28235,10 @@ void st_select_lex::print(THD *thd, String *str, enum_query_type query_type) str->append(" */ "); } - str->append(STRING_WITH_LEN("select ")); + if (sel_type == SELECT_CMD || + sel_type == INSERT_CMD || + sel_type == REPLACE_CMD) + str->append(STRING_WITH_LEN("select ")); if (join && join->cleaned) { @@ -28067,57 +28284,66 @@ void st_select_lex::print(THD *thd, String *str, enum_query_type query_type) } //Item List - bool first= 1; + if (sel_type == SELECT_CMD || + sel_type == INSERT_CMD || + sel_type == REPLACE_CMD) + print_item_list(thd, str, query_type); /* - outer_select() can not be used here because it is for name resolution - and will return NULL at any end of name resolution chain (view/derived) + from clause + TODO: support USING/FORCE/IGNORE index */ - bool top_level= (get_master()->get_master() == 0); - List_iterator_fast it(item_list); - Item *item; - while ((item= it++)) + if (table_list.elements) { - if (first) - first= 0; - else - str->append(','); - - if ((is_subquery_function() && item->is_autogenerated_name) || - !item->name.str) + if (sel_type == SELECT_CMD || + sel_type == INSERT_CMD || + sel_type == REPLACE_CMD) { - /* - Do not print auto-generated aliases in subqueries. It has no purpose - in a view definition or other contexts where the query is printed. - */ - item->print(str, query_type); + str->append(STRING_WITH_LEN(" from ")); + /* go through join tree */ + print_join(thd, join? join->eliminated_tables: 0, str, &top_join_list, + query_type); } - else + if (sel_type == UPDATE_CMD || sel_type == DELETE_CMD) + str->append(STRING_WITH_LEN(get_explainable_cmd_name(sel_type))); + if (sel_type == DELETE_CMD) { - /* - Do not print illegal names (if it is not top level SELECT). - Top level view checked (and correct name are assigned), - other cases of top level SELECT are not important, because - it is not "table field". - */ - if (top_level || - !item->is_autogenerated_name || - !check_column_name(item->name.str)) - item->print_item_w_name(str, query_type); + str->append(STRING_WITH_LEN(" from ")); + bool first= true; + for (TABLE_LIST *target_tbl= thd->lex->auxiliary_table_list.first; + target_tbl; + target_tbl= target_tbl->next_local) + { + if (first) + first= false; + else + str->append(','); + target_tbl->correspondent_table->print_leaf_tables(thd, str, + query_type); + } + + if (!first) + str->append(STRING_WITH_LEN(" using ")); + } + if (sel_type == UPDATE_CMD || sel_type == DELETE_CMD) + { + if (join) + print_join(thd, 0, str, &top_join_list, query_type); else - item->print(str, query_type); + { + bool first= true; + List_iterator_fast li(leaf_tables); + TABLE_LIST *tbl; + while ((tbl= li++)) + { + if (first) + first= false; + else + str->append(','); + tbl->print(thd, 0, str, query_type); + } + } } } - - /* - from clause - TODO: support USING/FORCE/IGNORE index - */ - if (table_list.elements) - { - str->append(STRING_WITH_LEN(" from ")); - /* go through join tree */ - print_join(thd, join? join->eliminated_tables: 0, str, &top_join_list, query_type); - } else if (where) { /* @@ -28127,10 +28353,15 @@ void st_select_lex::print(THD *thd, String *str, enum_query_type query_type) str->append(STRING_WITH_LEN(" from DUAL ")); } + if (sel_type == UPDATE_CMD) + print_set_clause(thd, str, query_type); + // Where Item *cur_where= where; if (join) cur_where= join->conds; + else if (sel_type == UPDATE_CMD || sel_type == DELETE_CMD) + cur_where= thd->lex->upd_del_where; if (cur_where || cond_value != Item::COND_UNDEF) { str->append(STRING_WITH_LEN(" where ")); @@ -28187,6 +28418,15 @@ void st_select_lex::print(THD *thd, String *str, enum_query_type query_type) else if (lock_type == TL_WRITE) str->append(" for update"); + if ((sel_type == INSERT_CMD || sel_type == REPLACE_CMD) && + thd->lex->update_list.elements) + print_on_duplicate_key_clause(thd, str, query_type); + + // returning clause + if (sel_type == DELETE_CMD && !item_list.elements) + { + print_item_list(thd, str, query_type); + } // PROCEDURE unsupported here } diff --git a/sql/sql_update.cc b/sql/sql_update.cc index a29807170184b..834fa6111e51a 100644 --- a/sql/sql_update.cc +++ b/sql/sql_update.cc @@ -1371,7 +1371,8 @@ int mysql_update(THD *thd, goto err; emit_explain_and_leave: - int err2= thd->lex->explain->send_explain(thd); + bool extended= thd->lex->describe & DESCRIBE_EXTENDED; + int err2= thd->lex->explain->send_explain(thd, extended); delete select; free_underlaid_joins(thd, select_lex); @@ -1445,6 +1446,8 @@ bool mysql_prepare_update(THD *thd, TABLE_LIST *table_list, select_lex->fix_prepare_information(thd, conds, &fake_conds); + if (!thd->lex->upd_del_where) + thd->lex->upd_del_where= *conds; DBUG_RETURN(FALSE); } @@ -1974,7 +1977,10 @@ bool mysql_multi_update(THD *thd, TABLE_LIST *table_list, List *fields, else { if (thd->lex->describe || thd->lex->analyze_stmt) - res= thd->lex->explain->send_explain(thd); + { + bool extended= thd->lex->describe & DESCRIBE_EXTENDED; + res= thd->lex->explain->send_explain(thd, extended); + } } thd->abort_on_warning= 0; DBUG_RETURN(res); diff --git a/sql/table.h b/sql/table.h index c4b0d78959d65..6f7f4e634739a 100644 --- a/sql/table.h +++ b/sql/table.h @@ -2708,6 +2708,8 @@ struct TABLE_LIST } void print(THD *thd, table_map eliminated_tables, String *str, enum_query_type query_type); + void print_leaf_tables(THD *thd, String *str, + enum_query_type query_type); bool check_single_table(TABLE_LIST **table, table_map map, TABLE_LIST *view); bool set_insert_values(MEM_ROOT *mem_root); From d575b07c862daf68ddb124486ca8e829cd23cdd9 Mon Sep 17 00:00:00 2001 From: Debjyoti Date: Mon, 6 Mar 2023 23:02:03 +0530 Subject: [PATCH 58/92] MDEV-24453 Added support for a 5th --verbose parameter in mariadb-upgrade to show mysql results for mysql_fix_privilege_tables --- client/mysql_upgrade.c | 14 ++++++++++---- man/mysql_upgrade.1 | 3 ++- 2 files changed, 12 insertions(+), 5 deletions(-) diff --git a/client/mysql_upgrade.c b/client/mysql_upgrade.c index 99c9e7415a729..78297320b6ecb 100644 --- a/client/mysql_upgrade.c +++ b/client/mysql_upgrade.c @@ -75,6 +75,8 @@ char upgrade_from_version[sizeof("10.20.456-MariaDB")+30]; static my_bool opt_write_binlog; +static void print_conn_args(const char *tool_name); + #define OPT_SILENT OPT_MAX_CLIENT_OPTION static struct my_option my_long_options[]= @@ -154,7 +156,10 @@ static struct my_option my_long_options[]= GET_BOOL, NO_ARG, 0, 0, 0, 0, 0, 0}, {"user", 'u', "User for login.", &opt_user, &opt_user, 0, GET_STR, REQUIRED_ARG, 0, 0, 0, 0, 0, 0}, - {"verbose", 'v', "Display more output about the process; Using it twice will print connection argument; Using it 3 times will print out all CHECK, RENAME and ALTER TABLE during the check phase.", + {"verbose", 'v', "Display more output about the process; Using it twice will print connection argument;" + "Using it 3 times will print out all CHECK, RENAME and ALTER TABLE during the check phase;" + "Using it 4 times (added in MariaDB 10.0.14) will also write out all mariadb-check commands used;" + "Using it 5 times will print all the mariadb commands used and their results while running mysql_fix_privilege_tables script.", &opt_not_used, &opt_not_used, 0, GET_BOOL, NO_ARG, 1, 0, 0, 0, 0, 0}, {"version", 'V', "Output version information and exit.", 0, 0, 0, GET_NO_ARG, NO_ARG, 0, 0, 0, 0, 0, 0}, @@ -208,6 +213,7 @@ static void die(const char *fmt, ...) DBUG_ENTER("die"); /* Print the error message */ + print_conn_args("mariadb-check"); fflush(stdout); va_start(args, fmt); if (fmt) @@ -622,6 +628,7 @@ static int run_query(const char *query, DYNAMIC_STRING *ds_res, "--database=mysql", "--batch", /* Turns off pager etc. */ force ? "--force": "--skip-force", + opt_verbose >= 5 ? "--verbose" : "", ds_res || opt_silent ? "--silent": "", "<", query_file_path, @@ -1243,9 +1250,7 @@ static int run_sql_fix_privilege_tables(void) dynstr_append(&ds_script, *query_ptr); } - run_query(ds_script.str, - &ds_result, /* Collect result */ - TRUE); + run_query(ds_script.str, (opt_verbose >= 5) ? NULL : &ds_result, TRUE); { /* @@ -1413,6 +1418,7 @@ int main(int argc, char **argv) DBUG_ASSERT(phase == phases_total); end: + print_conn_args("mariadb-check"); free_used_memory(); my_end(my_end_arg); exit(0); diff --git a/man/mysql_upgrade.1 b/man/mysql_upgrade.1 index 62f13ae2e5296..09ade95b94276 100644 --- a/man/mysql_upgrade.1 +++ b/man/mysql_upgrade.1 @@ -656,7 +656,8 @@ The MariaDB user name to use when connecting to the server and not using the cur Display more output about the process\&. Using it twice will print connection arguments; using it 3 times will print out all CHECK, RENAME and ALTER TABLE commands used during the check phase; using it 4 times (added in MariaDB 10.0.14) -will also write out all mysqlcheck commands used\&. +will also write out all mariadb-check commands used; using it 5 times will print all +the mariadb commands used and their results while running mysql_fix_privilege_tables script\&. .RE .sp .RS 4 From 4c226c185015faa40fbd9b5e70bca5d819f2c3d5 Mon Sep 17 00:00:00 2001 From: Vlad Lesin Date: Thu, 23 Mar 2023 16:26:17 +0300 Subject: [PATCH 59/92] MDEV-29050 mariabackup issues error messages during InnoDB tablespaces export on partial backup preparing The solution is to suppress error messages for missing tablespaces if mariabackup is launched with "--prepare --export" options. "mariabackup --prepare --export" invokes itself with --mysqld parameter. If the parameter is set, then it starts server to feed "FLUSH TABLES ... FOR EXPORT;" queries for exported tablespaces. This is "normal" server start, that's why new srv_operation value is introduced. Reviewed by Marko Makela. --- extra/mariabackup/xtrabackup.cc | 1 + .../suite/mariabackup/partial_exclude.result | 7 ++++ .../suite/mariabackup/partial_exclude.test | 20 ++++++++++ storage/innobase/fil/fil0fil.cc | 16 ++++++-- storage/innobase/fsp/fsp0file.cc | 2 +- storage/innobase/fsp/fsp0sysspace.cc | 2 +- storage/innobase/include/os0file.h | 15 ++++---- storage/innobase/include/srv0srv.h | 3 ++ storage/innobase/log/log0recv.cc | 11 +++--- storage/innobase/os/os0file.cc | 38 ++++--------------- storage/innobase/srv/srv0start.cc | 13 +++++-- 11 files changed, 76 insertions(+), 52 deletions(-) diff --git a/extra/mariabackup/xtrabackup.cc b/extra/mariabackup/xtrabackup.cc index d2ce3395da8fe..5e01e64f490b2 100644 --- a/extra/mariabackup/xtrabackup.cc +++ b/extra/mariabackup/xtrabackup.cc @@ -6830,6 +6830,7 @@ int main(int argc, char **argv) */ if (strcmp(argv[1], "--mysqld") == 0) { + srv_operation= SRV_OPERATION_EXPORT_RESTORED; extern int mysqld_main(int argc, char **argv); argc--; argv++; diff --git a/mysql-test/suite/mariabackup/partial_exclude.result b/mysql-test/suite/mariabackup/partial_exclude.result index 628613040e094..9f4c1042d9353 100644 --- a/mysql-test/suite/mariabackup/partial_exclude.result +++ b/mysql-test/suite/mariabackup/partial_exclude.result @@ -8,8 +8,15 @@ CREATE DATABASE db2; USE db2; CREATE TABLE t1(i INT) ENGINE INNODB; USE test; +BEGIN; +INSERT INTO db2.t1 VALUES(20); +INSERT INTO test.t1 VALUES(20); +INSERT INTO test.t2 VALUES(20); # xtrabackup backup +COMMIT; t1.ibd DROP TABLE t1; DROP TABLE t2; DROP DATABASE db2; +NOT FOUND /Operating system error number/ in backup.log +NOT FOUND /Could not find a valid tablespace file for/ in backup.log diff --git a/mysql-test/suite/mariabackup/partial_exclude.test b/mysql-test/suite/mariabackup/partial_exclude.test index 99d14e58231a3..beff778e7bcc1 100644 --- a/mysql-test/suite/mariabackup/partial_exclude.test +++ b/mysql-test/suite/mariabackup/partial_exclude.test @@ -19,6 +19,11 @@ CREATE TABLE t1(i INT) ENGINE INNODB; USE test; +BEGIN; +INSERT INTO db2.t1 VALUES(20); +INSERT INTO test.t1 VALUES(20); +INSERT INTO test.t2 VALUES(20); + echo # xtrabackup backup; let $targetdir=$MYSQLTEST_VARDIR/tmp/backup; @@ -26,6 +31,8 @@ let $targetdir=$MYSQLTEST_VARDIR/tmp/backup; exec $XTRABACKUP --defaults-file=$MYSQLTEST_VARDIR/my.cnf --backup "--tables-exclude=test.*2" "--databases-exclude=db2" --target-dir=$targetdir; --enable_result_log +COMMIT; + # check that only t1 table is in backup (t2 is excluded) list_files $targetdir/test *.ibd; # check that db2 database is not in the backup (excluded) @@ -46,4 +53,17 @@ DROP DATABASE db2; rmdir $MYSQLD_DATADIR/db3; rmdir $MYSQLD_DATADIR/db4; rmdir $MYSQLD_DATADIR/db5; + +--let $backup_log=$MYSQLTEST_VARDIR/tmp/backup.log +--disable_result_log +exec $XTRABACKUP --defaults-file=$MYSQLTEST_VARDIR/my.cnf --export --prepare --target-dir="$targetdir" > $backup_log; +--enable_result_log + +--let SEARCH_FILE=$backup_log +--let SEARCH_PATTERN=Operating system error number +--source include/search_pattern_in_file.inc +--let SEARCH_PATTERN=Could not find a valid tablespace file for +--source include/search_pattern_in_file.inc +--remove_file $backup_log + rmdir $targetdir; diff --git a/storage/innobase/fil/fil0fil.cc b/storage/innobase/fil/fil0fil.cc index 53387657ebcb6..ebeb1f66101cc 100644 --- a/storage/innobase/fil/fil0fil.cc +++ b/storage/innobase/fil/fil0fil.cc @@ -3235,10 +3235,15 @@ fil_ibd_open( } } + const bool operation_not_for_export = + srv_operation != SRV_OPERATION_RESTORE_EXPORT + && srv_operation != SRV_OPERATION_EXPORT_RESTORED; + /* Always look for a file at the default location. But don't log an error if the tablespace is already open in remote or dict. */ ut_a(df_default.filepath()); - const bool strict = (tablespaces_found == 0); + const bool strict = operation_not_for_export + && (tablespaces_found == 0); if (df_default.open_read_only(strict) == DB_SUCCESS) { ut_ad(df_default.is_open()); ++tablespaces_found; @@ -3284,9 +3289,11 @@ fil_ibd_open( /* Make sense of these three possible locations. First, bail out if no tablespace files were found. */ if (valid_tablespaces_found == 0) { - os_file_get_last_error(true); - ib::error() << "Could not find a valid tablespace file for `" - << tablename << "`. " << TROUBLESHOOT_DATADICT_MSG; + os_file_get_last_error( + operation_not_for_export, !operation_not_for_export); + if (operation_not_for_export) + ib::error() << "Could not find a valid tablespace file for `" + << tablename << "`. " << TROUBLESHOOT_DATADICT_MSG; goto corrupted; } if (!validate) { @@ -3617,6 +3624,7 @@ fil_ibd_discover( case SRV_OPERATION_RESTORE: break; case SRV_OPERATION_NORMAL: + case SRV_OPERATION_EXPORT_RESTORED: df_rem_per.set_name(db); if (df_rem_per.open_link_file() != DB_SUCCESS) { break; diff --git a/storage/innobase/fsp/fsp0file.cc b/storage/innobase/fsp/fsp0file.cc index 5f6d70bb3b540..8d89c98e383ec 100644 --- a/storage/innobase/fsp/fsp0file.cc +++ b/storage/innobase/fsp/fsp0file.cc @@ -787,7 +787,7 @@ the double write buffer. bool Datafile::restore_from_doublewrite() { - if (srv_operation != SRV_OPERATION_NORMAL) { + if (srv_operation > SRV_OPERATION_EXPORT_RESTORED) { return true; } diff --git a/storage/innobase/fsp/fsp0sysspace.cc b/storage/innobase/fsp/fsp0sysspace.cc index 5fcf8ea4e5127..dcab09e5eec25 100644 --- a/storage/innobase/fsp/fsp0sysspace.cc +++ b/storage/innobase/fsp/fsp0sysspace.cc @@ -580,7 +580,7 @@ SysTablespace::read_lsn_and_check_flags(lsn_t* flushed_lsn) ut_a(it->order() == 0); - if (srv_operation == SRV_OPERATION_NORMAL) { + if (srv_operation <= SRV_OPERATION_EXPORT_RESTORED) { buf_dblwr_init_or_load_pages(it->handle(), it->filepath()); } diff --git a/storage/innobase/include/os0file.h b/storage/innobase/include/os0file.h index be363b8eea598..20fcc0b64b8c6 100644 --- a/storage/innobase/include/os0file.h +++ b/storage/innobase/include/os0file.h @@ -1210,13 +1210,14 @@ os_file_flush_func( /** Retrieves the last error number if an error occurs in a file io function. The number should be retrieved before any other OS calls (because they may overwrite the error number). If the number is not known to this program, -the OS error number + 100 is returned. -@param[in] report true if we want an error message printed - for all errors -@return error number, or OS error number + 100 */ -ulint -os_file_get_last_error( - bool report); +the OS error number + OS_FILE_ERROR_MAX is returned. +@param[in] report_all_errors true if we want an error message + printed of all errors +@param[in] on_error_silent true then don't print any diagnostic + to the log +@return error number, or OS error number + OS_FILE_ERROR_MAX */ +ulint os_file_get_last_error(bool report_all_errors, + bool on_error_silent= false); /** NOTE! Use the corresponding macro os_file_read(), not directly this function! diff --git a/storage/innobase/include/srv0srv.h b/storage/innobase/include/srv0srv.h index 6d9d162e78e7b..1624619e8976d 100644 --- a/storage/innobase/include/srv0srv.h +++ b/storage/innobase/include/srv0srv.h @@ -469,6 +469,9 @@ extern my_bool innodb_encrypt_temporary_tables; enum srv_operation_mode { /** Normal mode (MariaDB Server) */ SRV_OPERATION_NORMAL, + /** Mariabackup is executing server to export already restored + tablespaces */ + SRV_OPERATION_EXPORT_RESTORED, /** Mariabackup taking a backup */ SRV_OPERATION_BACKUP, /** Mariabackup restoring a backup for subsequent --copy-back */ diff --git a/storage/innobase/log/log0recv.cc b/storage/innobase/log/log0recv.cc index 3ecbcb180c910..eb4cb9106794b 100644 --- a/storage/innobase/log/log0recv.cc +++ b/storage/innobase/log/log0recv.cc @@ -406,7 +406,7 @@ fil_name_process( return; } - ut_ad(srv_operation == SRV_OPERATION_NORMAL + ut_ad(srv_operation <= SRV_OPERATION_EXPORT_RESTORED || is_mariabackup_restore_or_export()); /* We will also insert space=NULL into the map, so that @@ -2286,7 +2286,7 @@ buf_block_t* recv_recovery_create_page_low(const page_id_t page_id) performed as part of the operation */ void recv_apply_hashed_log_recs(bool last_batch) { - ut_ad(srv_operation == SRV_OPERATION_NORMAL + ut_ad(srv_operation <= SRV_OPERATION_EXPORT_RESTORED || is_mariabackup_restore_or_export()); mutex_enter(&recv_sys.mutex); @@ -3603,7 +3603,7 @@ recv_recovery_from_checkpoint_start(lsn_t flush_lsn) byte* buf; dberr_t err = DB_SUCCESS; - ut_ad(srv_operation == SRV_OPERATION_NORMAL + ut_ad(srv_operation <= SRV_OPERATION_EXPORT_RESTORED || is_mariabackup_restore_or_export()); /* Initialize red-black tree for fast insertions into the @@ -3797,7 +3797,7 @@ recv_recovery_from_checkpoint_start(lsn_t flush_lsn) recv_sys.parse_start_lsn = checkpoint_lsn; - if (srv_operation == SRV_OPERATION_NORMAL) { + if (srv_operation <= SRV_OPERATION_EXPORT_RESTORED) { buf_dblwr_process(); } @@ -3862,7 +3862,8 @@ recv_recovery_from_checkpoint_start(lsn_t flush_lsn) log_sys.last_checkpoint_lsn = checkpoint_lsn; - if (!srv_read_only_mode && srv_operation == SRV_OPERATION_NORMAL) { + if (!srv_read_only_mode + && srv_operation <= SRV_OPERATION_EXPORT_RESTORED) { /* Write a MLOG_CHECKPOINT marker as the first thing, before generating any other redo log. This ensures that subsequent crash recovery will be possible even diff --git a/storage/innobase/os/os0file.cc b/storage/innobase/os/os0file.cc index b40e41cbab9d1..832f5e0565859 100644 --- a/storage/innobase/os/os0file.cc +++ b/storage/innobase/os/os0file.cc @@ -2287,15 +2287,11 @@ The number should be retrieved before any other OS calls (because they may overwrite the error number). If the number is not known to this program, the OS error number + OS_FILE_ERROR_MAX is returned. @param[in] report_all_errors true if we want an error message - printed of all errors + printed of all errors @param[in] on_error_silent true then don't print any diagnostic - to the log + to the log @return error number, or OS error number + OS_FILE_ERROR_MAX */ -static -ulint -os_file_get_last_error_low( - bool report_all_errors, - bool on_error_silent) +ulint os_file_get_last_error(bool report_all_errors, bool on_error_silent) { int err = errno; @@ -3407,16 +3403,12 @@ os_file_flush_func( The number should be retrieved before any other OS calls (because they may overwrite the error number). If the number is not known to this program, the OS error number + 100 is returned. -@param[in] report_all_errors true if we want an error message printed - of all errors +@param[in] report_all_errors true if we want an error message +printed of all errors @param[in] on_error_silent true then don't print any diagnostic - to the log + to the log @return error number, or OS error number + 100 */ -static -ulint -os_file_get_last_error_low( - bool report_all_errors, - bool on_error_silent) +ulint os_file_get_last_error(bool report_all_errors, bool on_error_silent) { ulint err = (ulint) GetLastError(); @@ -4700,20 +4692,6 @@ os_file_read_page( return err; } -/** Retrieves the last error number if an error occurs in a file io function. -The number should be retrieved before any other OS calls (because they may -overwrite the error number). If the number is not known to this program, -the OS error number + 100 is returned. -@param[in] report_all_errors true if we want an error printed - for all errors -@return error number, or OS error number + 100 */ -ulint -os_file_get_last_error( - bool report_all_errors) -{ - return(os_file_get_last_error_low(report_all_errors, false)); -} - /** Handle errors for file operations. @param[in] name name of a file or NULL @param[in] operation operation @@ -4730,7 +4708,7 @@ os_file_handle_error_cond_exit( { ulint err; - err = os_file_get_last_error_low(false, on_error_silent); + err = os_file_get_last_error(false, on_error_silent); switch (err) { case OS_FILE_DISK_FULL: diff --git a/storage/innobase/srv/srv0start.cc b/storage/innobase/srv/srv0start.cc index 30e2d7c6fbb78..b8b74263ebadf 100644 --- a/storage/innobase/srv/srv0start.cc +++ b/storage/innobase/srv/srv0start.cc @@ -810,7 +810,7 @@ srv_undo_tablespaces_init(bool create_new_db) srv_undo_tablespaces_open = 0; ut_a(srv_undo_tablespaces <= TRX_SYS_N_RSEGS); - ut_a(!create_new_db || srv_operation == SRV_OPERATION_NORMAL); + ut_a(!create_new_db || srv_operation <= SRV_OPERATION_EXPORT_RESTORED); if (srv_undo_tablespaces == 1) { /* 1 is not allowed, make it 0 */ srv_undo_tablespaces = 0; @@ -876,6 +876,7 @@ srv_undo_tablespaces_init(bool create_new_db) prev_space_id = srv_undo_space_id_start - 1; break; case SRV_OPERATION_NORMAL: + case SRV_OPERATION_EXPORT_RESTORED: case SRV_OPERATION_RESTORE_ROLLBACK_XA: case SRV_OPERATION_RESTORE: case SRV_OPERATION_RESTORE_EXPORT: @@ -1132,6 +1133,7 @@ srv_shutdown_all_bg_threads() case SRV_OPERATION_RESTORE_DELTA: break; case SRV_OPERATION_NORMAL: + case SRV_OPERATION_EXPORT_RESTORED: case SRV_OPERATION_RESTORE_ROLLBACK_XA: case SRV_OPERATION_RESTORE: case SRV_OPERATION_RESTORE_EXPORT: @@ -1310,7 +1312,7 @@ dberr_t srv_start(bool create_new_db) size_t dirnamelen; unsigned i = 0; - ut_ad(srv_operation == SRV_OPERATION_NORMAL + ut_ad(srv_operation <= SRV_OPERATION_EXPORT_RESTORED || is_mariabackup_restore_or_export()); @@ -1894,6 +1896,7 @@ dberr_t srv_start(bool create_new_db) switch (srv_operation) { case SRV_OPERATION_NORMAL: + case SRV_OPERATION_EXPORT_RESTORED: case SRV_OPERATION_RESTORE_ROLLBACK_XA: case SRV_OPERATION_RESTORE_EXPORT: /* Initialize the change buffer. */ @@ -2304,7 +2307,8 @@ dberr_t srv_start(bool create_new_db) return(srv_init_abort(err)); } - if (!srv_read_only_mode && srv_operation == SRV_OPERATION_NORMAL) { + if (!srv_read_only_mode + && srv_operation <= SRV_OPERATION_EXPORT_RESTORED) { /* Initialize the innodb_temporary tablespace and keep it open until shutdown. */ err = srv_open_tmp_tablespace(create_new_db); @@ -2326,7 +2330,7 @@ dberr_t srv_start(bool create_new_db) } if (!srv_read_only_mode - && (srv_operation == SRV_OPERATION_NORMAL + && (srv_operation <= SRV_OPERATION_EXPORT_RESTORED || srv_operation == SRV_OPERATION_RESTORE_ROLLBACK_XA) && srv_force_recovery < SRV_FORCE_NO_BACKGROUND) { @@ -2465,6 +2469,7 @@ void innodb_shutdown() fil_close_all_files(); break; case SRV_OPERATION_NORMAL: + case SRV_OPERATION_EXPORT_RESTORED: /* Shut down the persistent files. */ logs_empty_and_mark_files_at_shutdown(); From 113bef50e33a838c5cb637ef4a042cbcad79e7a2 Mon Sep 17 00:00:00 2001 From: Yuchen Pei Date: Thu, 23 Mar 2023 09:41:45 +1100 Subject: [PATCH 60/92] MDEV-30581 Add a testcase for MDEV-29904 --- storage/spider/mysql-test/spider/bugfix/r/mdev_29904.result | 4 ++++ storage/spider/mysql-test/spider/bugfix/t/mdev_29904.test | 6 ++++++ 2 files changed, 10 insertions(+) create mode 100644 storage/spider/mysql-test/spider/bugfix/r/mdev_29904.result create mode 100644 storage/spider/mysql-test/spider/bugfix/t/mdev_29904.test diff --git a/storage/spider/mysql-test/spider/bugfix/r/mdev_29904.result b/storage/spider/mysql-test/spider/bugfix/r/mdev_29904.result new file mode 100644 index 0000000000000..c89309a514db6 --- /dev/null +++ b/storage/spider/mysql-test/spider/bugfix/r/mdev_29904.result @@ -0,0 +1,4 @@ +# +# MDEV-29904 SPIDER plugin initialization fails upon startup +# +# restart: --plugin-load-add=ha_spider diff --git a/storage/spider/mysql-test/spider/bugfix/t/mdev_29904.test b/storage/spider/mysql-test/spider/bugfix/t/mdev_29904.test new file mode 100644 index 0000000000000..d3dcb363890cb --- /dev/null +++ b/storage/spider/mysql-test/spider/bugfix/t/mdev_29904.test @@ -0,0 +1,6 @@ +--echo # +--echo # MDEV-29904 SPIDER plugin initialization fails upon startup +--echo # + +--let $restart_parameters=--plugin-load-add=ha_spider +--source include/restart_mysqld.inc From e093e5abbed1a7883b8a78935c11505bd0bcb0d6 Mon Sep 17 00:00:00 2001 From: Daniel Black Date: Thu, 15 Dec 2022 12:38:27 +1100 Subject: [PATCH 61/92] MDEV-30276 - wsrep_sst_mariabackup to use mariadb-backup rather than mariabackup internally, and change and messages accordingly. --- scripts/wsrep_sst_mariabackup.sh | 32 ++++++++++++++++---------------- 1 file changed, 16 insertions(+), 16 deletions(-) diff --git a/scripts/wsrep_sst_mariabackup.sh b/scripts/wsrep_sst_mariabackup.sh index 7e26af83701ce..6ec975f5a593f 100644 --- a/scripts/wsrep_sst_mariabackup.sh +++ b/scripts/wsrep_sst_mariabackup.sh @@ -95,9 +95,9 @@ sst_ver=1 declare -a RC -BACKUP_BIN=$(commandex 'mariabackup') +BACKUP_BIN=$(commandex 'mariadb-backup') if [ -z "$BACKUP_BIN" ]; then - wsrep_log_error 'mariabackup binary not found in path' + wsrep_log_error 'mariadb-backup binary not found in path' exit 42 fi @@ -685,7 +685,7 @@ cleanup_at_exit() if [ -n "$BACKUP_PID" ]; then if check_pid "$BACKUP_PID" 1; then wsrep_log_error \ - "mariabackup process is still running. Killing..." + "mariadb-backup process is still running. Killing..." cleanup_pid $CHECK_PID "$BACKUP_PID" fi fi @@ -761,7 +761,7 @@ check_extra() if [ "$thread_handling" = 'pool-of-threads' ]; then local eport=$(parse_cnf '--mysqld' 'extra-port') if [ -n "$eport" ]; then - # mariabackup works only locally. + # mariadb-backup works only locally. # Hence, setting host to 127.0.0.1 unconditionally: wsrep_log_info "SST through extra_port $eport" INNOEXTRA="$INNOEXTRA --host=127.0.0.1 --port=$eport" @@ -930,7 +930,7 @@ cd "$OLD_PWD" if [ $ssyslog -eq 1 ]; then if [ -n "$(commandex logger)" ]; then - wsrep_log_info "Logging all stderr of SST/mariabackup to syslog" + wsrep_log_info "Logging all stderr of SST/mariadb-backup to syslog" exec 2> >(logger -p daemon.err -t ${ssystag}wsrep-sst-$WSREP_SST_OPT_ROLE) @@ -1053,11 +1053,11 @@ if [ "$WSREP_SST_OPT_ROLE" = 'donor' ]; then xtmpdir=$(TMPDIR="$tmpdir"; mktemp '-d') fi - wsrep_log_info "Using '$xtmpdir' as mariabackup temporary directory" + wsrep_log_info "Using '$xtmpdir' as mariadb-backup temporary directory" tmpopts=" --tmpdir='$xtmpdir'" itmpdir="$(mktemp -d)" - wsrep_log_info "Using '$itmpdir' as mariabackup working directory" + wsrep_log_info "Using '$itmpdir' as mariadb-abackup working directory" usrst=0 if [ -n "$WSREP_SST_OPT_USER" ]; then @@ -1148,7 +1148,7 @@ if [ "$WSREP_SST_OPT_ROLE" = 'donor' ]; then fi # if compression is enabled for backup files, then add the - # appropriate options to the mariabackup command line: + # appropriate options to the mariadb-backup command line: if [ "$compress" != 'none' ]; then iopts="--compress${compress:+=$compress}${iopts:+ }$iopts" if [ -n "$compress_threads" ]; then @@ -1170,7 +1170,7 @@ if [ "$WSREP_SST_OPT_ROLE" = 'donor' ]; then set -e if [ ${RC[0]} -ne 0 ]; then - wsrep_log_error "mariabackup finished with error: ${RC[0]}." \ + wsrep_log_error "mariadb-backup finished with error: ${RC[0]}." \ "Check syslog or '$INNOBACKUPLOG' for details" exit 22 elif [ ${RC[$(( ${#RC[@]}-1 ))]} -eq 1 ]; then @@ -1178,7 +1178,7 @@ if [ "$WSREP_SST_OPT_ROLE" = 'donor' ]; then exit 22 fi - # mariabackup implicitly writes PID to fixed location in $xtmpdir + # mariadb-backup implicitly writes PID to fixed location in $xtmpdir BACKUP_PID="$xtmpdir/xtrabackup_pid" else # BYPASS FOR IST @@ -1450,14 +1450,14 @@ else # joiner if [ ! -s "$DATA/xtrabackup_checkpoints" ]; then wsrep_log_error "xtrabackup_checkpoints missing," \ - "failed mariabackup/SST on donor" + "failed mariadb-backup/SST on donor" exit 2 fi - # Compact backups are not supported by mariabackup + # Compact backups are not supported by mariadb-backup if grep -qw -F 'compact = 1' "$DATA/xtrabackup_checkpoints"; then wsrep_log_info "Index compaction detected" - wsrel_log_error "Compact backups are not supported by mariabackup" + wsrel_log_error "Compact backups are not supported by mariadb-backup" exit 2 fi @@ -1509,9 +1509,9 @@ else # joiner wsrep_log_info "Preparing the backup at $DATA" setup_commands - timeit 'mariabackup prepare stage' "$INNOAPPLY" + timeit 'mariadb-backup prepare stage' "$INNOAPPLY" if [ $? -ne 0 ]; then - wsrep_log_error "mariabackup apply finished with errors." \ + wsrep_log_error "mariadb-backup apply finished with errors." \ "Check syslog or '$INNOAPPLYLOG' for details." exit 22 fi @@ -1556,7 +1556,7 @@ else # joiner MAGIC_FILE="$TDATA/$INFO_FILE" wsrep_log_info "Moving the backup to $TDATA" - timeit 'mariabackup move stage' "$INNOMOVE" + timeit 'mariadb-backup move stage' "$INNOMOVE" if [ $? -eq 0 ]; then wsrep_log_info "Move successful, removing $DATA" rm -rf "$DATA" From 03b4a2d6e5b3d6e4bd88c3451cbff8ba4df7bd71 Mon Sep 17 00:00:00 2001 From: Alexander Barkov Date: Wed, 29 Mar 2023 11:56:44 +0400 Subject: [PATCH 62/92] MDEV-26765 UNIX_TIMESTAMP(CURRENT_TIME()) return null ?!? Problem: UNIX_TIMESTAMP() called for a expression of the TIME data type returned NULL. Inside Type_handler_timestamp_common::Item_val_native_with_conversion the call for item->get_date() did not convert TIME to DATETIME automatically (because it does not have to, by design). As a result, Type_handler_timestamp_common::TIME_to_native() received a MYSQL_TIME value with zero date 0000-00-00 and therefore returned "true" (indicating SQL NULL value). Fix: Removing the call for item->get_date(). Instantiating Datetime(item) instead. This forces automatic TIME to DATETIME conversion (unless @@old_mode is zero_date_time_cast). --- mysql-test/main/old-mode.result | 36 ++++++++++++++++++++++++++++++++ mysql-test/main/old-mode.test | 20 ++++++++++++++++++ mysql-test/main/type_time.result | 26 +++++++++++++++++++++++ mysql-test/main/type_time.test | 19 +++++++++++++++++ sql/sql_type.cc | 6 +++--- 5 files changed, 104 insertions(+), 3 deletions(-) diff --git a/mysql-test/main/old-mode.result b/mysql-test/main/old-mode.result index e0a3412bbdf29..bb65acd54ce8c 100644 --- a/mysql-test/main/old-mode.result +++ b/mysql-test/main/old-mode.result @@ -221,3 +221,39 @@ a UNIX_TIMESTAMP(t1.a) a UNIX_TIMESTAMP(t2.a) DROP TABLE t1; SET time_zone=DEFAULT; SET global mysql56_temporal_format=true; +# +# MDEV-26765 UNIX_TIMESTAMP(CURRENT_TIME()) return null ?!? +# +SET old_mode=zero_date_time_cast; +SET @@time_zone='+00:00'; +SET timestamp=1234567; +SELECT CURRENT_TIMESTAMP; +CURRENT_TIMESTAMP +1970-01-15 06:56:07 +SELECT UNIX_TIMESTAMP(CURRENT_TIME()); +UNIX_TIMESTAMP(CURRENT_TIME()) +NULL +Warnings: +Warning 1292 Truncated incorrect datetime value: '06:56:07' +SELECT UNIX_TIMESTAMP(TIME'06:56:07'); +UNIX_TIMESTAMP(TIME'06:56:07') +NULL +Warnings: +Warning 1292 Truncated incorrect datetime value: '06:56:07' +SELECT UNIX_TIMESTAMP(TIME'10:20:30'); +UNIX_TIMESTAMP(TIME'10:20:30') +NULL +Warnings: +Warning 1292 Truncated incorrect datetime value: '10:20:30' +CREATE OR REPLACE TABLE t1 (a TIME); +INSERT INTO t1 VALUES (TIME'06:56:07'),('10:20:30'); +SELECT UNIX_TIMESTAMP(a) FROM t1 ORDER BY a; +UNIX_TIMESTAMP(a) +NULL +NULL +Warnings: +Warning 1264 Out of range value for column 'a' at row 1 +Warning 1264 Out of range value for column 'a' at row 2 +DROP TABLE t1; +SET @@time_zone=DEFAULT; +SET TIMESTAMP=DEFAULT; diff --git a/mysql-test/main/old-mode.test b/mysql-test/main/old-mode.test index a09de1cf87d04..d3fc254110d90 100644 --- a/mysql-test/main/old-mode.test +++ b/mysql-test/main/old-mode.test @@ -149,3 +149,23 @@ SELECT t1.a, UNIX_TIMESTAMP(t1.a), t2.a, UNIX_TIMESTAMP(t2.a) FROM t1 t1, t1 t2 DROP TABLE t1; SET time_zone=DEFAULT; SET global mysql56_temporal_format=true; + + +--echo # +--echo # MDEV-26765 UNIX_TIMESTAMP(CURRENT_TIME()) return null ?!? +--echo # + +SET old_mode=zero_date_time_cast; +SET @@time_zone='+00:00'; +SET timestamp=1234567; +SELECT CURRENT_TIMESTAMP; +SELECT UNIX_TIMESTAMP(CURRENT_TIME()); +SELECT UNIX_TIMESTAMP(TIME'06:56:07'); +SELECT UNIX_TIMESTAMP(TIME'10:20:30'); +CREATE OR REPLACE TABLE t1 (a TIME); +INSERT INTO t1 VALUES (TIME'06:56:07'),('10:20:30'); +SELECT UNIX_TIMESTAMP(a) FROM t1 ORDER BY a; +DROP TABLE t1; + +SET @@time_zone=DEFAULT; +SET TIMESTAMP=DEFAULT; diff --git a/mysql-test/main/type_time.result b/mysql-test/main/type_time.result index e383704fdb89d..7b40328892d7c 100644 --- a/mysql-test/main/type_time.result +++ b/mysql-test/main/type_time.result @@ -2420,5 +2420,31 @@ SET @@global.mysql56_temporal_format=default; DROP PROCEDURE p1; SET timestamp=DEFAULT; # +# MDEV-26765 UNIX_TIMESTAMP(CURRENT_TIME()) return null ?!? +# +SET @@time_zone='+00:00'; +SET timestamp=1234567; +SELECT CURRENT_TIMESTAMP; +CURRENT_TIMESTAMP +1970-01-15 06:56:07 +SELECT UNIX_TIMESTAMP(CURRENT_TIME()); +UNIX_TIMESTAMP(CURRENT_TIME()) +1234567 +SELECT UNIX_TIMESTAMP(TIME'06:56:07'); +UNIX_TIMESTAMP(TIME'06:56:07') +1234567 +SELECT UNIX_TIMESTAMP(TIME'10:20:30'); +UNIX_TIMESTAMP(TIME'10:20:30') +1246830 +CREATE OR REPLACE TABLE t1 (a TIME); +INSERT INTO t1 VALUES (TIME'06:56:07'),('10:20:30'); +SELECT UNIX_TIMESTAMP(a) FROM t1 ORDER BY a; +UNIX_TIMESTAMP(a) +1234567 +1246830 +DROP TABLE t1; +SET @@time_zone=DEFAULT; +SET TIMESTAMP=DEFAULT; +# # End of 10.4 tests # diff --git a/mysql-test/main/type_time.test b/mysql-test/main/type_time.test index 0f67223238c45..9ed5c3a73dce1 100644 --- a/mysql-test/main/type_time.test +++ b/mysql-test/main/type_time.test @@ -1566,6 +1566,25 @@ SET @@global.mysql56_temporal_format=default; DROP PROCEDURE p1; SET timestamp=DEFAULT; +--echo # +--echo # MDEV-26765 UNIX_TIMESTAMP(CURRENT_TIME()) return null ?!? +--echo # + +SET @@time_zone='+00:00'; +SET timestamp=1234567; +SELECT CURRENT_TIMESTAMP; +SELECT UNIX_TIMESTAMP(CURRENT_TIME()); +SELECT UNIX_TIMESTAMP(TIME'06:56:07'); +SELECT UNIX_TIMESTAMP(TIME'10:20:30'); +CREATE OR REPLACE TABLE t1 (a TIME); +INSERT INTO t1 VALUES (TIME'06:56:07'),('10:20:30'); +SELECT UNIX_TIMESTAMP(a) FROM t1 ORDER BY a; +DROP TABLE t1; + +SET @@time_zone=DEFAULT; +SET TIMESTAMP=DEFAULT; + + --echo # --echo # End of 10.4 tests --echo # diff --git a/sql/sql_type.cc b/sql/sql_type.cc index a9610195e6562..92bf2b39f9021 100644 --- a/sql/sql_type.cc +++ b/sql/sql_type.cc @@ -8619,13 +8619,13 @@ Type_handler_timestamp_common::Item_val_native_with_conversion(THD *thd, Item *item, Native *to) const { - MYSQL_TIME ltime; if (item->type_handler()->type_handler_for_native_format() == &type_handler_timestamp2) return item->val_native(thd, to); + Datetime dt(thd, item, Datetime::Options(TIME_NO_ZERO_IN_DATE, thd)); return - item->get_date(thd, <ime, Datetime::Options(TIME_NO_ZERO_IN_DATE, thd)) || - TIME_to_native(thd, <ime, to, item->datetime_precision(thd)); + !dt.is_valid_datetime() || + TIME_to_native(thd, dt.get_mysql_time(), to, item->datetime_precision(thd)); } bool Type_handler_null::union_element_finalize(Item_type_holder *item) const From a6780df49b443b172124e7e881ed0bea54d75907 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marko=20M=C3=A4kel=C3=A4?= Date: Wed, 29 Mar 2023 16:49:10 +0300 Subject: [PATCH 63/92] MDEV-30453 Setting innodb_buffer_pool_filename to an empty string attempts to delete the data directory on shutdown Let us make innodb_buffer_pool_filename a read-only variable so that a malicious user cannot cause an important file to be deleted on InnoDB shutdown. An attempt to delete a directory will fail because it is not a regular file, but what if the variable pointed to (say) ibdata1, ib_logfile0 or some *.ibd file? It does not seem to make much sense for this parameter to be configurable in the first place, but we will not change that in order to avoid breaking compatibility. --- .../r/innodb_buffer_pool_dump_pct.result | 3 -- .../innodb/r/innodb_sys_var_valgrind.result | 21 ---------- .../innodb/t/innodb_buffer_pool_dump_pct.test | 10 ++--- .../innodb/t/innodb_sys_var_valgrind.test | 18 -------- .../suite/sys_vars/r/sysvars_innodb.result | 2 +- storage/innobase/handler/ha_innodb.cc | 42 +------------------ 6 files changed, 6 insertions(+), 90 deletions(-) diff --git a/mysql-test/suite/innodb/r/innodb_buffer_pool_dump_pct.result b/mysql-test/suite/innodb/r/innodb_buffer_pool_dump_pct.result index d9f5e4dfeed5d..fa17487df9767 100644 --- a/mysql-test/suite/innodb/r/innodb_buffer_pool_dump_pct.result +++ b/mysql-test/suite/innodb/r/innodb_buffer_pool_dump_pct.result @@ -2,13 +2,11 @@ CREATE TABLE tab5 (col1 int auto_increment primary key, col2 VARCHAR(25), col3 varchar(25)) ENGINE=InnoDB; CREATE INDEX idx1 ON tab5(col2(10)); CREATE INDEX idx2 ON tab5(col3(10)); -SET GLOBAL innodb_buffer_pool_filename=ib_buffer_pool100; SET GLOBAL innodb_buffer_pool_dump_pct=100; SELECT variable_value INTO @IBPDS FROM information_schema.global_status WHERE variable_name = 'INNODB_BUFFER_POOL_DUMP_STATUS'; SET GLOBAL innodb_buffer_pool_dump_now=ON; -SET GLOBAL innodb_buffer_pool_filename=ib_buffer_pool1; SET GLOBAL innodb_buffer_pool_dump_pct=1; SELECT @@global.innodb_buffer_pool_dump_pct; @@global.innodb_buffer_pool_dump_pct @@ -18,5 +16,4 @@ FROM information_schema.global_status WHERE variable_name = 'INNODB_BUFFER_POOL_DUMP_STATUS'; SET GLOBAL innodb_buffer_pool_dump_now=ON; SET GLOBAL innodb_buffer_pool_dump_pct=DEFAULT; -SET GLOBAL innodb_buffer_pool_filename=DEFAULT; DROP TABLE tab5; diff --git a/mysql-test/suite/innodb/r/innodb_sys_var_valgrind.result b/mysql-test/suite/innodb/r/innodb_sys_var_valgrind.result index 32d87b4668a23..6932b8f22926e 100644 --- a/mysql-test/suite/innodb/r/innodb_sys_var_valgrind.result +++ b/mysql-test/suite/innodb/r/innodb_sys_var_valgrind.result @@ -25,27 +25,6 @@ select @@innodb_ft_server_stopword_table; @@innodb_ft_server_stopword_table NULL drop table user_stopword_1, user_stopword_2; -select @@innodb_buffer_pool_filename; -@@innodb_buffer_pool_filename -ib_buffer_pool -set @blah='hello'; -set global innodb_buffer_pool_filename = @blah; -select @@innodb_buffer_pool_filename; -@@innodb_buffer_pool_filename -hello -set global innodb_buffer_pool_filename="bye"; -select @@innodb_buffer_pool_filename; -@@innodb_buffer_pool_filename -bye -set global innodb_buffer_pool_filename=NULL; -ERROR 42000: Variable 'innodb_buffer_pool_filename' can't be set to the value of 'NULL' -select @@innodb_buffer_pool_filename; -@@innodb_buffer_pool_filename -bye -set global innodb_buffer_pool_filename=default; -select @@innodb_buffer_pool_filename; -@@innodb_buffer_pool_filename -ib_buffer_pool CREATE TABLE t1 ( id INT UNSIGNED AUTO_INCREMENT NOT NULL PRIMARY KEY, opening_line TEXT(500), author VARCHAR(200), title VARCHAR(200), FULLTEXT idx (opening_line)) ENGINE=InnoDB; diff --git a/mysql-test/suite/innodb/t/innodb_buffer_pool_dump_pct.test b/mysql-test/suite/innodb/t/innodb_buffer_pool_dump_pct.test index a7a414d61da61..381091165ef08 100644 --- a/mysql-test/suite/innodb/t/innodb_buffer_pool_dump_pct.test +++ b/mysql-test/suite/innodb/t/innodb_buffer_pool_dump_pct.test @@ -15,7 +15,6 @@ col2 VARCHAR(25), col3 varchar(25)) ENGINE=InnoDB; CREATE INDEX idx1 ON tab5(col2(10)); CREATE INDEX idx2 ON tab5(col3(10)); -SET GLOBAL innodb_buffer_pool_filename=ib_buffer_pool100; SET GLOBAL innodb_buffer_pool_dump_pct=100; #*********************************************************** @@ -58,8 +57,7 @@ AND variable_value != @IBPDS AND variable_value like 'Buffer pool(s) dump completed at%'; --source include/wait_condition.inc ---file_exists $MYSQLD_DATADIR/ib_buffer_pool100 -SET GLOBAL innodb_buffer_pool_filename=ib_buffer_pool1; +--move_file $MYSQLD_DATADIR/ib_buffer_pool $MYSQLD_DATADIR/ib_buffer_pool100 SET GLOBAL innodb_buffer_pool_dump_pct=1; SELECT @@global.innodb_buffer_pool_dump_pct; @@ -83,17 +81,15 @@ AND variable_value != @IBPDS AND variable_value like 'Buffer pool(s) dump completed at%'; --source include/wait_condition.inc ---file_exists $MYSQLD_DATADIR/ib_buffer_pool1 +--file_exists $MYSQLD_DATADIR/ib_buffer_pool perl; -my $size1 = -s "$ENV{MYSQLD_DATADIR}/ib_buffer_pool1"; +my $size1 = -s "$ENV{MYSQLD_DATADIR}/ib_buffer_pool"; my $size100 = -s "$ENV{MYSQLD_DATADIR}/ib_buffer_pool100"; die "$size100<=$size1\n" unless $size100 > $size1; EOF SET GLOBAL innodb_buffer_pool_dump_pct=DEFAULT; -SET GLOBAL innodb_buffer_pool_filename=DEFAULT; --remove_file $MYSQLD_DATADIR/ib_buffer_pool100 ---remove_file $MYSQLD_DATADIR/ib_buffer_pool1 DROP TABLE tab5; diff --git a/mysql-test/suite/innodb/t/innodb_sys_var_valgrind.test b/mysql-test/suite/innodb/t/innodb_sys_var_valgrind.test index 2e1391355b93f..4383e26877d12 100644 --- a/mysql-test/suite/innodb/t/innodb_sys_var_valgrind.test +++ b/mysql-test/suite/innodb/t/innodb_sys_var_valgrind.test @@ -25,24 +25,6 @@ select @@innodb_ft_server_stopword_table; drop table user_stopword_1, user_stopword_2; -#Test innodb_buffer_pool_filename (global variable) - -select @@innodb_buffer_pool_filename; - -set @blah='hello'; -set global innodb_buffer_pool_filename = @blah; -select @@innodb_buffer_pool_filename; - -set global innodb_buffer_pool_filename="bye"; -select @@innodb_buffer_pool_filename; - ---error ER_WRONG_VALUE_FOR_VAR -set global innodb_buffer_pool_filename=NULL; -select @@innodb_buffer_pool_filename; - -set global innodb_buffer_pool_filename=default; -select @@innodb_buffer_pool_filename; - #Test innodb_ft_aux_table (global variable) CREATE TABLE t1 ( id INT UNSIGNED AUTO_INCREMENT NOT NULL PRIMARY KEY, opening_line TEXT(500), author VARCHAR(200), title VARCHAR(200), FULLTEXT idx diff --git a/mysql-test/suite/sys_vars/r/sysvars_innodb.result b/mysql-test/suite/sys_vars/r/sysvars_innodb.result index 6a23651b9dc31..7b8982dca1c3f 100644 --- a/mysql-test/suite/sys_vars/r/sysvars_innodb.result +++ b/mysql-test/suite/sys_vars/r/sysvars_innodb.result @@ -221,7 +221,7 @@ NUMERIC_MIN_VALUE NULL NUMERIC_MAX_VALUE NULL NUMERIC_BLOCK_SIZE NULL ENUM_VALUE_LIST NULL -READ_ONLY NO +READ_ONLY YES COMMAND_LINE_ARGUMENT REQUIRED VARIABLE_NAME INNODB_BUFFER_POOL_INSTANCES SESSION_VALUE NULL diff --git a/storage/innobase/handler/ha_innodb.cc b/storage/innobase/handler/ha_innodb.cc index 485e525aed8f8..c4a23a95d8519 100644 --- a/storage/innobase/handler/ha_innodb.cc +++ b/storage/innobase/handler/ha_innodb.cc @@ -18020,44 +18020,6 @@ innodb_monitor_update( return; } -/** Validate SET GLOBAL innodb_buffer_pool_filename. -On Windows, file names with colon (:) are not allowed. -@param thd connection -@param save &srv_buf_dump_filename -@param value new value to be validated -@return 0 for valid name */ -static int innodb_srv_buf_dump_filename_validate(THD *thd, st_mysql_sys_var*, - void *save, - st_mysql_value *value) -{ - char buff[OS_FILE_MAX_PATH]; - int len= sizeof buff; - - if (const char *buf_name= value->val_str(value, buff, &len)) - { -#ifdef _WIN32 - if (!is_filename_allowed(buf_name, len, FALSE)) - { - push_warning_printf(thd, Sql_condition::WARN_LEVEL_WARN, - ER_WRONG_ARGUMENTS, - "InnoDB: innodb_buffer_pool_filename " - "cannot have colon (:) in the file name."); - return 1; - } -#endif /* _WIN32 */ - if (buf_name == buff) - { - ut_ad(static_cast(len) < sizeof buff); - buf_name= thd_strmake(thd, buf_name, len); - } - - *static_cast(save)= buf_name; - return 0; - } - - return 1; -} - #ifdef UNIV_DEBUG static char* srv_buffer_pool_evict; @@ -19363,9 +19325,9 @@ static MYSQL_SYSVAR_ULONG(buffer_pool_instances, srv_buf_pool_instances, NULL, NULL, srv_buf_pool_instances_default, 0, MAX_BUFFER_POOLS, 0); static MYSQL_SYSVAR_STR(buffer_pool_filename, srv_buf_dump_filename, - PLUGIN_VAR_RQCMDARG | PLUGIN_VAR_MEMALLOC, + PLUGIN_VAR_RQCMDARG | PLUGIN_VAR_READONLY, "Filename to/from which to dump/load the InnoDB buffer pool", - innodb_srv_buf_dump_filename_validate, NULL, SRV_BUF_DUMP_FILENAME_DEFAULT); + NULL, NULL, SRV_BUF_DUMP_FILENAME_DEFAULT); static MYSQL_SYSVAR_BOOL(buffer_pool_dump_now, innodb_buffer_pool_dump_now, PLUGIN_VAR_RQCMDARG, From 169def14f64492466a305114b0ca13b2b5775164 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jan=20Lindstr=C3=B6m?= Date: Thu, 30 Mar 2023 13:32:44 +0200 Subject: [PATCH 64/92] MDEV-30413 : run sequence nextval got [Note] WSREP: MDL BF-BF conflict and [ERROR] Aborting Sequence objects are implemented using special tables. These tables do not have primary key and only one row. NEXTVAL is basically update from existing value to new value. In Galera this could mean that two write-sets from different nodes do not conflict and this could lead situation where write-sets are executed concurrently and possibly in wrong seqno order. This is fixed by using table-level exclusive key for SEQUENCE updates. Note that this naturally works correctly only if InnoDB storage engine is used for sequence. This fix does not contain a test case because while it is possible to syncronize appliers using dbug_sync it was too hard to syncronize MDL-lock requests to exact objects. Testing done for this fix is documented on MDEV. Signed-off-by: Julius Goryavsky --- storage/innobase/handler/ha_innodb.cc | 46 ++++++++++++++++++++--- storage/innobase/include/ha_prototypes.h | 10 +++++ storage/innobase/row/row0ins.cc | 48 ++++-------------------- 3 files changed, 59 insertions(+), 45 deletions(-) diff --git a/storage/innobase/handler/ha_innodb.cc b/storage/innobase/handler/ha_innodb.cc index c6a515b21d3f5..3f62a09045db9 100644 --- a/storage/innobase/handler/ha_innodb.cc +++ b/storage/innobase/handler/ha_innodb.cc @@ -8543,6 +8543,37 @@ wsrep_calc_row_hash( return(0); } + +/** Append table-level exclusive key. +@param thd MySQL thread handle +@param table table +@retval false on success +@retval true on failure */ +ATTRIBUTE_COLD bool wsrep_append_table_key(MYSQL_THD thd, const dict_table_t &table) +{ + char db_buf[NAME_LEN + 1]; + char tbl_buf[NAME_LEN + 1]; + ulint db_buf_len, tbl_buf_len; + + if (!table.parse_name(db_buf, tbl_buf, &db_buf_len, &tbl_buf_len)) + { + WSREP_ERROR("Parse_name for table key append failed: %s", + wsrep_thd_query(thd)); + return true; + } + + /* Append table-level exclusive key */ + const int rcode = wsrep_thd_append_table_key(thd, db_buf, + tbl_buf, WSREP_SERVICE_KEY_EXCLUSIVE); + if (rcode) + { + WSREP_ERROR("Appending table key failed: %s, %d", + wsrep_thd_query(thd), rcode); + return true; + } + + return false; +} #endif /* WITH_WSREP */ /** @@ -8713,11 +8744,16 @@ ha_innobase::update_row( && !wsrep_thd_ignore_table(m_user_thd)) { DBUG_PRINT("wsrep", ("update row key")); - if (wsrep_append_keys(m_user_thd, - wsrep_protocol_version >= 4 - ? WSREP_SERVICE_KEY_UPDATE - : WSREP_SERVICE_KEY_EXCLUSIVE, - old_row, new_row)){ + /* We use table-level exclusive key for SEQUENCES + and normal key append for others. */ + if (table->s->table_type == TABLE_TYPE_SEQUENCE) { + if (wsrep_append_table_key(m_user_thd, *m_prebuilt->table)) + DBUG_RETURN(HA_ERR_INTERNAL_ERROR); + } else if (wsrep_append_keys(m_user_thd, + wsrep_protocol_version >= 4 + ? WSREP_SERVICE_KEY_UPDATE + : WSREP_SERVICE_KEY_EXCLUSIVE, + old_row, new_row)) { WSREP_DEBUG("WSREP: UPDATE_ROW_KEY FAILED"); DBUG_PRINT("wsrep", ("row key failed")); DBUG_RETURN(HA_ERR_INTERNAL_ERROR); diff --git a/storage/innobase/include/ha_prototypes.h b/storage/innobase/include/ha_prototypes.h index da9dec0582798..d5239ec3f9a32 100644 --- a/storage/innobase/include/ha_prototypes.h +++ b/storage/innobase/include/ha_prototypes.h @@ -462,5 +462,15 @@ void destroy_background_thd(MYSQL_THD thd); void innobase_reset_background_thd(MYSQL_THD); +#ifdef WITH_WSREP +/** Append table-level exclusive key. +@param thd MySQL thread handle +@param table table +@retval false on success +@retval true on failure */ +struct dict_table_t; +bool wsrep_append_table_key(MYSQL_THD thd, const dict_table_t &table); +#endif /* WITH_WSREP */ + #endif /* !UNIV_INNOCHECKSUM */ #endif /* HA_INNODB_PROTOTYPES_H */ diff --git a/storage/innobase/row/row0ins.cc b/storage/innobase/row/row0ins.cc index a44711045439a..bd998094f4270 100644 --- a/storage/innobase/row/row0ins.cc +++ b/storage/innobase/row/row0ins.cc @@ -49,6 +49,7 @@ Created 4/20/1996 Heikki Tuuri #ifdef WITH_WSREP #include #include +#include "ha_prototypes.h" #endif /* WITH_WSREP */ /************************************************************************* @@ -2574,42 +2575,6 @@ but GCC 4.8.5 does not support pop_options. */ # pragma GCC optimize ("O0") #endif -#ifdef WITH_WSREP -/** Start bulk insert operation for Galera by appending -table-level exclusive key for bulk insert. -@param trx transaction -@param index index -@retval false on success -@retval true on failure */ -ATTRIBUTE_COLD static bool row_ins_wsrep_start_bulk(trx_t *trx, const dict_index_t &index) -{ - char db_buf[NAME_LEN + 1]; - char tbl_buf[NAME_LEN + 1]; - ulint db_buf_len, tbl_buf_len; - - if (!index.table->parse_name(db_buf, tbl_buf, &db_buf_len, &tbl_buf_len)) - { - WSREP_ERROR("Parse_name for bulk insert failed: %s", - wsrep_thd_query(trx->mysql_thd)); - trx->error_state = DB_ROLLBACK; - return true; - } - - /* Append table-level exclusive key for bulk insert. */ - const int rcode = wsrep_thd_append_table_key(trx->mysql_thd, db_buf, - tbl_buf, WSREP_SERVICE_KEY_EXCLUSIVE); - if (rcode) - { - WSREP_ERROR("Appending table key for bulk insert failed: %s, %d", - wsrep_thd_query(trx->mysql_thd), rcode); - trx->error_state = DB_ROLLBACK; - return true; - } - - return false; -} -#endif - /***************************************************************//** Tries to insert an entry into a clustered index, ignoring foreign key constraints. If a record with the same unique key is found, the other @@ -2770,10 +2735,13 @@ row_ins_clust_index_entry_low( #ifdef WITH_WSREP if (trx->is_wsrep()) { - if (!wsrep_thd_is_local_transaction(trx->mysql_thd)) - goto skip_bulk_insert; - if (row_ins_wsrep_start_bulk(trx, *index)) - goto err_exit; + if (!wsrep_thd_is_local_transaction(trx->mysql_thd)) + goto skip_bulk_insert; + if (wsrep_append_table_key(trx->mysql_thd, *index->table)) + { + trx->error_state = DB_ROLLBACK; + goto err_exit; + } } #endif /* WITH_WSREP */ From f70de1451ba24e0459edcdbe2e67e3df5f348050 Mon Sep 17 00:00:00 2001 From: Weijun Huang Date: Sat, 11 Mar 2023 11:06:03 +0100 Subject: [PATCH 65/92] MDEV-30351 crash in Item_func_left::val_str When using LEFT() function with a string that is without a charset, the function crashes. This is because the function assumes that the string has a charset, and tries to use it to calculate the length of the string. Two functions, UNHEX and WEIGHT_STRING, returned a string without the charset being set to a not null value. The fix is to set charset when calling val_str on these two functions. Reviewed-by: Alexander Barkov Reviewed-by: Daniel Black --- mysql-test/main/func_str.result | 9 +++++++++ mysql-test/main/func_str.test | 10 ++++++++-- sql/item_strfunc.cc | 2 ++ 3 files changed, 19 insertions(+), 2 deletions(-) diff --git a/mysql-test/main/func_str.result b/mysql-test/main/func_str.result index 2f692f9135ed0..4e36acd25cad3 100644 --- a/mysql-test/main/func_str.result +++ b/mysql-test/main/func_str.result @@ -5240,6 +5240,15 @@ DROP TABLE crash_test_2; # Start of 10.4 tests # # +# MDEV-30351 crash in Item_func_left::val_str +# +SELECT WEIGHT_STRING('aa') IN (LEFT(WEIGHT_STRING('aaa'),4),'bbb') as expect_1; +expect_1 +1 +SELECT UNHEX('0032') in (LEFT(UNHEX('003200'), 2),'dog') as expect_1; +expect_1 +1 +# # MDEV-21841 CONV() function truncates the result type to 21 symbol. # CREATE TABLE t1(i BIGINT); diff --git a/mysql-test/main/func_str.test b/mysql-test/main/func_str.test index 910214901e581..da3483dd08a83 100644 --- a/mysql-test/main/func_str.test +++ b/mysql-test/main/func_str.test @@ -2256,16 +2256,22 @@ CREATE TABLE crash_test_2 ( DROP TABLE t1; DROP TABLE crash_test_2; - --echo # --echo # End of 10.3 tests --echo # - --echo # --echo # Start of 10.4 tests --echo # +--echo # +--echo # MDEV-30351 crash in Item_func_left::val_str +--echo # + +SELECT WEIGHT_STRING('aa') IN (LEFT(WEIGHT_STRING('aaa'),4),'bbb') as expect_1; + +SELECT UNHEX('0032') in (LEFT(UNHEX('003200'), 2),'dog') as expect_1; + --echo # --echo # MDEV-21841 CONV() function truncates the result type to 21 symbol. --echo # diff --git a/sql/item_strfunc.cc b/sql/item_strfunc.cc index a57fbd7bebca2..f95f47958208e 100644 --- a/sql/item_strfunc.cc +++ b/sql/item_strfunc.cc @@ -3729,6 +3729,7 @@ String *Item_func_weight_string::val_str(String *str) flags); DBUG_ASSERT(frm_length <= tmp_length); + str->set_charset(&my_charset_bin); str->length(frm_length); null_value= 0; return str; @@ -3808,6 +3809,7 @@ String *Item_func_unhex::val_str(String *str) from= res->ptr(); null_value= 0; + str->set_charset(&my_charset_bin); str->length(length); to= (char*) str->ptr(); if (res->length() % 2) From cadc3efcddb078fe8fe19a6121cc2a95be9a97de Mon Sep 17 00:00:00 2001 From: Teemu Ollakka Date: Mon, 13 Feb 2023 18:14:50 +0200 Subject: [PATCH 66/92] MDEV-27317 wsrep_checkpoint order violation due to certification failure With binlogs enabled, debug assertion ut_ad(xid_seqno > wsrep_seqno) fired in trx_rseg_update_wsrep_checkpoint() when an applier thread synced the seqno out of order for write set which had failed certification. This was caused by releasing commit order too early when binlogs were on, allowing group commit to run in parallel and commit following transactions too early. Fixed by extending the commit order critical section to cover call to wsrep_set_SE_checkpoint() also when binlogs are on. Signed-off-by: Julius Goryavsky --- sql/wsrep_high_priority_service.cc | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/sql/wsrep_high_priority_service.cc b/sql/wsrep_high_priority_service.cc index c396a9eeae598..96269481559a0 100644 --- a/sql/wsrep_high_priority_service.cc +++ b/sql/wsrep_high_priority_service.cc @@ -472,7 +472,13 @@ int Wsrep_high_priority_service::log_dummy_write_set(const wsrep::ws_handle& ws_ if (!WSREP_EMULATE_BINLOG(m_thd)) { wsrep_register_for_group_commit(m_thd); - ret = ret || cs.provider().commit_order_leave(ws_handle, ws_meta, err); + /* wait_for_prior_commit() ensures that all preceding transactions + have been committed and seqno has been synced into + storage engine. We don't release commit order here yet to + avoid following transactions to sync seqno before + wsrep_set_SE_checkpoint() below returns. This effectively pauses + group commit for the checkpoint operation, but is the only way to + ensure proper ordering. */ m_thd->wait_for_prior_commit(); } @@ -482,10 +488,7 @@ int Wsrep_high_priority_service::log_dummy_write_set(const wsrep::ws_handle& ws_ { wsrep_unregister_from_group_commit(m_thd); } - else - { - ret= ret || cs.provider().commit_order_leave(ws_handle, ws_meta, err); - } + ret= ret || cs.provider().commit_order_leave(ws_handle, ws_meta, err); cs.after_applying(); } DBUG_RETURN(ret); From eaebe8b5600b144c51a9405de42a70bd4b710987 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jan=20Lindstr=C3=B6m?= Date: Fri, 31 Mar 2023 12:48:13 +0200 Subject: [PATCH 67/92] MDEV-25045 : Assertion `client_state_.mode() != wsrep::client_state::m_toi' failed in int wsrep::transaction::before_commit() CREATE [TEMPORARY] SEQUENCE is internally CREATE+INSERT (initial value) and it is replicated using statement based replication. In Galera we use either TOI or RSU so we should skip commit time hooks for it. Signed-off-by: Julius Goryavsky --- .../suite/galera/r/galera_sequences.result | 61 ++++++++++++++++++- .../suite/galera/t/galera_sequences.cnf | 9 +++ .../suite/galera/t/galera_sequences.test | 53 +++++++++++++++- .../suite/galera_3nodes/galera_2x3nodes.cnf | 2 +- sql/wsrep_trans_observer.h | 15 ++++- 5 files changed, 133 insertions(+), 7 deletions(-) create mode 100644 mysql-test/suite/galera/t/galera_sequences.cnf diff --git a/mysql-test/suite/galera/r/galera_sequences.result b/mysql-test/suite/galera/r/galera_sequences.result index 7276cb8dbdeb5..da669e6774e42 100644 --- a/mysql-test/suite/galera/r/galera_sequences.result +++ b/mysql-test/suite/galera/r/galera_sequences.result @@ -1,6 +1,11 @@ connection node_2; connection node_1; connection node_1; +CALL mtr.add_suppression("SEQUENCES declared without `NOCACHE` will not behave correctly in galera cluster."); +CALL mtr.add_suppression("WSREP: CREATE TABLE isolation failure"); +connection node_2; +CALL mtr.add_suppression("SEQUENCES declared without `NOCACHE` will not behave correctly in galera cluster."); +connection node_1; CREATE SEQUENCE `seq` start with 1 minvalue 1 maxvalue 1000000 increment by 0 cache 1000 nocycle ENGINE=InnoDB; SHOW CREATE SEQUENCE seq; Table Create Table @@ -47,6 +52,58 @@ NEXT VALUE FOR Seq1_1 3001 connection node_1; DROP SEQUENCE Seq1_1; -CALL mtr.add_suppression("SEQUENCES declared without `NOCACHE` will not behave correctly in galera cluster."); +connection node_1; +CREATE TABLE t2 (d CHAR(1)KEY); +SET SESSION autocommit=0; +INSERT INTO t2 VALUES(1); +CREATE TEMPORARY SEQUENCE seq1 NOCACHE ENGINE=INNODB; +CREATE SEQUENCE seq2 NOCACHE ENGINE=INNODB; +COMMIT; +SET SESSION AUTOCOMMIT=1; +SHOW CREATE TABLE seq1; +Table Create Table +seq1 CREATE TEMPORARY TABLE `seq1` ( + `next_not_cached_value` bigint(21) NOT NULL, + `minimum_value` bigint(21) NOT NULL, + `maximum_value` bigint(21) NOT NULL, + `start_value` bigint(21) NOT NULL COMMENT 'start value when sequences is created or value if RESTART is used', + `increment` bigint(21) NOT NULL COMMENT 'increment value', + `cache_size` bigint(21) unsigned NOT NULL, + `cycle_option` tinyint(1) unsigned NOT NULL COMMENT '0 if no cycles are allowed, 1 if the sequence should begin a new cycle when maximum_value is passed', + `cycle_count` bigint(21) NOT NULL COMMENT 'How many cycles have been done' +) ENGINE=InnoDB SEQUENCE=1 connection node_2; -CALL mtr.add_suppression("SEQUENCES declared without `NOCACHE` will not behave correctly in galera cluster."); +SHOW CREATE SEQUENCE seq1; +ERROR 42S02: Table 'test.seq1' doesn't exist +SHOW CREATE SEQUENCE seq2; +Table Create Table +seq2 CREATE SEQUENCE `seq2` start with 1 minvalue 1 maxvalue 9223372036854775806 increment by 1 nocache nocycle ENGINE=InnoDB +connection node_1; +SET SESSION autocommit=1; +DROP SEQUENCE seq1; +DROP SEQUENCE seq2; +DROP TABLE t2; +SET SESSION AUTOCOMMIT=0; +SET SESSION wsrep_OSU_method='RSU'; +CREATE TABLE t1(c1 VARCHAR(10)); +INSERT INTO t1 (c1) VALUES(''); +create temporary sequence sq1 NOCACHE engine=innodb; +create sequence sq2 NOCACHE engine=innodb; +COMMIT; +SHOW CREATE SEQUENCE sq1; +Table Create Table +sq1 CREATE SEQUENCE `sq1` start with 1 minvalue 1 maxvalue 9223372036854775806 increment by 1 nocache nocycle ENGINE=InnoDB +SHOW CREATE SEQUENCE sq2; +Table Create Table +sq2 CREATE SEQUENCE `sq2` start with 1 minvalue 1 maxvalue 9223372036854775806 increment by 1 nocache nocycle ENGINE=InnoDB +connection node_2; +SHOW CREATE SEQUENCE sq1; +ERROR 42S02: Table 'test.sq1' doesn't exist +SHOW CREATE SEQUENCE sq2; +ERROR 42S02: Table 'test.sq2' doesn't exist +connection node_1; +SET SESSION AUTOCOMMIT=1; +DROP TABLE t1; +DROP SEQUENCE sq1; +DROP SEQUENCE sq2; +SET SESSION wsrep_OSU_method='TOI'; diff --git a/mysql-test/suite/galera/t/galera_sequences.cnf b/mysql-test/suite/galera/t/galera_sequences.cnf new file mode 100644 index 0000000000000..98e724fb2d0f4 --- /dev/null +++ b/mysql-test/suite/galera/t/galera_sequences.cnf @@ -0,0 +1,9 @@ +!include ../galera_2nodes.cnf + +[mysqld.1] +log-bin +log-slave-updates + +[mysqld.2] +log-bin +log-slave-updates diff --git a/mysql-test/suite/galera/t/galera_sequences.test b/mysql-test/suite/galera/t/galera_sequences.test index d469cc73516ea..faa3b46d2a797 100644 --- a/mysql-test/suite/galera/t/galera_sequences.test +++ b/mysql-test/suite/galera/t/galera_sequences.test @@ -4,6 +4,13 @@ # MDEV-19353 : Alter Sequence do not replicate to another nodes with in Galera Cluster # +--connection node_1 +CALL mtr.add_suppression("SEQUENCES declared without `NOCACHE` will not behave correctly in galera cluster."); +CALL mtr.add_suppression("WSREP: CREATE TABLE isolation failure"); +--connection node_2 + +CALL mtr.add_suppression("SEQUENCES declared without `NOCACHE` will not behave correctly in galera cluster."); + --connection node_1 CREATE SEQUENCE `seq` start with 1 minvalue 1 maxvalue 1000000 increment by 0 cache 1000 nocycle ENGINE=InnoDB; SHOW CREATE SEQUENCE seq; @@ -45,8 +52,48 @@ select NEXT VALUE FOR Seq1_1; --connection node_1 DROP SEQUENCE Seq1_1; -CALL mtr.add_suppression("SEQUENCES declared without `NOCACHE` will not behave correctly in galera cluster."); +# +# MDEV-24045 : Assertion client_state_.mode() != wsrep::client_state::m_toi failed in int wsrep::transaction::before_commit() +# +--connection node_1 +CREATE TABLE t2 (d CHAR(1)KEY); +SET SESSION autocommit=0; +INSERT INTO t2 VALUES(1); +CREATE TEMPORARY SEQUENCE seq1 NOCACHE ENGINE=INNODB; +CREATE SEQUENCE seq2 NOCACHE ENGINE=INNODB; +COMMIT; +SET SESSION AUTOCOMMIT=1; +SHOW CREATE TABLE seq1; --connection node_2 - -CALL mtr.add_suppression("SEQUENCES declared without `NOCACHE` will not behave correctly in galera cluster."); +--error ER_NO_SUCH_TABLE +SHOW CREATE SEQUENCE seq1; +SHOW CREATE SEQUENCE seq2; +--connection node_1 +SET SESSION autocommit=1; +DROP SEQUENCE seq1; +DROP SEQUENCE seq2; +DROP TABLE t2; +# +# Case2 +# +SET SESSION AUTOCOMMIT=0; +SET SESSION wsrep_OSU_method='RSU'; +CREATE TABLE t1(c1 VARCHAR(10)); +INSERT INTO t1 (c1) VALUES(''); +create temporary sequence sq1 NOCACHE engine=innodb; +create sequence sq2 NOCACHE engine=innodb; +COMMIT; +SHOW CREATE SEQUENCE sq1; +SHOW CREATE SEQUENCE sq2; +--connection node_2 +--error ER_NO_SUCH_TABLE +SHOW CREATE SEQUENCE sq1; +--error ER_NO_SUCH_TABLE +SHOW CREATE SEQUENCE sq2; +--connection node_1 +SET SESSION AUTOCOMMIT=1; +DROP TABLE t1; +DROP SEQUENCE sq1; +DROP SEQUENCE sq2; +SET SESSION wsrep_OSU_method='TOI'; diff --git a/mysql-test/suite/galera_3nodes/galera_2x3nodes.cnf b/mysql-test/suite/galera_3nodes/galera_2x3nodes.cnf index 9f99adbd711d6..cd7a892f4c911 100644 --- a/mysql-test/suite/galera_3nodes/galera_2x3nodes.cnf +++ b/mysql-test/suite/galera_3nodes/galera_2x3nodes.cnf @@ -55,7 +55,7 @@ wsrep-on=1 #galera_port=@OPT.port #ist_port=@OPT.port #sst_port=@OPT.port -wsrep_cluster_address='gcomm:// +wsrep_cluster_address=gcomm:// wsrep_provider_options='repl.causal_read_timeout=PT90S;base_port=@mysqld.4.#galera_port;evs.suspect_timeout=PT10S;evs.inactive_timeout=PT30S;evs.install_timeout=PT15S;pc.wait_prim_timeout=PT60S;gcache.size=10M' wsrep_node_address='127.0.0.1:@mysqld.4.#galera_port' wsrep_node_incoming_address=127.0.0.1:@mysqld.4.port diff --git a/sql/wsrep_trans_observer.h b/sql/wsrep_trans_observer.h index f1d0eebf6dd38..5f799d56c0539 100644 --- a/sql/wsrep_trans_observer.h +++ b/sql/wsrep_trans_observer.h @@ -1,4 +1,4 @@ -/* Copyright 2016-2022 Codership Oy +/* Copyright 2016-2023 Codership Oy 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 @@ -214,6 +214,19 @@ static inline bool wsrep_run_commit_hook(THD* thd, bool all) } mysql_mutex_unlock(&thd->LOCK_thd_data); } + + mysql_mutex_lock(&thd->LOCK_thd_data); + /* Transaction creating sequence is TOI or RSU, + CREATE [TEMPORARY] SEQUENCE = CREATE + INSERT (initial value) + and replicated using statement based replication, thus + the commit hooks will be skipped */ + if (ret && + (thd->wsrep_cs().mode() == wsrep::client_state::m_toi || + thd->wsrep_cs().mode() == wsrep::client_state::m_rsu) && + thd->lex->sql_command == SQLCOM_CREATE_SEQUENCE) + ret= false; + mysql_mutex_unlock(&thd->LOCK_thd_data); + DBUG_PRINT("wsrep", ("return: %d", ret)); DBUG_RETURN(ret); } From dc1d6213f9a5ad4a53d35a886f52adf4ee0a2b5c Mon Sep 17 00:00:00 2001 From: Sergei Petrunia Date: Tue, 7 Mar 2023 19:49:57 +0300 Subject: [PATCH 68/92] MDEV-30806: ANALYZE FORMAT=JSON: better support for BNL and BNL-H joins In block-nl-join, add: - r_loops - this shows how many incoming record combinations this query plan node had. - r_effective_rows - this shows the average number of matching rows that this table had for each incoming record combination. This is comparable with r_rows in non-blocked access methods. For BNL-joins, it is always equal to $.table.r_rows * $.table.r_filtered For BNL-H joins the value cannot be computed from other values Reviewed by: Monty --- mysql-test/main/analyze_format_json.result | 140 +++++++++++++++++++- mysql-test/main/analyze_format_json.test | 42 ++++++ mysql-test/main/analyze_stmt_orderby.result | 8 +- mysql-test/main/except.result | 16 ++- mysql-test/main/except_all.result | 16 ++- mysql-test/main/explain_json.result | 4 +- mysql-test/main/intersect.result | 8 +- mysql-test/main/intersect_all.result | 8 +- mysql-test/main/rowid_filter_innodb.result | 8 +- sql/sql_analyze_stmt.h | 32 ++++- sql/sql_explain.cc | 19 ++- sql/sql_explain.h | 4 + sql/sql_select.cc | 3 + sql/sql_select.h | 1 + 14 files changed, 279 insertions(+), 30 deletions(-) diff --git a/mysql-test/main/analyze_format_json.result b/mysql-test/main/analyze_format_json.result index fc643d1a8aff3..abe3fab4643e8 100644 --- a/mysql-test/main/analyze_format_json.result +++ b/mysql-test/main/analyze_format_json.result @@ -151,7 +151,9 @@ ANALYZE "buffer_type": "flat", "buffer_size": "1Kb", "join_type": "BNL", - "r_filtered": 100 + "r_loops": 20, + "r_filtered": 100, + "r_effective_rows": 60 } } } @@ -192,7 +194,9 @@ ANALYZE "buffer_size": "1Kb", "join_type": "BNL", "attached_condition": "tbl1.c > tbl2.c", - "r_filtered": 15.83333333 + "r_loops": 20, + "r_filtered": 15.83333333, + "r_effective_rows": 60 } } } @@ -652,7 +656,9 @@ ANALYZE "buffer_size": "65", "join_type": "BNL", "attached_condition": "(t2.b,t2.b in (subquery#2))", - "r_filtered": null + "r_loops": 2, + "r_filtered": null, + "r_effective_rows": 0 }, "subqueries": [ { @@ -742,7 +748,9 @@ ANALYZE "buffer_type": "flat", "buffer_size": "1", "join_type": "BNL", - "r_filtered": null + "r_loops": 2, + "r_filtered": null, + "r_effective_rows": 0 }, "subqueries": [ { @@ -774,7 +782,9 @@ ANALYZE "buffer_size": "65", "join_type": "BNL", "attached_condition": "t2.f2 = t3.f3", - "r_filtered": null + "r_loops": 0, + "r_filtered": null, + "r_effective_rows": null } } } @@ -849,3 +859,123 @@ ANALYZE } } drop table t0,t1,t2; +# +# MDEV-30806: ANALYZE FORMAT=JSON: better support for BNL and BNL-H joins +# +create table t10 ( +a int, +b int +); +insert into t10 select seq, seq/3 from seq_0_to_999; +create table t11 ( +a int, +b int +); +insert into t11 select seq, seq/5 from seq_0_to_999; +analyze table t10,t11 persistent for all; +Table Op Msg_type Msg_text +test.t10 analyze status Engine-independent statistics collected +test.t10 analyze status OK +test.t11 analyze status Engine-independent statistics collected +test.t11 analyze status OK +analyze format=json +select * from t10, t11 +where +t10.a < 700 and +t11.a < 100 +and t10.b=t11.b; +ANALYZE +{ + "query_block": { + "select_id": 1, + "r_loops": 1, + "r_total_time_ms": "REPLACED", + "table": { + "table_name": "t11", + "access_type": "ALL", + "r_loops": 1, + "rows": 1000, + "r_rows": 1000, + "r_table_time_ms": "REPLACED", + "r_other_time_ms": "REPLACED", + "filtered": 10.15625, + "r_filtered": 10, + "attached_condition": "t11.a < 100" + }, + "block-nl-join": { + "table": { + "table_name": "t10", + "access_type": "ALL", + "r_loops": 1, + "rows": 1000, + "r_rows": 1000, + "r_table_time_ms": "REPLACED", + "r_other_time_ms": "REPLACED", + "filtered": 70.3125, + "r_filtered": 70, + "attached_condition": "t10.a < 700" + }, + "buffer_type": "flat", + "buffer_size": "1Kb", + "join_type": "BNL", + "attached_condition": "t10.b = t11.b", + "r_loops": 100, + "r_filtered": 0.424285714, + "r_effective_rows": 700 + } + } +} +set @tmp=@@join_cache_level, join_cache_level=6; +analyze format=json +select * from t10, t11 +where +t10.a < 700 and +t11.a < 100 +and t10.b=t11.b; +ANALYZE +{ + "query_block": { + "select_id": 1, + "r_loops": 1, + "r_total_time_ms": "REPLACED", + "table": { + "table_name": "t11", + "access_type": "ALL", + "r_loops": 1, + "rows": 1000, + "r_rows": 1000, + "r_table_time_ms": "REPLACED", + "r_other_time_ms": "REPLACED", + "filtered": 10.15625, + "r_filtered": 10, + "attached_condition": "t11.a < 100 and t11.b is not null" + }, + "block-nl-join": { + "table": { + "table_name": "t10", + "access_type": "hash_ALL", + "key": "#hash#$hj", + "key_length": "5", + "used_key_parts": ["b"], + "ref": ["test.t11.b"], + "r_loops": 1, + "rows": 1000, + "r_rows": 1000, + "r_table_time_ms": "REPLACED", + "r_other_time_ms": "REPLACED", + "filtered": 70.3125, + "r_filtered": 70, + "attached_condition": "t10.a < 700" + }, + "buffer_type": "flat", + "buffer_size": "3Kb", + "join_type": "BNLH", + "attached_condition": "t10.b = t11.b", + "r_loops": 100, + "r_filtered": 100, + "r_effective_rows": 2.97 + } + } +} +set join_cache_level=@tmp; +drop table t10, t11; diff --git a/mysql-test/main/analyze_format_json.test b/mysql-test/main/analyze_format_json.test index 3f3324e9eec52..84f44869afe68 100644 --- a/mysql-test/main/analyze_format_json.test +++ b/mysql-test/main/analyze_format_json.test @@ -226,3 +226,45 @@ create table t2 as select * from t1; --source include/analyze-format.inc analyze format=json select a, (select t2.b from t2 where t2.atimed)) \ { (tracker)->stop_tracking(thd); } + +/* + Just a counter to increment one value. Wrapped in a class to be uniform + with other counters used by ANALYZE. +*/ + +class Counter_tracker +{ +public: + Counter_tracker() : r_scans(0) {} + ha_rows r_scans; + + inline void on_scan_init() { r_scans++; } + + bool has_scans() const { return (r_scans != 0); } + ha_rows get_loops() const { return r_scans; } +}; + + /* A class for collecting read statistics. @@ -168,20 +187,16 @@ class Time_and_counter_tracker: public Exec_time_tracker It can be used to track reading from files, buffers, etc). */ -class Table_access_tracker +class Table_access_tracker { public: - Table_access_tracker() : - r_scans(0), r_rows(0), /*r_rows_after_table_cond(0),*/ - r_rows_after_where(0) + Table_access_tracker() : r_scans(0), r_rows(0), r_rows_after_where(0) {} - ha_rows r_scans; /* How many scans were ran on this join_tab */ + ha_rows r_scans; /* how many scans were ran on this join_tab */ ha_rows r_rows; /* How many rows we've got after that */ ha_rows r_rows_after_where; /* Rows after applying attached part of WHERE */ - bool has_scans() const { return (r_scans != 0); } - ha_rows get_loops() const { return r_scans; } double get_avg_rows() const { return r_scans @@ -200,6 +215,9 @@ class Table_access_tracker inline void on_scan_init() { r_scans++; } inline void on_record_read() { r_rows++; } inline void on_record_after_where() { r_rows_after_where++; } + + bool has_scans() const { return (r_scans != 0); } + ha_rows get_loops() const { return r_scans; } }; diff --git a/sql/sql_explain.cc b/sql/sql_explain.cc index 480a1259ba85a..caec818d130bc 100644 --- a/sql/sql_explain.cc +++ b/sql/sql_explain.cc @@ -1891,12 +1891,29 @@ void Explain_table_access::print_explain_json(Explain_query *query, if (is_analyze) { - //writer->add_member("r_loops").add_ll(jbuf_tracker.get_loops()); + writer->add_member("r_loops").add_ll(jbuf_loops_tracker.get_loops()); + writer->add_member("r_filtered"); if (jbuf_tracker.has_scans()) writer->add_double(jbuf_tracker.get_filtered_after_where()*100.0); else writer->add_null(); + /* + effective_rows is average number of matches we got for an incoming + row. The row is stored in the join buffer and then is read + from there, possibly multiple times. We can't count this number + directly. Infer it as: + total_number_of_row_combinations_considered / r_loops. + */ + writer->add_member("r_effective_rows"); + if (jbuf_loops_tracker.has_scans()) + { + double loops= (double)jbuf_loops_tracker.get_loops(); + double row_combinations= (double)jbuf_tracker.r_rows; + writer->add_double(row_combinations / loops); + } + else + writer->add_null(); } } diff --git a/sql/sql_explain.h b/sql/sql_explain.h index 31143ca9f777e..746e1db1abdfc 100644 --- a/sql/sql_explain.h +++ b/sql/sql_explain.h @@ -842,8 +842,12 @@ class Explain_table_access : public Sql_alloc Exec_time_tracker op_tracker; Gap_time_tracker extra_time_tracker; + /* When using join buffer: Track the reads from join buffer */ Table_access_tracker jbuf_tracker; + /* When using join buffer: Track the number of incoming record combinations */ + Counter_tracker jbuf_loops_tracker; + Explain_rowid_filter *rowid_filter; int print_explain(select_result_sink *output, uint8 explain_flags, diff --git a/sql/sql_select.cc b/sql/sql_select.cc index 147663022983a..2889d757e20d7 100644 --- a/sql/sql_select.cc +++ b/sql/sql_select.cc @@ -21231,6 +21231,8 @@ sub_select_cache(JOIN *join, JOIN_TAB *join_tab, bool end_of_records) /* The user has aborted the execution of the query */ DBUG_RETURN(NESTED_LOOP_KILLED); } + join_tab->jbuf_loops_tracker->on_scan_init(); + if (!test_if_use_dynamic_range_scan(join_tab)) { if (!cache->put_record()) @@ -27393,6 +27395,7 @@ bool JOIN_TAB::save_explain_data(Explain_table_access *eta, // psergey-todo: data for filtering! tracker= &eta->tracker; jbuf_tracker= &eta->jbuf_tracker; + jbuf_loops_tracker= &eta->jbuf_loops_tracker; /* Enable the table access time tracker only for "ANALYZE stmt" */ if (thd->lex->analyze_stmt) diff --git a/sql/sql_select.h b/sql/sql_select.h index 4ff95b31f3f71..178573413aff3 100644 --- a/sql/sql_select.h +++ b/sql/sql_select.h @@ -309,6 +309,7 @@ typedef struct st_join_table { Table_access_tracker *tracker; Table_access_tracker *jbuf_tracker; + Counter_tracker *jbuf_loops_tracker; /* Bitmap of TAB_INFO_* bits that encodes special line for EXPLAIN 'Extra' column, or 0 if there is no info. From 3b6424407025aad39b00e60bd0d711b67272513f Mon Sep 17 00:00:00 2001 From: Hugo Wen Date: Fri, 24 Mar 2023 16:06:11 +0000 Subject: [PATCH 69/92] Handle meaningless addr2line results and increase timeout MariaDB server prints the stack information if a crash happens. It traverses the stack frames in function `print_with_addr_resolve`. For *EACH* frame, it tries to parse the file name and line number of the frame using `addr2line`, or prints `backtrace_symbols_fd` if `addr2line` fails. 1. Logic in `addr_resolve` function uses addr2line to get the file name and line numbers. It has a timeout of 500ms to wait for the response from addr2line. However, that's not enough on small instances especially if the debug information is in a separate file or compressed. Increase the timeout to 5 seconds to support some edge cases, as experiments showed addr2line may take 2-3 seconds on some frames. 2. While parsing a frame inside of a shared library using `addr2line`, the file name and line numbers could be `??`, empty or `0` if the debug info is not loaded. It's easy to reproduce when glibc-debuginfo is not installed. Instead of printing a meaningless frame like: :0(__GI___poll)[0x1505e9197639] ... ??:0(__libc_start_main)[0x7ffff6c8913a] We want to print the frame information using `backtrace_symbols_fd`, with the shared library name and a hexadecimal offset. Stacktrace example on a real instance with this commit: /lib64/libc.so.6(__poll+0x49)[0x145cbf71a639] ... /lib64/libc.so.6(__libc_start_main+0xea)[0x7f4d0034d13a] `addr_resolve` has considered the case of meaningless combination of file name and line number returned by `addr2line`. e.g. `??:?` However, conditions like `:0` and `??:0` are not handled. So now the function will rollback to `backtrace_symbols_fd` in above cases. All new code of the whole pull request, including one or several files that are either new files or modified ones, are contributed under the BSD-new license. I am contributing on behalf of my employer Amazon Web Services, Inc. --- mysys/my_addr_resolve.c | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/mysys/my_addr_resolve.c b/mysys/my_addr_resolve.c index ac1bdae187c9f..52fcaaf67bb7d 100644 --- a/mysys/my_addr_resolve.c +++ b/mysys/my_addr_resolve.c @@ -252,10 +252,10 @@ int my_addr_resolve(void *ptr, my_addr_loc *loc) return 3; - /* 500 ms should be plenty of time for addr2line to issue a response. */ + /* 5000 ms should be plenty of time for addr2line to issue a response. */ /* Read in a loop till all the output from addr2line is complete. */ while (parsed == total_bytes_read && - (ret= poll(&poll_fds, 1, 500))) + (ret= poll(&poll_fds, 1, 5000))) { /* error during poll */ if (ret < 0) @@ -299,7 +299,8 @@ int my_addr_resolve(void *ptr, my_addr_loc *loc) loc->line= atoi(output + line_number_start); /* Addr2line was unable to extract any meaningful information. */ - if (strcmp(loc->file, "??") == 0) + if ((strcmp(loc->file, "??") == 0 || strcmp(loc->file, "") == 0) && + (loc->func[0] == '?' || loc->line == 0)) return 6; loc->file= strip_path(loc->file); From 1767390be4239c031ecbe999fa09bbc6c99c1c65 Mon Sep 17 00:00:00 2001 From: Oleksandr Byelkin Date: Sat, 1 Apr 2023 14:42:05 +0200 Subject: [PATCH 70/92] Fix passing correct length of string in command print. --- sql/sql_select.cc | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/sql/sql_select.cc b/sql/sql_select.cc index c4fc2d191561d..0651c1d58bdde 100644 --- a/sql/sql_select.cc +++ b/sql/sql_select.cc @@ -27990,19 +27990,19 @@ enum explainable_cmd_type }; static -const char * const explainable_cmd_name []= +const LEX_CSTRING explainable_cmd_name []= { - "select ", - "insert ", - "replace ", - "update ", - "delete ", + {STRING_WITH_LEN("select ")}, + {STRING_WITH_LEN("insert ")}, + {STRING_WITH_LEN("replace ")}, + {STRING_WITH_LEN("update ")}, + {STRING_WITH_LEN("delete ")}, }; static -char const *get_explainable_cmd_name(enum explainable_cmd_type cmd) +const LEX_CSTRING* get_explainable_cmd_name(enum explainable_cmd_type cmd) { - return explainable_cmd_name[cmd]; + return explainable_cmd_name + cmd; } static @@ -28304,7 +28304,7 @@ void st_select_lex::print(THD *thd, String *str, enum_query_type query_type) query_type); } if (sel_type == UPDATE_CMD || sel_type == DELETE_CMD) - str->append(STRING_WITH_LEN(get_explainable_cmd_name(sel_type))); + str->append(get_explainable_cmd_name(sel_type)); if (sel_type == DELETE_CMD) { str->append(STRING_WITH_LEN(" from ")); From 6a10468ed35167cbc5dc57c1091f8d8dcb572f0a Mon Sep 17 00:00:00 2001 From: Sergei Golubchik Date: Wed, 15 Mar 2023 22:03:51 +0100 Subject: [PATCH 71/92] MDEV-13255 main.status failed in buildbot Test fails sporadically and very rarely on this: ``` let $org_queries= `SHOW STATUS LIKE 'Queries'`; SELECT f1(); CALL p1(); let $new_queries= `SHOW STATUS LIKE 'Queries'`; let $diff= `SELECT SUBSTRING('$new_queries',9)-SUBSTRING('$org_queries',9)`; ``` if COM_QUIT from one of the earlier (in the test) disconnect's happens between the two SHOW STATUS commands. Because COM_QUIT increments "Queries". The directly previous test uses wait_condition to wait for its disconnects to complete. But there are more disconnects earlier in the test file and nothing waits for them. Let's change wait_condition to wait for *all* disconnect to complete. --- mysql-test/main/status.test | 9 ++------- 1 file changed, 2 insertions(+), 7 deletions(-) diff --git a/mysql-test/main/status.test b/mysql-test/main/status.test index 221a24aedf49a..ae1b90f9f7ff4 100644 --- a/mysql-test/main/status.test +++ b/mysql-test/main/status.test @@ -280,7 +280,6 @@ show status like 'Com%function'; # connect (root, localhost, root,,test); connection root; -let $root_connection_id= `select connection_id()`; --disable_warnings create database db37908; --enable_warnings @@ -296,7 +295,6 @@ delimiter ;| connect (user1,localhost,mysqltest_1,,test); connection user1; -let $user1_connection_id= `select connection_id()`; --error ER_TABLEACCESS_DENIED_ERROR select * from db37908.t1; @@ -315,11 +313,8 @@ drop procedure proc37908; drop function func37908; REVOKE ALL PRIVILEGES, GRANT OPTION FROM mysqltest_1@localhost; DROP USER mysqltest_1@localhost; -# Wait till the sessions user1 and root are disconnected -let $wait_condition = - SELECT COUNT(*) = 0 - FROM information_schema.processlist - WHERE id in ('$root_connection_id','$user1_connection_id'); +# Wait until all non-default sessions are disconnected +let $wait_condition = SELECT COUNT(*) = 1 FROM information_schema.processlist; --source include/wait_condition.inc # From 0a6343909fcf8b193a1b517b3a16eabd4ae89a83 Mon Sep 17 00:00:00 2001 From: Sergei Golubchik Date: Sat, 1 Apr 2023 15:58:14 +0200 Subject: [PATCH 72/92] ensure that STRING_WITH_LEN is only used with string literals This is allowed: STRING_WITH_LEN("string literal") This is not: char *str = "pointer to string"; ... STRING_WITH_LEN(str) .. In C++ this is also allowed: const char str[] = "string literal"; ... STRING_WITH_LEN(str) ... --- include/m_string.h | 19 ++++++++++++++++--- sql/debug_sync.cc | 2 +- .../PerconaFT/portability/toku_debug_sync.h | 9 ++++++--- 3 files changed, 23 insertions(+), 7 deletions(-) diff --git a/include/m_string.h b/include/m_string.h index 4a06b90c1aa73..0133d81f6df5e 100644 --- a/include/m_string.h +++ b/include/m_string.h @@ -198,9 +198,22 @@ extern ulonglong strtoull(const char *str, char **ptr, int base); #include -#define STRING_WITH_LEN(X) (X), ((size_t) (sizeof(X) - 1)) -#define USTRING_WITH_LEN(X) ((uchar*) X), ((size_t) (sizeof(X) - 1)) -#define C_STRING_WITH_LEN(X) ((char *) (X)), ((size_t) (sizeof(X) - 1)) +#ifdef __cplusplus +#include +template inline const char *_swl_check(T s) +{ + static_assert(std::is_same::value + || std::is_same::value, + "Wrong argument for STRING_WITH_LEN()"); + return s; +} +#define STRING_WITH_LEN(X) _swl_check(X), ((size_t) (sizeof(X) - 1)) +#else +#define STRING_WITH_LEN(X) (X ""), ((size_t) (sizeof(X) - 1)) +#endif + +#define USTRING_WITH_LEN(X) (uchar*) STRING_WITH_LEN(X) +#define C_STRING_WITH_LEN(X) (char *) STRING_WITH_LEN(X) #define LEX_STRING_WITH_LEN(X) (X).str, (X).length typedef struct st_mysql_const_lex_string LEX_CSTRING; diff --git a/sql/debug_sync.cc b/sql/debug_sync.cc index 16ff4abafe12e..5cb8fb715bfcf 100644 --- a/sql/debug_sync.cc +++ b/sql/debug_sync.cc @@ -1292,7 +1292,7 @@ uchar *debug_sync_value_ptr(THD *thd) if (opt_debug_sync_timeout) { - static char on[]= "ON - current signal: '"; + static const char on[]= "ON - current signal: '"; // Ensure exclusive access to debug_sync_global.ds_signal mysql_mutex_lock(&debug_sync_global.ds_mutex); diff --git a/storage/tokudb/PerconaFT/portability/toku_debug_sync.h b/storage/tokudb/PerconaFT/portability/toku_debug_sync.h index affe3054214b9..ff99c99d81e8a 100644 --- a/storage/tokudb/PerconaFT/portability/toku_debug_sync.h +++ b/storage/tokudb/PerconaFT/portability/toku_debug_sync.h @@ -64,9 +64,12 @@ inline void toku_debug_sync(struct tokutxn *txn, const char *sync_point_name) { void *client_extra; THD *thd; - toku_txn_get_client_id(txn, &client_id, &client_extra); - thd = reinterpret_cast(client_extra); - DEBUG_SYNC(thd, sync_point_name); + if (debug_sync_service) + { + toku_txn_get_client_id(txn, &client_id, &client_extra); + thd = reinterpret_cast(client_extra); + debug_sync_service(thd, sync_point_name, strlen(sync_point_name)); + } } #else // defined(ENABLED_DEBUG_SYNC) From 2a5763224e6424f9249b0ae97a819922a5fe0265 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Otto=20Kek=C3=A4l=C3=A4inen?= Date: Thu, 5 Jan 2023 21:56:14 -0800 Subject: [PATCH 73/92] Deb: Sync Salsa-CI from Debian MariaDB 10.6 Compare to Debian packaging of MariaDB 1:10.6.11-2 release at commit https://salsa.debian.org/mariadb-team/mariadb-server/-/commit/2934e8a795cbd1eba79e33b8d6c82ed2b0897128 and sync upstream everything that is relevant for upstream and safe to import on a stable 10.6 release. * Use OpenSSL 1.1 from Debian Snapshots https://salsa.debian.org/mariadb-team/mariadb-server/-/commit/0040c272bf8a9a253fcd393b235b18cd5cdc9289 Related: https://jira.mariadb.org/browse/MDEV-30322 * Prefer using bullseye-backports in mosts tests over buster-bpo https://salsa.debian.org/mariadb-team/mariadb-server/-/commit/daa827ecded9dc1f096ecb05242116173298d602 * Add new upgrade test for MySQL Community Cluster 8.0 https://salsa.debian.org/mariadb-team/mariadb-server/-/commit/3c71bec9b7626d25a55e23b2e570b4e125d5d5df * Enable automatic datadir move also on upgrades from MySQL.com packages https://salsa.debian.org/mariadb-team/mariadb-server/-/commit/4cbbcb7e56d9604a67230d11a68543d5a83960e3 * Update Breaks/Replaces https://salsa.debian.org/mariadb-team/mariadb-server/-/commit/2cab13d05959fe8f6ea56b866df51f3bfe17dd3f * Normalize apt-get and curl commands https://salsa.debian.org/mariadb-team/mariadb-server/-/commit/8754ea2578bd214d75a2a9e6a0f7b4b74c062b41 * Standardize on using capitalized 'ON' in CMake build options https://salsa.debian.org/mariadb-team/mariadb-server/-/commit/938757a85aee44c727f3f6996677ef1126c2f5aa * Apply wrap-and-sort -av and other minor tweaks and inline documentation NOTE TO MERGERS: This commit is made on 10.6 branch and can be merged to all later branches (10.7, 10.8, ..., 11.0). --- debian/control | 42 +++- debian/libmariadb-dev.install | 2 +- debian/libmariadb-dev.lintian-overrides | 1 + debian/mariadb-server-10.6.preinst | 16 +- debian/mariadb-server-core-10.6.install | 2 +- debian/mariadb-test.install | 2 +- debian/mariadb-test.links | 6 +- debian/rules | 18 +- debian/salsa-ci.yml | 304 +++++++++++++++++++----- 9 files changed, 307 insertions(+), 86 deletions(-) diff --git a/debian/control b/debian/control index 7f0d88e991ce8..70da8ba296e78 100644 --- a/debian/control +++ b/debian/control @@ -305,13 +305,17 @@ Breaks: mariadb-server-10.0, mariadb-server-core-10.4, mariadb-server-core-10.5, mariadb-server-core-10.6 (<< ${source:Version}), + mysql-cluster-community-client-plugins, mysql-server-core-5.5, mysql-server-core-5.6, mysql-server-core-5.7, mysql-server-core-8.0, percona-server-server-5.6, + percona-server-server-5.7, + percona-server-server-8.0, percona-xtradb-cluster-server-5.6, - percona-xtradb-cluster-server-5.7 + percona-xtradb-cluster-server-5.7, + percona-xtradb-cluster-server-8.0 Replaces: mariadb-client-10.0, mariadb-client-10.1, mariadb-client-10.2, @@ -351,13 +355,17 @@ Replaces: mariadb-client-10.0, mysql-client-core-5.6, mysql-client-core-5.7, mysql-client-core-8.0, + mysql-cluster-community-client-plugins, mysql-server-core-5.5, mysql-server-core-5.6, mysql-server-core-5.7, mysql-server-core-8.0, percona-server-server-5.6, + percona-server-server-5.7, + percona-server-server-8.0, percona-xtradb-cluster-server-5.6, percona-xtradb-cluster-server-5.7, + percona-xtradb-cluster-server-8.0, virtual-mysql-client-core Provides: default-mysql-client-core, virtual-mysql-client-core @@ -540,6 +548,7 @@ Breaks: mariadb-client-10.0, mariadb-client-10.6 (<< ${source:Version}), mariadb-server-10.0, mariadb-server-10.1, + mariadb-server-10.2, mariadb-server-10.3, mariadb-server-10.4, mariadb-server-10.5, @@ -561,6 +570,7 @@ Replaces: mariadb-client-10.0, mariadb-client-10.6 (<< ${source:Version}), mariadb-server-10.0, mariadb-server-10.1, + mariadb-server-10.2, mariadb-server-10.3, mariadb-server-10.4, mariadb-server-10.5, @@ -733,9 +743,11 @@ Package: mariadb-backup Architecture: any Breaks: mariadb-backup-10.1, mariadb-backup-10.2, + mariadb-backup-10.3, mariadb-client-10.1 Replaces: mariadb-backup-10.1, mariadb-backup-10.2, + mariadb-backup-10.3, mariadb-client-10.1 Depends: mariadb-client-core-10.6 (= ${binary:Version}), ${misc:Depends}, @@ -758,12 +770,16 @@ Breaks: mariadb-connect-engine-10.0, mariadb-connect-engine-10.1, mariadb-connect-engine-10.2, mariadb-connect-engine-10.3, - mariadb-connect-engine-10.4 + mariadb-connect-engine-10.4, + mariadb-server-10.0, + mariadb-server-10.1 Replaces: mariadb-connect-engine-10.0, mariadb-connect-engine-10.1, mariadb-connect-engine-10.2, mariadb-connect-engine-10.3, - mariadb-connect-engine-10.4 + mariadb-connect-engine-10.4, + mariadb-server-10.0, + mariadb-server-10.1 Description: Connect storage engine for MariaDB Connect engine supports a number of file formats (dbf, xml, txt, bin, etc), connections to ODBC tables and remote MySQL tables, as well as a number of @@ -784,7 +800,7 @@ Description: Amazon S3 archival storage engine for MariaDB Package: mariadb-plugin-rocksdb Architecture: amd64 arm64 mips64el ppc64el Depends: mariadb-server-10.6 (= ${server:Version}), - python3, + python3:any, rocksdb-tools, ${misc:Depends}, ${shlibs:Depends} @@ -810,12 +826,16 @@ Breaks: mariadb-oqgraph-engine-10.0, mariadb-oqgraph-engine-10.1, mariadb-oqgraph-engine-10.2, mariadb-oqgraph-engine-10.3, - mariadb-oqgraph-engine-10.4 + mariadb-oqgraph-engine-10.4, + mariadb-server-10.0, + mariadb-server-10.1 Replaces: mariadb-oqgraph-engine-10.0, mariadb-oqgraph-engine-10.1, mariadb-oqgraph-engine-10.2, mariadb-oqgraph-engine-10.3, - mariadb-oqgraph-engine-10.4 + mariadb-oqgraph-engine-10.4, + mariadb-server-10.0, + mariadb-server-10.1 Description: OQGraph storage engine for MariaDB The OQGraph engine is a computation engine plugin for handling hierarchies (trees) and graphs (friend-of-a-friend, etc) cleanly through standard SQL. @@ -871,11 +891,15 @@ Depends: libgssapi-krb5-2, Breaks: mariadb-gssapi-server-10.1, mariadb-gssapi-server-10.2, mariadb-gssapi-server-10.3, - mariadb-gssapi-server-10.4 + mariadb-gssapi-server-10.4, + mariadb-server-10.0, + mariadb-server-10.1 Replaces: mariadb-gssapi-server-10.1, mariadb-gssapi-server-10.2, mariadb-gssapi-server-10.3, - mariadb-gssapi-server-10.4 + mariadb-gssapi-server-10.4, + mariadb-server-10.0, + mariadb-server-10.1 Description: GSSAPI authentication plugin for MariaDB server This plugin includes support for Kerberos on Unix, but can also be used for Windows authentication with or without domain environment. @@ -954,6 +978,8 @@ Replaces: mariadb-test-10.0, mariadb-test-5.5, mysql-client-5.5, mysql-server-5.5, + mysql-server-5.7, + mysql-server-core-8.0, mysql-testsuite, mysql-testsuite-5.5, mysql-testsuite-5.6, diff --git a/debian/libmariadb-dev.install b/debian/libmariadb-dev.install index a0737fee00c22..08be370ca6d45 100644 --- a/debian/libmariadb-dev.install +++ b/debian/libmariadb-dev.install @@ -11,10 +11,10 @@ usr/include/mariadb/mariadb_dyncol.h usr/include/mariadb/mariadb_rpl.h usr/include/mariadb/mariadb_stmt.h usr/include/mariadb/mariadb_version.h +usr/include/mariadb/my_alloca.h usr/include/mariadb/my_config.h usr/include/mariadb/my_global.h usr/include/mariadb/my_sys.h -usr/include/mariadb/my_alloca.h usr/include/mariadb/mysql.h usr/include/mariadb/mysql/ usr/include/mariadb/mysql/client_plugin.h diff --git a/debian/libmariadb-dev.lintian-overrides b/debian/libmariadb-dev.lintian-overrides index 345b537a52171..6a162120f2427 100644 --- a/debian/libmariadb-dev.lintian-overrides +++ b/debian/libmariadb-dev.lintian-overrides @@ -1 +1,2 @@ +# This is how upstream does it, wont' fix arch-dependent-file-not-in-arch-specific-directory usr/bin/mariadb_config diff --git a/debian/mariadb-server-10.6.preinst b/debian/mariadb-server-10.6.preinst index 79c6ccc8500e2..b79f20a980369 100644 --- a/debian/mariadb-server-10.6.preinst +++ b/debian/mariadb-server-10.6.preinst @@ -119,6 +119,18 @@ then fi +# If there is no debian-*.flag, and no version was detected, but a file that +# indicated MySQL 8.0 is found (undo_001 is created by default in MySQL 8.0+ +# installs), then that file is enough of additional indication to trigger the +# move of the data directory. +if [ -z "$found_version" ] && + [ -z "$(find $mysql_datadir/debian-*.flag 2> /dev/null)" ] && + [ -f "$mysql_datadir/undo_001" ] +then + echo "$mysql_datadir: no server version flag found, assuming MySQL 8.0 data encountered" + downgrade_detected=true + found_version="previous" # Just use dummy name as we don't know real version +fi # Don't abort dpkg if downgrade is detected (as was done previously). # Instead simply move the old datadir and create a new for this_version. @@ -133,8 +145,8 @@ then echo "Please manually export/import your data (e.g. with mysqldump) if needed." 1>&2 mv -f "$mysql_datadir" "$mysql_datadir-$found_version" # Also move away the old debian.cnf file that included credentials that are - # no longer valid - mv -f /etc/mysql/debian.cnf "/etc/mysql/debian.cnf-$found_version" + # no longer valid. If none existed, ignore error and let dpkg continue. + mv -f /etc/mysql/debian.cnf "/etc/mysql/debian.cnf-$found_version" || true fi # to be sure diff --git a/debian/mariadb-server-core-10.6.install b/debian/mariadb-server-core-10.6.install index def9526851257..6d159ba4c6a1d 100644 --- a/debian/mariadb-server-core-10.6.install +++ b/debian/mariadb-server-core-10.6.install @@ -12,8 +12,8 @@ usr/share/man/man1/resolveip.1 usr/share/man/man8/mariadbd.8 usr/share/man/man8/mysqld.8 usr/share/mysql/bulgarian -usr/share/mysql/chinese usr/share/mysql/charsets +usr/share/mysql/chinese usr/share/mysql/czech usr/share/mysql/danish usr/share/mysql/dutch diff --git a/debian/mariadb-test.install b/debian/mariadb-test.install index 36b49bdab975a..e587a3bf73df0 100644 --- a/debian/mariadb-test.install +++ b/debian/mariadb-test.install @@ -37,8 +37,8 @@ usr/share/mysql/mysql-test/README.stress usr/share/mysql/mysql-test/dgcov.pl usr/share/mysql/mysql-test/lib usr/share/mysql/mysql-test/mariadb-stress-test.pl -usr/share/mysql/mysql-test/mysql-test-run.pl usr/share/mysql/mysql-test/mariadb-test-run.pl +usr/share/mysql/mysql-test/mysql-test-run.pl usr/share/mysql/mysql-test/purify.supp usr/share/mysql/mysql-test/suite.pm usr/share/mysql/mysql-test/valgrind.supp diff --git a/debian/mariadb-test.links b/debian/mariadb-test.links index 3c45bb955c41f..c7e4ae10063bb 100644 --- a/debian/mariadb-test.links +++ b/debian/mariadb-test.links @@ -2,7 +2,7 @@ usr/bin/mariadb-client-test usr/bin/mysql_client_test usr/bin/mariadb-client-test-embedded usr/bin/mysql_client_test_embedded usr/bin/mariadb-test usr/bin/mysqltest usr/bin/mariadb-test-embedded usr/bin/mysqltest_embedded -usr/share/mysql/mysql-test/mariadb-test-run.pl usr/share/mysql/mysql-test/mysql-test-run.pl -usr/share/mysql/mysql-test/mariadb-test-run.pl usr/share/mysql/mysql-test/mysql-test-run -usr/share/mysql/mysql-test/mariadb-test-run.pl usr/share/mysql/mysql-test/mtr usr/share/mysql/mysql-test/mariadb-test-run.pl usr/share/mysql/mysql-test/mariadb-test-run +usr/share/mysql/mysql-test/mariadb-test-run.pl usr/share/mysql/mysql-test/mtr +usr/share/mysql/mysql-test/mariadb-test-run.pl usr/share/mysql/mysql-test/mysql-test-run +usr/share/mysql/mysql-test/mariadb-test-run.pl usr/share/mysql/mysql-test/mysql-test-run.pl diff --git a/debian/rules b/debian/rules index 7dcc9a2ba3cb6..062ff03e82220 100755 --- a/debian/rules +++ b/debian/rules @@ -1,10 +1,7 @@ #!/usr/bin/make -f -export DH_VERBOSE=1 -export DEB_BUILD_HARDENING=1 - -# enable Debian Hardening -# see: https://wiki.debian.org/Hardening +# Enable Debian Hardening +# https://wiki.debian.org/Hardening export DEB_BUILD_MAINT_OPTIONS = hardening=+all # Disable LTO on Ubuntu, see LP: #1970634 and https://jira.mariadb.org/browse/MDEV-25633 @@ -64,8 +61,8 @@ endif # Only attempt to build with PMEM on archs that have package libpmem-dev available # See https://packages.debian.org/search?searchon=names&keywords=libpmem-dev -ifneq (,$(filter $(DEB_HOST_ARCH_CPU),amd64 arm64 ppc64el riscv64)) - CMAKEFLAGS += -DWITH_PMEM=YES +ifneq (,$(filter $(DEB_HOST_ARCH),amd64 arm64 ppc64el riscv64)) + CMAKEFLAGS += -DWITH_PMEM=ON endif # Add support for verbose builds @@ -93,6 +90,9 @@ endif # quality standards in Debian. Also building it requires an extra 4 GB of disk # space which makes native Debian builds fail as the total disk space needed # for MariaDB becomes over 10 GB. Only build CS via autobake-deb.sh. + # + # Note: Don't use '-DWITH_URING=ON' as some Buildbot builders are missing it + # and would fail permanently. PATH=$${MYSQL_BUILD_PATH:-"/usr/lib/ccache:/usr/local/bin:/usr/bin:/bin"} \ NO_UPDATE_BUILD_VERSION=1 \ dh_auto_configure --builddirectory=$(BUILDDIR) -- \ @@ -107,8 +107,7 @@ endif -DCONC_DEFAULT_CHARSET=utf8mb4 \ -DPLUGIN_AWS_KEY_MANAGEMENT=NO \ -DPLUGIN_COLUMNSTORE=NO \ - -DIGNORE_AIO_CHECK=YES \ - -DWITH_URING=YES \ + -DIGNORE_AIO_CHECK=ON \ -DDEB=$(DEB_VENDOR) # This is needed, otherwise 'make test' will run before binaries have been built @@ -123,6 +122,7 @@ override_dh_auto_test: dh_testdir # Ensure at least an empty file exists touch mysql-test/unstable-tests + # Skip unstable tests if such are defined for arch [ ! -f debian/unstable-tests.$(DEB_HOST_ARCH) ] || cat debian/unstable-tests.$(DEB_HOST_ARCH) >> mysql-test/unstable-tests # Run testsuite ifeq (,$(filter nocheck,$(DEB_BUILD_OPTIONS))) diff --git a/debian/salsa-ci.yml b/debian/salsa-ci.yml index 436756a5e6c6d..d8a6b93925064 100644 --- a/debian/salsa-ci.yml +++ b/debian/salsa-ci.yml @@ -26,7 +26,7 @@ stages: - build - test - upgrade in Sid - - upgrade from Bullseye + - upgrade from Buster/Bullseye - upgrade extras - test extras - publish # Stage referenced by Salsa-CI template aptly stanza, so must exist even though not used @@ -115,13 +115,20 @@ blhc: # Avoid the warnings of "debconf: unable to initialize frontend: Dialog" echo 'debconf debconf/frontend select Noninteractive' | debconf-set-selections # Prime the apt cache so later apt commands can run - apt-get update + apt-get update -qq # Readline was removed from Debian Sid (and Bullseye) in Feb 2021. To be able to install older # versions of MariaDB that depend on it, fetch and install it from Buster. .test-install-readline-in-sid-for-backwards-compat: &test-install-readline-in-sid-for-backwards-compat | - curl -O http://ftp.de.debian.org/debian/pool/main/r/readline5/libreadline5_5.2+dfsg-3+b13_amd64.deb - apt install -y ./libreadline5_5.2+dfsg-3+b13_amd64.deb + curl -sS -O http://ftp.de.debian.org/debian/pool/main/r/readline5/libreadline5_5.2+dfsg-3+b13_amd64.deb + apt-get -qq install --no-install-recommends --yes ./libreadline5_5.2+dfsg-3+b13_amd64.deb + +# OpenSSL 1.1 was Debian Sid in Dec 2022 (as Bookworm will ship with OpenSSL 3.0 +# only). To be able to install versions of MariaDB that depend on OpenSSL 1.1, +# fetch and install it manually. +.test-install-openssl1-in-sid-for-backwards-compat: &test-install-openssl1-in-sid-for-backwards-compat | + curl -sS -O https://snapshot.debian.org/archive/debian/20220507T034236Z/pool/main/o/openssl/libssl1.1_1.1.1o-1_amd64.deb + apt-get -qq install --no-install-recommends --yes ./libssl1.1_1.1.1o-1_amd64.deb .test-verify-initial: &test-verify-initial | dpkg -l | grep -iE 'maria|mysql|galera' || true # List installed @@ -132,12 +139,37 @@ blhc: mysql --table -e "SELECT * FROM plugin;" mysql mysql --table -e "SHOW PLUGINS;" mysql -.test-enable-sid-repos: &test-enable-sid-repos | +.test-enable-sid-repos: &test-enable-sid-repos # Replace any old repos with just Sid - echo 'deb http://deb.debian.org/debian sid main' > /etc/apt/sources.list + - echo 'deb http://deb.debian.org/debian sid main' > /etc/apt/sources.list # Upgrade minimal stack first - apt-get update - apt-get install -y apt + - apt-get update -qq + # Next step will fail on https://bugs.debian.org/993755 + # /usr/bin/perl: error while loading shared libraries: libcrypt.so.1: cannot + # open shared object file: No such file or directory + # dpkg: error processing package libc6:amd64 (--configure): + - apt-get install -y apt || true + # Apply workaround + - cd $(mktemp -d) # Use temp dir where apt can download and unpack files + - apt-get -y download libcrypt1 + - dpkg-deb -x libcrypt1_*.deb . + - cp -ra lib/* /lib/ + - cd - # Back to /builds/$USER/mariadb-server/debian/output + - find /lib/*/libcrypt.* -ls # Show that new libcrypt is there + - apt-get -y --fix-broken install + # Complete upgrade of minimal stack + - apt-get install -y apt + +.test-enable-bullseye-backports-repos: &test-enable-bullseye-backports-repos | + # Enable bullseye-backports (assumes environment already Debian Bullseye) + echo 'deb http://deb.debian.org/debian bullseye-backports main' > /etc/apt/sources.list.d/bullseye-backports.list + # Increase default backports priority policy from '100' to '500' so it can actually be used + cat << EOF > /etc/apt/preferences.d/enable-backports-to-satisfy-dependencies + Package: * + Pin: release n=bullseye-* + Pin-Priority: 500 + EOF + apt-get update -qq .test-enable-buster-backports-repos: &test-enable-buster-backports-repos | # Enable buster-backports (assumes environment already Debian Buster) @@ -148,7 +180,7 @@ blhc: Pin: release n=buster-* Pin-Priority: 500 EOF - apt-get update + apt-get update -qq .test-install: &test-install | # Install MariaDB built in this commit @@ -249,6 +281,33 @@ mariadb-10.6 Sid upgrade: - ${WORKING_DIR}/debug script: - *test-prepare-container + - apt-get install -y 'default-mysql*' 'mariadb-*' 'libmariadb*' + - *test-install + - service mariadb status # There is no init.d/mysql in MariaDB 10.5+ + - *test-verify-final + variables: + GIT_STRATEGY: none + except: + variables: + - $CI_COMMIT_TAG != null && $SALSA_CI_ENABLE_PIPELINE_ON_TAGS !~ /^(1|yes|true)$/ + +mariadb-10.5 with Bullseye backports upgrade: + stage: upgrade extras + needs: + - job: build bullseye-backports + image: debian:bullseye + artifacts: + when: always + name: "$CI_BUILD_NAME" + paths: + - ${WORKING_DIR}/debug + script: + - *test-prepare-container + # Install everything MariaDB currently in Debian Buster + - apt-get install -y 'default-mysql*' 'mariadb-*' 'libmariadb*' + # Verify installation of MariaDB from Buster + - *test-verify-initial + - *test-enable-bullseye-backports-repos - *test-install - service mariadb status # There is no init.d/mysql in MariaDB 10.5+ - *test-verify-final @@ -258,8 +317,36 @@ mariadb-10.6 Sid upgrade: variables: - $CI_COMMIT_TAG != null && $SALSA_CI_ENABLE_PIPELINE_ON_TAGS !~ /^(1|yes|true)$/ +mariadb-10.3 with Buster backports upgrade: + stage: upgrade extras + needs: + - job: build buster-backports + image: debian:buster + artifacts: + when: always + name: "$CI_BUILD_NAME" + paths: + - ${WORKING_DIR}/debug + script: + - *test-prepare-container + # Install everything MariaDB currently in Debian Buster + - apt-get install -y 'default-mysql*' 'mariadb-*' 'libmariadb*' + # Verify installation of MariaDB from Buster + - *test-verify-initial + - *test-enable-buster-backports-repos + - *test-install + # mariadb-10.3 in Buster ships a /etc/init.d/mysql so it should continue to work + - service mysql status + - service mariadb status + - *test-verify-final + variables: + GIT_STRATEGY: none + except: + variables: + - $CI_COMMIT_TAG != null && $SALSA_CI_ENABLE_PIPELINE_ON_TAGS !~ /^(1|yes|true)$/ + mariadb-10.5 Bullseye to mariadb-10.6 upgrade: - stage: upgrade from Bullseye + stage: upgrade from Buster/Bullseye needs: - job: build image: debian:bullseye @@ -276,7 +363,7 @@ mariadb-10.5 Bullseye to mariadb-10.6 upgrade: - *test-verify-initial - *test-enable-sid-repos - *test-install - - service mariadb status + - service mariadb status # There is no init.d/mysql in MariaDB 10.5+ - *test-verify-final variables: GIT_STRATEGY: none @@ -284,12 +371,10 @@ mariadb-10.5 Bullseye to mariadb-10.6 upgrade: variables: - $CI_COMMIT_TAG != null && $SALSA_CI_ENABLE_PIPELINE_ON_TAGS !~ /^(1|yes|true)$/ -# Upgrade of libcrypt.so.1 no longer possible from Buster to Sid, -# so test upgrade only inside Buster (https://bugs.debian.org/993755) -mariadb-10.3 to mariadb-10.6 upgrade in Buster: - stage: upgrade extras +mariadb-10.3 Buster to mariadb-10.6 upgrade: + stage: upgrade from Buster/Bullseye needs: - - job: build buster-backports + - job: build image: debian:buster artifacts: when: always @@ -302,9 +387,11 @@ mariadb-10.3 to mariadb-10.6 upgrade in Buster: - apt-get install -y 'default-mysql*' 'mariadb-*' 'libmariadb*' # Verify installation of MariaDB from Buster - *test-verify-initial - - *test-enable-buster-backports-repos + - *test-enable-sid-repos - *test-install + # mariadb-10.3 in Buster ships a /etc/init.d/mysql so it should continue to work - service mysql status + - service mariadb status - *test-verify-final variables: GIT_STRATEGY: none @@ -470,7 +557,7 @@ default-libmysqlclient-dev Sid upgrade: - $CI_COMMIT_TAG != null && $SALSA_CI_ENABLE_PIPELINE_ON_TAGS !~ /^(1|yes|true)$/ default-libmysqlclient-dev Bullseye upgrade: - stage: upgrade from Bullseye + stage: upgrade from Buster/Bullseye needs: - job: build image: debian:bullseye @@ -490,9 +577,49 @@ default-libmysqlclient-dev Bullseye upgrade: variables: - $CI_COMMIT_TAG != null && $SALSA_CI_ENABLE_PIPELINE_ON_TAGS !~ /^(1|yes|true)$/ -# Upgrade of libcrypt.so.1 no longer possible from Buster to Sid, -# so test upgrade only inside Buster (https://bugs.debian.org/993755) -default-libmysqlclient-dev upgrade in Buster: +default-libmysqlclient-dev Buster upgrade: + stage: upgrade from Buster/Bullseye + needs: + - job: build + image: debian:buster + artifacts: + when: always + name: "$CI_BUILD_NAME" + paths: + - ${WORKING_DIR}/debug + script: + - *test-prepare-container + - apt-get install -y pkg-config default-libmysqlclient-dev + - pkg-config --list-all + - *test-enable-sid-repos + - *test-install-all-libs + - *test-verify-libs + except: + variables: + - $CI_COMMIT_TAG != null && $SALSA_CI_ENABLE_PIPELINE_ON_TAGS !~ /^(1|yes|true)$/ + +default-libmysqlclient-dev with Bullseye backports upgrade: + stage: upgrade extras + needs: + - job: build bullseye-backports + image: debian:bullseye + artifacts: + when: always + name: "$CI_BUILD_NAME" + paths: + - ${WORKING_DIR}/debug + script: + - *test-prepare-container + - apt-get install -y pkg-config default-libmysqlclient-dev + - pkg-config --list-all + - *test-enable-bullseye-backports-repos + - *test-install-all-libs + - *test-verify-libs + except: + variables: + - $CI_COMMIT_TAG != null && $SALSA_CI_ENABLE_PIPELINE_ON_TAGS !~ /^(1|yes|true)$/ + +default-libmysqlclient-dev with Buster backports upgrade: stage: upgrade extras needs: - job: build buster-backports @@ -531,18 +658,14 @@ mysql-8.0 Sid to mariadb-10.6 upgrade: - apt-get install -y procps mysql-server 'libmysqlc*' - *test-verify-initial - *test-install - # The Debian version of MariaDB 10.6 still maintains compatibility and there - # running 'service mysql status' in Salsa-CI job 'mysql-8.0 Sid to - # mariadb-10.6 upgrade' still works. - # - # However, due to debian/control changes, the upstream MariaDB 10.6 when - # installed on a system with a previous installation of MySQL 8.0 will first - # fully remove MySQL, including the /etc/init.d/mysql file, so previous - # techniques in mariadb-server-10.6.postinst to maintain backwards - # compatibility with 'service mysql status' after installing MariaDB on top - # MySQL no longer works, and thus the step to test it now intentionally has - # a fallback to use the service name 'mariadb' instead, and the fallback is - # always used. + # Due to some (currently unknown) changes in MySQL 8.0 packaging or apt + # behaviour changes, a system with a previous installation of MySQL 8.0 will + # on upgrades to MariaDB first fully remove MySQL, including the + # /etc/init.d/mysql file, so previous techniques in + # mariadb-server-10.6.postinst to maintain backwards compatibility with + # 'service mysql status' after installing MariaDB on top MySQL no longer + # works. Thus the step to test it now intentionally has a fallback to use + # the service name 'mariadb' instead, and the fallback is always used. - sleep 5 # Give the mysql_upgrade a bit of time to complete before querying the server - service mysql status || service mariadb status - *test-verify-final @@ -554,11 +677,14 @@ mysql-8.0 Sid to mariadb-10.6 upgrade: # Upgrading from MySQL 8.0 with datadir in place is not possible. Users need to do a data dump. # The Debian maintainer scripts detect this situation and simply moves old datadir aside and start fresh. -mysql-8.0 Focal to mariadb-10.6 upgrade in Buster: +# +# Testing on Focal binaries on Buster works. Using Jammy binaries on Bullseye +# does not work as libc in Jammy is too new. +mysql-8.0 from Ubuntu 22.04 with Bullseye backports upgrade: stage: upgrade extras needs: - - job: build buster-backports - image: debian:buster + - job: build bullseye-backports + image: debian:bullseye artifacts: when: always name: "$CI_BUILD_NAME" @@ -570,13 +696,13 @@ mysql-8.0 Focal to mariadb-10.6 upgrade in Buster: - apt-get install --no-install-recommends --yes gpg gpg-agent dirmngr ca-certificates # Bare minimal (<4MB) for apt-key to work - apt-key adv --recv-keys --keyserver hkps://keyserver.ubuntu.com:443 871920D1991BC93C 3B4FE6ACC0B21F32 - echo "deb http://archive.ubuntu.com/ubuntu/ focal main restricted" > /etc/apt/sources.list.d/ubuntu.list - - apt-get update + - apt-get update -qq # First install often fail due to bug in mysql-8.0 - apt-get install -y mysql-server 'libmysqlc*' || true - sleep 10 && apt-get install -f - *test-verify-initial # Enable backports to make galera-4 available - - echo "deb http://deb.debian.org/debian buster-backports main" > /etc/apt/sources.list.d/backports.list && apt-get update + - echo "deb http://deb.debian.org/debian bullseye-backports main" > /etc/apt/sources.list.d/backports.list && apt-get update -qq - *test-install - service mysql status - sleep 5 # Give the mysql_upgrade a bit of time to complete before querying the server @@ -587,6 +713,45 @@ mysql-8.0 Focal to mariadb-10.6 upgrade in Buster: variables: - $CI_COMMIT_TAG != null && $SALSA_CI_ENABLE_PIPELINE_ON_TAGS !~ /^(1|yes|true)$/ +# Upgrading from MySQL 8.0 with datadir in place is not possible. Users need to do a data dump. +# The Debian maintainer scripts detect this situation and simply moves old datadir aside and start fresh. +mysql-community-cluster-8.0 from MySQL.com with Bullseye backports upgrade: + stage: upgrade extras + needs: + - job: build bullseye-backports + image: debian:bullseye + artifacts: + when: always + name: "$CI_BUILD_NAME" + paths: + - ${WORKING_DIR}/debug + script: + - *test-prepare-container + - apt-get install --no-install-recommends --yes ca-certificates curl systemctl + - curl -sS "https://keyserver.ubuntu.com/pks/lookup?op=get&search=0x859be8d7c586f538430b19c2467b942d3a79bd29" -o /etc/apt/trusted.gpg.d/mysql.asc + - echo "deb https://repo.mysql.com/apt/debian/ bullseye mysql-cluster-8.0" > /etc/apt/sources.list.d/mysql.list + - apt-get update -qq + - apt-get install -y mysql-cluster-community-server + - sed 's/ExecStartPre=+/ExecStartPre=/' -i /lib/systemd/system/mysql.service # Hack to make file compatible with systemctl shim + - systemctl start mysql + - dpkg -l | grep -iE 'maria|mysql|galera' + - systemctl status mysql; mysql -e 'SELECT VERSION()' + - systemctl stop mysql # Stop manually as maintainer scripts don't handle this with systemctl shim + # Enable backports to make galera-4 available + - echo "deb http://deb.debian.org/debian bullseye-backports main" > /etc/apt/sources.list.d/backports.list && apt-get update -qq + - *test-install + # Ignore systemctl shim result as MariaDB systemd file is incompatible with it and yields: + # ERROR:systemctl:the ExecStartPre control process exited with error code + - systemctl status mysql || true + - mysql -e 'SELECT VERSION()' || true + - sleep 5 # Give the mysql_upgrade a bit of time to complete before querying the server + - *test-verify-final + variables: + GIT_STRATEGY: none + except: + variables: + - $CI_COMMIT_TAG != null && $SALSA_CI_ENABLE_PIPELINE_ON_TAGS !~ /^(1|yes|true)$/ + mariadb.org-10.6 to mariadb-10.6 upgrade: stage: upgrade extras needs: @@ -599,10 +764,10 @@ mariadb.org-10.6 to mariadb-10.6 upgrade: - ${WORKING_DIR}/debug script: - *test-prepare-container - - apt install -y curl + - apt-get -qq install --no-install-recommends --yes ca-certificates curl - curl -sS https://mariadb.org/mariadb_release_signing_key.asc -o /etc/apt/trusted.gpg.d/mariadb.asc - echo "deb https://deb.mariadb.org/10.6/debian ${RELEASE} main" > /etc/apt/sources.list.d/mariadb.list - - apt-get update + - apt-get update -qq # Package libmariadbclient-dev from mariadb.org conflicts with libmariadb-dev in Sid, so cannot use wildcard that would include it # Enable this line when there is a way to install them only from the mariadb.org repo # - apt-get install -y 'mariadb*' libmariadb3 'libmariadb-*' 'libmariadbd*' @@ -622,6 +787,7 @@ mariadb.org-10.6 to mariadb-10.6 upgrade: variables: - $CI_COMMIT_TAG != null && $SALSA_CI_ENABLE_PIPELINE_ON_TAGS !~ /^(1|yes|true)$/ +# archive.mariadb.org for Debian Sid latest is 10.5.13 mariadb.org-10.5 to mariadb-10.6 upgrade: stage: upgrade extras needs: @@ -634,10 +800,11 @@ mariadb.org-10.5 to mariadb-10.6 upgrade: - ${WORKING_DIR}/debug script: - *test-prepare-container - - apt install -y curl + - apt-get -qq install --no-install-recommends --yes ca-certificates curl - curl -sS https://mariadb.org/mariadb_release_signing_key.asc -o /etc/apt/trusted.gpg.d/mariadb.asc - echo "deb https://archive.mariadb.org/mariadb-10.5/repo/debian ${RELEASE} main" > /etc/apt/sources.list.d/mariadb.list - - apt-get update + - apt-get update -qq + - *test-install-openssl1-in-sid-for-backwards-compat - apt-get install -y mariadb-server-10.5 - *test-verify-initial # Install MariaDB built in this commit @@ -652,6 +819,7 @@ mariadb.org-10.5 to mariadb-10.6 upgrade: variables: - $CI_COMMIT_TAG != null && $SALSA_CI_ENABLE_PIPELINE_ON_TAGS !~ /^(1|yes|true)$/ +# archive.mariadb.org for Debian Sid latest is 10.4.17 mariadb.org-10.4 to mariadb-10.6 upgrade: stage: upgrade extras needs: @@ -664,11 +832,12 @@ mariadb.org-10.4 to mariadb-10.6 upgrade: - ${WORKING_DIR}/debug script: - *test-prepare-container - - apt install -y curl systemctl # systemctl shim needed on platforms that don't have systemd + - apt-get -qq install --no-install-recommends --yes ca-certificates curl systemctl # systemctl shim needed on platforms that don't have systemd - curl -sS https://mariadb.org/mariadb_release_signing_key.asc -o /etc/apt/trusted.gpg.d/mariadb.asc - echo "deb https://archive.mariadb.org/mariadb-10.4/repo/debian ${RELEASE} main" > /etc/apt/sources.list.d/mariadb.list - - apt-get update + - apt-get update -qq - *test-install-readline-in-sid-for-backwards-compat + - *test-install-openssl1-in-sid-for-backwards-compat - apt-get install -y mariadb-server-10.4 # MariaDB.org version of 10.4 and early 10.5 do not install an init file, so # it must be installed here manually @@ -685,6 +854,7 @@ mariadb.org-10.4 to mariadb-10.6 upgrade: variables: - $CI_COMMIT_TAG != null && $SALSA_CI_ENABLE_PIPELINE_ON_TAGS !~ /^(1|yes|true)$/ +# archive.mariadb.org for Debian Sid latest is 10.3.27 mariadb.org-10.3 to mariadb-10.6 upgrade: stage: upgrade extras needs: @@ -697,11 +867,12 @@ mariadb.org-10.3 to mariadb-10.6 upgrade: - ${WORKING_DIR}/debug script: - *test-prepare-container - - apt install -y curl + - apt-get -qq install --no-install-recommends --yes ca-certificates curl - curl -sS https://mariadb.org/mariadb_release_signing_key.asc -o /etc/apt/trusted.gpg.d/mariadb.asc - echo "deb https://archive.mariadb.org/mariadb-10.3/repo/debian ${RELEASE} main" > /etc/apt/sources.list.d/mariadb.list - - apt-get update + - apt-get update -qq - *test-install-readline-in-sid-for-backwards-compat + - *test-install-openssl1-in-sid-for-backwards-compat - apt-get install -y mariadb-server-10.3 - *test-verify-initial - *test-install @@ -716,6 +887,7 @@ mariadb.org-10.3 to mariadb-10.6 upgrade: variables: - $CI_COMMIT_TAG != null && $SALSA_CI_ENABLE_PIPELINE_ON_TAGS !~ /^(1|yes|true)$/ +# archive.mariadb.org for Debian Sid latest is 10.2.21 mariadb.org-10.2 to mariadb-10.6 upgrade: stage: upgrade extras needs: @@ -728,11 +900,12 @@ mariadb.org-10.2 to mariadb-10.6 upgrade: - ${WORKING_DIR}/debug script: - *test-prepare-container - - apt install -y curl + - apt-get -qq install --no-install-recommends --yes ca-certificates curl - curl -sS https://mariadb.org/mariadb_release_signing_key.asc -o /etc/apt/trusted.gpg.d/mariadb.asc - echo "deb https://archive.mariadb.org/mariadb-10.2/repo/debian ${RELEASE} main" > /etc/apt/sources.list.d/mariadb.list - - apt-get update + - apt-get update -qq - *test-install-readline-in-sid-for-backwards-compat + - *test-install-openssl1-in-sid-for-backwards-compat - apt-get install -y mariadb-server-10.2 # Verify initial state before upgrade - dpkg -l | grep -iE 'maria|mysql|galera' || true # List installed @@ -755,11 +928,11 @@ mariadb.org-10.2 to mariadb-10.6 upgrade: variables: - $CI_COMMIT_TAG != null && $SALSA_CI_ENABLE_PIPELINE_ON_TAGS !~ /^(1|yes|true)$/ -mysql.com-5.7 to mariadb-10.6 upgrade in Buster: +mysql.com-5.7 with Bullseye backports upgrade: stage: upgrade extras needs: - - job: build buster-backports - image: debian:buster + - job: build bullseye-backports + image: debian:bullseye artifacts: when: always name: "$CI_BUILD_NAME" @@ -770,14 +943,23 @@ mysql.com-5.7 to mariadb-10.6 upgrade in Buster: - | apt-get install --no-install-recommends --yes gpg gpg-agent dirmngr ca-certificates # Bare minimal (<4MB) for apt-key to work apt-key adv --recv-keys --keyserver hkps://keyserver.ubuntu.com:443 467B942D3A79BD29 - echo "deb https://repo.mysql.com/apt/debian/ buster mysql-5.7" > /etc/apt/sources.list.d/mysql.list - apt-get update + echo "deb https://repo.mysql.com/apt/debian/ bullseye mysql-5.7" > /etc/apt/sources.list.d/mysql.list + apt-get update -qq apt-get install -y 'mysql*' 'libmysqlc*' - *test-verify-initial # Enable backports to make galera-4 available - - echo "deb http://deb.debian.org/debian buster-backports main" >> /etc/apt/sources.list.d/backports.list && apt-get update + - echo "deb http://deb.debian.org/debian bullseye-backports main" >> /etc/apt/sources.list.d/backports.list && apt-get update -qq - *test-install - - service mysql status + # Due to some (currently unknown) changes in MySQL 5.7 packaging or apt + # behaviour changes, a system with a previous installation of MySQL will + # on upgrades to MariaDB first fully remove MySQL, including the + # /etc/init.d/mysql file, so previous techniques in + # mariadb-server-10.6.postinst to maintain backwards compatibility with + # 'service mysql status' after installing MariaDB on top MySQL no longer + # works. Thus the step to test it now intentionally has a fallback to use + # the service name 'mariadb' instead, and the fallback is always used. + - sleep 5 # Give the mysql_upgrade a bit of time to complete before querying the server + - service mysql status || service mariadb status - sleep 15 # Give the mysql_upgrade a bit of extra time to complete with MySQL 5.7 before querying the server - *test-verify-final variables: @@ -786,11 +968,11 @@ mysql.com-5.7 to mariadb-10.6 upgrade in Buster: variables: - $CI_COMMIT_TAG != null && $SALSA_CI_ENABLE_PIPELINE_ON_TAGS !~ /^(1|yes|true)$/ -percona-xtradb-5.7 to mariadb-10.6 upgrade in Buster (MDEV-22679): +percona-xtradb-5.7 with bullseye backports upgrade: stage: upgrade extras needs: - - job: build buster-backports - image: debian:buster + - job: build bullseye-backports + image: debian:bullseye artifacts: when: always name: "$CI_BUILD_NAME" @@ -801,13 +983,13 @@ percona-xtradb-5.7 to mariadb-10.6 upgrade in Buster (MDEV-22679): - | apt-get install --no-install-recommends --yes gpg gpg-agent dirmngr ca-certificates # Bare minimal (<4MB) for apt-key to work apt-key adv --recv-keys --keyserver hkps://keyserver.ubuntu.com:443 9334A25F8507EFA5 - echo "deb https://repo.percona.com/apt/ buster main" > /etc/apt/sources.list.d/mysql.list - apt-get update + echo "deb https://repo.percona.com/apt/ bullseye main" > /etc/apt/sources.list.d/mysql.list + apt-get update -qq apt-get install -y percona-xtradb-cluster-full-57 percona-xtrabackup-24 percona-toolkit pmm2-client - service mysql status - *test-verify-initial # Enable backports to make galera-4 available - - echo "deb http://deb.debian.org/debian buster-backports main" >> /etc/apt/sources.list.d/backports.list && apt-get update + - echo "deb http://deb.debian.org/debian bullseye-backports main" >> /etc/apt/sources.list.d/backports.list && apt-get update -qq - *test-install - service mysql status - sleep 15 # Give the mysql_upgrade a bit of extra time to complete with MySQL 5.7 before querying the server From ee68fe3272904e720f37542120590b7c815d99cf Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Otto=20Kek=C3=A4l=C3=A4inen?= Date: Sat, 18 Mar 2023 20:12:13 -0700 Subject: [PATCH 74/92] Deb: Update Salsa-CI to use Bullseye instead of Sid Tests that try to upgrade MariaDB 10.6 in Debian Sid can no longer work properly on versions < 10.11 as MariaDB 10.11 in now Debian Sid. Change RELEASE to use Bullseye and refactor builds and upgrade tests to use primarily Bullseye, as it has MariaDB 10.5 and thus testing upgrades to MariaDB 10.6 and higher can work. Add on new 'build sid' job to continue at least on build on Sid as well, even though it is not tested in other jobs. Due to this many Sid specific workarounds are can also be dropped, and since Bullseye is now used for everything, the old bullseye-backports jobs are obsolete and removed. Tests that upgrade MySQL in Sid to MariaDB are also removed, as no test in Debian Sid with MariaDB < 10.11 can reliably work anymore. Also disable reprotest as unnecessary on old branches, refactor the naming of autobake-deb.sh and native Debian build jobs to be more clear. NOTE TO MERGERS: This commit is made on 10.6 branch and can be merged to all later branches (10.7, 10.8, ..., 11.0). If/when some jobs break, they will be fixed per branch on follow-up commits. --- debian/salsa-ci.yml | 354 ++++++++------------------------------------ 1 file changed, 59 insertions(+), 295 deletions(-) diff --git a/debian/salsa-ci.yml b/debian/salsa-ci.yml index d8a6b93925064..c7ca3613fd38f 100644 --- a/debian/salsa-ci.yml +++ b/debian/salsa-ci.yml @@ -7,7 +7,7 @@ include: # Override Salsa-CI with MariaDB specific variations variables: DEB_BUILD_OPTIONS: "nocheck noautodbgsym" - RELEASE: sid + RELEASE: bullseye SALSA_CI_DISABLE_REPROTEST: 1 SALSA_CI_DISABLE_MISSING_BREAKS: 0 SALSA_CI_DISABLE_RC_BUGS: 1 @@ -25,8 +25,8 @@ stages: - provisioning - build - test - - upgrade in Sid - - upgrade from Buster/Bullseye + - upgrade in Bullseye + - upgrade from Buster - upgrade extras - test extras - publish # Stage referenced by Salsa-CI template aptly stanza, so must exist even though not used @@ -51,10 +51,17 @@ build: - ccache -s # Show ccache stats to validate it worked - mv ${CCACHE_TMP_DIR} ${CCACHE_WORK_DIR} -build bullseye-backports: +build i386: + extends: .build-package-i386 + script: + - *autobake-deb-steps + +build sid: extends: .build-package + script: + - *autobake-deb-steps variables: - RELEASE: bullseye-backports + RELEASE: sid build buster-backports: extends: .build-package @@ -70,21 +77,14 @@ build buster-backports: variables: RELEASE: buster-backports -# base image missing git -build i386: - extends: .build-package - script: - - apt-get update && apt-get install -y --no-install-recommends git - - *autobake-deb-steps - image: $SALSA_CI_IMAGES_BASE_I386 - variables: - ARCH: 'i386' - # Build native deb without using autobake-deb.sh. This way we will detect # if the debian/control file and other packaging is correct as-is for Debian Sid. -build native deb: +build native deb amd64: extends: .build-package +build native deb i386: + extends: .build-package-i386 + autopkgtest: extends: .test-autopkgtest artifacts: @@ -100,7 +100,7 @@ blhc: stage: test extras # Build log checker needs a .build file and thus only works on native build needs: - - job: build native deb + - job: build native deb amd64 # In addition to Salsa-CI, also run these fully MariaDB specific build jobs @@ -117,19 +117,6 @@ blhc: # Prime the apt cache so later apt commands can run apt-get update -qq -# Readline was removed from Debian Sid (and Bullseye) in Feb 2021. To be able to install older -# versions of MariaDB that depend on it, fetch and install it from Buster. -.test-install-readline-in-sid-for-backwards-compat: &test-install-readline-in-sid-for-backwards-compat | - curl -sS -O http://ftp.de.debian.org/debian/pool/main/r/readline5/libreadline5_5.2+dfsg-3+b13_amd64.deb - apt-get -qq install --no-install-recommends --yes ./libreadline5_5.2+dfsg-3+b13_amd64.deb - -# OpenSSL 1.1 was Debian Sid in Dec 2022 (as Bookworm will ship with OpenSSL 3.0 -# only). To be able to install versions of MariaDB that depend on OpenSSL 1.1, -# fetch and install it manually. -.test-install-openssl1-in-sid-for-backwards-compat: &test-install-openssl1-in-sid-for-backwards-compat | - curl -sS -O https://snapshot.debian.org/archive/debian/20220507T034236Z/pool/main/o/openssl/libssl1.1_1.1.1o-1_amd64.deb - apt-get -qq install --no-install-recommends --yes ./libssl1.1_1.1.1o-1_amd64.deb - .test-verify-initial: &test-verify-initial | dpkg -l | grep -iE 'maria|mysql|galera' || true # List installed service mysql status || service mariadb status # Early MariaDB 10.5 only had 'mariadb' @@ -139,25 +126,11 @@ blhc: mysql --table -e "SELECT * FROM plugin;" mysql mysql --table -e "SHOW PLUGINS;" mysql -.test-enable-sid-repos: &test-enable-sid-repos +.test-enable-bullseye-repos: &test-enable-bullseye-repos # Replace any old repos with just Sid - - echo 'deb http://deb.debian.org/debian sid main' > /etc/apt/sources.list + - echo 'deb http://deb.debian.org/debian bullseye main' > /etc/apt/sources.list # Upgrade minimal stack first - apt-get update -qq - # Next step will fail on https://bugs.debian.org/993755 - # /usr/bin/perl: error while loading shared libraries: libcrypt.so.1: cannot - # open shared object file: No such file or directory - # dpkg: error processing package libc6:amd64 (--configure): - - apt-get install -y apt || true - # Apply workaround - - cd $(mktemp -d) # Use temp dir where apt can download and unpack files - - apt-get -y download libcrypt1 - - dpkg-deb -x libcrypt1_*.deb . - - cp -ra lib/* /lib/ - - cd - # Back to /builds/$USER/mariadb-server/debian/output - - find /lib/*/libcrypt.* -ls # Show that new libcrypt is there - - apt-get -y --fix-broken install - # Complete upgrade of minimal stack - apt-get install -y apt .test-enable-bullseye-backports-repos: &test-enable-bullseye-backports-repos | @@ -269,8 +242,8 @@ fresh install: variables: - $CI_COMMIT_TAG != null && $SALSA_CI_ENABLE_PIPELINE_ON_TAGS !~ /^(1|yes|true)$/ -mariadb-10.6 Sid upgrade: - stage: upgrade in Sid +mariadb-10.5 Bullseye upgrade: + stage: upgrade in Bullseye needs: - job: build image: debian:${RELEASE} @@ -281,33 +254,9 @@ mariadb-10.6 Sid upgrade: - ${WORKING_DIR}/debug script: - *test-prepare-container + # Install everything MariaDB 10.5 currently in Debian Bullseye - apt-get install -y 'default-mysql*' 'mariadb-*' 'libmariadb*' - - *test-install - - service mariadb status # There is no init.d/mysql in MariaDB 10.5+ - - *test-verify-final - variables: - GIT_STRATEGY: none - except: - variables: - - $CI_COMMIT_TAG != null && $SALSA_CI_ENABLE_PIPELINE_ON_TAGS !~ /^(1|yes|true)$/ - -mariadb-10.5 with Bullseye backports upgrade: - stage: upgrade extras - needs: - - job: build bullseye-backports - image: debian:bullseye - artifacts: - when: always - name: "$CI_BUILD_NAME" - paths: - - ${WORKING_DIR}/debug - script: - - *test-prepare-container - # Install everything MariaDB currently in Debian Buster - - apt-get install -y 'default-mysql*' 'mariadb-*' 'libmariadb*' - # Verify installation of MariaDB from Buster - *test-verify-initial - - *test-enable-bullseye-backports-repos - *test-install - service mariadb status # There is no init.d/mysql in MariaDB 10.5+ - *test-verify-final @@ -329,10 +278,11 @@ mariadb-10.3 with Buster backports upgrade: - ${WORKING_DIR}/debug script: - *test-prepare-container - # Install everything MariaDB currently in Debian Buster + # Install everything MariaDB 10.3 currently in Debian Buster - apt-get install -y 'default-mysql*' 'mariadb-*' 'libmariadb*' # Verify installation of MariaDB from Buster - *test-verify-initial + # Buster backports is needed for liburing1 (>= 0.7) and galera-4 (>= 26.4) - *test-enable-buster-backports-repos - *test-install # mariadb-10.3 in Buster ships a /etc/init.d/mysql so it should continue to work @@ -345,34 +295,8 @@ mariadb-10.3 with Buster backports upgrade: variables: - $CI_COMMIT_TAG != null && $SALSA_CI_ENABLE_PIPELINE_ON_TAGS !~ /^(1|yes|true)$/ -mariadb-10.5 Bullseye to mariadb-10.6 upgrade: - stage: upgrade from Buster/Bullseye - needs: - - job: build - image: debian:bullseye - artifacts: - when: always - name: "$CI_BUILD_NAME" - paths: - - ${WORKING_DIR}/debug - script: - - *test-prepare-container - # Install everything MariaDB currently in Debian Bullseye - - apt-get install -y 'default-mysql*' 'mariadb-*' 'libmariadb*' - # Verify installation of MariaDB from Bullseye - - *test-verify-initial - - *test-enable-sid-repos - - *test-install - - service mariadb status # There is no init.d/mysql in MariaDB 10.5+ - - *test-verify-final - variables: - GIT_STRATEGY: none - except: - variables: - - $CI_COMMIT_TAG != null && $SALSA_CI_ENABLE_PIPELINE_ON_TAGS !~ /^(1|yes|true)$/ - -mariadb-10.3 Buster to mariadb-10.6 upgrade: - stage: upgrade from Buster/Bullseye +mariadb-10.3 Buster upgrade: + stage: upgrade from Buster needs: - job: build image: debian:buster @@ -383,11 +307,11 @@ mariadb-10.3 Buster to mariadb-10.6 upgrade: - ${WORKING_DIR}/debug script: - *test-prepare-container - # Install everything MariaDB currently in Debian Buster + # Install everything MariaDB 10.3 currently in Debian Buster - apt-get install -y 'default-mysql*' 'mariadb-*' 'libmariadb*' # Verify installation of MariaDB from Buster - *test-verify-initial - - *test-enable-sid-repos + - *test-enable-bullseye-repos - *test-install # mariadb-10.3 in Buster ships a /etc/init.d/mysql so it should continue to work - service mysql status @@ -503,41 +427,8 @@ build mariadbclient consumer Python-MySQLdb: variables: - $CI_COMMIT_TAG != null && $SALSA_CI_ENABLE_PIPELINE_ON_TAGS !~ /^(1|yes|true)$/ -libmysql* to libmariadb* upgrade: - stage: upgrade in Sid - needs: - - job: build - image: debian:${RELEASE} - artifacts: - when: always - name: "$CI_BUILD_NAME" - paths: - - ${WORKING_DIR}/debug - script: - - *test-prepare-container - # Install all libmysql* available in Debian unstable - - apt-get install -y pkg-config libmysqlclient-dev - - pkg-config --list-all - - pkg-config --cflags mysqlclient # mysqlclient.pc from original package - - apt-get install -y ./libmariadb3_*.deb ./mariadb-common_*.deb - - pkg-config --list-all - - apt-get install -y ./libmariadb-dev_*.deb - - pkg-config --list-all - - apt-get install -y ./libmariadb-dev-compat_*.deb - - pkg-config --cflags mysqlclient # mysqlclient.pc from compat package - - pkg-config --list-all - - apt-get install -y ./libmariadbd19_*.deb - - pkg-config --list-all - - apt-get install -y ./libmariadbd-dev_*.deb - - pkg-config --list-all - - apt-get install -y default-libmysqlclient-dev default-libmysqld-dev - - *test-verify-libs - except: - variables: - - $CI_COMMIT_TAG != null && $SALSA_CI_ENABLE_PIPELINE_ON_TAGS !~ /^(1|yes|true)$/ - -default-libmysqlclient-dev Sid upgrade: - stage: upgrade in Sid +default-libmysqlclient-dev Bullseye upgrade: + stage: upgrade in Bullseye needs: - job: build image: debian:${RELEASE} @@ -556,29 +447,8 @@ default-libmysqlclient-dev Sid upgrade: variables: - $CI_COMMIT_TAG != null && $SALSA_CI_ENABLE_PIPELINE_ON_TAGS !~ /^(1|yes|true)$/ -default-libmysqlclient-dev Bullseye upgrade: - stage: upgrade from Buster/Bullseye - needs: - - job: build - image: debian:bullseye - artifacts: - when: always - name: "$CI_BUILD_NAME" - paths: - - ${WORKING_DIR}/debug - script: - - *test-prepare-container - - apt-get install -y pkg-config default-libmysqlclient-dev - - pkg-config --list-all - - *test-enable-sid-repos - - *test-install-all-libs - - *test-verify-libs - except: - variables: - - $CI_COMMIT_TAG != null && $SALSA_CI_ENABLE_PIPELINE_ON_TAGS !~ /^(1|yes|true)$/ - default-libmysqlclient-dev Buster upgrade: - stage: upgrade from Buster/Bullseye + stage: upgrade from Buster needs: - job: build image: debian:buster @@ -591,28 +461,7 @@ default-libmysqlclient-dev Buster upgrade: - *test-prepare-container - apt-get install -y pkg-config default-libmysqlclient-dev - pkg-config --list-all - - *test-enable-sid-repos - - *test-install-all-libs - - *test-verify-libs - except: - variables: - - $CI_COMMIT_TAG != null && $SALSA_CI_ENABLE_PIPELINE_ON_TAGS !~ /^(1|yes|true)$/ - -default-libmysqlclient-dev with Bullseye backports upgrade: - stage: upgrade extras - needs: - - job: build bullseye-backports - image: debian:bullseye - artifacts: - when: always - name: "$CI_BUILD_NAME" - paths: - - ${WORKING_DIR}/debug - script: - - *test-prepare-container - - apt-get install -y pkg-config default-libmysqlclient-dev - - pkg-config --list-all - - *test-enable-bullseye-backports-repos + - *test-enable-bullseye-repos - *test-install-all-libs - *test-verify-libs except: @@ -640,51 +489,16 @@ default-libmysqlclient-dev with Buster backports upgrade: variables: - $CI_COMMIT_TAG != null && $SALSA_CI_ENABLE_PIPELINE_ON_TAGS !~ /^(1|yes|true)$/ -# Upgrading from MySQL 8.0 with datadir in place is not possible. Users need to do a data dump. -# The Debian maintainer scripts detect this situation and simply moves old datadir aside and start fresh. -mysql-8.0 Sid to mariadb-10.6 upgrade: - stage: upgrade in Sid - needs: - - job: build - image: debian:sid - artifacts: - when: always - name: "$CI_BUILD_NAME" - paths: - - ${WORKING_DIR}/debug - script: - - *test-prepare-container - # The postinst fails often if 'ps' is missing from system, so install procps - - apt-get install -y procps mysql-server 'libmysqlc*' - - *test-verify-initial - - *test-install - # Due to some (currently unknown) changes in MySQL 8.0 packaging or apt - # behaviour changes, a system with a previous installation of MySQL 8.0 will - # on upgrades to MariaDB first fully remove MySQL, including the - # /etc/init.d/mysql file, so previous techniques in - # mariadb-server-10.6.postinst to maintain backwards compatibility with - # 'service mysql status' after installing MariaDB on top MySQL no longer - # works. Thus the step to test it now intentionally has a fallback to use - # the service name 'mariadb' instead, and the fallback is always used. - - sleep 5 # Give the mysql_upgrade a bit of time to complete before querying the server - - service mysql status || service mariadb status - - *test-verify-final - variables: - GIT_STRATEGY: none - except: - variables: - - $CI_COMMIT_TAG != null && $SALSA_CI_ENABLE_PIPELINE_ON_TAGS !~ /^(1|yes|true)$/ - # Upgrading from MySQL 8.0 with datadir in place is not possible. Users need to do a data dump. # The Debian maintainer scripts detect this situation and simply moves old datadir aside and start fresh. # # Testing on Focal binaries on Buster works. Using Jammy binaries on Bullseye # does not work as libc in Jammy is too new. -mysql-8.0 from Ubuntu 22.04 with Bullseye backports upgrade: +mysql-8.0 from Ubuntu 22.04 upgrade: stage: upgrade extras needs: - - job: build bullseye-backports - image: debian:bullseye + - job: build + image: debian:${RELEASE} artifacts: when: always name: "$CI_BUILD_NAME" @@ -701,8 +515,6 @@ mysql-8.0 from Ubuntu 22.04 with Bullseye backports upgrade: - apt-get install -y mysql-server 'libmysqlc*' || true - sleep 10 && apt-get install -f - *test-verify-initial - # Enable backports to make galera-4 available - - echo "deb http://deb.debian.org/debian bullseye-backports main" > /etc/apt/sources.list.d/backports.list && apt-get update -qq - *test-install - service mysql status - sleep 5 # Give the mysql_upgrade a bit of time to complete before querying the server @@ -715,11 +527,11 @@ mysql-8.0 from Ubuntu 22.04 with Bullseye backports upgrade: # Upgrading from MySQL 8.0 with datadir in place is not possible. Users need to do a data dump. # The Debian maintainer scripts detect this situation and simply moves old datadir aside and start fresh. -mysql-community-cluster-8.0 from MySQL.com with Bullseye backports upgrade: +mysql-community-cluster-8.0 from MySQL.com upgrade: stage: upgrade extras needs: - - job: build bullseye-backports - image: debian:bullseye + - job: build + image: debian:${RELEASE} artifacts: when: always name: "$CI_BUILD_NAME" @@ -737,8 +549,6 @@ mysql-community-cluster-8.0 from MySQL.com with Bullseye backports upgrade: - dpkg -l | grep -iE 'maria|mysql|galera' - systemctl status mysql; mysql -e 'SELECT VERSION()' - systemctl stop mysql # Stop manually as maintainer scripts don't handle this with systemctl shim - # Enable backports to make galera-4 available - - echo "deb http://deb.debian.org/debian bullseye-backports main" > /etc/apt/sources.list.d/backports.list && apt-get update -qq - *test-install # Ignore systemctl shim result as MariaDB systemd file is incompatible with it and yields: # ERROR:systemctl:the ExecStartPre control process exited with error code @@ -787,7 +597,6 @@ mariadb.org-10.6 to mariadb-10.6 upgrade: variables: - $CI_COMMIT_TAG != null && $SALSA_CI_ENABLE_PIPELINE_ON_TAGS !~ /^(1|yes|true)$/ -# archive.mariadb.org for Debian Sid latest is 10.5.13 mariadb.org-10.5 to mariadb-10.6 upgrade: stage: upgrade extras needs: @@ -804,7 +613,6 @@ mariadb.org-10.5 to mariadb-10.6 upgrade: - curl -sS https://mariadb.org/mariadb_release_signing_key.asc -o /etc/apt/trusted.gpg.d/mariadb.asc - echo "deb https://archive.mariadb.org/mariadb-10.5/repo/debian ${RELEASE} main" > /etc/apt/sources.list.d/mariadb.list - apt-get update -qq - - *test-install-openssl1-in-sid-for-backwards-compat - apt-get install -y mariadb-server-10.5 - *test-verify-initial # Install MariaDB built in this commit @@ -819,12 +627,11 @@ mariadb.org-10.5 to mariadb-10.6 upgrade: variables: - $CI_COMMIT_TAG != null && $SALSA_CI_ENABLE_PIPELINE_ON_TAGS !~ /^(1|yes|true)$/ -# archive.mariadb.org for Debian Sid latest is 10.4.17 -mariadb.org-10.4 to mariadb-10.6 upgrade: +mariadb.org-10.4 to mariadb-10.6 with Buster backports upgrade: stage: upgrade extras needs: - - job: build - image: debian:${RELEASE} + - job: build buster-backports + image: debian:buster artifacts: when: always name: "$CI_BUILD_NAME" @@ -832,17 +639,17 @@ mariadb.org-10.4 to mariadb-10.6 upgrade: - ${WORKING_DIR}/debug script: - *test-prepare-container - - apt-get -qq install --no-install-recommends --yes ca-certificates curl systemctl # systemctl shim needed on platforms that don't have systemd + - apt-get -qq install --no-install-recommends --yes ca-certificates curl - curl -sS https://mariadb.org/mariadb_release_signing_key.asc -o /etc/apt/trusted.gpg.d/mariadb.asc - - echo "deb https://archive.mariadb.org/mariadb-10.4/repo/debian ${RELEASE} main" > /etc/apt/sources.list.d/mariadb.list + - echo "deb https://archive.mariadb.org/mariadb-10.4/repo/debian buster main" > /etc/apt/sources.list.d/mariadb.list - apt-get update -qq - - *test-install-readline-in-sid-for-backwards-compat - - *test-install-openssl1-in-sid-for-backwards-compat - apt-get install -y mariadb-server-10.4 # MariaDB.org version of 10.4 and early 10.5 do not install an init file, so # it must be installed here manually - cp /usr/share/mysql/mysql.init /etc/init.d/mysql; chmod +x /etc/init.d/mysql; service mysql start; sleep 5 - *test-verify-initial + # Buster backports is needed for liburing1 (>= 0.7) and galera-4 (>= 26.4) + - *test-enable-buster-backports-repos - *test-install - sleep 5 # Give the mysql_upgrade a bit of time to complete before querying the server - service mysql status @@ -854,12 +661,11 @@ mariadb.org-10.4 to mariadb-10.6 upgrade: variables: - $CI_COMMIT_TAG != null && $SALSA_CI_ENABLE_PIPELINE_ON_TAGS !~ /^(1|yes|true)$/ -# archive.mariadb.org for Debian Sid latest is 10.3.27 -mariadb.org-10.3 to mariadb-10.6 upgrade: +mariadb.org-10.3 to mariadb-10.6 with Buster backports upgrade: stage: upgrade extras needs: - - job: build - image: debian:${RELEASE} + - job: build buster-backports + image: debian:buster artifacts: when: always name: "$CI_BUILD_NAME" @@ -869,12 +675,12 @@ mariadb.org-10.3 to mariadb-10.6 upgrade: - *test-prepare-container - apt-get -qq install --no-install-recommends --yes ca-certificates curl - curl -sS https://mariadb.org/mariadb_release_signing_key.asc -o /etc/apt/trusted.gpg.d/mariadb.asc - - echo "deb https://archive.mariadb.org/mariadb-10.3/repo/debian ${RELEASE} main" > /etc/apt/sources.list.d/mariadb.list + - echo "deb https://archive.mariadb.org/mariadb-10.3/repo/debian buster main" > /etc/apt/sources.list.d/mariadb.list - apt-get update -qq - - *test-install-readline-in-sid-for-backwards-compat - - *test-install-openssl1-in-sid-for-backwards-compat - apt-get install -y mariadb-server-10.3 - *test-verify-initial + # Buster backports is needed for liburing1 (>= 0.7) and galera-4 (>= 26.4) + - *test-enable-buster-backports-repos - *test-install - service mysql status # Give the mariadb-upgrade plenty of time to complete, otherwise next commands @@ -887,52 +693,14 @@ mariadb.org-10.3 to mariadb-10.6 upgrade: variables: - $CI_COMMIT_TAG != null && $SALSA_CI_ENABLE_PIPELINE_ON_TAGS !~ /^(1|yes|true)$/ -# archive.mariadb.org for Debian Sid latest is 10.2.21 -mariadb.org-10.2 to mariadb-10.6 upgrade: +# archive.mariadb.org has for 10.2 only Stretch, so we can't test upgrades to +# 10.6 with only Buster and Bullseye builds + +mysql.com-5.7 upgrade: stage: upgrade extras needs: - job: build image: debian:${RELEASE} - artifacts: - when: always - name: "$CI_BUILD_NAME" - paths: - - ${WORKING_DIR}/debug - script: - - *test-prepare-container - - apt-get -qq install --no-install-recommends --yes ca-certificates curl - - curl -sS https://mariadb.org/mariadb_release_signing_key.asc -o /etc/apt/trusted.gpg.d/mariadb.asc - - echo "deb https://archive.mariadb.org/mariadb-10.2/repo/debian ${RELEASE} main" > /etc/apt/sources.list.d/mariadb.list - - apt-get update -qq - - *test-install-readline-in-sid-for-backwards-compat - - *test-install-openssl1-in-sid-for-backwards-compat - - apt-get install -y mariadb-server-10.2 - # Verify initial state before upgrade - - dpkg -l | grep -iE 'maria|mysql|galera' || true # List installed - - service mysql status - # prepending with --defaults-file=/etc/mysql/debian.cnf is needed in upstream 5.5–10.3 - - | - mysql --defaults-file=/etc/mysql/debian.cnf --skip-column-names -e "SELECT @@version, @@version_comment" - mysql --defaults-file=/etc/mysql/debian.cnf --table -e "SHOW DATABASES;" - mysql --defaults-file=/etc/mysql/debian.cnf --table -e "SELECT * FROM mysql.user; SHOW CREATE USER root@localhost;" - mysql --defaults-file=/etc/mysql/debian.cnf --table -e "SELECT * FROM mysql.plugin; SHOW PLUGINS;" - - *test-install - - service mysql status - # Give the mariadb-upgrade plenty of time to complete, otherwise next commands - # fail on non-existing mariadb.sys user - - sleep 15 - - *test-verify-final - variables: - GIT_STRATEGY: none - except: - variables: - - $CI_COMMIT_TAG != null && $SALSA_CI_ENABLE_PIPELINE_ON_TAGS !~ /^(1|yes|true)$/ - -mysql.com-5.7 with Bullseye backports upgrade: - stage: upgrade extras - needs: - - job: build bullseye-backports - image: debian:bullseye artifacts: when: always name: "$CI_BUILD_NAME" @@ -947,8 +715,6 @@ mysql.com-5.7 with Bullseye backports upgrade: apt-get update -qq apt-get install -y 'mysql*' 'libmysqlc*' - *test-verify-initial - # Enable backports to make galera-4 available - - echo "deb http://deb.debian.org/debian bullseye-backports main" >> /etc/apt/sources.list.d/backports.list && apt-get update -qq - *test-install # Due to some (currently unknown) changes in MySQL 5.7 packaging or apt # behaviour changes, a system with a previous installation of MySQL will @@ -968,11 +734,11 @@ mysql.com-5.7 with Bullseye backports upgrade: variables: - $CI_COMMIT_TAG != null && $SALSA_CI_ENABLE_PIPELINE_ON_TAGS !~ /^(1|yes|true)$/ -percona-xtradb-5.7 with bullseye backports upgrade: +percona-xtradb-5.7 upgrade: stage: upgrade extras needs: - - job: build bullseye-backports - image: debian:bullseye + - job: build + image: debian:${RELEASE} artifacts: when: always name: "$CI_BUILD_NAME" @@ -983,13 +749,11 @@ percona-xtradb-5.7 with bullseye backports upgrade: - | apt-get install --no-install-recommends --yes gpg gpg-agent dirmngr ca-certificates # Bare minimal (<4MB) for apt-key to work apt-key adv --recv-keys --keyserver hkps://keyserver.ubuntu.com:443 9334A25F8507EFA5 - echo "deb https://repo.percona.com/apt/ bullseye main" > /etc/apt/sources.list.d/mysql.list + echo "deb https://repo.percona.com/apt/ ${RELEASE} main" > /etc/apt/sources.list.d/mysql.list apt-get update -qq apt-get install -y percona-xtradb-cluster-full-57 percona-xtrabackup-24 percona-toolkit pmm2-client - service mysql status - *test-verify-initial - # Enable backports to make galera-4 available - - echo "deb http://deb.debian.org/debian bullseye-backports main" >> /etc/apt/sources.list.d/backports.list && apt-get update -qq - *test-install - service mysql status - sleep 15 # Give the mysql_upgrade a bit of extra time to complete with MySQL 5.7 before querying the server From 18342cd5e1ba4bd8a9547844e0309f288dc939a4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Otto=20Kek=C3=A4l=C3=A4inen?= Date: Sat, 25 Mar 2023 14:06:20 -0700 Subject: [PATCH 75/92] Deb: Add missing installation step to Salsa-CI job for 10.5 upgrades Add vital missing step to MariaDB 10.5 upgrade job to actually install the new binary being built. Without this the test was happily passing all the time but actually not testing the upgrade. Also stop using oneliner syntax for the install step to make the debugging of failing installs/upgrades from build logs easier. NOTE TO MERGERS: This commit is made on 10.6 branch and can be merged to all later branches (10.7, 10.8, ..., 11.0). If/when some jobs break, they will be fixed per branch on follow-up commits. --- debian/salsa-ci.yml | 13 +++++-------- 1 file changed, 5 insertions(+), 8 deletions(-) diff --git a/debian/salsa-ci.yml b/debian/salsa-ci.yml index c7ca3613fd38f..918d5e0711d7a 100644 --- a/debian/salsa-ci.yml +++ b/debian/salsa-ci.yml @@ -155,12 +155,12 @@ blhc: EOF apt-get update -qq -.test-install: &test-install | +.test-install: &test-install # Install MariaDB built in this commit - apt-get install -y ./*.deb + - apt-get install -y ./*.deb # Verify installation of MariaDB built in this commit - dpkg -l | grep -iE 'maria|mysql|galera' || true # List installed - mariadb --version # Client version + - dpkg -l | grep -iE 'maria|mysql|galera' || true # List installed + - mariadb --version # Client version .test-verify-final: &test-verify-final | mkdir -p debug # Ensure dir exists before using it @@ -615,10 +615,7 @@ mariadb.org-10.5 to mariadb-10.6 upgrade: - apt-get update -qq - apt-get install -y mariadb-server-10.5 - *test-verify-initial - # Install MariaDB built in this commit - # Verify installation of MariaDB built in this commit - - dpkg -l | grep -iE 'maria|mysql|galera' || true # List installed - - mariadb --version # Client version + - *test-install - service mariadb status # There is no init.d/mysql in MariaDB 10.5+ - *test-verify-final variables: From da73db2382d6cfaaa74fe5c37e7df18aa2d44238 Mon Sep 17 00:00:00 2001 From: Lorna Luo Date: Mon, 13 Mar 2023 17:27:28 -0400 Subject: [PATCH 76/92] Make 'move_file' command more reliable in mysqltest The tests innodb.import_tablespace_race, innodn.restart, and innodb.innodb-wl5522 move the tablespace file between the data directory and the tmp directory specified by global environment variables. However this is risky because it's not unusual that the set tmp directory (often under /tmp) is mounted on another disk partition or device, and 'move_file' command may fail with "Errcode: 18 'Invalid cross-device link.'" To stabilize mysqltest in the described scenario, and prevent such behavior in the future, let make_file() check both from file path and to file path and make sure they are either both under MYSQLTEST_VARDIR or MYSQL_TMP_DIR. All new code of the whole pull request, including one or several files that are either new files or modified ones, are contributed under the BSD-new license. I am contributing on behalf of my employer Amazon Web Services, Inc. --- client/mysqltest.cc | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) diff --git a/client/mysqltest.cc b/client/mysqltest.cc index 214b7542374f2..6330d4f881d7b 100644 --- a/client/mysqltest.cc +++ b/client/mysqltest.cc @@ -3814,9 +3814,21 @@ void do_move_file(struct st_command *command) sizeof(move_file_args)/sizeof(struct command_arg), ' '); - if (bad_path(ds_to_file.str)) - DBUG_VOID_RETURN; + size_t from_plen = strlen(ds_from_file.str); + size_t to_plen = strlen(ds_to_file.str); + const char *vardir= getenv("MYSQLTEST_VARDIR"); + const char *tmpdir= getenv("MYSQL_TMP_DIR"); + if (!((is_sub_path(ds_from_file.str, from_plen, vardir) && + is_sub_path(ds_to_file.str, to_plen, vardir)) || + (is_sub_path(ds_from_file.str, from_plen, tmpdir) && + is_sub_path(ds_to_file.str, to_plen, tmpdir)))) { + report_or_die("Paths '%s' and '%s' are not both under MYSQLTEST_VARDIR '%s'" + "or both under MYSQL_TMP_DIR '%s'", + ds_from_file, ds_to_file, vardir, tmpdir); + DBUG_VOID_RETURN; + } + DBUG_PRINT("info", ("Move %s to %s", ds_from_file.str, ds_to_file.str)); error= (my_rename(ds_from_file.str, ds_to_file.str, MYF(disable_warnings ? 0 : MY_WME)) != 0); From 0cc1694e9c7481b59d372af7f759bb0bcf552bfa Mon Sep 17 00:00:00 2001 From: Lorna Luo Date: Fri, 31 Mar 2023 19:17:56 +0000 Subject: [PATCH 77/92] Make 'move_file' command more reliable in 3 innodb tests The tests innodb.import_tablespace_race, innodn.restart, and innodb.innodb-wl5522 move the tablespace file between the data directory and the tmp directory specified by global environment variables. However this is risky because it's not unusual that the set tmp directory (often under /tmp) is mounted on another disk partition or device, and 'move_file' command may fail with "Errcode: 18 'Invalid cross-device link.'" For innodb.import_tablespace_race and innodb.innodb-wl5522, moving files across directories is not necessary. Modify the tests so they rename files under the same directory. For innodb.restart, instead of moving between datadir and MYSQL_TMPDIR, move the files under MYSQLTEST_VARDIR. All new code of the whole pull request, including one or several files that are either new files or modified ones, are contributed under the BSD-new license. I am contributing on behalf of my employer Amazon Web Services, Inc. --- .../suite/innodb/r/innodb-wl5522.result | 14 +++++++++++ .../innodb/t/import_tablespace_race.test | 8 +++---- mysql-test/suite/innodb/t/innodb-wl5522.test | 21 ++++++++--------- mysql-test/suite/innodb/t/restart.test | 23 ++++++++++--------- 4 files changed, 40 insertions(+), 26 deletions(-) diff --git a/mysql-test/suite/innodb/r/innodb-wl5522.result b/mysql-test/suite/innodb/r/innodb-wl5522.result index b3bc42ee3d854..c44443a35af58 100644 --- a/mysql-test/suite/innodb/r/innodb-wl5522.result +++ b/mysql-test/suite/innodb/r/innodb-wl5522.result @@ -63,16 +63,24 @@ a b c # Done restarting server # List before t1 DISCARD db.opt +t1.cfg.sav t1.frm t1.ibd +t1.ibd.sav +t2.cfg.sav t2.frm t2.ibd +t2.ibd.sav ALTER TABLE t1 DISCARD TABLESPACE; # List after t1 DISCARD db.opt +t1.cfg.sav t1.frm +t1.ibd.sav +t2.cfg.sav t2.frm t2.ibd +t2.ibd.sav ALTER TABLE t1 IMPORT TABLESPACE; ALTER TABLE t1 ENGINE InnoDB; SELECT COUNT(*) FROM t1; @@ -90,10 +98,14 @@ a b c 638 Cavalry ..asdasdfaeraf db.opt t1.cfg +t1.cfg.sav t1.frm t1.ibd +t1.ibd.sav +t2.cfg.sav t2.frm t2.ibd +t2.ibd.sav SELECT COUNT(*) FROM t1; COUNT(*) 640 @@ -112,7 +124,9 @@ ALTER TABLE t2 ROW_FORMAT=DYNAMIC; ALTER TABLE t2 DISCARD TABLESPACE; # List after t2 DISCARD db.opt +t2.cfg.sav t2.frm +t2.ibd.sav ALTER TABLE t2 IMPORT TABLESPACE; ERROR HY000: Schema mismatch (Table flags don't match, server table has 0x21 and the meta-data file has 0x1; .cfg file uses ROW_FORMAT=COMPACT) ALTER TABLE t2 IMPORT TABLESPACE; diff --git a/mysql-test/suite/innodb/t/import_tablespace_race.test b/mysql-test/suite/innodb/t/import_tablespace_race.test index 532c2684ddecf..4540834cf7574 100644 --- a/mysql-test/suite/innodb/t/import_tablespace_race.test +++ b/mysql-test/suite/innodb/t/import_tablespace_race.test @@ -36,8 +36,8 @@ ALTER TABLE t NOWAIT ADD INDEX (c); FLUSH TABLE t FOR EXPORT; --let $create= query_get_value(SHOW CREATE TABLE t, Create Table, 1) ---copy_file $datadir/test/t.cfg $MYSQL_TMP_DIR/t.cfg ---copy_file $datadir/test/t.ibd $MYSQL_TMP_DIR/t.ibd +--copy_file $datadir/test/t.cfg $datadir/test/t.cfg.sav +--copy_file $datadir/test/t.ibd $datadir/test/t.ibd.sav UNLOCK TABLES; DROP TABLE t; @@ -46,8 +46,8 @@ eval $create; --enable_query_log ALTER TABLE t DISCARD TABLESPACE; ---move_file $MYSQL_TMP_DIR/t.cfg $datadir/test/t.cfg ---move_file $MYSQL_TMP_DIR/t.ibd $datadir/test/t.ibd +--move_file $datadir/test/t.cfg.sav $datadir/test/t.cfg +--move_file $datadir/test/t.ibd.sav $datadir/test/t.ibd ALTER TABLE t IMPORT TABLESPACE; # Cleanup diff --git a/mysql-test/suite/innodb/t/innodb-wl5522.test b/mysql-test/suite/innodb/t/innodb-wl5522.test index 47ea432540370..1a55d9d2da0ab 100644 --- a/mysql-test/suite/innodb/t/innodb-wl5522.test +++ b/mysql-test/suite/innodb/t/innodb-wl5522.test @@ -9,7 +9,6 @@ call mtr.add_suppression("InnoDB: Unable to import tablespace .* because it alre call mtr.add_suppression("Index for table 't2' is corrupt; try to repair it"); FLUSH TABLES; -let $MYSQLD_TMPDIR = `SELECT @@tmpdir`; let $MYSQLD_DATADIR = `SELECT @@datadir`; let $checksum_algorithm = `SELECT @@innodb_checksum_algorithm`; @@ -39,10 +38,10 @@ CREATE TABLE t2(a INT PRIMARY KEY) ENGINE=InnoDB ROW_FORMAT=COMPACT; FLUSH TABLE t1, t2 FOR EXPORT; --echo # List before copying files --list_files $MYSQLD_DATADIR/test ---copy_file $MYSQLD_DATADIR/test/t1.cfg $MYSQLD_TMPDIR/t1.cfg ---copy_file $MYSQLD_DATADIR/test/t1.ibd $MYSQLD_TMPDIR/t1.ibd ---move_file $MYSQLD_DATADIR/test/t2.cfg $MYSQLD_TMPDIR/t2.cfg ---copy_file $MYSQLD_DATADIR/test/t2.ibd $MYSQLD_TMPDIR/t2.ibd +--copy_file $MYSQLD_DATADIR/test/t1.cfg $MYSQLD_DATADIR/test/t1.cfg.sav +--copy_file $MYSQLD_DATADIR/test/t1.ibd $MYSQLD_DATADIR/test/t1.ibd.sav +--move_file $MYSQLD_DATADIR/test/t2.cfg $MYSQLD_DATADIR/test/t2.cfg.sav +--copy_file $MYSQLD_DATADIR/test/t2.ibd $MYSQLD_DATADIR/test/t2.ibd.sav UNLOCK TABLES; INSERT INTO t1 (b, c) SELECT b,c FROM t1 ORDER BY a; SELECT COUNT(*) FROM t1; @@ -56,8 +55,8 @@ SELECT * FROM t1 ORDER BY a DESC LIMIT 3; ALTER TABLE t1 DISCARD TABLESPACE; --echo # List after t1 DISCARD --list_files $MYSQLD_DATADIR/test ---copy_file $MYSQLD_TMPDIR/t1.cfg $MYSQLD_DATADIR/test/t1.cfg ---copy_file $MYSQLD_TMPDIR/t1.ibd $MYSQLD_DATADIR/test/t1.ibd +--copy_file $MYSQLD_DATADIR/test/t1.cfg.sav $MYSQLD_DATADIR/test/t1.cfg +--copy_file $MYSQLD_DATADIR/test/t1.ibd.sav $MYSQLD_DATADIR/test/t1.ibd ALTER TABLE t1 IMPORT TABLESPACE; ALTER TABLE t1 ENGINE InnoDB; SELECT COUNT(*) FROM t1; @@ -68,15 +67,15 @@ SELECT COUNT(*) FROM t1; SELECT * FROM t1 ORDER BY b,a DESC LIMIT 3; SELECT * FROM t1 ORDER BY a DESC LIMIT 3; DROP TABLE t1; ---remove_file $MYSQLD_TMPDIR/t1.cfg ---remove_file $MYSQLD_TMPDIR/t1.ibd +--remove_file $MYSQLD_DATADIR/test/t1.cfg.sav +--remove_file $MYSQLD_DATADIR/test/t1.ibd.sav ALTER TABLE t2 ROW_FORMAT=DYNAMIC; ALTER TABLE t2 DISCARD TABLESPACE; --echo # List after t2 DISCARD --list_files $MYSQLD_DATADIR/test ---move_file $MYSQLD_TMPDIR/t2.ibd $MYSQLD_DATADIR/test/t2.ibd ---move_file $MYSQLD_TMPDIR/t2.cfg $MYSQLD_DATADIR/test/t2.cfg +--move_file $MYSQLD_DATADIR/test/t2.ibd.sav $MYSQLD_DATADIR/test/t2.ibd +--move_file $MYSQLD_DATADIR/test/t2.cfg.sav $MYSQLD_DATADIR/test/t2.cfg --error ER_TABLE_SCHEMA_MISMATCH ALTER TABLE t2 IMPORT TABLESPACE; --remove_file $MYSQLD_DATADIR/test/t2.cfg diff --git a/mysql-test/suite/innodb/t/restart.test b/mysql-test/suite/innodb/t/restart.test index 3e726c971abf4..859d932598541 100644 --- a/mysql-test/suite/innodb/t/restart.test +++ b/mysql-test/suite/innodb/t/restart.test @@ -4,6 +4,7 @@ let datadir= `select @@datadir`; let page_size= `select @@innodb_page_size`; +let tmp_in_vardir=$MYSQLTEST_VARDIR/tmp; --echo # --echo # MDEV-15333 MariaDB (still) slow start @@ -28,19 +29,19 @@ call mtr.add_suppression("\\[Warning\\] InnoDB: Ignoring tablespace for `test`\\ CREATE TABLE tr(a INT)ENGINE=InnoDB ROW_FORMAT=REDUNDANT; CREATE TABLE tc(a INT)ENGINE=InnoDB ROW_FORMAT=COMPACT PAGE_COMPRESSED=1 PAGE_COMPRESSION_LEVEL=9; ---replace_result $MYSQL_TMP_DIR MYSQL_TMP_DIR +--replace_result $tmp_in_vardir MYSQL_TMP_DIR eval CREATE TABLE td(a INT)ENGINE=InnoDB ROW_FORMAT=DYNAMIC -STATS_PERSISTENT=0 DATA DIRECTORY='$MYSQL_TMP_DIR'; +STATS_PERSISTENT=0 DATA DIRECTORY='$tmp_in_vardir'; --source include/shutdown_mysqld.inc --move_file $datadir/test/tr.ibd $datadir/test/tr0.ibd --move_file $datadir/test/tc.ibd $datadir/test/tc0.ibd ---move_file $MYSQL_TMP_DIR/test/td.ibd $datadir/test/td0.ibd +--move_file $tmp_in_vardir/test/td.ibd $datadir/test/td0.ibd # TODO: test that MariaDB does not even attempt to open the files #--mkdir $datadir/test/tr.ibd #--mkdir $datadir/test/tc.ibd -#--mkdir $MYSQL_TMP_DIR/test/td.ibd +#--mkdir $tmp_in_vardir/test/td.ibd perl; die unless open OUT, ">", "$ENV{datadir}/test/tr.ibd"; @@ -49,7 +50,7 @@ close OUT or die; die unless open OUT, ">", "$ENV{datadir}/test/tc.ibd"; print OUT "bar " x $ENV{page_size}; close OUT or die; -die unless open OUT, ">", "$ENV{MYSQL_TMP_DIR}/test/td.ibd"; +die unless open OUT, ">", "$ENV{tmp_in_vardir}/test/td.ibd"; print OUT "Xyz " x $ENV{page_size}; close OUT or die; EOF @@ -67,14 +68,14 @@ AND support IN ('YES', 'DEFAULT', 'ENABLED'); # TODO: test that MariaDB does not even attempt to open the files #--rmdir $datadir/test/tr.ibd #--rmdir $datadir/test/tc.ibd -#--rmdir $MYSQL_TMP_DIR/test/td.ibd +#--rmdir $tmp_in_vardir/test/td.ibd --remove_file $datadir/test/tr.ibd --remove_file $datadir/test/tc.ibd ---remove_file $MYSQL_TMP_DIR/test/td.ibd +--remove_file $tmp_in_vardir/test/td.ibd --move_file $datadir/test/tr0.ibd $datadir/test/tr.ibd --move_file $datadir/test/tc0.ibd $datadir/test/tc.ibd ---move_file $datadir/test/td0.ibd $MYSQL_TMP_DIR/test/td.ibd +--move_file $datadir/test/td0.ibd $tmp_in_vardir/test/td.ibd --source include/start_mysqld.inc SELECT * FROM tr; @@ -144,13 +145,13 @@ if ($MTR_COMBINATION_64K) } --error 1 -exec $MYSQLD --no-defaults --skip-networking --innodb_data_file_path=ibdata1:$ibdata_size --innodb-page-size=$page_size --datadir=$MYSQLD_DATADIR --log-error=$MYSQL_TMP_DIR/attempted_start.err; +exec $MYSQLD --no-defaults --skip-networking --innodb_data_file_path=ibdata1:$ibdata_size --innodb-page-size=$page_size --datadir=$MYSQLD_DATADIR --log-error=$tmp_in_vardir/attempted_start.err; -let SEARCH_FILE= $MYSQL_TMP_DIR/attempted_start.err; +let SEARCH_FILE= $tmp_in_vardir/attempted_start.err; let SEARCH_PATTERN= InnoDB: MySQL-8\.0 tablespace in \./ibdata1; source include/search_pattern_in_file.inc; ---remove_file $MYSQL_TMP_DIR/attempted_start.err +--remove_file $tmp_in_vardir/attempted_start.err --remove_file $MYSQLD_DATADIR/ibdata1 --move_file $MYSQLD_DATADIR/ibdata1.bak $MYSQLD_DATADIR/ibdata1 From 8020b1bd735c686818f1563e2c2317e263d5bd3a Mon Sep 17 00:00:00 2001 From: Alexander Barkov Date: Fri, 31 Mar 2023 17:20:03 +0400 Subject: [PATCH 78/92] MDEV-30034 UNIQUE USING HASH accepts duplicate entries for tricky collations - Adding a new argument "flag" to MY_COLLATION_HANDLER::strnncollsp_nchars() and a flag MY_STRNNCOLLSP_NCHARS_EMULATE_TRIMMED_TRAILING_SPACES. The flag defines if strnncollsp_nchars() should emulate trailing spaces which were possibly trimmed earlier (e.g. in InnoDB CHAR compression). This is important for NOPAD collations. For example, with this input: - str1= 'a ' (Latin letter a followed by one space) - str2= 'a ' (Latin letter a followed by two spaces) - nchars= 3 if the flag is given, strnncollsp_nchars() will virtually restore one trailing space to str1 up to nchars (3) characters and compare two strings as equal: - str1= 'a ' (one extra trailing space emulated) - str2= 'a ' (as is) If the flag is not given, strnncollsp_nchars() does not add trailing virtual spaces, so in case of a NOPAD collation, str1 will be compared as less than str2 because it is shorter. - Field_string::cmp_prefix() now passes the new flag. Field_varstring::cmp_prefix() and Field_blob::cmp_prefix() do not pass the new flag. - The branch in cmp_whole_field() in storage/innobase/rem/rem0cmp.cc (which handles the CHAR data type) now also passed the new flag. - Fixing UCA collations to respect the new flag. Other collations are possibly also affected, however I had no success in making an SQL script demonstrating the problem. Other collations will be extended to respect this flags in a separate patch later. - Changing the meaning of the last parameter of Field::cmp_prefix() from "number of bytes" (internal length) to "number of characters" (user visible length). The code calling cmp_prefix() from handler.cc was wrong. After this change, the call in handler.cc became correct. The code calling cmp_prefix() from key_rec_cmp() in key.cc was adjusted according to this change. - Old strnncollsp_nchar() related tests in unittest/strings/strings-t.c now pass the new flag. A few new tests also were added, without the flag. --- include/m_ctype.h | 25 +- .../include/ctype_nopad_prefix_unique.inc | 85 ++++ mysql-test/main/ctype_utf8_uca.result | 148 ++++++ mysql-test/main/ctype_utf8_uca.test | 18 + .../suite/innodb/r/innodb_ctype_utf8.result | 98 ++++ .../suite/innodb/t/innodb_ctype_utf8.test | 12 + sql/field.cc | 21 +- sql/field.h | 9 +- sql/key.cc | 3 +- storage/innobase/rem/rem0cmp.cc | 3 +- strings/ctype-bin.c | 6 +- strings/ctype-simple.c | 3 +- strings/ctype-tis620.c | 3 +- strings/ctype-uca.inl | 27 +- strings/ctype.c | 6 +- strings/strcoll.inl | 3 +- strings/strings_def.h | 6 +- unittest/strings/strings-t.c | 420 +++++++++--------- 18 files changed, 659 insertions(+), 237 deletions(-) create mode 100644 mysql-test/include/ctype_nopad_prefix_unique.inc diff --git a/include/m_ctype.h b/include/m_ctype.h index 484cd0a657e11..96eea74d5baf9 100644 --- a/include/m_ctype.h +++ b/include/m_ctype.h @@ -248,6 +248,28 @@ extern MY_UNI_CTYPE my_uni_ctype[256]; #define MY_STRXFRM_REVERSE_LEVEL6 0x00200000 /* if reverse order for level6 */ #define MY_STRXFRM_REVERSE_SHIFT 16 +/* Flags to strnncollsp_nchars */ +/* + MY_STRNNCOLLSP_NCHARS_EMULATE_TRIMMED_TRAILING_SPACES - + defines if inside strnncollsp_nchars() + short strings should be virtually extended to "nchars" + characters by emulating trimmed trailing spaces. + + This flag is needed when comparing packed strings of the CHAR + data type, when trailing spaces are trimmed on storage (like in InnoDB), + however the actual values (after unpacking) will have those trailing + spaces. + + If this flag is passed, strnncollsp_nchars() performs both + truncating longer strings and extending shorter strings + to exactly "nchars". + + If this flag is not passed, strnncollsp_nchars() only truncates longer + strings to "nchars", but does not extend shorter strings to "nchars". +*/ +#define MY_STRNNCOLLSP_NCHARS_EMULATE_TRIMMED_TRAILING_SPACES 1 + + /* Collation IDs for MariaDB that should not conflict with MySQL. We reserve 256..511, because MySQL will most likely use this range @@ -383,7 +405,8 @@ struct my_collation_handler_st int (*strnncollsp_nchars)(CHARSET_INFO *, const uchar *str1, size_t len1, const uchar *str2, size_t len2, - size_t nchars); + size_t nchars, + uint flags); size_t (*strnxfrm)(CHARSET_INFO *, uchar *dst, size_t dstlen, uint nweights, const uchar *src, size_t srclen, uint flags); diff --git a/mysql-test/include/ctype_nopad_prefix_unique.inc b/mysql-test/include/ctype_nopad_prefix_unique.inc new file mode 100644 index 0000000000000..b25128e9fef17 --- /dev/null +++ b/mysql-test/include/ctype_nopad_prefix_unique.inc @@ -0,0 +1,85 @@ +--echo # +--echo # MDEV-30034 UNIQUE USING HASH accepts duplicate entries for tricky collations +--echo # + +# TEXT + +if (`SELECT UPPER(@@storage_engine) != 'MEMORY'`) +{ +EXECUTE IMMEDIATE REPLACE( + 'CREATE TABLE t1 ( ' + ' a TEXT COLLATE ,' + 'UNIQUE(a(3)))', + '', @@collation_connection); +SHOW CREATE TABLE t1; +INSERT INTO t1 VALUES ('ss '); +--error ER_DUP_ENTRY +INSERT INTO t1 VALUES (_utf8mb3 0xC39F20)/*SZ+SPACE*/; +DROP TABLE t1; + + +EXECUTE IMMEDIATE REPLACE( + 'CREATE TABLE t1 ( ' + ' a TEXT COLLATE ,' + 'UNIQUE(a(3)) USING HASH)', + '', @@collation_connection); +SHOW CREATE TABLE t1; +INSERT INTO t1 VALUES ('ss '); +--error ER_DUP_ENTRY +INSERT INTO t1 VALUES (_utf8mb3 0xC39F20)/*SZ+SPACE*/; +DROP TABLE t1; +} + + +# VARCHAR + +EXECUTE IMMEDIATE REPLACE( + 'CREATE TABLE t1 ( ' + ' a VARCHAR(2000) COLLATE ,' + 'UNIQUE(a(3)))', + '', @@collation_connection); +SHOW CREATE TABLE t1; +INSERT INTO t1 VALUES ('ss '); +--error ER_DUP_ENTRY +INSERT INTO t1 VALUES (_utf8mb3 0xC39F20)/*SZ+SPACE*/; +DROP TABLE t1; + + +EXECUTE IMMEDIATE REPLACE( + 'CREATE TABLE t1 ( ' + ' a VARCHAR(2000) COLLATE ,' + 'UNIQUE(a(3)) USING HASH)', + '', @@collation_connection); +SHOW CREATE TABLE t1; +INSERT INTO t1 VALUES ('ss '); +--error ER_DUP_ENTRY +INSERT INTO t1 VALUES (_utf8mb3 0xC39F20)/*SZ+SPACE*/; +DROP TABLE t1; + +# CHAR + +# MyISAM is buggy on CHAR+BTREE+UNIQUE+PREFIX (see MDEV-30048), disable for now +# Other engines work fine + +if (`SELECT UPPER(@@storage_engine) != 'MYISAM'`) +{ +EXECUTE IMMEDIATE REPLACE( + 'CREATE TABLE t1 ( ' + ' a CHAR(20) COLLATE ,' + 'UNIQUE(a(3)))', + '', @@collation_connection); +SHOW CREATE TABLE t1; +INSERT INTO t1 VALUES ('ss '); +INSERT INTO t1 VALUES (_utf8mb3 0xC39F20)/*SZ+SPACE*/; +DROP TABLE t1; +} + +EXECUTE IMMEDIATE REPLACE( + 'CREATE TABLE t1 ( ' + ' a CHAR(20) COLLATE ,' + 'UNIQUE(a(3)) USING HASH)', + '', @@collation_connection); +SHOW CREATE TABLE t1; +INSERT INTO t1 VALUES ('ss '); +INSERT INTO t1 VALUES (_utf8mb3 0xC39F20)/*SZ+SPACE*/; +DROP TABLE t1; diff --git a/mysql-test/main/ctype_utf8_uca.result b/mysql-test/main/ctype_utf8_uca.result index bf4e5ed2fd87f..2e22097e6ac1f 100644 --- a/mysql-test/main/ctype_utf8_uca.result +++ b/mysql-test/main/ctype_utf8_uca.result @@ -761,3 +761,151 @@ DROP TABLE case_folding; # # End of 10.3 tests # +# +# Start of 10.4 tests +# +SET STORAGE_ENGINE=MyISAM; +SET NAMES utf8mb3 COLLATE utf8mb3_unicode_nopad_ci; +# +# MDEV-30034 UNIQUE USING HASH accepts duplicate entries for tricky collations +# +EXECUTE IMMEDIATE REPLACE( +'CREATE TABLE t1 ( ' + ' a TEXT COLLATE ,' + 'UNIQUE(a(3)))', +'', @@collation_connection); +SHOW CREATE TABLE t1; +Table Create Table +t1 CREATE TABLE `t1` ( + `a` text CHARACTER SET utf8 COLLATE utf8_unicode_nopad_ci DEFAULT NULL, + UNIQUE KEY `a` (`a`(3)) +) ENGINE=MyISAM DEFAULT CHARSET=latin1 COLLATE=latin1_swedish_ci +INSERT INTO t1 VALUES ('ss '); +INSERT INTO t1 VALUES (_utf8mb3 0xC39F20)/*SZ+SPACE*/; +ERROR 23000: Duplicate entry 'ß ' for key 'a' +DROP TABLE t1; +EXECUTE IMMEDIATE REPLACE( +'CREATE TABLE t1 ( ' + ' a TEXT COLLATE ,' + 'UNIQUE(a(3)) USING HASH)', +'', @@collation_connection); +SHOW CREATE TABLE t1; +Table Create Table +t1 CREATE TABLE `t1` ( + `a` text CHARACTER SET utf8 COLLATE utf8_unicode_nopad_ci DEFAULT NULL, + UNIQUE KEY `a` (`a`(3)) USING HASH +) ENGINE=MyISAM DEFAULT CHARSET=latin1 COLLATE=latin1_swedish_ci +INSERT INTO t1 VALUES ('ss '); +INSERT INTO t1 VALUES (_utf8mb3 0xC39F20)/*SZ+SPACE*/; +ERROR 23000: Duplicate entry 'ß ' for key 'a' +DROP TABLE t1; +EXECUTE IMMEDIATE REPLACE( +'CREATE TABLE t1 ( ' + ' a VARCHAR(2000) COLLATE ,' + 'UNIQUE(a(3)))', +'', @@collation_connection); +SHOW CREATE TABLE t1; +Table Create Table +t1 CREATE TABLE `t1` ( + `a` varchar(2000) CHARACTER SET utf8 COLLATE utf8_unicode_nopad_ci DEFAULT NULL, + UNIQUE KEY `a` (`a`(3)) +) ENGINE=MyISAM DEFAULT CHARSET=latin1 COLLATE=latin1_swedish_ci +INSERT INTO t1 VALUES ('ss '); +INSERT INTO t1 VALUES (_utf8mb3 0xC39F20)/*SZ+SPACE*/; +ERROR 23000: Duplicate entry 'ß ' for key 'a' +DROP TABLE t1; +EXECUTE IMMEDIATE REPLACE( +'CREATE TABLE t1 ( ' + ' a VARCHAR(2000) COLLATE ,' + 'UNIQUE(a(3)) USING HASH)', +'', @@collation_connection); +SHOW CREATE TABLE t1; +Table Create Table +t1 CREATE TABLE `t1` ( + `a` varchar(2000) CHARACTER SET utf8 COLLATE utf8_unicode_nopad_ci DEFAULT NULL, + UNIQUE KEY `a` (`a`(3)) USING HASH +) ENGINE=MyISAM DEFAULT CHARSET=latin1 COLLATE=latin1_swedish_ci +INSERT INTO t1 VALUES ('ss '); +INSERT INTO t1 VALUES (_utf8mb3 0xC39F20)/*SZ+SPACE*/; +ERROR 23000: Duplicate entry 'ß ' for key 'a' +DROP TABLE t1; +EXECUTE IMMEDIATE REPLACE( +'CREATE TABLE t1 ( ' + ' a CHAR(20) COLLATE ,' + 'UNIQUE(a(3)) USING HASH)', +'', @@collation_connection); +SHOW CREATE TABLE t1; +Table Create Table +t1 CREATE TABLE `t1` ( + `a` char(20) CHARACTER SET utf8 COLLATE utf8_unicode_nopad_ci DEFAULT NULL, + UNIQUE KEY `a` (`a`(3)) USING HASH +) ENGINE=MyISAM DEFAULT CHARSET=latin1 COLLATE=latin1_swedish_ci +INSERT INTO t1 VALUES ('ss '); +INSERT INTO t1 VALUES (_utf8mb3 0xC39F20)/*SZ+SPACE*/; +DROP TABLE t1; +SET STORAGE_ENGINE=HEAP; +# +# MDEV-30034 UNIQUE USING HASH accepts duplicate entries for tricky collations +# +EXECUTE IMMEDIATE REPLACE( +'CREATE TABLE t1 ( ' + ' a VARCHAR(2000) COLLATE ,' + 'UNIQUE(a(3)))', +'', @@collation_connection); +SHOW CREATE TABLE t1; +Table Create Table +t1 CREATE TABLE `t1` ( + `a` varchar(2000) CHARACTER SET utf8 COLLATE utf8_unicode_nopad_ci DEFAULT NULL, + UNIQUE KEY `a` (`a`(3)) +) ENGINE=MEMORY DEFAULT CHARSET=latin1 COLLATE=latin1_swedish_ci +INSERT INTO t1 VALUES ('ss '); +INSERT INTO t1 VALUES (_utf8mb3 0xC39F20)/*SZ+SPACE*/; +ERROR 23000: Duplicate entry 'ß ' for key 'a' +DROP TABLE t1; +EXECUTE IMMEDIATE REPLACE( +'CREATE TABLE t1 ( ' + ' a VARCHAR(2000) COLLATE ,' + 'UNIQUE(a(3)) USING HASH)', +'', @@collation_connection); +SHOW CREATE TABLE t1; +Table Create Table +t1 CREATE TABLE `t1` ( + `a` varchar(2000) CHARACTER SET utf8 COLLATE utf8_unicode_nopad_ci DEFAULT NULL, + UNIQUE KEY `a` (`a`(3)) USING HASH +) ENGINE=MEMORY DEFAULT CHARSET=latin1 COLLATE=latin1_swedish_ci +INSERT INTO t1 VALUES ('ss '); +INSERT INTO t1 VALUES (_utf8mb3 0xC39F20)/*SZ+SPACE*/; +ERROR 23000: Duplicate entry 'ß ' for key 'a' +DROP TABLE t1; +EXECUTE IMMEDIATE REPLACE( +'CREATE TABLE t1 ( ' + ' a CHAR(20) COLLATE ,' + 'UNIQUE(a(3)))', +'', @@collation_connection); +SHOW CREATE TABLE t1; +Table Create Table +t1 CREATE TABLE `t1` ( + `a` char(20) CHARACTER SET utf8 COLLATE utf8_unicode_nopad_ci DEFAULT NULL, + UNIQUE KEY `a` (`a`(3)) +) ENGINE=MEMORY DEFAULT CHARSET=latin1 COLLATE=latin1_swedish_ci +INSERT INTO t1 VALUES ('ss '); +INSERT INTO t1 VALUES (_utf8mb3 0xC39F20)/*SZ+SPACE*/; +DROP TABLE t1; +EXECUTE IMMEDIATE REPLACE( +'CREATE TABLE t1 ( ' + ' a CHAR(20) COLLATE ,' + 'UNIQUE(a(3)) USING HASH)', +'', @@collation_connection); +SHOW CREATE TABLE t1; +Table Create Table +t1 CREATE TABLE `t1` ( + `a` char(20) CHARACTER SET utf8 COLLATE utf8_unicode_nopad_ci DEFAULT NULL, + UNIQUE KEY `a` (`a`(3)) USING HASH +) ENGINE=MEMORY DEFAULT CHARSET=latin1 COLLATE=latin1_swedish_ci +INSERT INTO t1 VALUES ('ss '); +INSERT INTO t1 VALUES (_utf8mb3 0xC39F20)/*SZ+SPACE*/; +DROP TABLE t1; +SET STORAGE_ENGINE=DEFAULT; +# +# End of 10.4 tests +# diff --git a/mysql-test/main/ctype_utf8_uca.test b/mysql-test/main/ctype_utf8_uca.test index 38bcce8f4bacf..255390b5ce5f0 100644 --- a/mysql-test/main/ctype_utf8_uca.test +++ b/mysql-test/main/ctype_utf8_uca.test @@ -50,3 +50,21 @@ SET NAMES utf8mb3 COLLATE utf8mb3_thai_520_w2; --echo # --echo # End of 10.3 tests --echo # + + +--echo # +--echo # Start of 10.4 tests +--echo # + +SET STORAGE_ENGINE=MyISAM; +SET NAMES utf8mb3 COLLATE utf8mb3_unicode_nopad_ci; +--source include/ctype_nopad_prefix_unique.inc + +SET STORAGE_ENGINE=HEAP; +--source include/ctype_nopad_prefix_unique.inc + +SET STORAGE_ENGINE=DEFAULT; + +--echo # +--echo # End of 10.4 tests +--echo # diff --git a/mysql-test/suite/innodb/r/innodb_ctype_utf8.result b/mysql-test/suite/innodb/r/innodb_ctype_utf8.result index 3b0fb4150562e..ab193db6e7510 100644 --- a/mysql-test/suite/innodb/r/innodb_ctype_utf8.result +++ b/mysql-test/suite/innodb/r/innodb_ctype_utf8.result @@ -283,3 +283,101 @@ DROP TABLE t1; # # End of 10.2 tests # +# +# Start of 10.4 tests +# +SET NAMES utf8mb3 COLLATE utf8mb3_unicode_nopad_ci; +# +# MDEV-30034 UNIQUE USING HASH accepts duplicate entries for tricky collations +# +EXECUTE IMMEDIATE REPLACE( +'CREATE TABLE t1 ( ' + ' a TEXT COLLATE ,' + 'UNIQUE(a(3)))', +'', @@collation_connection); +SHOW CREATE TABLE t1; +Table Create Table +t1 CREATE TABLE `t1` ( + `a` text CHARACTER SET utf8 COLLATE utf8_unicode_nopad_ci DEFAULT NULL, + UNIQUE KEY `a` (`a`(3)) +) ENGINE=InnoDB DEFAULT CHARSET=latin1 COLLATE=latin1_swedish_ci +INSERT INTO t1 VALUES ('ss '); +INSERT INTO t1 VALUES (_utf8mb3 0xC39F20)/*SZ+SPACE*/; +ERROR 23000: Duplicate entry 'ß ' for key 'a' +DROP TABLE t1; +EXECUTE IMMEDIATE REPLACE( +'CREATE TABLE t1 ( ' + ' a TEXT COLLATE ,' + 'UNIQUE(a(3)) USING HASH)', +'', @@collation_connection); +SHOW CREATE TABLE t1; +Table Create Table +t1 CREATE TABLE `t1` ( + `a` text CHARACTER SET utf8 COLLATE utf8_unicode_nopad_ci DEFAULT NULL, + UNIQUE KEY `a` (`a`(3)) USING HASH +) ENGINE=InnoDB DEFAULT CHARSET=latin1 COLLATE=latin1_swedish_ci +INSERT INTO t1 VALUES ('ss '); +INSERT INTO t1 VALUES (_utf8mb3 0xC39F20)/*SZ+SPACE*/; +ERROR 23000: Duplicate entry 'ß ' for key 'a' +DROP TABLE t1; +EXECUTE IMMEDIATE REPLACE( +'CREATE TABLE t1 ( ' + ' a VARCHAR(2000) COLLATE ,' + 'UNIQUE(a(3)))', +'', @@collation_connection); +SHOW CREATE TABLE t1; +Table Create Table +t1 CREATE TABLE `t1` ( + `a` varchar(2000) CHARACTER SET utf8 COLLATE utf8_unicode_nopad_ci DEFAULT NULL, + UNIQUE KEY `a` (`a`(3)) +) ENGINE=InnoDB DEFAULT CHARSET=latin1 COLLATE=latin1_swedish_ci +INSERT INTO t1 VALUES ('ss '); +INSERT INTO t1 VALUES (_utf8mb3 0xC39F20)/*SZ+SPACE*/; +ERROR 23000: Duplicate entry 'ß ' for key 'a' +DROP TABLE t1; +EXECUTE IMMEDIATE REPLACE( +'CREATE TABLE t1 ( ' + ' a VARCHAR(2000) COLLATE ,' + 'UNIQUE(a(3)) USING HASH)', +'', @@collation_connection); +SHOW CREATE TABLE t1; +Table Create Table +t1 CREATE TABLE `t1` ( + `a` varchar(2000) CHARACTER SET utf8 COLLATE utf8_unicode_nopad_ci DEFAULT NULL, + UNIQUE KEY `a` (`a`(3)) USING HASH +) ENGINE=InnoDB DEFAULT CHARSET=latin1 COLLATE=latin1_swedish_ci +INSERT INTO t1 VALUES ('ss '); +INSERT INTO t1 VALUES (_utf8mb3 0xC39F20)/*SZ+SPACE*/; +ERROR 23000: Duplicate entry 'ß ' for key 'a' +DROP TABLE t1; +EXECUTE IMMEDIATE REPLACE( +'CREATE TABLE t1 ( ' + ' a CHAR(20) COLLATE ,' + 'UNIQUE(a(3)))', +'', @@collation_connection); +SHOW CREATE TABLE t1; +Table Create Table +t1 CREATE TABLE `t1` ( + `a` char(20) CHARACTER SET utf8 COLLATE utf8_unicode_nopad_ci DEFAULT NULL, + UNIQUE KEY `a` (`a`(3)) +) ENGINE=InnoDB DEFAULT CHARSET=latin1 COLLATE=latin1_swedish_ci +INSERT INTO t1 VALUES ('ss '); +INSERT INTO t1 VALUES (_utf8mb3 0xC39F20)/*SZ+SPACE*/; +DROP TABLE t1; +EXECUTE IMMEDIATE REPLACE( +'CREATE TABLE t1 ( ' + ' a CHAR(20) COLLATE ,' + 'UNIQUE(a(3)) USING HASH)', +'', @@collation_connection); +SHOW CREATE TABLE t1; +Table Create Table +t1 CREATE TABLE `t1` ( + `a` char(20) CHARACTER SET utf8 COLLATE utf8_unicode_nopad_ci DEFAULT NULL, + UNIQUE KEY `a` (`a`(3)) USING HASH +) ENGINE=InnoDB DEFAULT CHARSET=latin1 COLLATE=latin1_swedish_ci +INSERT INTO t1 VALUES ('ss '); +INSERT INTO t1 VALUES (_utf8mb3 0xC39F20)/*SZ+SPACE*/; +DROP TABLE t1; +# +# End 10.4 tests +# diff --git a/mysql-test/suite/innodb/t/innodb_ctype_utf8.test b/mysql-test/suite/innodb/t/innodb_ctype_utf8.test index 105f771d8b33b..9bc6408e0e06c 100644 --- a/mysql-test/suite/innodb/t/innodb_ctype_utf8.test +++ b/mysql-test/suite/innodb/t/innodb_ctype_utf8.test @@ -23,3 +23,15 @@ let $coll_pad='utf8_bin'; --echo # --echo # End of 10.2 tests --echo # + + +--echo # +--echo # Start of 10.4 tests +--echo # + +SET NAMES utf8mb3 COLLATE utf8mb3_unicode_nopad_ci; +--source include/ctype_nopad_prefix_unique.inc + +--echo # +--echo # End 10.4 tests +--echo # diff --git a/sql/field.cc b/sql/field.cc index 2006f0e3096f4..14252033a0139 100644 --- a/sql/field.cc +++ b/sql/field.cc @@ -7435,7 +7435,8 @@ int Field_string::cmp(const uchar *a_ptr, const uchar *b_ptr) return field_charset->coll->strnncollsp_nchars(field_charset, a_ptr, field_length, b_ptr, field_length, - Field_string::char_length()); + Field_string::char_length(), + MY_STRNNCOLLSP_NCHARS_EMULATE_TRIMMED_TRAILING_SPACES); } @@ -7835,10 +7836,11 @@ int Field_varstring::cmp(const uchar *a_ptr, const uchar *b_ptr) int Field_varstring::cmp_prefix(const uchar *a_ptr, const uchar *b_ptr, - size_t prefix_len) + size_t prefix_char_len) { - /* avoid expensive well_formed_char_length if possible */ - if (prefix_len == table->field[field_index]->field_length) + /* avoid more expensive strnncollsp_nchars() if possible */ + if (prefix_char_len * field_charset->mbmaxlen == + table->field[field_index]->field_length) return Field_varstring::cmp(a_ptr, b_ptr); size_t a_length, b_length; @@ -7858,7 +7860,8 @@ int Field_varstring::cmp_prefix(const uchar *a_ptr, const uchar *b_ptr, a_length, b_ptr + length_bytes, b_length, - prefix_len / field_charset->mbmaxlen); + prefix_char_len, + 0); } @@ -8635,7 +8638,7 @@ int Field_blob::cmp(const uchar *a_ptr, const uchar *b_ptr) int Field_blob::cmp_prefix(const uchar *a_ptr, const uchar *b_ptr, - size_t prefix_len) + size_t prefix_char_len) { uchar *blob1,*blob2; memcpy(&blob1, a_ptr+packlength, sizeof(char*)); @@ -8644,7 +8647,8 @@ int Field_blob::cmp_prefix(const uchar *a_ptr, const uchar *b_ptr, return field_charset->coll->strnncollsp_nchars(field_charset, blob1, a_len, blob2, b_len, - prefix_len / field_charset->mbmaxlen); + prefix_char_len, + 0); } @@ -10114,7 +10118,8 @@ my_decimal *Field_bit::val_decimal(my_decimal *deciaml_value) The a and b pointer must be pointers to the field in a record (not the table->record[0] necessarily) */ -int Field_bit::cmp_prefix(const uchar *a, const uchar *b, size_t prefix_len) +int Field_bit::cmp_prefix(const uchar *a, const uchar *b, + size_t prefix_char_len) { my_ptrdiff_t a_diff= a - ptr; my_ptrdiff_t b_diff= b - ptr; diff --git a/sql/field.h b/sql/field.h index 23bb00e68cbf7..a8bb9e2c9cbbf 100644 --- a/sql/field.h +++ b/sql/field.h @@ -1109,7 +1109,8 @@ class Field: public Value_source The following method is used for comparing prefix keys. Currently it's only used in partitioning. */ - virtual int cmp_prefix(const uchar *a, const uchar *b, size_t prefix_len) + virtual int cmp_prefix(const uchar *a, const uchar *b, + size_t prefix_char_len) { return cmp(a, b); } virtual int cmp_binary(const uchar *a,const uchar *b, uint32 max_length=~0U) { return memcmp(a,b,pack_length()); } @@ -3728,7 +3729,7 @@ class Field_varstring :public Field_longstr { String *val_str(String*,String *); my_decimal *val_decimal(my_decimal *); int cmp(const uchar *a,const uchar *b); - int cmp_prefix(const uchar *a, const uchar *b, size_t prefix_len); + int cmp_prefix(const uchar *a, const uchar *b, size_t prefix_char_len); void sort_string(uchar *buff,uint length); uint get_key_image(uchar *buff,uint length, imagetype type); void set_key_image(const uchar *buff,uint length); @@ -3964,7 +3965,7 @@ class Field_blob :public Field_longstr { String *val_str(String*,String *); my_decimal *val_decimal(my_decimal *); int cmp(const uchar *a,const uchar *b); - int cmp_prefix(const uchar *a, const uchar *b, size_t prefix_len); + int cmp_prefix(const uchar *a, const uchar *b, size_t prefix_char_len); int cmp(const uchar *a, uint32 a_length, const uchar *b, uint32 b_length); int cmp_binary(const uchar *a,const uchar *b, uint32 max_length=~0U); int key_cmp(const uchar *,const uchar*); @@ -4501,7 +4502,7 @@ class Field_bit :public Field { } int cmp_binary_offset(uint row_offset) { return cmp_offset(row_offset); } - int cmp_prefix(const uchar *a, const uchar *b, size_t prefix_len); + int cmp_prefix(const uchar *a, const uchar *b, size_t prefix_char_len); int key_cmp(const uchar *a, const uchar *b) { return cmp_binary((uchar *) a, (uchar *) b); } int key_cmp(const uchar *str, uint length); diff --git a/sql/key.cc b/sql/key.cc index 72f4e603023b8..2485e33af185c 100644 --- a/sql/key.cc +++ b/sql/key.cc @@ -612,7 +612,8 @@ int key_rec_cmp(void *key_p, uchar *first_rec, uchar *second_rec) that take the max length into account. */ if ((result= field->cmp_prefix(field->ptr+first_diff, field->ptr+sec_diff, - key_part->length))) + key_part->length / + field->charset()->mbmaxlen))) DBUG_RETURN(result); next_loop: key_part++; diff --git a/storage/innobase/rem/rem0cmp.cc b/storage/innobase/rem/rem0cmp.cc index e4248ed4ca431..539d4279a6ba3 100644 --- a/storage/innobase/rem/rem0cmp.cc +++ b/storage/innobase/rem/rem0cmp.cc @@ -327,7 +327,8 @@ static int cmp_whole_field(ulint mtype, ulint prtype, if (CHARSET_INFO *cs= get_charset(dtype_get_charset_coll(prtype), MYF(MY_WME))) return cs->coll->strnncollsp_nchars(cs, a, a_length, b, b_length, - std::max(a_length, b_length)); + std::max(a_length, b_length), + MY_STRNNCOLLSP_NCHARS_EMULATE_TRIMMED_TRAILING_SPACES); } ib::fatal() << "Unable to find charset-collation for " << prtype; diff --git a/strings/ctype-bin.c b/strings/ctype-bin.c index 2893aadd99f93..1a2d52c510950 100644 --- a/strings/ctype-bin.c +++ b/strings/ctype-bin.c @@ -128,7 +128,8 @@ static int my_strnncollsp_binary(CHARSET_INFO * cs __attribute__((unused)), static int my_strnncollsp_nchars_binary(CHARSET_INFO * cs __attribute__((unused)), const uchar *s, size_t slen, const uchar *t, size_t tlen, - size_t nchars) + size_t nchars, + uint flags) { set_if_smaller(slen, nchars); set_if_smaller(tlen, nchars); @@ -213,7 +214,8 @@ static int my_strnncollsp_8bit_bin(CHARSET_INFO * cs __attribute__((unused)), static int my_strnncollsp_nchars_8bit_bin(CHARSET_INFO * cs, const uchar *a, size_t a_length, const uchar *b, size_t b_length, - size_t nchars) + size_t nchars, + uint flags) { set_if_smaller(a_length, nchars); set_if_smaller(b_length, nchars); diff --git a/strings/ctype-simple.c b/strings/ctype-simple.c index d150e457673db..51f140a66208d 100644 --- a/strings/ctype-simple.c +++ b/strings/ctype-simple.c @@ -212,7 +212,8 @@ static int my_strnncollsp_nchars_simple(CHARSET_INFO * cs, const uchar *a, size_t a_length, const uchar *b, size_t b_length, - size_t nchars) + size_t nchars, + uint flags) { set_if_smaller(a_length, nchars); set_if_smaller(b_length, nchars); diff --git a/strings/ctype-tis620.c b/strings/ctype-tis620.c index b19832cc79279..66dc3e1d54b61 100644 --- a/strings/ctype-tis620.c +++ b/strings/ctype-tis620.c @@ -589,7 +589,8 @@ static int my_strnncollsp_nchars_tis620(CHARSET_INFO * cs, const uchar *a, size_t a_length, const uchar *b, size_t b_length, - size_t nchars) + size_t nchars, + uint flags) { set_if_smaller(a_length, nchars); set_if_smaller(b_length, nchars); diff --git a/strings/ctype-uca.inl b/strings/ctype-uca.inl index 7c9d34d217e7f..55b2c1ef7ce3b 100644 --- a/strings/ctype-uca.inl +++ b/strings/ctype-uca.inl @@ -317,6 +317,7 @@ MY_FUNCTION_NAME(strnncollsp_nopad_multilevel)(CHARSET_INFO *cs, static inline weight_and_nchars_t MY_FUNCTION_NAME(scanner_next_pad_trim)(my_uca_scanner *scanner, size_t nchars, + uint flags, uint *generated) { weight_and_nchars_t res; @@ -330,7 +331,10 @@ MY_FUNCTION_NAME(scanner_next_pad_trim)(my_uca_scanner *scanner, We reached the end of the string, but the caller wants more weights. Perform space padding. */ - res.weight= my_space_weight(scanner->level); + res.weight= + flags & MY_STRNNCOLLSP_NCHARS_EMULATE_TRIMMED_TRAILING_SPACES ? + my_space_weight(scanner->level) : 0; + res.nchars= 1; (*generated)++; } @@ -367,7 +371,8 @@ MY_FUNCTION_NAME(strnncollsp_nchars_onelevel)(CHARSET_INFO *cs, const MY_UCA_WEIGHT_LEVEL *level, const uchar *s, size_t slen, const uchar *t, size_t tlen, - size_t nchars) + size_t nchars, + uint flags) { my_uca_scanner sscanner; my_uca_scanner tscanner; @@ -385,15 +390,17 @@ MY_FUNCTION_NAME(strnncollsp_nchars_onelevel)(CHARSET_INFO *cs, int diff; s_res= MY_FUNCTION_NAME(scanner_next_pad_trim)(&sscanner, s_nchars_left, - &generated); + flags, &generated); t_res= MY_FUNCTION_NAME(scanner_next_pad_trim)(&tscanner, t_nchars_left, - &generated); + flags, &generated); + if ((diff= (s_res.weight - t_res.weight))) return diff; if (generated == 2) { - if (cs->state & MY_CS_NOPAD) + if ((cs->state & MY_CS_NOPAD) && + (flags & MY_STRNNCOLLSP_NCHARS_EMULATE_TRIMMED_TRAILING_SPACES)) { /* Both values are auto-generated. There's no real data any more. @@ -445,11 +452,12 @@ static int MY_FUNCTION_NAME(strnncollsp_nchars)(CHARSET_INFO *cs, const uchar *s, size_t slen, const uchar *t, size_t tlen, - size_t nchars) + size_t nchars, + uint flags) { return MY_FUNCTION_NAME(strnncollsp_nchars_onelevel)(cs, &cs->uca->level[0], s, slen, t, tlen, - nchars); + nchars, flags); } @@ -460,7 +468,8 @@ static int MY_FUNCTION_NAME(strnncollsp_nchars_multilevel)(CHARSET_INFO *cs, const uchar *s, size_t slen, const uchar *t, size_t tlen, - size_t nchars) + size_t nchars, + uint flags) { uint num_level= cs->levels_for_order; uint i; @@ -470,7 +479,7 @@ MY_FUNCTION_NAME(strnncollsp_nchars_multilevel)(CHARSET_INFO *cs, &cs->uca->level[i], s, slen, t, tlen, - nchars); + nchars, flags); if (ret) return ret; } diff --git a/strings/ctype.c b/strings/ctype.c index 0cf1131ab57f2..07e2ecd0349fe 100644 --- a/strings/ctype.c +++ b/strings/ctype.c @@ -1215,7 +1215,8 @@ my_convert_fix(CHARSET_INFO *to_cs, char *to, size_t to_length, int my_strnncollsp_nchars_generic(CHARSET_INFO *cs, const uchar *str1, size_t len1, const uchar *str2, size_t len2, - size_t nchars) + size_t nchars, + uint flags) { int error; len1= my_well_formed_length(cs, (const char *) str1, @@ -1232,7 +1233,8 @@ int my_strnncollsp_nchars_generic(CHARSET_INFO *cs, int my_strnncollsp_nchars_generic_8bit(CHARSET_INFO *cs, const uchar *str1, size_t len1, const uchar *str2, size_t len2, - size_t nchars) + size_t nchars, + uint flags) { set_if_smaller(len1, nchars); set_if_smaller(len2, nchars); diff --git a/strings/strcoll.inl b/strings/strcoll.inl index 392a5dac589b4..13385d29f9a72 100644 --- a/strings/strcoll.inl +++ b/strings/strcoll.inl @@ -304,7 +304,8 @@ static int MY_FUNCTION_NAME(strnncollsp_nchars)(CHARSET_INFO *cs __attribute__((unused)), const uchar *a, size_t a_length, const uchar *b, size_t b_length, - size_t nchars) + size_t nchars, + uint flags) { const uchar *a_end= a + a_length; const uchar *b_end= b + b_length; diff --git a/strings/strings_def.h b/strings/strings_def.h index 8bf089ec6957d..b5d0a4f422919 100644 --- a/strings/strings_def.h +++ b/strings/strings_def.h @@ -108,12 +108,14 @@ static inline const uchar *skip_trailing_space(const uchar *ptr,size_t len) int my_strnncollsp_nchars_generic(CHARSET_INFO *cs, const uchar *str1, size_t len1, const uchar *str2, size_t len2, - size_t nchars); + size_t nchars, + uint flags); int my_strnncollsp_nchars_generic_8bit(CHARSET_INFO *cs, const uchar *str1, size_t len1, const uchar *str2, size_t len2, - size_t nchars); + size_t nchars, + uint flags); uint my_8bit_charset_flags_from_data(CHARSET_INFO *cs); uint my_8bit_collation_flags_from_data(CHARSET_INFO *cs); diff --git a/unittest/strings/strings-t.c b/unittest/strings/strings-t.c index 338d2f53b0550..f5563247f17dd 100644 --- a/unittest/strings/strings-t.c +++ b/unittest/strings/strings-t.c @@ -787,9 +787,14 @@ typedef struct LEX_CSTRING a; LEX_CSTRING b; size_t nchars; + uint flags; int res; } STRNNCOLLSP_CHAR_PARAM; +#undef TCHAR +#define TCHAR MY_STRNNCOLLSP_NCHARS_EMULATE_TRIMMED_TRAILING_SPACES + +#define TVCHAR 0 /* Some lines in the below test data are marked as follows: @@ -811,266 +816,273 @@ typedef struct */ static STRNNCOLLSP_CHAR_PARAM strnncollsp_char_mbminlen1_xpad_common[]= { - {{CSTR("a")}, {CSTR("a")}, 0, 0}, - {{CSTR("a")}, {CSTR("a")}, 1, 0}, - {{CSTR("a")}, {CSTR("a")}, 2, 0}, - {{CSTR("a")}, {CSTR("a")}, 3, 0}, - {{CSTR("a")}, {CSTR("a")}, 100, 0}, - - {{CSTR("a")}, {CSTR("ab")}, 0, 0}, - {{CSTR("a")}, {CSTR("ab")}, 1, 0}, - {{CSTR("a")}, {CSTR("ab")}, 2, -1}, - {{CSTR("a")}, {CSTR("ab")}, 3, -1}, - {{CSTR("a")}, {CSTR("ab")}, 100, -1}, - - {{CSTR("a")}, {CSTR("a ")}, 0, 0}, - {{CSTR("a")}, {CSTR("a ")}, 1, 0}, - {{CSTR("a")}, {CSTR("a ")}, 2, 0}, - {{CSTR("a")}, {CSTR("a ")}, 3, 0}, - {{CSTR("a")}, {CSTR("a ")}, 100, 0}, - - {{CSTR("a")}, {CSTR("a ")}, 0, 0}, - {{CSTR("a")}, {CSTR("a ")}, 1, 0}, - {{CSTR("a")}, {CSTR("a ")}, 2, 0}, - {{CSTR("a")}, {CSTR("a ")}, 3, 0}, - {{CSTR("a")}, {CSTR("a ")}, 100, 0}, - - {{CSTR("ss")}, {CSTR("ss")}, 0, 0}, - {{CSTR("ss")}, {CSTR("ss")}, 1, 0}, - {{CSTR("ss")}, {CSTR("ss")}, 2, 0}, - {{CSTR("ss")}, {CSTR("ss")}, 3, 0}, - {{CSTR("ss")}, {CSTR("ss")}, 100, 0}, - - {{NULL, 0}, {NULL, 0}, 0, 0} + {{CSTR("a")}, {CSTR("a")}, 0, TCHAR, 0}, + {{CSTR("a")}, {CSTR("a")}, 1, TCHAR, 0}, + {{CSTR("a")}, {CSTR("a")}, 2, TCHAR, 0}, + {{CSTR("a")}, {CSTR("a")}, 3, TCHAR, 0}, + {{CSTR("a")}, {CSTR("a")}, 100, TCHAR, 0}, + + {{CSTR("a")}, {CSTR("ab")}, 0, TCHAR, 0}, + {{CSTR("a")}, {CSTR("ab")}, 1, TCHAR, 0}, + {{CSTR("a")}, {CSTR("ab")}, 2, TCHAR, -1}, + {{CSTR("a")}, {CSTR("ab")}, 3, TCHAR, -1}, + {{CSTR("a")}, {CSTR("ab")}, 100, TCHAR, -1}, + + {{CSTR("a")}, {CSTR("a ")}, 0, TCHAR, 0}, + {{CSTR("a")}, {CSTR("a ")}, 1, TCHAR, 0}, + {{CSTR("a")}, {CSTR("a ")}, 2, TCHAR, 0}, + {{CSTR("a")}, {CSTR("a ")}, 3, TCHAR, 0}, + {{CSTR("a")}, {CSTR("a ")}, 100, TCHAR, 0}, + + {{CSTR("a")}, {CSTR("a ")}, 0, TCHAR, 0}, + {{CSTR("a")}, {CSTR("a ")}, 1, TCHAR, 0}, + {{CSTR("a")}, {CSTR("a ")}, 2, TCHAR, 0}, + {{CSTR("a")}, {CSTR("a ")}, 3, TCHAR, 0}, + {{CSTR("a")}, {CSTR("a ")}, 100, TCHAR, 0}, + + {{CSTR("ss")}, {CSTR("ss")}, 0, TCHAR, 0}, + {{CSTR("ss")}, {CSTR("ss")}, 1, TCHAR, 0}, + {{CSTR("ss")}, {CSTR("ss")}, 2, TCHAR, 0}, + {{CSTR("ss")}, {CSTR("ss")}, 3, TCHAR, 0}, + {{CSTR("ss")}, {CSTR("ss")}, 100, TCHAR, 0}, + + {{NULL, 0}, {NULL, 0}, 0, 0, 0} }; /* Tests for utf8, for both PAD SPACE and NOPAD collations */ static STRNNCOLLSP_CHAR_PARAM strnncollsp_char_utf8mbx_xpad_common[]= { - {{CSTR(UTF8_sz)}, {CSTR(UTF8_sz)}, 0, 0}, - {{CSTR(UTF8_sz)}, {CSTR(UTF8_sz)}, 1, 0}, - {{CSTR(UTF8_sz)}, {CSTR(UTF8_sz)}, 2, 0}, - {{CSTR(UTF8_sz)}, {CSTR(UTF8_sz)}, 3, 0}, - {{CSTR(UTF8_sz)}, {CSTR(UTF8_sz)}, 100, 0}, + {{CSTR(UTF8_sz)}, {CSTR(UTF8_sz)}, 0, TCHAR, 0}, + {{CSTR(UTF8_sz)}, {CSTR(UTF8_sz)}, 1, TCHAR, 0}, + {{CSTR(UTF8_sz)}, {CSTR(UTF8_sz)}, 2, TCHAR, 0}, + {{CSTR(UTF8_sz)}, {CSTR(UTF8_sz)}, 3, TCHAR, 0}, + {{CSTR(UTF8_sz)}, {CSTR(UTF8_sz)}, 100, TCHAR, 0}, - {{NULL, 0}, {NULL, 0}, 0, 0} + {{NULL, 0}, {NULL, 0}, 0, 0, 0} }; /* Tests for latin1, for both PAD and NOPAD collations */ static STRNNCOLLSP_CHAR_PARAM strnncollsp_char_latin1_xpad_common[]= { - {{CSTR(LATIN1_sz)}, {CSTR(LATIN1_sz)}, 0, 0}, - {{CSTR(LATIN1_sz)}, {CSTR(LATIN1_sz)}, 1, 0}, - {{CSTR(LATIN1_sz)}, {CSTR(LATIN1_sz)}, 2, 0}, - {{CSTR(LATIN1_sz)}, {CSTR(LATIN1_sz)}, 3, 0}, - {{CSTR(LATIN1_sz)}, {CSTR(LATIN1_sz)}, 100, 0}, + {{CSTR(LATIN1_sz)}, {CSTR(LATIN1_sz)}, 0, TCHAR, 0}, + {{CSTR(LATIN1_sz)}, {CSTR(LATIN1_sz)}, 1, TCHAR, 0}, + {{CSTR(LATIN1_sz)}, {CSTR(LATIN1_sz)}, 2, TCHAR, 0}, + {{CSTR(LATIN1_sz)}, {CSTR(LATIN1_sz)}, 3, TCHAR, 0}, + {{CSTR(LATIN1_sz)}, {CSTR(LATIN1_sz)}, 100, TCHAR, 0}, - {{NULL, 0}, {NULL, 0}, 0, 0} + {{NULL, 0}, {NULL, 0}, 0, 0, 0} }; /* Tests for utf8 collations that sort "A WITH DIAERESIS" equal to "A" */ static STRNNCOLLSP_CHAR_PARAM strnncollsp_char_utf8mbx_xpad_a_eq_auml[]= { - {{CSTR(UTF8_auml "h")}, {CSTR("ah")}, 0, 0}, - {{CSTR(UTF8_auml "h")}, {CSTR("ah")}, 1, 0}, - {{CSTR(UTF8_auml "h")}, {CSTR("ah")}, 2, 0}, - {{CSTR(UTF8_auml "h")}, {CSTR("ah")}, 3, 0}, - {{CSTR(UTF8_auml "h")}, {CSTR("ah")}, 100, 0}, - - {{CSTR(UTF8_auml "h")}, {CSTR("ah ")}, 0, 0}, - {{CSTR(UTF8_auml "h")}, {CSTR("ah ")}, 1, 0}, - {{CSTR(UTF8_auml "h")}, {CSTR("ah ")}, 2, 0}, - {{CSTR(UTF8_auml "h")}, {CSTR("ah ")}, 3, 0}, - {{CSTR(UTF8_auml "h")}, {CSTR("ah ")}, 100, 0}, - - {{NULL, 0}, {NULL, 0}, 0, 0} + {{CSTR(UTF8_auml "h")}, {CSTR("ah")}, 0, TCHAR, 0}, + {{CSTR(UTF8_auml "h")}, {CSTR("ah")}, 1, TCHAR, 0}, + {{CSTR(UTF8_auml "h")}, {CSTR("ah")}, 2, TCHAR, 0}, + {{CSTR(UTF8_auml "h")}, {CSTR("ah")}, 3, TCHAR, 0}, + {{CSTR(UTF8_auml "h")}, {CSTR("ah")}, 100, TCHAR, 0}, + + {{CSTR(UTF8_auml "h")}, {CSTR("ah ")}, 0, TCHAR, 0}, + {{CSTR(UTF8_auml "h")}, {CSTR("ah ")}, 1, TCHAR, 0}, + {{CSTR(UTF8_auml "h")}, {CSTR("ah ")}, 2, TCHAR, 0}, + {{CSTR(UTF8_auml "h")}, {CSTR("ah ")}, 3, TCHAR, 0}, + {{CSTR(UTF8_auml "h")}, {CSTR("ah ")}, 100, TCHAR, 0}, + + {{NULL, 0}, {NULL, 0}, 0, 0, 0} }; static STRNNCOLLSP_CHAR_PARAM strnncollsp_char_utf8mb3_unicode_ci[]= { - {{CSTR("ss")}, {CSTR("s" "\x00" "s")}, 0, 0}, - {{CSTR("ss")}, {CSTR("s" "\x00" "s")}, 1, 0}, - {{CSTR("ss")}, {CSTR("s" "\x00" "s")}/*IF*/, 2, 1}, - {{CSTR("ss")}, {CSTR("s" "\x00" "s")}, 3, 0}, - {{CSTR("ss")}, {CSTR("s" "\x00" "s")}, 4, 0}, - {{CSTR("ss")}, {CSTR("s" "\x00" "s")}, 100, 0}, - - {{CSTR("ss")}, {CSTR(UTF8_sz)}, 0, 0}, - {{CSTR("ss")}, {CSTR(UTF8_sz)}, 1, -1}, - {{CSTR("ss")}, {CSTR(UTF8_sz)}, 2, 0}, - {{CSTR("ss")}, {CSTR(UTF8_sz)}, 3, 0}, - {{CSTR("ss")}, {CSTR(UTF8_sz)}, 4, 0}, - {{CSTR("ss")}, {CSTR(UTF8_sz)}, 100, 0}, - - {{NULL, 0}, {NULL, 0}, 0, 0} + {{CSTR("ss")}, {CSTR("s" "\x00" "s")}, 0, TCHAR, 0}, + {{CSTR("ss")}, {CSTR("s" "\x00" "s")}, 1, TCHAR, 0}, + {{CSTR("ss")}, {CSTR("s" "\x00" "s")}/*IF*/, 2, TCHAR, 1}, + {{CSTR("ss")}, {CSTR("s" "\x00" "s")}, 3, TCHAR, 0}, + {{CSTR("ss")}, {CSTR("s" "\x00" "s")}, 4, TCHAR, 0}, + {{CSTR("ss")}, {CSTR("s" "\x00" "s")}, 100, TCHAR, 0}, + + {{CSTR("ss")}, {CSTR(UTF8_sz)}, 0, TCHAR, 0}, + {{CSTR("ss")}, {CSTR(UTF8_sz)}, 1, TCHAR, -1}, + {{CSTR("ss")}, {CSTR(UTF8_sz)}, 2, TCHAR, 0}, + {{CSTR("ss")}, {CSTR(UTF8_sz)}, 3, TCHAR, 0}, + {{CSTR("ss")}, {CSTR(UTF8_sz)}, 4, TCHAR, 0}, + {{CSTR("ss")}, {CSTR(UTF8_sz)}, 100, TCHAR, 0}, + + {{NULL, 0}, {NULL, 0}, 0, 0, 0} }; static STRNNCOLLSP_CHAR_PARAM strnncollsp_char_utf8mb3_unicode_nopad_ci[]= { - {{CSTR("ss")}, {CSTR("s" "\x00" "s")}, 0, 0}, - {{CSTR("ss")}, {CSTR("s" "\x00" "s")}, 1, 0}, - {{CSTR("ss")}, {CSTR("s" "\x00" "s")}/*IF*/, 2, 1}, - {{CSTR("ss")}, {CSTR("s" "\x00" "s")}, 3, 1}, - {{CSTR("ss")}, {CSTR("s" "\x00" "s")}, 4, 1}, - {{CSTR("ss")}, {CSTR("s" "\x00" "s")}, 100, 1}, - - {{CSTR("ss")}, {CSTR(UTF8_sz)}, 0, 0}, - {{CSTR("ss")}, {CSTR(UTF8_sz)}, 1, -1}, - {{CSTR("ss")}, {CSTR(UTF8_sz)}, 2, -1}, - {{CSTR("ss")}, {CSTR(UTF8_sz)}, 3, -1}, - {{CSTR("ss")}, {CSTR(UTF8_sz)}, 4, -1}, - {{CSTR("ss")}, {CSTR(UTF8_sz)}, 100, -1}, - - {{NULL, 0}, {NULL, 0}, 0, 0} + {{CSTR("ss")}, {CSTR("s" "\x00" "s")}, 0, TCHAR, 0}, + {{CSTR("ss")}, {CSTR("s" "\x00" "s")}, 1, TCHAR, 0}, + {{CSTR("ss")}, {CSTR("s" "\x00" "s")}/*IF*/, 2, TCHAR, 1}, + {{CSTR("ss")}, {CSTR("s" "\x00" "s")}, 3, TCHAR, 1}, + {{CSTR("ss")}, {CSTR("s" "\x00" "s")}, 4, TCHAR, 1}, + {{CSTR("ss")}, {CSTR("s" "\x00" "s")}, 100, TCHAR, 1}, + + {{CSTR("ss")}, {CSTR(UTF8_sz)}, 0, TCHAR, 0}, + {{CSTR("ss")}, {CSTR(UTF8_sz)}, 1, TCHAR, -1}, + {{CSTR("ss")}, {CSTR(UTF8_sz)}, 2, TCHAR, -1}, + {{CSTR("ss")}, {CSTR(UTF8_sz)}, 3, TCHAR, -1}, + {{CSTR("ss")}, {CSTR(UTF8_sz)}, 4, TCHAR, -1}, + {{CSTR("ss")}, {CSTR(UTF8_sz)}, 100, TCHAR, -1}, + + {{CSTR("ss")}, {CSTR(UTF8_sz)}, 0, TVCHAR, 0}, + {{CSTR("ss")}, {CSTR(UTF8_sz)}, 1, TVCHAR, -1}, + {{CSTR("ss")}, {CSTR(UTF8_sz)}, 2, TVCHAR, 0}, + {{CSTR("ss")}, {CSTR(UTF8_sz)}, 3, TVCHAR, 0}, + {{CSTR("ss")}, {CSTR(UTF8_sz)}, 4, TVCHAR, 0}, + {{CSTR("ss")}, {CSTR(UTF8_sz)}, 100, TVCHAR, 0}, + + {{NULL, 0}, {NULL, 0}, 0, 0, 0} }; static STRNNCOLLSP_CHAR_PARAM strnncollsp_char_utf8mb3_danish_ci[]= { - {{CSTR("aa")}, {CSTR("")}, 0, 0}, - {{CSTR("aa")}/*CF*/, {CSTR("")}, 1, 1}, - {{CSTR("aa")}, {CSTR("")}, 2, 1}, - {{CSTR("aa")}, {CSTR("")}, 3, 1}, - {{CSTR("aa")}, {CSTR("")}, 100, 1}, - - {{CSTR("aa")}, {CSTR("a")}, 0, 0}, - {{CSTR("aa")}/*CF*/, {CSTR("a")}, 1, 0}, - {{CSTR("aa")}, {CSTR("a")}, 2, 1}, - {{CSTR("aa")}, {CSTR("a")}, 3, 1}, - {{CSTR("aa")}, {CSTR("a")}, 100, 1}, - - {{CSTR("aa")}, {CSTR("aa")}, 0, 0}, - {{CSTR("aa")}/*CF*/, {CSTR("aa")}/*CF*/, 1, 0}, - {{CSTR("aa")}, {CSTR("aa")}, 2, 0}, - {{CSTR("aa")}, {CSTR("aa")}, 3, 0}, - {{CSTR("aa")}, {CSTR("aa")}, 100, 0}, - - {{CSTR("aa")}, {CSTR("\x00" "a")}, 0, 0}, - {{CSTR("aa")}/*CF*/, {CSTR("\x00" "a")}/*IF*/, 1, 1}, - {{CSTR("aa")}, {CSTR("\x00" "a")}, 2, 1}, - {{CSTR("aa")}, {CSTR("\x00" "a")}, 3, 1}, - {{CSTR("aa")}, {CSTR("\x00" "a")}, 100, 1}, - - {{CSTR("aa")}, {CSTR("\x00" "aa")}, 0, 0}, - {{CSTR("aa")}/*CF*/, {CSTR("\x00" "aa")}/*IF*/, 1, 1}, - {{CSTR("aa")}, {CSTR("\x00" "aa")}/*IF*/, 2, 1}, - {{CSTR("aa")}, {CSTR("\x00" "aa")}, 3, 0}, - {{CSTR("aa")}, {CSTR("\x00" "aa")}, 100, 0}, - - {{CSTR("aa")}, {CSTR("a" "\x00" "a")}, 0, 0}, - {{CSTR("aa")}/*CF*/, {CSTR("a" "\x00" "a")}, 1, 0}, - {{CSTR("aa")}, {CSTR("a" "\x00" "a")}/*IF*/, 2, 1}, - {{CSTR("aa")}, {CSTR("a" "\x00" "a")}, 3, 1}, - {{CSTR("aa")}, {CSTR("a" "\x00" "a")}, 100, 1}, - - {{CSTR("aa")}, {CSTR(UTF8_ARING)}, 0, 0}, - {{CSTR("aa")}/*CF*/, {CSTR(UTF8_ARING)}, 1, -1}, - {{CSTR("aa")}, {CSTR(UTF8_ARING)}, 2, 0}, - {{CSTR("aa")}, {CSTR(UTF8_ARING)}, 3, 0}, - {{CSTR("aa")}, {CSTR(UTF8_ARING)}, 100, 0}, - - {{NULL, 0}, {NULL, 0}, 0, 0} + {{CSTR("aa")}, {CSTR("")}, 0, TCHAR, 0}, + {{CSTR("aa")}/*CF*/, {CSTR("")}, 1, TCHAR, 1}, + {{CSTR("aa")}, {CSTR("")}, 2, TCHAR, 1}, + {{CSTR("aa")}, {CSTR("")}, 3, TCHAR, 1}, + {{CSTR("aa")}, {CSTR("")}, 100, TCHAR, 1}, + + {{CSTR("aa")}, {CSTR("a")}, 0, TCHAR, 0}, + {{CSTR("aa")}/*CF*/, {CSTR("a")}, 1, TCHAR, 0}, + {{CSTR("aa")}, {CSTR("a")}, 2, TCHAR, 1}, + {{CSTR("aa")}, {CSTR("a")}, 3, TCHAR, 1}, + {{CSTR("aa")}, {CSTR("a")}, 100, TCHAR, 1}, + + {{CSTR("aa")}, {CSTR("aa")}, 0, TCHAR, 0}, + {{CSTR("aa")}/*CF*/, {CSTR("aa")}/*CF*/, 1, TCHAR, 0}, + {{CSTR("aa")}, {CSTR("aa")}, 2, TCHAR, 0}, + {{CSTR("aa")}, {CSTR("aa")}, 3, TCHAR, 0}, + {{CSTR("aa")}, {CSTR("aa")}, 100, TCHAR, 0}, + + {{CSTR("aa")}, {CSTR("\x00" "a")}, 0, TCHAR, 0}, + {{CSTR("aa")}/*CF*/, {CSTR("\x00" "a")}/*IF*/, 1, TCHAR, 1}, + {{CSTR("aa")}, {CSTR("\x00" "a")}, 2, TCHAR, 1}, + {{CSTR("aa")}, {CSTR("\x00" "a")}, 3, TCHAR, 1}, + {{CSTR("aa")}, {CSTR("\x00" "a")}, 100, TCHAR, 1}, + + {{CSTR("aa")}, {CSTR("\x00" "aa")}, 0, TCHAR, 0}, + {{CSTR("aa")}/*CF*/, {CSTR("\x00" "aa")}/*IF*/, 1, TCHAR, 1}, + {{CSTR("aa")}, {CSTR("\x00" "aa")}/*IF*/, 2, TCHAR, 1}, + {{CSTR("aa")}, {CSTR("\x00" "aa")}, 3, TCHAR, 0}, + {{CSTR("aa")}, {CSTR("\x00" "aa")}, 100, TCHAR, 0}, + + {{CSTR("aa")}, {CSTR("a" "\x00" "a")}, 0, TCHAR, 0}, + {{CSTR("aa")}/*CF*/, {CSTR("a" "\x00" "a")}, 1, TCHAR, 0}, + {{CSTR("aa")}, {CSTR("a" "\x00" "a")}/*IF*/, 2, TCHAR, 1}, + {{CSTR("aa")}, {CSTR("a" "\x00" "a")}, 3, TCHAR, 1}, + {{CSTR("aa")}, {CSTR("a" "\x00" "a")}, 100, TCHAR, 1}, + + {{CSTR("aa")}, {CSTR(UTF8_ARING)}, 0, TCHAR, 0}, + {{CSTR("aa")}/*CF*/, {CSTR(UTF8_ARING)}, 1, TCHAR, -1}, + {{CSTR("aa")}, {CSTR(UTF8_ARING)}, 2, TCHAR, 0}, + {{CSTR("aa")}, {CSTR(UTF8_ARING)}, 3, TCHAR, 0}, + {{CSTR("aa")}, {CSTR(UTF8_ARING)}, 100, TCHAR, 0}, + + {{NULL, 0}, {NULL, 0}, 0, 0, 0} }; static STRNNCOLLSP_CHAR_PARAM strnncollsp_char_latin1_german2_ci[]= { - {{CSTR("ss")}, {CSTR(LATIN1_sz)}, 0, 0}, - {{CSTR("ss")}, {CSTR(LATIN1_sz)}, 1, -1}, - {{CSTR("ss")}, {CSTR(LATIN1_sz)}, 2, 0}, - {{CSTR("ss")}, {CSTR(LATIN1_sz)}, 3, 0}, - {{CSTR("ss")}, {CSTR(LATIN1_sz)}, 100, 0}, - - {{CSTR("ae")}, {CSTR(LATIN1_auml)}, 0, 0}, - {{CSTR("ae")}, {CSTR(LATIN1_auml)}, 1, -1}, - {{CSTR("ae")}, {CSTR(LATIN1_auml)}, 2, 0}, - {{CSTR("ae")}, {CSTR(LATIN1_auml)}, 3, 0}, - {{CSTR("ae")}, {CSTR(LATIN1_auml)}, 100, 0}, - - {{CSTR("ae")}, {CSTR(LATIN1_auml " ")}, 0, 0}, - {{CSTR("ae")}, {CSTR(LATIN1_auml " ")}, 1, -1}, - {{CSTR("ae")}, {CSTR(LATIN1_auml " ")}, 2, 0}, - {{CSTR("ae")}, {CSTR(LATIN1_auml " ")}, 3, 0}, - {{CSTR("ae")}, {CSTR(LATIN1_auml " ")}, 100, 0}, - - {{NULL, 0}, {NULL, 0}, 0, 0} + {{CSTR("ss")}, {CSTR(LATIN1_sz)}, 0, TCHAR, 0}, + {{CSTR("ss")}, {CSTR(LATIN1_sz)}, 1, TCHAR, -1}, + {{CSTR("ss")}, {CSTR(LATIN1_sz)}, 2, TCHAR, 0}, + {{CSTR("ss")}, {CSTR(LATIN1_sz)}, 3, TCHAR, 0}, + {{CSTR("ss")}, {CSTR(LATIN1_sz)}, 100, TCHAR, 0}, + + {{CSTR("ae")}, {CSTR(LATIN1_auml)}, 0, TCHAR, 0}, + {{CSTR("ae")}, {CSTR(LATIN1_auml)}, 1, TCHAR, -1}, + {{CSTR("ae")}, {CSTR(LATIN1_auml)}, 2, TCHAR, 0}, + {{CSTR("ae")}, {CSTR(LATIN1_auml)}, 3, TCHAR, 0}, + {{CSTR("ae")}, {CSTR(LATIN1_auml)}, 100, TCHAR, 0}, + + {{CSTR("ae")}, {CSTR(LATIN1_auml " ")}, 0, TCHAR, 0}, + {{CSTR("ae")}, {CSTR(LATIN1_auml " ")}, 1, TCHAR, -1}, + {{CSTR("ae")}, {CSTR(LATIN1_auml " ")}, 2, TCHAR, 0}, + {{CSTR("ae")}, {CSTR(LATIN1_auml " ")}, 3, TCHAR, 0}, + {{CSTR("ae")}, {CSTR(LATIN1_auml " ")}, 100, TCHAR, 0}, + + {{NULL, 0}, {NULL, 0}, 0, 0, 0} }; static STRNNCOLLSP_CHAR_PARAM strnncollsp_char_utf8mbx_german2_ci[]= { - {{CSTR("ss")}, {CSTR(UTF8_sz)}, 0, 0}, - {{CSTR("ss")}, {CSTR(UTF8_sz)}, 1, -1}, - {{CSTR("ss")}, {CSTR(UTF8_sz)}, 2, 0}, - {{CSTR("ss")}, {CSTR(UTF8_sz)}, 3, 0}, - {{CSTR("ss")}, {CSTR(UTF8_sz)}, 100, 0}, - - {{CSTR("ae")}, {CSTR(UTF8_auml)}, 0, 0}, - {{CSTR("ae")}, {CSTR(UTF8_auml)}, 1, -1}, - {{CSTR("ae")}, {CSTR(UTF8_auml)}, 2, 0}, - {{CSTR("ae")}, {CSTR(UTF8_auml)}, 3, 0}, - {{CSTR("ae")}, {CSTR(UTF8_auml)}, 100, 0}, - - {{CSTR("ae")}, {CSTR(UTF8_auml " ")}, 0, 0}, - {{CSTR("ae")}, {CSTR(UTF8_auml " ")}, 1, -1}, - {{CSTR("ae")}, {CSTR(UTF8_auml " ")}, 2, 0}, - {{CSTR("ae")}, {CSTR(UTF8_auml " ")}, 3, 0}, - {{CSTR("ae")}, {CSTR(UTF8_auml " ")}, 100, 0}, - - {{NULL, 0}, {NULL, 0}, 0, 0} + {{CSTR("ss")}, {CSTR(UTF8_sz)}, 0, TCHAR, 0}, + {{CSTR("ss")}, {CSTR(UTF8_sz)}, 1, TCHAR, -1}, + {{CSTR("ss")}, {CSTR(UTF8_sz)}, 2, TCHAR, 0}, + {{CSTR("ss")}, {CSTR(UTF8_sz)}, 3, TCHAR, 0}, + {{CSTR("ss")}, {CSTR(UTF8_sz)}, 100, TCHAR, 0}, + + {{CSTR("ae")}, {CSTR(UTF8_auml)}, 0, TCHAR, 0}, + {{CSTR("ae")}, {CSTR(UTF8_auml)}, 1, TCHAR, -1}, + {{CSTR("ae")}, {CSTR(UTF8_auml)}, 2, TCHAR, 0}, + {{CSTR("ae")}, {CSTR(UTF8_auml)}, 3, TCHAR, 0}, + {{CSTR("ae")}, {CSTR(UTF8_auml)}, 100, TCHAR, 0}, + + {{CSTR("ae")}, {CSTR(UTF8_auml " ")}, 0, TCHAR, 0}, + {{CSTR("ae")}, {CSTR(UTF8_auml " ")}, 1, TCHAR, -1}, + {{CSTR("ae")}, {CSTR(UTF8_auml " ")}, 2, TCHAR, 0}, + {{CSTR("ae")}, {CSTR(UTF8_auml " ")}, 3, TCHAR, 0}, + {{CSTR("ae")}, {CSTR(UTF8_auml " ")}, 100, TCHAR, 0}, + + {{NULL, 0}, {NULL, 0}, 0, 0, 0} }; static STRNNCOLLSP_CHAR_PARAM strnncollsp_char_mbminlen1_xpad_czech[]= { - {{CSTR("c")}, {CSTR("ch")}, 0, 0}, - {{CSTR("c")}, {CSTR("ch")}, 1, 0}, - {{CSTR("c")}, {CSTR("ch")}, 2, -1}, + {{CSTR("c")}, {CSTR("ch")}, 0, TCHAR, 0}, + {{CSTR("c")}, {CSTR("ch")}, 1, TCHAR, 0}, + {{CSTR("c")}, {CSTR("ch")}, 2, TCHAR, -1}, - {{CSTR("h")}, {CSTR("ch")}, 0, 0}, - {{CSTR("h")}, {CSTR("ch")}, 1, 1}, - {{CSTR("h")}, {CSTR("ch")}, 2, -1}, + {{CSTR("h")}, {CSTR("ch")}, 0, TCHAR, 0}, + {{CSTR("h")}, {CSTR("ch")}, 1, TCHAR, 1}, + {{CSTR("h")}, {CSTR("ch")}, 2, TCHAR, -1}, - {{CSTR("i")}, {CSTR("ch")}, 0, 0}, - {{CSTR("i")}, {CSTR("ch")}, 1, 1}, - {{CSTR("i")}, {CSTR("ch")}, 2, 1}, + {{CSTR("i")}, {CSTR("ch")}, 0, TCHAR, 0}, + {{CSTR("i")}, {CSTR("ch")}, 1, TCHAR, 1}, + {{CSTR("i")}, {CSTR("ch")}, 2, TCHAR, 1}, - {{NULL, 0}, {NULL, 0}, 0, 0} + {{NULL, 0}, {NULL, 0}, 0, 0, 0} }; static STRNNCOLLSP_CHAR_PARAM strnncollsp_char_mbminlen2_xpad_common[]= { - {{CSTR(UCS2_a)}, {CSTR(UCS2_a)}, 0, 0}, - {{CSTR(UCS2_a)}, {CSTR(UCS2_a)}, 1, 0}, - {{CSTR(UCS2_a)}, {CSTR(UCS2_a)}, 2, 0}, - {{CSTR(UCS2_a)}, {CSTR(UCS2_a)}, 3, 0}, - {{CSTR(UCS2_a)}, {CSTR(UCS2_a)}, 100, 0}, - - {{CSTR(UCS2_a)}, {CSTR(UCS2_a UCS2_sp)}, 0, 0}, - {{CSTR(UCS2_a)}, {CSTR(UCS2_a UCS2_sp)}, 1, 0}, - {{CSTR(UCS2_a)}, {CSTR(UCS2_a UCS2_sp)}, 2, 0}, - {{CSTR(UCS2_a)}, {CSTR(UCS2_a UCS2_sp)}, 3, 0}, - {{CSTR(UCS2_a)}, {CSTR(UCS2_a UCS2_sp)}, 100, 0}, - - {{CSTR(UCS2_a)}, {CSTR(UCS2_a UCS2_sp UCS2_sp)}, 0, 0}, - {{CSTR(UCS2_a)}, {CSTR(UCS2_a UCS2_sp UCS2_sp)}, 1, 0}, - {{CSTR(UCS2_a)}, {CSTR(UCS2_a UCS2_sp UCS2_sp)}, 2, 0}, - {{CSTR(UCS2_a)}, {CSTR(UCS2_a UCS2_sp UCS2_sp)}, 3, 0}, - {{CSTR(UCS2_a)}, {CSTR(UCS2_a UCS2_sp UCS2_sp)}, 100, 0}, - - {{CSTR(UCS2_a)}, {CSTR(UCS2_a UCS2_b)}, 0, 0}, - {{CSTR(UCS2_a)}, {CSTR(UCS2_a UCS2_b)}, 1, 0}, - {{CSTR(UCS2_a)}, {CSTR(UCS2_a UCS2_b)}, 2, -1}, - {{CSTR(UCS2_a)}, {CSTR(UCS2_a UCS2_b)}, 3, -1}, - {{CSTR(UCS2_a)}, {CSTR(UCS2_a UCS2_b)}, 100, -1}, - - {{NULL, 0}, {NULL, 0}, 0, 0} + {{CSTR(UCS2_a)}, {CSTR(UCS2_a)}, 0, TCHAR, 0}, + {{CSTR(UCS2_a)}, {CSTR(UCS2_a)}, 1, TCHAR, 0}, + {{CSTR(UCS2_a)}, {CSTR(UCS2_a)}, 2, TCHAR, 0}, + {{CSTR(UCS2_a)}, {CSTR(UCS2_a)}, 3, TCHAR, 0}, + {{CSTR(UCS2_a)}, {CSTR(UCS2_a)}, 100, TCHAR, 0}, + + {{CSTR(UCS2_a)}, {CSTR(UCS2_a UCS2_sp)}, 0, TCHAR, 0}, + {{CSTR(UCS2_a)}, {CSTR(UCS2_a UCS2_sp)}, 1, TCHAR, 0}, + {{CSTR(UCS2_a)}, {CSTR(UCS2_a UCS2_sp)}, 2, TCHAR, 0}, + {{CSTR(UCS2_a)}, {CSTR(UCS2_a UCS2_sp)}, 3, TCHAR, 0}, + {{CSTR(UCS2_a)}, {CSTR(UCS2_a UCS2_sp)}, 100, TCHAR, 0}, + + {{CSTR(UCS2_a)}, {CSTR(UCS2_a UCS2_sp UCS2_sp)}, 0, TCHAR, 0}, + {{CSTR(UCS2_a)}, {CSTR(UCS2_a UCS2_sp UCS2_sp)}, 1, TCHAR, 0}, + {{CSTR(UCS2_a)}, {CSTR(UCS2_a UCS2_sp UCS2_sp)}, 2, TCHAR, 0}, + {{CSTR(UCS2_a)}, {CSTR(UCS2_a UCS2_sp UCS2_sp)}, 3, TCHAR, 0}, + {{CSTR(UCS2_a)}, {CSTR(UCS2_a UCS2_sp UCS2_sp)}, 100, TCHAR, 0}, + + {{CSTR(UCS2_a)}, {CSTR(UCS2_a UCS2_b)}, 0, TCHAR, 0}, + {{CSTR(UCS2_a)}, {CSTR(UCS2_a UCS2_b)}, 1, TCHAR, 0}, + {{CSTR(UCS2_a)}, {CSTR(UCS2_a UCS2_b)}, 2, TCHAR, -1}, + {{CSTR(UCS2_a)}, {CSTR(UCS2_a UCS2_b)}, 3, TCHAR, -1}, + {{CSTR(UCS2_a)}, {CSTR(UCS2_a UCS2_b)}, 100, TCHAR, -1}, + + {{NULL, 0}, {NULL, 0}, 0, 0, 0} }; @@ -1082,7 +1094,7 @@ strnncollsp_char_one(CHARSET_INFO *cs, const STRNNCOLLSP_CHAR_PARAM *p) int res= cs->coll->strnncollsp_nchars(cs, (uchar *) p->a.str, p->a.length, (uchar *) p->b.str, p->b.length, - p->nchars); + p->nchars, p->flags); str2hex(ahex, sizeof(ahex), p->a.str, p->a.length); str2hex(bhex, sizeof(bhex), p->b.str, p->b.length); diag("%-25s %-12s %-12s %3d %7d %7d%s", @@ -1098,7 +1110,7 @@ strnncollsp_char_one(CHARSET_INFO *cs, const STRNNCOLLSP_CHAR_PARAM *p) res= cs->coll->strnncollsp_nchars(cs, (uchar *) p->b.str, p->b.length, (uchar *) p->a.str, p->a.length, - p->nchars); + p->nchars, p->flags); if (!eqres(res, -p->res)) { diag("Comparison in reverse order failed. Expected %d, got %d", From 0269d82d5309c4dc2022ac8dd4d6945699e0ea69 Mon Sep 17 00:00:00 2001 From: Sergei Petrunia Date: Fri, 10 Mar 2023 18:02:14 +0300 Subject: [PATCH 79/92] ANALYZE FORMAT=JSON: Backport block-nl-join.r_unpack_time_ms from 11.0 +fix MDEV-30830. Also fix it to work with hashed join (MDEV-30830). Reviewed by: Monty --- mysql-test/include/analyze-format.inc | 2 +- mysql-test/main/analyze_format_json.result | 7 ++ .../main/analyze_format_json_timings.result | 89 +++++++++++++++++++ .../main/analyze_format_json_timings.test | 77 ++++++++++++++++ mysql-test/main/analyze_stmt_orderby.result | 2 + mysql-test/main/except.result | 4 + mysql-test/main/except_all.result | 4 + mysql-test/main/explain_json.result | 1 + mysql-test/main/intersect.result | 2 + mysql-test/main/intersect_all.result | 2 + mysql-test/main/rowid_filter_innodb.result | 2 + sql/sql_explain.cc | 3 + sql/sql_explain.h | 10 ++- sql/sql_join_cache.cc | 6 +- sql/sql_select.cc | 4 +- sql/sql_select.h | 1 + 16 files changed, 210 insertions(+), 6 deletions(-) create mode 100644 mysql-test/main/analyze_format_json_timings.result create mode 100644 mysql-test/main/analyze_format_json_timings.test diff --git a/mysql-test/include/analyze-format.inc b/mysql-test/include/analyze-format.inc index 7e18524e44eef..330be82ef9633 100644 --- a/mysql-test/include/analyze-format.inc +++ b/mysql-test/include/analyze-format.inc @@ -1,3 +1,3 @@ # The time on ANALYSE FORMAT=JSON is rather variable ---replace_regex /("(r_total_time_ms|r_table_time_ms|r_other_time_ms|r_buffer_size|r_filling_time_ms)": )[^, \n]*/\1"REPLACED"/ +--replace_regex /("(r_[a-z_]*_time_ms|r_buffer_size)": )[^, \n]*/\1"REPLACED"/ diff --git a/mysql-test/main/analyze_format_json.result b/mysql-test/main/analyze_format_json.result index abe3fab4643e8..2329ef2ce6094 100644 --- a/mysql-test/main/analyze_format_json.result +++ b/mysql-test/main/analyze_format_json.result @@ -153,6 +153,7 @@ ANALYZE "join_type": "BNL", "r_loops": 20, "r_filtered": 100, + "r_unpack_time_ms": "REPLACED", "r_effective_rows": 60 } } @@ -196,6 +197,7 @@ ANALYZE "attached_condition": "tbl1.c > tbl2.c", "r_loops": 20, "r_filtered": 15.83333333, + "r_unpack_time_ms": "REPLACED", "r_effective_rows": 60 } } @@ -658,6 +660,7 @@ ANALYZE "attached_condition": "(t2.b,t2.b in (subquery#2))", "r_loops": 2, "r_filtered": null, + "r_unpack_time_ms": "REPLACED", "r_effective_rows": 0 }, "subqueries": [ @@ -750,6 +753,7 @@ ANALYZE "join_type": "BNL", "r_loops": 2, "r_filtered": null, + "r_unpack_time_ms": "REPLACED", "r_effective_rows": 0 }, "subqueries": [ @@ -784,6 +788,7 @@ ANALYZE "attached_condition": "t2.f2 = t3.f3", "r_loops": 0, "r_filtered": null, + "r_unpack_time_ms": "REPLACED", "r_effective_rows": null } } @@ -921,6 +926,7 @@ ANALYZE "attached_condition": "t10.b = t11.b", "r_loops": 100, "r_filtered": 0.424285714, + "r_unpack_time_ms": "REPLACED", "r_effective_rows": 700 } } @@ -973,6 +979,7 @@ ANALYZE "attached_condition": "t10.b = t11.b", "r_loops": 100, "r_filtered": 100, + "r_unpack_time_ms": "REPLACED", "r_effective_rows": 2.97 } } diff --git a/mysql-test/main/analyze_format_json_timings.result b/mysql-test/main/analyze_format_json_timings.result new file mode 100644 index 0000000000000..4d8a65ae0e70b --- /dev/null +++ b/mysql-test/main/analyze_format_json_timings.result @@ -0,0 +1,89 @@ +# +# MDEV-30830: ANALYZE FORMAT=JSON: r_unpack_time_ms is empty for the hashed joins +# +# +# First, check a regular BNL-join +# +create table t1 ( +a int, +b int +); +insert into t1 select seq, seq/3 from seq_0_to_99; +create table t2 ( +a int, +b int +); +insert into t2 select seq, seq/5 from seq_0_to_99; +set @js='$out'; +set @out=(select json_extract(@js,'$**.block-nl-join.r_unpack_time_ms')); +select cast(json_extract(@out,'$[0]') as DOUBLE) > 0; +cast(json_extract(@out,'$[0]') as DOUBLE) > 0 +1 +drop table t1,t2; +# +# Now, check the hashed, BNL-H join +# +create table t1 ( +a int, +b int +); +insert into t1 select seq, seq/3 from seq_0_to_499; +create table t2 ( +a int, +b int +); +insert into t2 select seq, seq/5 from seq_0_to_499; +set @tmp=@@join_cache_level, join_cache_level=6; +select '$out' as X; +X +{ + "query_block": { + "select_id": 1, + "r_loops": 1, + "r_total_time_ms": "REPLACED", + "table": { + "table_name": "t1", + "access_type": "ALL", + "r_loops": 1, + "rows": 500, + "r_rows": 500, + "r_table_time_ms": "REPLACED", + "r_other_time_ms": "REPLACED", + "filtered": 100, + "r_filtered": 100, + "attached_condition": "t1.a < 700 and t1.b is not null" + }, + "block-nl-join": { + "table": { + "table_name": "t2", + "access_type": "hash_ALL", + "key": "#hash#$hj", + "key_length": "5", + "used_key_parts": ["b"], + "ref": ["test.t1.b"], + "r_loops": 1, + "rows": 500, + "r_rows": 500, + "r_table_time_ms": "REPLACED", + "r_other_time_ms": "REPLACED", + "filtered": 100, + "r_filtered": 20, + "attached_condition": "t2.a < 100" + }, + "buffer_type": "flat", + "buffer_size": "18Kb", + "join_type": "BNLH", + "attached_condition": "t2.b = t1.b", + "r_loops": 500, + "r_filtered": 100, + "r_unpack_time_ms": "REPLACED", + "r_effective_rows": 0.594 + } + } +} +set @out=(select json_extract(@js,'$**.block-nl-join.r_unpack_time_ms')); +select cast(json_extract(@out,'$[0]') as DOUBLE) > 0; +cast(json_extract(@out,'$[0]') as DOUBLE) > 0 +1 +set join_cache_level=@tmp; +drop table t1, t2; diff --git a/mysql-test/main/analyze_format_json_timings.test b/mysql-test/main/analyze_format_json_timings.test new file mode 100644 index 0000000000000..fdb4c8d598967 --- /dev/null +++ b/mysql-test/main/analyze_format_json_timings.test @@ -0,0 +1,77 @@ +# +# Tests to check that r_something_time_ms is non-zero in +# ANALYZE FORMAT=JSON +# +--source include/default_optimizer_switch.inc +--source include/have_sequence.inc + +# The tests here are large so that we get non-zero timings +--source include/big_test.inc + +--echo # +--echo # MDEV-30830: ANALYZE FORMAT=JSON: r_unpack_time_ms is empty for the hashed joins +--echo # + +--echo # +--echo # First, check a regular BNL-join +--echo # +create table t1 ( + a int, + b int +); +insert into t1 select seq, seq/3 from seq_0_to_99; + +create table t2 ( + a int, + b int +); +insert into t2 select seq, seq/5 from seq_0_to_99; + +let $out=` +analyze format=json +select * from t1, t2 +where + t1.a < 700 and + t2.a < 100 + and t1.b=t2.b +`; + +evalp set @js='$out'; +set @out=(select json_extract(@js,'$**.block-nl-join.r_unpack_time_ms')); +select cast(json_extract(@out,'$[0]') as DOUBLE) > 0; +drop table t1,t2; + +--echo # +--echo # Now, check the hashed, BNL-H join +--echo # +create table t1 ( + a int, + b int +); +insert into t1 select seq, seq/3 from seq_0_to_499; + +create table t2 ( + a int, + b int +); +insert into t2 select seq, seq/5 from seq_0_to_499; +set @tmp=@@join_cache_level, join_cache_level=6; + +let $out=` +analyze format=json +select * from t1, t2 +where + t1.a < 700 and + t2.a < 100 + and t1.b=t2.b +`; + +--source include/analyze-format.inc +evalp select '$out' as X; + +set @out=(select json_extract(@js,'$**.block-nl-join.r_unpack_time_ms')); +select cast(json_extract(@out,'$[0]') as DOUBLE) > 0; + +set join_cache_level=@tmp; +drop table t1, t2; + diff --git a/mysql-test/main/analyze_stmt_orderby.result b/mysql-test/main/analyze_stmt_orderby.result index d6aeeafeb73c2..c615d1e7d5f17 100644 --- a/mysql-test/main/analyze_stmt_orderby.result +++ b/mysql-test/main/analyze_stmt_orderby.result @@ -443,6 +443,7 @@ ANALYZE "attached_condition": "t3.a = t0.a", "r_loops": 10, "r_filtered": 10, + "r_unpack_time_ms": "REPLACED", "r_effective_rows": 10 } } @@ -520,6 +521,7 @@ ANALYZE "attached_condition": "t5.a = t6.a", "r_loops": 4, "r_filtered": 21.42857143, + "r_unpack_time_ms": "REPLACED", "r_effective_rows": 7 } } diff --git a/mysql-test/main/except.result b/mysql-test/main/except.result index bf92ceaafea97..67fee0bcabfde 100644 --- a/mysql-test/main/except.result +++ b/mysql-test/main/except.result @@ -336,6 +336,7 @@ ANALYZE "join_type": "BNL", "r_loops": 2, "r_filtered": 100, + "r_unpack_time_ms": "REPLACED", "r_effective_rows": 2 } } @@ -374,6 +375,7 @@ ANALYZE "join_type": "BNL", "r_loops": 2, "r_filtered": 100, + "r_unpack_time_ms": "REPLACED", "r_effective_rows": 2 } } @@ -441,6 +443,7 @@ ANALYZE "join_type": "BNL", "r_loops": 2, "r_filtered": 100, + "r_unpack_time_ms": "REPLACED", "r_effective_rows": 2 } } @@ -479,6 +482,7 @@ ANALYZE "join_type": "BNL", "r_loops": 2, "r_filtered": 100, + "r_unpack_time_ms": "REPLACED", "r_effective_rows": 2 } } diff --git a/mysql-test/main/except_all.result b/mysql-test/main/except_all.result index 6224be8021afe..70b52f13161ac 100644 --- a/mysql-test/main/except_all.result +++ b/mysql-test/main/except_all.result @@ -455,6 +455,7 @@ ANALYZE "join_type": "BNL", "r_loops": 3, "r_filtered": 100, + "r_unpack_time_ms": "REPLACED", "r_effective_rows": 3 } } @@ -493,6 +494,7 @@ ANALYZE "join_type": "BNL", "r_loops": 2, "r_filtered": 100, + "r_unpack_time_ms": "REPLACED", "r_effective_rows": 3 } } @@ -559,6 +561,7 @@ ANALYZE "join_type": "BNL", "r_loops": 3, "r_filtered": 100, + "r_unpack_time_ms": "REPLACED", "r_effective_rows": 3 } } @@ -597,6 +600,7 @@ ANALYZE "join_type": "BNL", "r_loops": 2, "r_filtered": 100, + "r_unpack_time_ms": "REPLACED", "r_effective_rows": 3 } } diff --git a/mysql-test/main/explain_json.result b/mysql-test/main/explain_json.result index 3c3ee55e59e83..3976d14913b89 100644 --- a/mysql-test/main/explain_json.result +++ b/mysql-test/main/explain_json.result @@ -1546,6 +1546,7 @@ ANALYZE "mrr_type": "Rowid-ordered scan", "r_loops": 10, "r_filtered": 100, + "r_unpack_time_ms": "REPLACED", "r_effective_rows": 1 } } diff --git a/mysql-test/main/intersect.result b/mysql-test/main/intersect.result index 149e67850e0d3..d491aab03ff66 100644 --- a/mysql-test/main/intersect.result +++ b/mysql-test/main/intersect.result @@ -397,6 +397,7 @@ ANALYZE "join_type": "BNL", "r_loops": 3, "r_filtered": 100, + "r_unpack_time_ms": "REPLACED", "r_effective_rows": 3 } } @@ -482,6 +483,7 @@ ANALYZE "join_type": "BNL", "r_loops": 3, "r_filtered": 100, + "r_unpack_time_ms": "REPLACED", "r_effective_rows": 3 } } diff --git a/mysql-test/main/intersect_all.result b/mysql-test/main/intersect_all.result index d046a5ea8811f..89420280133d4 100644 --- a/mysql-test/main/intersect_all.result +++ b/mysql-test/main/intersect_all.result @@ -428,6 +428,7 @@ ANALYZE "join_type": "BNL", "r_loops": 5, "r_filtered": 100, + "r_unpack_time_ms": "REPLACED", "r_effective_rows": 7 } } @@ -513,6 +514,7 @@ ANALYZE "join_type": "BNL", "r_loops": 5, "r_filtered": 100, + "r_unpack_time_ms": "REPLACED", "r_effective_rows": 7 } } diff --git a/mysql-test/main/rowid_filter_innodb.result b/mysql-test/main/rowid_filter_innodb.result index 113d4d0cb2205..e20d5aacfeab3 100644 --- a/mysql-test/main/rowid_filter_innodb.result +++ b/mysql-test/main/rowid_filter_innodb.result @@ -3687,6 +3687,7 @@ ANALYZE "attached_condition": "a.atp = 1", "r_loops": 3, "r_filtered": 100, + "r_unpack_time_ms": "REPLACED", "r_effective_rows": 1 }, "block-nl-join": { @@ -3713,6 +3714,7 @@ ANALYZE "attached_condition": "fi.fh in (6311439873746261694,-397087483897438286,8518228073041491534,-5420422472375069774)", "r_loops": 3, "r_filtered": 40, + "r_unpack_time_ms": "REPLACED", "r_effective_rows": 26.66666667 } } diff --git a/sql/sql_explain.cc b/sql/sql_explain.cc index caec818d130bc..e8f77317c841d 100644 --- a/sql/sql_explain.cc +++ b/sql/sql_explain.cc @@ -1898,6 +1898,9 @@ void Explain_table_access::print_explain_json(Explain_query *query, writer->add_double(jbuf_tracker.get_filtered_after_where()*100.0); else writer->add_null(); + + writer->add_member("r_unpack_time_ms"); + writer->add_double(jbuf_unpack_tracker.get_time_ms()); /* effective_rows is average number of matches we got for an incoming row. The row is stored in the join buffer and then is read diff --git a/sql/sql_explain.h b/sql/sql_explain.h index 746e1db1abdfc..a80d4049e4cc4 100644 --- a/sql/sql_explain.h +++ b/sql/sql_explain.h @@ -722,7 +722,7 @@ class Explain_range_checked_fer : public Sql_alloc class Explain_table_access : public Sql_alloc { public: - Explain_table_access(MEM_ROOT *root) : + Explain_table_access(MEM_ROOT *root, bool timed) : derived_select_number(0), non_merged_sjm_number(0), extra_tags(root), @@ -735,6 +735,7 @@ class Explain_table_access : public Sql_alloc pushed_index_cond(NULL), sjm_nest(NULL), pre_join_sort(NULL), + jbuf_unpack_tracker(timed), rowid_filter(NULL) {} ~Explain_table_access() { delete sjm_nest; } @@ -844,7 +845,12 @@ class Explain_table_access : public Sql_alloc /* When using join buffer: Track the reads from join buffer */ Table_access_tracker jbuf_tracker; - + + /* + Track the time to unpack rows from the join buffer. + */ + Time_and_counter_tracker jbuf_unpack_tracker; + /* When using join buffer: Track the number of incoming record combinations */ Counter_tracker jbuf_loops_tracker; diff --git a/sql/sql_join_cache.cc b/sql/sql_join_cache.cc index c7b6a0bf6e4c9..36eae30de1669 100644 --- a/sql/sql_join_cache.cc +++ b/sql/sql_join_cache.cc @@ -1614,7 +1614,7 @@ bool JOIN_CACHE::get_record() pos+= referenced_fields*size_of_fld_ofs; if (prev_cache) prev_cache->get_record_by_pos(prev_rec_ptr); - } + } return res; } @@ -2389,7 +2389,9 @@ enum_nested_loop_state JOIN_CACHE::join_matching_records(bool skip_last) (join_tab->first_inner && !not_exists_opt_is_applicable) || !skip_next_candidate_for_match(rec_ptr)) { - read_next_candidate_for_match(rec_ptr); + ANALYZE_START_TRACKING(join->thd, join_tab->jbuf_unpack_tracker); + read_next_candidate_for_match(rec_ptr); + ANALYZE_STOP_TRACKING(join->thd, join_tab->jbuf_unpack_tracker); rc= generate_full_extensions(rec_ptr); if (rc != NESTED_LOOP_OK && rc != NESTED_LOOP_NO_MORE_ROWS) goto finish; diff --git a/sql/sql_select.cc b/sql/sql_select.cc index 2889d757e20d7..4abf9f2fad653 100644 --- a/sql/sql_select.cc +++ b/sql/sql_select.cc @@ -27396,6 +27396,7 @@ bool JOIN_TAB::save_explain_data(Explain_table_access *eta, tracker= &eta->tracker; jbuf_tracker= &eta->jbuf_tracker; jbuf_loops_tracker= &eta->jbuf_loops_tracker; + jbuf_unpack_tracker= &eta->jbuf_unpack_tracker; /* Enable the table access time tracker only for "ANALYZE stmt" */ if (thd->lex->analyze_stmt) @@ -28029,7 +28030,8 @@ int JOIN::save_explain_data_intern(Explain_query *output, Explain_table_access *eta= (new (output->mem_root) - Explain_table_access(output->mem_root)); + Explain_table_access(output->mem_root, + thd->lex->analyze_stmt)); if (!eta) DBUG_RETURN(1); diff --git a/sql/sql_select.h b/sql/sql_select.h index 178573413aff3..043c414d01669 100644 --- a/sql/sql_select.h +++ b/sql/sql_select.h @@ -309,6 +309,7 @@ typedef struct st_join_table { Table_access_tracker *tracker; Table_access_tracker *jbuf_tracker; + Time_and_counter_tracker *jbuf_unpack_tracker; Counter_tracker *jbuf_loops_tracker; /* Bitmap of TAB_INFO_* bits that encodes special line for EXPLAIN 'Extra' From 31536b2477a744ea99f012b6d42adc6591565341 Mon Sep 17 00:00:00 2001 From: Sergei Petrunia Date: Fri, 31 Mar 2023 16:16:53 +0300 Subject: [PATCH 80/92] MDEV-30972: ANALYZE FORMAT=JSON: some time is unaccounted-for in BNL-H join After MDEV-30830 has added block-nl-join.r_unpack_time_ms, it became apparent that there is some unaccounted-for time in BNL join operation, namely the time that is spent after unpacking the join buffer record. Fix this by adding a Gap_time_tracker to track the time that is spent after unpacking the join buffer record and before any next time tracking. The collected time is printed in block-nl-join.r_other_time_ms. Reviewed by: Monty --- mysql-test/main/analyze_format_json.result | 7 ++ .../main/analyze_format_json_timings.result | 82 +++++++++++++++++++ .../main/analyze_format_json_timings.test | 50 +++++++++++ mysql-test/main/analyze_stmt_orderby.result | 2 + mysql-test/main/except.result | 4 + mysql-test/main/except_all.result | 4 + mysql-test/main/explain_json.result | 1 + mysql-test/main/intersect.result | 2 + mysql-test/main/intersect_all.result | 2 + mysql-test/main/rowid_filter_innodb.result | 2 + sql/sql_analyze_stmt.h | 13 ++- sql/sql_explain.cc | 3 + sql/sql_explain.h | 9 +- sql/sql_select.cc | 4 +- 14 files changed, 178 insertions(+), 7 deletions(-) diff --git a/mysql-test/main/analyze_format_json.result b/mysql-test/main/analyze_format_json.result index 2329ef2ce6094..b9f275af742c0 100644 --- a/mysql-test/main/analyze_format_json.result +++ b/mysql-test/main/analyze_format_json.result @@ -154,6 +154,7 @@ ANALYZE "r_loops": 20, "r_filtered": 100, "r_unpack_time_ms": "REPLACED", + "r_other_time_ms": "REPLACED", "r_effective_rows": 60 } } @@ -198,6 +199,7 @@ ANALYZE "r_loops": 20, "r_filtered": 15.83333333, "r_unpack_time_ms": "REPLACED", + "r_other_time_ms": "REPLACED", "r_effective_rows": 60 } } @@ -661,6 +663,7 @@ ANALYZE "r_loops": 2, "r_filtered": null, "r_unpack_time_ms": "REPLACED", + "r_other_time_ms": "REPLACED", "r_effective_rows": 0 }, "subqueries": [ @@ -754,6 +757,7 @@ ANALYZE "r_loops": 2, "r_filtered": null, "r_unpack_time_ms": "REPLACED", + "r_other_time_ms": "REPLACED", "r_effective_rows": 0 }, "subqueries": [ @@ -789,6 +793,7 @@ ANALYZE "r_loops": 0, "r_filtered": null, "r_unpack_time_ms": "REPLACED", + "r_other_time_ms": "REPLACED", "r_effective_rows": null } } @@ -927,6 +932,7 @@ ANALYZE "r_loops": 100, "r_filtered": 0.424285714, "r_unpack_time_ms": "REPLACED", + "r_other_time_ms": "REPLACED", "r_effective_rows": 700 } } @@ -980,6 +986,7 @@ ANALYZE "r_loops": 100, "r_filtered": 100, "r_unpack_time_ms": "REPLACED", + "r_other_time_ms": "REPLACED", "r_effective_rows": 2.97 } } diff --git a/mysql-test/main/analyze_format_json_timings.result b/mysql-test/main/analyze_format_json_timings.result index 4d8a65ae0e70b..6cced9ec6b1e2 100644 --- a/mysql-test/main/analyze_format_json_timings.result +++ b/mysql-test/main/analyze_format_json_timings.result @@ -77,6 +77,7 @@ X "r_loops": 500, "r_filtered": 100, "r_unpack_time_ms": "REPLACED", + "r_other_time_ms": "REPLACED", "r_effective_rows": 0.594 } } @@ -87,3 +88,84 @@ cast(json_extract(@out,'$[0]') as DOUBLE) > 0 1 set join_cache_level=@tmp; drop table t1, t2; +# +# MDEV-30972: ANALYZE FORMAT=JSON: some time is unaccounted-for in BNL-H join +# +create table t1 ( +a int, +col1 varchar(100), +col2 varchar(100), +col3 varchar(100) +); +insert into t1 select +seq/100, +concat('col1-', seq), +concat('col1-', seq), +concat('col1-', seq) +from seq_1_to_1000; +create table t2 ( +a int, +col1 varchar(100), +col2 varchar(100), +col3 varchar(100) +); +insert into t2 select +seq/100, +concat('col1-', seq), +concat('col1-', seq), +concat('col1-', seq) +from seq_1_to_2000; +set @tmp=@@join_cache_level, join_cache_level=6; +select '$out' as X; +X +{ + "query_block": { + "select_id": 1, + "r_loops": 1, + "r_total_time_ms": "REPLACED", + "table": { + "table_name": "t1", + "access_type": "ALL", + "r_loops": 1, + "rows": 1000, + "r_rows": 1000, + "r_table_time_ms": "REPLACED", + "r_other_time_ms": "REPLACED", + "filtered": 100, + "r_filtered": 100, + "attached_condition": "t1.a is not null" + }, + "block-nl-join": { + "table": { + "table_name": "t2", + "access_type": "hash_ALL", + "key": "#hash#$hj", + "key_length": "5", + "used_key_parts": ["a"], + "ref": ["test.t1.a"], + "r_loops": 1, + "rows": 2000, + "r_rows": 2000, + "r_table_time_ms": "REPLACED", + "r_other_time_ms": "REPLACED", + "filtered": 100, + "r_filtered": 100 + }, + "buffer_type": "flat", + "buffer_size": "256Kb", + "join_type": "BNLH", + "attached_condition": "t2.a = t1.a and concat(t1.col1,t1.col2,t1.col3) = concat(t2.col1,t2.col2,t2.col3)", + "r_loops": 1000, + "r_filtered": 1.025630506, + "r_unpack_time_ms": "REPLACED", + "r_other_time_ms": "REPLACED", + "r_effective_rows": 97.501 + } + } +} +set @out=(select json_extract(@js,'$**.block-nl-join.r_other_time_ms')); +select cast(json_extract(@out,'$[0]') as DOUBLE) > 0; +cast(json_extract(@out,'$[0]') as DOUBLE) > 0 +1 +set join_cache_level=@tmp; +drop table t1, t2; diff --git a/mysql-test/main/analyze_format_json_timings.test b/mysql-test/main/analyze_format_json_timings.test index fdb4c8d598967..fe02c31838893 100644 --- a/mysql-test/main/analyze_format_json_timings.test +++ b/mysql-test/main/analyze_format_json_timings.test @@ -75,3 +75,53 @@ select cast(json_extract(@out,'$[0]') as DOUBLE) > 0; set join_cache_level=@tmp; drop table t1, t2; +--echo # +--echo # MDEV-30972: ANALYZE FORMAT=JSON: some time is unaccounted-for in BNL-H join +--echo # + +create table t1 ( + a int, + col1 varchar(100), + col2 varchar(100), + col3 varchar(100) +); + +insert into t1 select + seq/100, + concat('col1-', seq), + concat('col1-', seq), + concat('col1-', seq) +from seq_1_to_1000; + +create table t2 ( + a int, + col1 varchar(100), + col2 varchar(100), + col3 varchar(100) +); + +insert into t2 select + seq/100, + concat('col1-', seq), + concat('col1-', seq), + concat('col1-', seq) +from seq_1_to_2000; + +set @tmp=@@join_cache_level, join_cache_level=6; + +let $out=` +analyze format=json +select * from t1, t2 +where + t1.a=t2.a + and concat(t1.col1, t1.col2, t1.col3)= concat(t2.col1, t2.col2, t2.col3) +`; +--source include/analyze-format.inc +evalp select '$out' as X; + +set @out=(select json_extract(@js,'$**.block-nl-join.r_other_time_ms')); +select cast(json_extract(@out,'$[0]') as DOUBLE) > 0; + +set join_cache_level=@tmp; +drop table t1, t2; + diff --git a/mysql-test/main/analyze_stmt_orderby.result b/mysql-test/main/analyze_stmt_orderby.result index c615d1e7d5f17..7f03e2b2673af 100644 --- a/mysql-test/main/analyze_stmt_orderby.result +++ b/mysql-test/main/analyze_stmt_orderby.result @@ -444,6 +444,7 @@ ANALYZE "r_loops": 10, "r_filtered": 10, "r_unpack_time_ms": "REPLACED", + "r_other_time_ms": "REPLACED", "r_effective_rows": 10 } } @@ -522,6 +523,7 @@ ANALYZE "r_loops": 4, "r_filtered": 21.42857143, "r_unpack_time_ms": "REPLACED", + "r_other_time_ms": "REPLACED", "r_effective_rows": 7 } } diff --git a/mysql-test/main/except.result b/mysql-test/main/except.result index 67fee0bcabfde..5614ab18bf054 100644 --- a/mysql-test/main/except.result +++ b/mysql-test/main/except.result @@ -337,6 +337,7 @@ ANALYZE "r_loops": 2, "r_filtered": 100, "r_unpack_time_ms": "REPLACED", + "r_other_time_ms": "REPLACED", "r_effective_rows": 2 } } @@ -376,6 +377,7 @@ ANALYZE "r_loops": 2, "r_filtered": 100, "r_unpack_time_ms": "REPLACED", + "r_other_time_ms": "REPLACED", "r_effective_rows": 2 } } @@ -444,6 +446,7 @@ ANALYZE "r_loops": 2, "r_filtered": 100, "r_unpack_time_ms": "REPLACED", + "r_other_time_ms": "REPLACED", "r_effective_rows": 2 } } @@ -483,6 +486,7 @@ ANALYZE "r_loops": 2, "r_filtered": 100, "r_unpack_time_ms": "REPLACED", + "r_other_time_ms": "REPLACED", "r_effective_rows": 2 } } diff --git a/mysql-test/main/except_all.result b/mysql-test/main/except_all.result index 70b52f13161ac..113c161a98b9e 100644 --- a/mysql-test/main/except_all.result +++ b/mysql-test/main/except_all.result @@ -456,6 +456,7 @@ ANALYZE "r_loops": 3, "r_filtered": 100, "r_unpack_time_ms": "REPLACED", + "r_other_time_ms": "REPLACED", "r_effective_rows": 3 } } @@ -495,6 +496,7 @@ ANALYZE "r_loops": 2, "r_filtered": 100, "r_unpack_time_ms": "REPLACED", + "r_other_time_ms": "REPLACED", "r_effective_rows": 3 } } @@ -562,6 +564,7 @@ ANALYZE "r_loops": 3, "r_filtered": 100, "r_unpack_time_ms": "REPLACED", + "r_other_time_ms": "REPLACED", "r_effective_rows": 3 } } @@ -601,6 +604,7 @@ ANALYZE "r_loops": 2, "r_filtered": 100, "r_unpack_time_ms": "REPLACED", + "r_other_time_ms": "REPLACED", "r_effective_rows": 3 } } diff --git a/mysql-test/main/explain_json.result b/mysql-test/main/explain_json.result index 3976d14913b89..c3cff36626dd1 100644 --- a/mysql-test/main/explain_json.result +++ b/mysql-test/main/explain_json.result @@ -1547,6 +1547,7 @@ ANALYZE "r_loops": 10, "r_filtered": 100, "r_unpack_time_ms": "REPLACED", + "r_other_time_ms": "REPLACED", "r_effective_rows": 1 } } diff --git a/mysql-test/main/intersect.result b/mysql-test/main/intersect.result index d491aab03ff66..25d81a7fc34f3 100644 --- a/mysql-test/main/intersect.result +++ b/mysql-test/main/intersect.result @@ -398,6 +398,7 @@ ANALYZE "r_loops": 3, "r_filtered": 100, "r_unpack_time_ms": "REPLACED", + "r_other_time_ms": "REPLACED", "r_effective_rows": 3 } } @@ -484,6 +485,7 @@ ANALYZE "r_loops": 3, "r_filtered": 100, "r_unpack_time_ms": "REPLACED", + "r_other_time_ms": "REPLACED", "r_effective_rows": 3 } } diff --git a/mysql-test/main/intersect_all.result b/mysql-test/main/intersect_all.result index 89420280133d4..da5d778daab70 100644 --- a/mysql-test/main/intersect_all.result +++ b/mysql-test/main/intersect_all.result @@ -429,6 +429,7 @@ ANALYZE "r_loops": 5, "r_filtered": 100, "r_unpack_time_ms": "REPLACED", + "r_other_time_ms": "REPLACED", "r_effective_rows": 7 } } @@ -515,6 +516,7 @@ ANALYZE "r_loops": 5, "r_filtered": 100, "r_unpack_time_ms": "REPLACED", + "r_other_time_ms": "REPLACED", "r_effective_rows": 7 } } diff --git a/mysql-test/main/rowid_filter_innodb.result b/mysql-test/main/rowid_filter_innodb.result index e20d5aacfeab3..c5a27f8b60ea1 100644 --- a/mysql-test/main/rowid_filter_innodb.result +++ b/mysql-test/main/rowid_filter_innodb.result @@ -3688,6 +3688,7 @@ ANALYZE "r_loops": 3, "r_filtered": 100, "r_unpack_time_ms": "REPLACED", + "r_other_time_ms": "REPLACED", "r_effective_rows": 1 }, "block-nl-join": { @@ -3715,6 +3716,7 @@ ANALYZE "r_loops": 3, "r_filtered": 40, "r_unpack_time_ms": "REPLACED", + "r_other_time_ms": "REPLACED", "r_effective_rows": 26.66666667 } } diff --git a/sql/sql_analyze_stmt.h b/sql/sql_analyze_stmt.h index fdbd5955f3319..e2037279a7a89 100644 --- a/sql/sql_analyze_stmt.h +++ b/sql/sql_analyze_stmt.h @@ -63,14 +63,19 @@ class Exec_time_tracker if (my_gap_tracker) attach_gap_time_tracker(thd, my_gap_tracker, end); } -public: - Exec_time_tracker() : count(0), cycles(0), my_gap_tracker(NULL) {} /* - The time spent between stop_tracking() call on this object and any - other time measurement will be billed to this tracker. + The time spent after stop_tracking() call on this object and any + subsequent time tracking call will be billed to this tracker. */ Gap_time_tracker *my_gap_tracker; +public: + Exec_time_tracker() : count(0), cycles(0), my_gap_tracker(NULL) {} + + void set_gap_tracker(Gap_time_tracker *gap_tracker) + { + my_gap_tracker= gap_tracker; + } // interface for collecting time void start_tracking(THD *thd) diff --git a/sql/sql_explain.cc b/sql/sql_explain.cc index e8f77317c841d..2874417d8df6c 100644 --- a/sql/sql_explain.cc +++ b/sql/sql_explain.cc @@ -1901,6 +1901,9 @@ void Explain_table_access::print_explain_json(Explain_query *query, writer->add_member("r_unpack_time_ms"); writer->add_double(jbuf_unpack_tracker.get_time_ms()); + + writer->add_member("r_other_time_ms"). + add_double(jbuf_extra_time_tracker.get_time_ms()); /* effective_rows is average number of matches we got for an incoming row. The row is stored in the join buffer and then is read diff --git a/sql/sql_explain.h b/sql/sql_explain.h index a80d4049e4cc4..84e2b1db89a28 100644 --- a/sql/sql_explain.h +++ b/sql/sql_explain.h @@ -846,10 +846,15 @@ class Explain_table_access : public Sql_alloc /* When using join buffer: Track the reads from join buffer */ Table_access_tracker jbuf_tracker; + /* When using join buffer: time spent unpacking rows from the join buffer */ + Time_and_counter_tracker jbuf_unpack_tracker; + /* - Track the time to unpack rows from the join buffer. + When using join buffer: time spent after unpacking rows from the join + buffer. This will capture the time spent checking the Join Condition: + the condition that depends on this table and preceding tables. */ - Time_and_counter_tracker jbuf_unpack_tracker; + Gap_time_tracker jbuf_extra_time_tracker; /* When using join buffer: Track the number of incoming record combinations */ Counter_tracker jbuf_loops_tracker; diff --git a/sql/sql_select.cc b/sql/sql_select.cc index 4abf9f2fad653..8769a03404dcd 100644 --- a/sql/sql_select.cc +++ b/sql/sql_select.cc @@ -27402,7 +27402,9 @@ bool JOIN_TAB::save_explain_data(Explain_table_access *eta, if (thd->lex->analyze_stmt) { table->file->set_time_tracker(&eta->op_tracker); - eta->op_tracker.my_gap_tracker = &eta->extra_time_tracker; + eta->op_tracker.set_gap_tracker(&eta->extra_time_tracker); + + eta->jbuf_unpack_tracker.set_gap_tracker(&eta->jbuf_extra_time_tracker); } /* No need to save id and select_type here, they are kept in Explain_select */ From afdf19cf3303bf3797fe47e5cef398227134cc32 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jan=20Lindstr=C3=B6m?= Date: Tue, 4 Apr 2023 03:11:41 +0200 Subject: [PATCH 81/92] MDEV-28641 : Query cache entries not invalidated on slave of a Galera cluster Query cache should be invalidated if we are not in applier. For some reason this condition was incorrect starting from 10.5 but it is correct in 10.4. Signed-off-by: Julius Goryavsky --- mysql-test/suite/galera/galera_2x2nodes.cnf | 77 +++++++++++ .../r/galera_query_cache_invalidate.result | 119 +++++++++++++++++ .../t/galera_query_cache_invalidate.cnf | 25 ++++ .../t/galera_query_cache_invalidate.test | 120 ++++++++++++++++++ sql/log_event_server.cc | 3 +- 5 files changed, 343 insertions(+), 1 deletion(-) create mode 100644 mysql-test/suite/galera/galera_2x2nodes.cnf create mode 100644 mysql-test/suite/galera/r/galera_query_cache_invalidate.result create mode 100644 mysql-test/suite/galera/t/galera_query_cache_invalidate.cnf create mode 100644 mysql-test/suite/galera/t/galera_query_cache_invalidate.test diff --git a/mysql-test/suite/galera/galera_2x2nodes.cnf b/mysql-test/suite/galera/galera_2x2nodes.cnf new file mode 100644 index 0000000000000..922906eac6f39 --- /dev/null +++ b/mysql-test/suite/galera/galera_2x2nodes.cnf @@ -0,0 +1,77 @@ +# Use default setting for mysqld processes +!include include/default_mysqld.cnf + +[mysqld] +loose-innodb +log-bin=mysqld-bin +log-slave-updates +binlog-format=row +innodb-autoinc-lock-mode=2 +default-storage-engine=innodb +wsrep_gtid_mode=1 +gtid_ignore_duplicates +auto_increment_increment=3 + +wsrep-provider=@ENV.WSREP_PROVIDER +# enforce read-committed characteristics across the cluster +# wsrep-causal-reads=ON +wsrep-sync-wait=15 + +[mysqld.1] +wsrep-on=1 +#galera_port=@OPT.port +#ist_port=@OPT.port +#sst_port=@OPT.port +wsrep_cluster_address=gcomm:// +wsrep_provider_options='repl.causal_read_timeout=PT90S;base_port=@mysqld.1.#galera_port;evs.suspect_timeout=PT10S;evs.inactive_timeout=PT30S;evs.install_timeout=PT15S;pc.wait_prim_timeout=PT60S;gcache.size=10M' +wsrep_node_address='127.0.0.1:@mysqld.1.#galera_port' +wsrep_node_incoming_address=127.0.0.1:@mysqld.1.port +wsrep_sst_receive_address='127.0.0.1:@mysqld.1.#sst_port' + +[mysqld.2] +wsrep-on=1 +#galera_port=@OPT.port +#ist_port=@OPT.port +#sst_port=@OPT.port +wsrep_cluster_address='gcomm://127.0.0.1:@mysqld.1.#galera_port' +wsrep_provider_options='repl.causal_read_timeout=PT90S;base_port=@mysqld.2.#galera_port;evs.suspect_timeout=PT10S;evs.inactive_timeout=PT30S;evs.install_timeout=PT15S;pc.wait_prim_timeout=PT60S;gcache.size=10M' +wsrep_node_address='127.0.0.1:@mysqld.2.#galera_port' +wsrep_node_incoming_address=127.0.0.1:@mysqld.2.port +wsrep_sst_receive_address='127.0.0.1:@mysqld.2.#sst_port' + +[mysqld.3] +wsrep-on=1 +#galera_port=@OPT.port +#ist_port=@OPT.port +#sst_port=@OPT.port +wsrep_cluster_address=gcomm:// +wsrep_provider_options='repl.causal_read_timeout=PT90S;base_port=@mysqld.3.#galera_port;evs.suspect_timeout=PT10S;evs.inactive_timeout=PT30S;evs.install_timeout=PT15S;pc.wait_prim_timeout=PT60S;gcache.size=10M' +wsrep_node_address='127.0.0.1:@mysqld.3.#galera_port' +wsrep_node_incoming_address=127.0.0.1:@mysqld.3.port +wsrep_sst_receive_address='127.0.0.1:@mysqld.3.#sst_port' + +[mysqld.4] +wsrep-on=1 +#galera_port=@OPT.port +#ist_port=@OPT.port +#sst_port=@OPT.port +wsrep_cluster_address='gcomm://127.0.0.1:@mysqld.3.#galera_port' +wsrep_provider_options='repl.causal_read_timeout=PT90S;base_port=@mysqld.4.#galera_port;evs.suspect_timeout=PT10S;evs.inactive_timeout=PT30S;evs.install_timeout=PT15S;pc.wait_prim_timeout=PT60S;gcache.size=10M' +wsrep_node_address='127.0.0.1:@mysqld.4.#galera_port' +wsrep_node_incoming_address=127.0.0.1:@mysqld.4.port +wsrep_sst_receive_address='127.0.0.1:@mysqld.4.#sst_port' + +[ENV] +NODE_MYPORT_1= @mysqld.1.port +NODE_MYSOCK_1= @mysqld.1.socket + +NODE_MYPORT_2= @mysqld.2.port +NODE_MYSOCK_2= @mysqld.2.socket + +NODE_MYPORT_3= @mysqld.3.port +NODE_MYSOCK_3= @mysqld.3.socket + +NODE_MYPORT_4= @mysqld.4.port +NODE_MYSOCK_4= @mysqld.4.socket + + diff --git a/mysql-test/suite/galera/r/galera_query_cache_invalidate.result b/mysql-test/suite/galera/r/galera_query_cache_invalidate.result new file mode 100644 index 0000000000000..98438b3b52782 --- /dev/null +++ b/mysql-test/suite/galera/r/galera_query_cache_invalidate.result @@ -0,0 +1,119 @@ +connection node_2; +connection node_1; +connect node_3, 127.0.0.1, root, , test, $NODE_MYPORT_3; +connect node_4, 127.0.0.1, root, , test, $NODE_MYPORT_4; +connection node_2; +call mtr.add_suppression("WSREP: Ignoring server id for non bootstrap node."); +connection node_4; +call mtr.add_suppression("WSREP: Ignoring server id for non bootstrap node."); +connection node_3; +CHANGE MASTER TO master_host='127.0.0.1', master_user='root', master_port=NODE_MYPORT_1, master_use_gtid=current_pos;; +START SLAVE; +include/wait_for_slave_to_start.inc +connection node_1; +CREATE TABLE t1 (id bigint primary key, msg varchar(100)) engine=innodb; +SET AUTOCOMMIT=1; +INSERT INTO t1 VALUES (4000000, 'foobar'); +SELECT COUNT(*) FROM t1; +COUNT(*) +50001 +connection node_3; +connection node_1; +# node_1 +SELECT * FROM t1 WHERE msg='foobar'; +id msg +4000000 foobar +SELECT * FROM t1 WHERE msg='foobar'; +id msg +4000000 foobar +connection node_2; +# node_2 +SELECT * FROM t1 WHERE msg='foobar'; +id msg +4000000 foobar +SELECT * FROM t1 WHERE msg='foobar'; +id msg +4000000 foobar +connection node_3; +# node_3 +SELECT * FROM t1 WHERE msg='foobar'; +id msg +4000000 foobar +SELECT * FROM t1 WHERE msg='foobar'; +id msg +4000000 foobar +connection node_4; +# node_4 +SELECT * FROM t1 WHERE msg='foobar'; +id msg +4000000 foobar +SELECT * FROM t1 WHERE msg='foobar'; +id msg +4000000 foobar +connection node_1; +# node_1 insert new +INSERT INTO t1 values (5000000, 'foobar'); +connection node_3; +SELECT * FROM t1 WHERE msg='foobar'; +id msg +4000000 foobar +5000000 foobar +SELECT * FROM t1 WHERE msg='foobar'; +id msg +4000000 foobar +5000000 foobar +connection node_2; +# node_2 +SELECT * FROM t1 WHERE msg='foobar'; +id msg +4000000 foobar +5000000 foobar +SELECT * FROM t1 WHERE msg='foobar'; +id msg +4000000 foobar +5000000 foobar +connection node_3; +# node_3 +SELECT * FROM t1 WHERE msg='foobar'; +id msg +4000000 foobar +5000000 foobar +SELECT * FROM t1 WHERE msg='foobar'; +id msg +4000000 foobar +5000000 foobar +connection node_4; +# node_4 +SELECT * FROM t1 WHERE msg='foobar'; +id msg +4000000 foobar +5000000 foobar +SELECT * FROM t1 WHERE msg='foobar'; +id msg +4000000 foobar +5000000 foobar +connection node_2; +# node_3 different query same table +SELECT id, msg FROM t1 WHERE msg='foobar'; +id msg +4000000 foobar +5000000 foobar +connection node_4; +# node_6 different query same table +SELECT id, msg FROM t1 WHERE msg='foobar'; +id msg +4000000 foobar +5000000 foobar +connection node_1; +drop table t1; +connection node_3; +connection node_3; +STOP SLAVE; +RESET SLAVE ALL; +connection node_1; +SET SESSION WSREP_ON=OFF; +RESET MASTER; +SET SESSION WSREP_ON=ON; +disconnect node_2; +disconnect node_1; +# End of test diff --git a/mysql-test/suite/galera/t/galera_query_cache_invalidate.cnf b/mysql-test/suite/galera/t/galera_query_cache_invalidate.cnf new file mode 100644 index 0000000000000..49269422a35fd --- /dev/null +++ b/mysql-test/suite/galera/t/galera_query_cache_invalidate.cnf @@ -0,0 +1,25 @@ +!include ../galera_2x2nodes.cnf + +[mysqld.1] +wsrep_gtid_domain_id=1 +server-id=11 +query_cache_type=1 +query_cache_size=15M + +[mysqld.2] +wsrep_gtid_domain_id=1 +server-id=12 +query_cache_type=1 +query_cache_size=15M + +[mysqld.3] +wsrep_gtid_domain_id=2 +server-id=13 +query_cache_type=1 +query_cache_size=15M + +[mysqld.4] +wsrep_gtid_domain_id=2 +server-id=21 +query_cache_type=1 +query_cache_size=15M diff --git a/mysql-test/suite/galera/t/galera_query_cache_invalidate.test b/mysql-test/suite/galera/t/galera_query_cache_invalidate.test new file mode 100644 index 0000000000000..d72d8a9ba40b1 --- /dev/null +++ b/mysql-test/suite/galera/t/galera_query_cache_invalidate.test @@ -0,0 +1,120 @@ +--source include/big_test.inc +--source include/force_restart.inc +--source include/galera_cluster.inc +--source include/have_sequence.inc + +# +# MDEV-28641 : Query cache entries not invalidated on slave of a Galera cluster +# +# We use two 2-node galera clusters as follows +# +# A(1) <-> B(2) {Galera cluster 1} +# | {Async replication} +# D(3) <-> E(4) {Galera cluster 2} +# +# Normal asyncronous replication is used between nodes 1 and 3 +# so that node_1 is master and node_3 a slave. +# +# In this test we can't test is some query fast or slow but we can +# test does all nodes see all rows (this is not true before fix) +# +--connect node_3, 127.0.0.1, root, , test, $NODE_MYPORT_3 +--connect node_4, 127.0.0.1, root, , test, $NODE_MYPORT_4 + +--connection node_2 +call mtr.add_suppression("WSREP: Ignoring server id for non bootstrap node."); +--connection node_4 +call mtr.add_suppression("WSREP: Ignoring server id for non bootstrap node."); + +--connection node_3 + +--replace_result $NODE_MYPORT_1 NODE_MYPORT_1 +--eval CHANGE MASTER TO master_host='127.0.0.1', master_user='root', master_port=$NODE_MYPORT_1, master_use_gtid=current_pos; +START SLAVE; +--source include/wait_for_slave_to_start.inc + +--connection node_1 + +CREATE TABLE t1 (id bigint primary key, msg varchar(100)) engine=innodb; +--disable_query_log +INSERT INTO t1 SELECT seq, md5(rand()) from seq_1_to_50000; +COMMIT; +--enable_query_log +SET AUTOCOMMIT=1; +INSERT INTO t1 VALUES (4000000, 'foobar'); +SELECT COUNT(*) FROM t1; +--sync_slave_with_master node_3 + +# +# All nodes should see one row and first query is slow and second fast +# +--connection node_1 +--echo # node_1 +SELECT * FROM t1 WHERE msg='foobar'; +SELECT * FROM t1 WHERE msg='foobar'; +--connection node_2 +--echo # node_2 +SELECT * FROM t1 WHERE msg='foobar'; +SELECT * FROM t1 WHERE msg='foobar'; +--connection node_3 +--echo # node_3 +SELECT * FROM t1 WHERE msg='foobar'; +SELECT * FROM t1 WHERE msg='foobar'; +--connection node_4 +--echo # node_4 +SELECT * FROM t1 WHERE msg='foobar'; +SELECT * FROM t1 WHERE msg='foobar'; +# +# Insert a new row in master, this should cause query cache +# invalidation +# +--connection node_1 +--echo # node_1 insert new +INSERT INTO t1 values (5000000, 'foobar'); +--sync_slave_with_master node_3 + +# +# All nodes should see 2 rows +# +SELECT * FROM t1 WHERE msg='foobar'; +SELECT * FROM t1 WHERE msg='foobar'; + +--connection node_2 +--echo # node_2 +SELECT * FROM t1 WHERE msg='foobar'; +SELECT * FROM t1 WHERE msg='foobar'; +--connection node_3 +--echo # node_3 +SELECT * FROM t1 WHERE msg='foobar'; +SELECT * FROM t1 WHERE msg='foobar'; +--connection node_4 +--echo # node_4 +SELECT * FROM t1 WHERE msg='foobar'; +SELECT * FROM t1 WHERE msg='foobar'; + +--connection node_2 +--echo # node_3 different query same table +SELECT id, msg FROM t1 WHERE msg='foobar'; + +--connection node_4 +--echo # node_6 different query same table +SELECT id, msg FROM t1 WHERE msg='foobar'; + +# +# Cleanup +# +--connection node_1 +drop table t1; +--sync_slave_with_master node_3 + +--connection node_3 +STOP SLAVE; +RESET SLAVE ALL; + +--connection node_1 +SET SESSION WSREP_ON=OFF; +RESET MASTER; +SET SESSION WSREP_ON=ON; + +--source include/galera_end.inc +--echo # End of test diff --git a/sql/log_event_server.cc b/sql/log_event_server.cc index 56d1c978ac4d6..c5fb637a00089 100644 --- a/sql/log_event_server.cc +++ b/sql/log_event_server.cc @@ -5586,7 +5586,8 @@ int Rows_log_event::do_apply_event(rpl_group_info *rgi) to avoid query cache being polluted with stale entries, */ # ifdef WITH_WSREP - if (!WSREP(thd) && !wsrep_thd_is_applying(thd)) + /* Query cache is not invalidated on wsrep applier here */ + if (!(WSREP(thd) && wsrep_thd_is_applying(thd))) # endif /* WITH_WSREP */ query_cache.invalidate_locked_for_write(thd, rgi->tables_to_lock); #endif /* HAVE_QUERY_CACHE */ From 8f9bb82640578054feeb67a775410989d28626a3 Mon Sep 17 00:00:00 2001 From: Alexander Barkov Date: Fri, 31 Mar 2023 05:41:00 +0400 Subject: [PATCH 82/92] MDEV-30971 Add a new system variable aria_data_home_dir --- .../suite/maria/aria_log_dir_path.result | 29 +++++++++ mysql-test/suite/maria/aria_log_dir_path.test | 65 +++++++++++++++++++ mysql-test/suite/maria/maria3.result | 1 + .../sys_vars/r/aria_log_dir_path_basic.result | 36 ++++++++++ .../suite/sys_vars/r/sysvars_aria.result | 12 ++++ .../sys_vars/r/sysvars_server_embedded.result | 10 +++ .../r/sysvars_server_notembedded.result | 10 +++ .../sys_vars/t/aria_log_dir_path_basic.test | 35 ++++++++++ mysql-test/suite/sys_vars/t/sysvars_aria.test | 4 ++ storage/maria/ha_maria.cc | 2 +- 10 files changed, 203 insertions(+), 1 deletion(-) create mode 100644 mysql-test/suite/maria/aria_log_dir_path.result create mode 100644 mysql-test/suite/maria/aria_log_dir_path.test create mode 100644 mysql-test/suite/sys_vars/r/aria_log_dir_path_basic.result create mode 100644 mysql-test/suite/sys_vars/t/aria_log_dir_path_basic.test diff --git a/mysql-test/suite/maria/aria_log_dir_path.result b/mysql-test/suite/maria/aria_log_dir_path.result new file mode 100644 index 0000000000000..0a4201544a5f3 --- /dev/null +++ b/mysql-test/suite/maria/aria_log_dir_path.result @@ -0,0 +1,29 @@ +# +# MDEV-30971 Add a new system variable aria_data_home_dir +# +# restart: --loose-aria-log-file-size=8388608 --loose-aria-log-dir-path=MYSQLTEST_VARDIR/tmp/aria_log_dir_path_1 +SET @@global.aria_log_purge_type=external; +SHOW VARIABLES LIKE 'aria_log_file_size'; +Variable_name Value +aria_log_file_size 8388608 +SELECT @@aria_log_dir_path; +@@aria_log_dir_path +MYSQLTEST_VARDIR/tmp/aria_log_dir_path_1 +SET @@global.aria_checkpoint_interval=DEFAULT /*Force checkpoint*/; +SHOW ENGINE aria logs; +Type Name Status +Aria aria_log.00000001 in use +CREATE TABLE t1 (id INT, txt LONGTEXT) ENGINE=Aria; +BEGIN NOT ATOMIC +FOR id IN 0..9 DO +INSERT INTO test.t1 (id, txt) VALUES (id, REPEAT(id,1024*1024)); +END FOR; +END; +$$ +SET @@global.aria_checkpoint_interval=DEFAULT /*Force checkpoint*/; +SHOW ENGINE aria logs; +Type Name Status +Aria aria_log.00000001 free +Aria aria_log.00000002 in use +DROP TABLE t1; +# restart diff --git a/mysql-test/suite/maria/aria_log_dir_path.test b/mysql-test/suite/maria/aria_log_dir_path.test new file mode 100644 index 0000000000000..bc0a31a76b933 --- /dev/null +++ b/mysql-test/suite/maria/aria_log_dir_path.test @@ -0,0 +1,65 @@ +--source include/have_maria.inc +--let $datadir= `SELECT @@datadir` + +--echo # +--echo # MDEV-30971 Add a new system variable aria_data_home_dir +--echo # + +--let $ARIA_LOGDIR=$MYSQLTEST_VARDIR/tmp/aria_log_dir_path_1 +--mkdir $ARIA_LOGDIR +--let $restart_parameters=--loose-aria-log-file-size=8388608 --loose-aria-log-dir-path=$ARIA_LOGDIR +--source include/restart_mysqld.inc + +# +# Test that: +# - aria_log_dir_path is set to a non-default directory. +# - New Aria log files are created in the non-default directory. +# - The contents of the log directory (according to "file_exists" commands) +# is in sync with the "SHOW ENGINE aria logs" ouput. +# + +# Prevent automatic purge +SET @@global.aria_log_purge_type=external; + +SHOW VARIABLES LIKE 'aria_log_file_size'; +--replace_result $MYSQLTEST_VARDIR MYSQLTEST_VARDIR +SELECT @@aria_log_dir_path; + + +SET @@global.aria_checkpoint_interval=DEFAULT /*Force checkpoint*/; +--file_exists $ARIA_LOGDIR/aria_log_control +--file_exists $ARIA_LOGDIR/aria_log.00000001 +--error 1 +--file_exists $ARIA_LOGDIR/aria_log.00000002 +--replace_regex /Size +[0-9]+ ; .+aria_log/aria_log/ +SHOW ENGINE aria logs; + + +CREATE TABLE t1 (id INT, txt LONGTEXT) ENGINE=Aria; +DELIMITER $$; +BEGIN NOT ATOMIC + FOR id IN 0..9 DO + INSERT INTO test.t1 (id, txt) VALUES (id, REPEAT(id,1024*1024)); + END FOR; +END; +$$ +DELIMITER ;$$ + + +SET @@global.aria_checkpoint_interval=DEFAULT /*Force checkpoint*/; +--file_exists $ARIA_LOGDIR/aria_log_control +--file_exists $ARIA_LOGDIR/aria_log.00000001 +--file_exists $ARIA_LOGDIR/aria_log.00000002 +--error 1 +--file_exists $ARIA_LOGDIR/aria_log.00000003 +--replace_regex /Size +[0-9]+ ; .+aria_log/aria_log/ +SHOW ENGINE aria logs; + +DROP TABLE t1; + +--let $restart_parameters= +--source include/restart_mysqld.inc +--remove_file $ARIA_LOGDIR/aria_log_control +--remove_file $ARIA_LOGDIR/aria_log.00000001 +--remove_file $ARIA_LOGDIR/aria_log.00000002 +--rmdir $ARIA_LOGDIR diff --git a/mysql-test/suite/maria/maria3.result b/mysql-test/suite/maria/maria3.result index 47a6ecaf4bb71..4d64033a9c905 100644 --- a/mysql-test/suite/maria/maria3.result +++ b/mysql-test/suite/maria/maria3.result @@ -311,6 +311,7 @@ aria_encrypt_tables # aria_force_start_after_recovery_failures # aria_group_commit # aria_group_commit_interval # +aria_log_dir_path # aria_log_file_size # aria_log_purge_type # aria_max_sort_file_size # diff --git a/mysql-test/suite/sys_vars/r/aria_log_dir_path_basic.result b/mysql-test/suite/sys_vars/r/aria_log_dir_path_basic.result new file mode 100644 index 0000000000000..8563b024a75d7 --- /dev/null +++ b/mysql-test/suite/sys_vars/r/aria_log_dir_path_basic.result @@ -0,0 +1,36 @@ +SELECT COUNT(@@GLOBAL.aria_log_dir_path); +COUNT(@@GLOBAL.aria_log_dir_path) +1 +SET @@GLOBAL.aria_log_dir_path=1; +ERROR HY000: Variable 'aria_log_dir_path' is a read only variable +SELECT COUNT(@@GLOBAL.aria_log_dir_path); +COUNT(@@GLOBAL.aria_log_dir_path) +1 +SELECT @@GLOBAL.aria_log_dir_path = VARIABLE_VALUE +FROM INFORMATION_SCHEMA.GLOBAL_VARIABLES +WHERE VARIABLE_NAME='aria_log_dir_path'; +@@GLOBAL.aria_log_dir_path = VARIABLE_VALUE +1 +SELECT COUNT(@@GLOBAL.aria_log_dir_path); +COUNT(@@GLOBAL.aria_log_dir_path) +1 +SELECT COUNT(VARIABLE_VALUE) +FROM INFORMATION_SCHEMA.GLOBAL_VARIABLES +WHERE VARIABLE_NAME='aria_log_dir_path'; +COUNT(VARIABLE_VALUE) +1 +SELECT @@aria_log_dir_path = @@GLOBAL.aria_log_dir_path; +@@aria_log_dir_path = @@GLOBAL.aria_log_dir_path +1 +SELECT COUNT(@@aria_log_dir_path); +COUNT(@@aria_log_dir_path) +1 +SELECT COUNT(@@local.aria_log_dir_path); +ERROR HY000: Variable 'aria_log_dir_path' is a GLOBAL variable +SELECT COUNT(@@SESSION.aria_log_dir_path); +ERROR HY000: Variable 'aria_log_dir_path' is a GLOBAL variable +SELECT COUNT(@@GLOBAL.aria_log_dir_path); +COUNT(@@GLOBAL.aria_log_dir_path) +1 +SELECT aria_log_dir_path = @@SESSION.aria_log_dir_path; +ERROR 42S22: Unknown column 'aria_log_dir_path' in 'field list' diff --git a/mysql-test/suite/sys_vars/r/sysvars_aria.result b/mysql-test/suite/sys_vars/r/sysvars_aria.result index 7b74c85b6da76..9f5585668b640 100644 --- a/mysql-test/suite/sys_vars/r/sysvars_aria.result +++ b/mysql-test/suite/sys_vars/r/sysvars_aria.result @@ -85,6 +85,18 @@ NUMERIC_BLOCK_SIZE 1 ENUM_VALUE_LIST NULL READ_ONLY NO COMMAND_LINE_ARGUMENT REQUIRED +VARIABLE_NAME ARIA_LOG_DIR_PATH +SESSION_VALUE NULL +DEFAULT_VALUE DATADIR +VARIABLE_SCOPE GLOBAL +VARIABLE_TYPE VARCHAR +VARIABLE_COMMENT Path to the directory where to store transactional log +NUMERIC_MIN_VALUE NULL +NUMERIC_MAX_VALUE NULL +NUMERIC_BLOCK_SIZE NULL +ENUM_VALUE_LIST NULL +READ_ONLY YES +COMMAND_LINE_ARGUMENT REQUIRED VARIABLE_NAME ARIA_LOG_FILE_SIZE SESSION_VALUE NULL DEFAULT_VALUE 1073741824 diff --git a/mysql-test/suite/sys_vars/r/sysvars_server_embedded.result b/mysql-test/suite/sys_vars/r/sysvars_server_embedded.result index 9e56242629151..9454f1b9d96dc 100644 --- a/mysql-test/suite/sys_vars/r/sysvars_server_embedded.result +++ b/mysql-test/suite/sys_vars/r/sysvars_server_embedded.result @@ -102,6 +102,16 @@ NUMERIC_BLOCK_SIZE 1 ENUM_VALUE_LIST NULL READ_ONLY NO COMMAND_LINE_ARGUMENT REQUIRED +VARIABLE_NAME ARIA_LOG_DIR_PATH +VARIABLE_SCOPE GLOBAL +VARIABLE_TYPE VARCHAR +VARIABLE_COMMENT Path to the directory where to store transactional log +NUMERIC_MIN_VALUE NULL +NUMERIC_MAX_VALUE NULL +NUMERIC_BLOCK_SIZE NULL +ENUM_VALUE_LIST NULL +READ_ONLY YES +COMMAND_LINE_ARGUMENT REQUIRED VARIABLE_NAME ARIA_LOG_FILE_SIZE VARIABLE_SCOPE GLOBAL VARIABLE_TYPE BIGINT UNSIGNED diff --git a/mysql-test/suite/sys_vars/r/sysvars_server_notembedded.result b/mysql-test/suite/sys_vars/r/sysvars_server_notembedded.result index b9e4aac328874..27e5daf761515 100644 --- a/mysql-test/suite/sys_vars/r/sysvars_server_notembedded.result +++ b/mysql-test/suite/sys_vars/r/sysvars_server_notembedded.result @@ -102,6 +102,16 @@ NUMERIC_BLOCK_SIZE 1 ENUM_VALUE_LIST NULL READ_ONLY NO COMMAND_LINE_ARGUMENT REQUIRED +VARIABLE_NAME ARIA_LOG_DIR_PATH +VARIABLE_SCOPE GLOBAL +VARIABLE_TYPE VARCHAR +VARIABLE_COMMENT Path to the directory where to store transactional log +NUMERIC_MIN_VALUE NULL +NUMERIC_MAX_VALUE NULL +NUMERIC_BLOCK_SIZE NULL +ENUM_VALUE_LIST NULL +READ_ONLY YES +COMMAND_LINE_ARGUMENT REQUIRED VARIABLE_NAME ARIA_LOG_FILE_SIZE VARIABLE_SCOPE GLOBAL VARIABLE_TYPE BIGINT UNSIGNED diff --git a/mysql-test/suite/sys_vars/t/aria_log_dir_path_basic.test b/mysql-test/suite/sys_vars/t/aria_log_dir_path_basic.test new file mode 100644 index 0000000000000..f09705e6f0d3a --- /dev/null +++ b/mysql-test/suite/sys_vars/t/aria_log_dir_path_basic.test @@ -0,0 +1,35 @@ +--source include/have_maria.inc + +SELECT COUNT(@@GLOBAL.aria_log_dir_path); +--error ER_INCORRECT_GLOBAL_LOCAL_VAR +SET @@GLOBAL.aria_log_dir_path=1; + +SELECT COUNT(@@GLOBAL.aria_log_dir_path); + + +SELECT @@GLOBAL.aria_log_dir_path = VARIABLE_VALUE +FROM INFORMATION_SCHEMA.GLOBAL_VARIABLES +WHERE VARIABLE_NAME='aria_log_dir_path'; + +SELECT COUNT(@@GLOBAL.aria_log_dir_path); + +SELECT COUNT(VARIABLE_VALUE) +FROM INFORMATION_SCHEMA.GLOBAL_VARIABLES +WHERE VARIABLE_NAME='aria_log_dir_path'; + + +SELECT @@aria_log_dir_path = @@GLOBAL.aria_log_dir_path; + + +SELECT COUNT(@@aria_log_dir_path); + +--Error ER_INCORRECT_GLOBAL_LOCAL_VAR +SELECT COUNT(@@local.aria_log_dir_path); + +--Error ER_INCORRECT_GLOBAL_LOCAL_VAR +SELECT COUNT(@@SESSION.aria_log_dir_path); + +SELECT COUNT(@@GLOBAL.aria_log_dir_path); + +--Error ER_BAD_FIELD_ERROR +SELECT aria_log_dir_path = @@SESSION.aria_log_dir_path; diff --git a/mysql-test/suite/sys_vars/t/sysvars_aria.test b/mysql-test/suite/sys_vars/t/sysvars_aria.test index b01e39eebf543..b042f1010f4b6 100644 --- a/mysql-test/suite/sys_vars/t/sysvars_aria.test +++ b/mysql-test/suite/sys_vars/t/sysvars_aria.test @@ -2,7 +2,11 @@ --source include/have_aria_used_for_temp_tables.inc --source include/word_size.inc +let datadir=`select @@datadir`; + --vertical_results + +--replace_result $datadir DATADIR select VARIABLE_NAME, SESSION_VALUE, DEFAULT_VALUE, VARIABLE_SCOPE, VARIABLE_TYPE, VARIABLE_COMMENT, NUMERIC_MIN_VALUE, NUMERIC_MAX_VALUE, NUMERIC_BLOCK_SIZE, ENUM_VALUE_LIST, READ_ONLY, COMMAND_LINE_ARGUMENT from information_schema.system_variables where variable_name like 'aria%' order by variable_name; diff --git a/storage/maria/ha_maria.cc b/storage/maria/ha_maria.cc index 0c9db691ca57b..2d6c8f85fe470 100644 --- a/storage/maria/ha_maria.cc +++ b/storage/maria/ha_maria.cc @@ -188,7 +188,7 @@ static MYSQL_SYSVAR_BOOL(page_checksum, maria_page_checksums, 0, /* It is only command line argument */ static MYSQL_SYSVAR_STR(log_dir_path, maria_data_root, - PLUGIN_VAR_NOSYSVAR | PLUGIN_VAR_RQCMDARG | PLUGIN_VAR_READONLY, + PLUGIN_VAR_RQCMDARG | PLUGIN_VAR_READONLY, "Path to the directory where to store transactional log", NULL, NULL, mysql_real_data_home); From 06393cd8f81e6c9a01e9ae1c8783a7f6dac21fbd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jan=20Lindstr=C3=B6m?= Date: Tue, 4 Apr 2023 20:12:36 +0200 Subject: [PATCH 83/92] MDEV-29602 : Galera debug build crashes when the spider plugin is enabled Spider system tables should be created so that wsrep_on=OFF. Signed-off-by: Julius Goryavsky --- storage/spider/spd_table.cc | 3 +++ 1 file changed, 3 insertions(+) diff --git a/storage/spider/spd_table.cc b/storage/spider/spd_table.cc index 3dbc391b9180f..2ff97ce357730 100644 --- a/storage/spider/spd_table.cc +++ b/storage/spider/spd_table.cc @@ -10058,6 +10058,8 @@ void *spider_table_bg_sts_action( thd->mysys_var->current_cond = &thread->cond; thd->mysys_var->current_mutex = &thread->mutex; } + bool spd_wsrep_on = thd->variables.wsrep_on; + thd->variables.wsrep_on = false; while (spider_init_queries[i].length && !thd->killed && !thread->killed && thread->init_command) { @@ -10071,6 +10073,7 @@ void *spider_table_bg_sts_action( } ++i; } + thd->variables.wsrep_on = spd_wsrep_on; thd->mysys_var->current_cond = &thread->cond; thd->mysys_var->current_mutex = &thread->mutex; thd->client_capabilities -= CLIENT_MULTI_RESULTS; From fb72dfbf7fb52a4be12bad7f173baa71942fd558 Mon Sep 17 00:00:00 2001 From: Alexander Barkov Date: Thu, 6 Apr 2023 09:45:05 +0400 Subject: [PATCH 84/92] MDEV-30415 MDEV-30415 PERIOD false positive overlap wtih utf8mb4_unicode_nopad_ci The problem was earlier fixed by the patch for MDEV-30034. Adding MTR tests only. --- mysql-test/suite/period/r/overlaps.result | 98 +++++++++++++++++++ mysql-test/suite/period/t/overlaps.test | 110 ++++++++++++++++++++++ 2 files changed, 208 insertions(+) diff --git a/mysql-test/suite/period/r/overlaps.result b/mysql-test/suite/period/r/overlaps.result index 3ed8e1a001474..78b1ac18b8da3 100644 --- a/mysql-test/suite/period/r/overlaps.result +++ b/mysql-test/suite/period/r/overlaps.result @@ -351,3 +351,101 @@ primary key(id, p without overlaps) ) engine=heap partition by hash(id); update t set id = 1; drop table t, t1; +# +# MDEV-30415 PERIOD false positive overlap wtih utf8mb4_unicode_nopad_ci +# +CREATE TABLE t1 ( +datetime_column_name_1 DATETIME(6) NOT NULL, +datetime_column_name_2 DATETIME(6) NOT NULL, +text_column_name TEXT COLLATE utf8mb4_unicode_nopad_ci NOT NULL, +PERIOD FOR period_name (datetime_column_name_1, datetime_column_name_2), +UNIQUE KEY index_name (text_column_name(191),period_name WITHOUT OVERLAPS) +) DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_nopad_ci; +INSERT INTO t1 (datetime_column_name_1, datetime_column_name_2, text_column_name) +VALUES +('2000-01-01 00:00:00.000000', '2001-01-01 00:00:00.000000', 'abc'), +('2000-01-01 00:00:00.000000', '2001-01-01 00:00:00.000000', 'abc '); +TRUNCATE TABLE t1; +INSERT INTO t1 (datetime_column_name_1, datetime_column_name_2, text_column_name) +VALUES +('2000-01-01 00:00:00.000000', '2001-01-01 00:00:00.000000', 'abc '), +('2000-01-01 00:00:00.000000', '2001-01-01 00:00:00.000000', 'abc'); +DROP TABLE t1; +CREATE TABLE `t1` ( +datetime_column_name_1 DATETIME(6) NOT NULL, +datetime_column_name_2 DATETIME(6) NOT NULL, +text_column_name TEXT COLLATE utf8mb4_unicode_nopad_ci NOT NULL, +PERIOD FOR period_name (datetime_column_name_1, datetime_column_name_2), +UNIQUE KEY index_name (text_column_name(191),period_name WITHOUT OVERLAPS) +) DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_nopad_ci; +INSERT INTO t1 VALUES +('2000-01-01 00:00:00.000000', '2001-01-01 00:00:00.000000', 'def '), +('2000-01-01 00:00:00.000000', '2001-01-01 00:00:00.000000', 'def'); +TRUNCATE TABLE t1; +INSERT INTO t1 VALUES +('2000-01-01 00:00:00.000000', '2001-01-01 00:00:00.000000', 'def'), +('2000-01-01 00:00:00.000000', '2001-01-01 00:00:00.000000', 'def '), +('2000-01-01 00:00:00.000000', '2001-01-01 00:00:00.000000', 'def '); +SELECT *, LENGTH(text_column_name) FROM t1; +datetime_column_name_1 datetime_column_name_2 text_column_name LENGTH(text_column_name) +2000-01-01 00:00:00.000000 2001-01-01 00:00:00.000000 def 3 +2000-01-01 00:00:00.000000 2001-01-01 00:00:00.000000 def 4 +2000-01-01 00:00:00.000000 2001-01-01 00:00:00.000000 def 5 +DROP TABLE t1; +CREATE TABLE t1 ( +datetime_column_name_1 DATETIME(6) NOT NULL, +datetime_column_name_2 DATETIME(6) NOT NULL, +text_column_name TEXT COLLATE utf8mb4_unicode_nopad_ci NOT NULL, +PERIOD FOR period_name (datetime_column_name_1, datetime_column_name_2), +UNIQUE KEY index_name (text_column_name(3),period_name WITHOUT OVERLAPS) +) DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_nopad_ci; +INSERT INTO t1 (datetime_column_name_1, datetime_column_name_2, text_column_name) +VALUES +('2000-01-01 00:00:00.000000', '2001-01-01 00:00:00.000000', 'abc'), +('2000-01-01 00:00:00.000000', '2001-01-01 00:00:00.000000', 'abc '); +ERROR 23000: Duplicate entry 'abc-2001-01-01 00:00:00.000000-2000-01-01 00:00:00.000000' for key 'index_name' +TRUNCATE TABLE t1; +INSERT INTO t1 (datetime_column_name_1, datetime_column_name_2, text_column_name) +VALUES +('2000-01-01 00:00:00.000000', '2001-01-01 00:00:00.000000', 'abc '), +('2000-01-01 00:00:00.000000', '2001-01-01 00:00:00.000000', 'abc'); +ERROR 23000: Duplicate entry 'abc-2001-01-01 00:00:00.000000-2000-01-01 00:00:00.000000' for key 'index_name' +DROP TABLE t1; +CREATE TABLE t1 ( +datetime_column_name_1 DATETIME(6) NOT NULL, +datetime_column_name_2 DATETIME(6) NOT NULL, +char_column_name CHAR(255) COLLATE utf8mb4_unicode_nopad_ci NOT NULL, +PERIOD FOR period_name (datetime_column_name_1, datetime_column_name_2), +UNIQUE KEY index_name (char_column_name(191),period_name WITHOUT OVERLAPS) +) DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_nopad_ci; +INSERT INTO t1 (datetime_column_name_1, datetime_column_name_2, char_column_name) +VALUES +('2000-01-01 00:00:00.000000', '2001-01-01 00:00:00.000000', 'abc'), +('2000-01-01 00:00:00.000000', '2001-01-01 00:00:00.000000', 'abc '); +ERROR 23000: Duplicate entry 'abc-2001-01-01 00:00:00.000000-2000-01-01 00:00:00.000000' for key 'index_name' +TRUNCATE TABLE t1; +INSERT INTO t1 (datetime_column_name_1, datetime_column_name_2, char_column_name) +VALUES +('2000-01-01 00:00:00.000000', '2001-01-01 00:00:00.000000', 'abc '), +('2000-01-01 00:00:00.000000', '2001-01-01 00:00:00.000000', 'abc'); +ERROR 23000: Duplicate entry 'abc-2001-01-01 00:00:00.000000-2000-01-01 00:00:00.000000' for key 'index_name' +DROP TABLE t1; +CREATE TABLE t1 ( +datetime_column_name_1 DATETIME(6) NOT NULL, +datetime_column_name_2 DATETIME(6) NOT NULL, +char_column_name CHAR(255) COLLATE utf8mb4_unicode_nopad_ci NOT NULL, +PERIOD FOR period_name (datetime_column_name_1, datetime_column_name_2), +UNIQUE KEY index_name (char_column_name(3),period_name WITHOUT OVERLAPS) +) DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_nopad_ci; +INSERT INTO t1 (datetime_column_name_1, datetime_column_name_2, char_column_name) +VALUES +('2000-01-01 00:00:00.000000', '2001-01-01 00:00:00.000000', 'abc'), +('2000-01-01 00:00:00.000000', '2001-01-01 00:00:00.000000', 'abc '); +ERROR 23000: Duplicate entry 'abc-2001-01-01 00:00:00.000000-2000-01-01 00:00:00.000000' for key 'index_name' +TRUNCATE TABLE t1; +INSERT INTO t1 (datetime_column_name_1, datetime_column_name_2, char_column_name) +VALUES +('2000-01-01 00:00:00.000000', '2001-01-01 00:00:00.000000', 'abc '), +('2000-01-01 00:00:00.000000', '2001-01-01 00:00:00.000000', 'abc'); +ERROR 23000: Duplicate entry 'abc-2001-01-01 00:00:00.000000-2000-01-01 00:00:00.000000' for key 'index_name' +DROP TABLE t1; diff --git a/mysql-test/suite/period/t/overlaps.test b/mysql-test/suite/period/t/overlaps.test index 6cd78769d4a40..4611aa15ddd2a 100644 --- a/mysql-test/suite/period/t/overlaps.test +++ b/mysql-test/suite/period/t/overlaps.test @@ -344,3 +344,113 @@ create or replace table t (id int, s date, e date, period for p(s,e), update t set id = 1; drop table t, t1; + +--echo # +--echo # MDEV-30415 PERIOD false positive overlap wtih utf8mb4_unicode_nopad_ci +--echo # + +# The originally reported script with a TEXT column (slightly modified) +CREATE TABLE t1 ( + datetime_column_name_1 DATETIME(6) NOT NULL, + datetime_column_name_2 DATETIME(6) NOT NULL, + text_column_name TEXT COLLATE utf8mb4_unicode_nopad_ci NOT NULL, + PERIOD FOR period_name (datetime_column_name_1, datetime_column_name_2), + UNIQUE KEY index_name (text_column_name(191),period_name WITHOUT OVERLAPS) +) DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_nopad_ci; +INSERT INTO t1 (datetime_column_name_1, datetime_column_name_2, text_column_name) +VALUES + ('2000-01-01 00:00:00.000000', '2001-01-01 00:00:00.000000', 'abc'), + ('2000-01-01 00:00:00.000000', '2001-01-01 00:00:00.000000', 'abc '); +TRUNCATE TABLE t1; +INSERT INTO t1 (datetime_column_name_1, datetime_column_name_2, text_column_name) +VALUES + ('2000-01-01 00:00:00.000000', '2001-01-01 00:00:00.000000', 'abc '), + ('2000-01-01 00:00:00.000000', '2001-01-01 00:00:00.000000', 'abc'); +DROP TABLE t1; + + +# The script reported by Alice with a TEXT column +CREATE TABLE `t1` ( + datetime_column_name_1 DATETIME(6) NOT NULL, + datetime_column_name_2 DATETIME(6) NOT NULL, + text_column_name TEXT COLLATE utf8mb4_unicode_nopad_ci NOT NULL, + PERIOD FOR period_name (datetime_column_name_1, datetime_column_name_2), + UNIQUE KEY index_name (text_column_name(191),period_name WITHOUT OVERLAPS) +) DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_nopad_ci; +INSERT INTO t1 VALUES + ('2000-01-01 00:00:00.000000', '2001-01-01 00:00:00.000000', 'def '), + ('2000-01-01 00:00:00.000000', '2001-01-01 00:00:00.000000', 'def'); +TRUNCATE TABLE t1; +INSERT INTO t1 VALUES + ('2000-01-01 00:00:00.000000', '2001-01-01 00:00:00.000000', 'def'), + ('2000-01-01 00:00:00.000000', '2001-01-01 00:00:00.000000', 'def '), + ('2000-01-01 00:00:00.000000', '2001-01-01 00:00:00.000000', 'def '); +--sorted_result +SELECT *, LENGTH(text_column_name) FROM t1; +DROP TABLE t1; + + +# A TEXT column with a short prefix +CREATE TABLE t1 ( + datetime_column_name_1 DATETIME(6) NOT NULL, + datetime_column_name_2 DATETIME(6) NOT NULL, + text_column_name TEXT COLLATE utf8mb4_unicode_nopad_ci NOT NULL, + PERIOD FOR period_name (datetime_column_name_1, datetime_column_name_2), + UNIQUE KEY index_name (text_column_name(3),period_name WITHOUT OVERLAPS) +) DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_nopad_ci; +--error ER_DUP_ENTRY +INSERT INTO t1 (datetime_column_name_1, datetime_column_name_2, text_column_name) +VALUES + ('2000-01-01 00:00:00.000000', '2001-01-01 00:00:00.000000', 'abc'), + ('2000-01-01 00:00:00.000000', '2001-01-01 00:00:00.000000', 'abc '); +TRUNCATE TABLE t1; +--error ER_DUP_ENTRY +INSERT INTO t1 (datetime_column_name_1, datetime_column_name_2, text_column_name) +VALUES + ('2000-01-01 00:00:00.000000', '2001-01-01 00:00:00.000000', 'abc '), + ('2000-01-01 00:00:00.000000', '2001-01-01 00:00:00.000000', 'abc'); +DROP TABLE t1; + + +# A CHAR with a long prefix +CREATE TABLE t1 ( + datetime_column_name_1 DATETIME(6) NOT NULL, + datetime_column_name_2 DATETIME(6) NOT NULL, + char_column_name CHAR(255) COLLATE utf8mb4_unicode_nopad_ci NOT NULL, + PERIOD FOR period_name (datetime_column_name_1, datetime_column_name_2), + UNIQUE KEY index_name (char_column_name(191),period_name WITHOUT OVERLAPS) +) DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_nopad_ci; +--error ER_DUP_ENTRY +INSERT INTO t1 (datetime_column_name_1, datetime_column_name_2, char_column_name) +VALUES + ('2000-01-01 00:00:00.000000', '2001-01-01 00:00:00.000000', 'abc'), + ('2000-01-01 00:00:00.000000', '2001-01-01 00:00:00.000000', 'abc '); +TRUNCATE TABLE t1; +--error ER_DUP_ENTRY +INSERT INTO t1 (datetime_column_name_1, datetime_column_name_2, char_column_name) +VALUES + ('2000-01-01 00:00:00.000000', '2001-01-01 00:00:00.000000', 'abc '), + ('2000-01-01 00:00:00.000000', '2001-01-01 00:00:00.000000', 'abc'); +DROP TABLE t1; + + +# A CHAR column with a short prefix +CREATE TABLE t1 ( + datetime_column_name_1 DATETIME(6) NOT NULL, + datetime_column_name_2 DATETIME(6) NOT NULL, + char_column_name CHAR(255) COLLATE utf8mb4_unicode_nopad_ci NOT NULL, + PERIOD FOR period_name (datetime_column_name_1, datetime_column_name_2), + UNIQUE KEY index_name (char_column_name(3),period_name WITHOUT OVERLAPS) +) DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_nopad_ci; +--error ER_DUP_ENTRY +INSERT INTO t1 (datetime_column_name_1, datetime_column_name_2, char_column_name) +VALUES + ('2000-01-01 00:00:00.000000', '2001-01-01 00:00:00.000000', 'abc'), + ('2000-01-01 00:00:00.000000', '2001-01-01 00:00:00.000000', 'abc '); +TRUNCATE TABLE t1; +--error ER_DUP_ENTRY +INSERT INTO t1 (datetime_column_name_1, datetime_column_name_2, char_column_name) +VALUES + ('2000-01-01 00:00:00.000000', '2001-01-01 00:00:00.000000', 'abc '), + ('2000-01-01 00:00:00.000000', '2001-01-01 00:00:00.000000', 'abc'); +DROP TABLE t1; From 375991a531f8885634e7a2af224bf396ee7e1f60 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marko=20M=C3=A4kel=C3=A4?= Date: Tue, 11 Apr 2023 14:42:08 +0300 Subject: [PATCH 85/92] MDEV-26827 fixup for DDL race condition buf_flush_try_neighbors(): Tolerate count<2 in case the tablespace is being dropped. --- storage/innobase/buf/buf0flu.cc | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/storage/innobase/buf/buf0flu.cc b/storage/innobase/buf/buf0flu.cc index 484f6a3abb7bc..031055d7cfd45 100644 --- a/storage/innobase/buf/buf0flu.cc +++ b/storage/innobase/buf/buf0flu.cc @@ -1122,13 +1122,11 @@ static ulint buf_flush_try_neighbors(fil_space_t *space, mysql_mutex_unlock(&buf_pool.mutex); } - ut_ad(!bpage); - - if (auto n= count - 1) + if (count > 1) { MONITOR_INC_VALUE_CUMULATIVE(MONITOR_FLUSH_NEIGHBOR_TOTAL_PAGE, MONITOR_FLUSH_NEIGHBOR_COUNT, - MONITOR_FLUSH_NEIGHBOR_PAGES, n); + MONITOR_FLUSH_NEIGHBOR_PAGES, count - 1); } return count; From a1ba06f2a795a63fd2e61aa671daf24730b5f66a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marko=20M=C3=A4kel=C3=A4?= Date: Wed, 12 Apr 2023 13:05:48 +0300 Subject: [PATCH 86/92] MDEV-27774 fixup: Remove an unused function --- storage/innobase/include/log0log.h | 1 - 1 file changed, 1 deletion(-) diff --git a/storage/innobase/include/log0log.h b/storage/innobase/include/log0log.h index 7f5eb482e976f..0bf8b03bf87d4 100644 --- a/storage/innobase/include/log0log.h +++ b/storage/innobase/include/log0log.h @@ -324,7 +324,6 @@ typedef srw_lock log_rwlock_t; lsn_t get_lsn(std::memory_order order= std::memory_order_relaxed) const { return lsn.load(order); } - void set_lsn(lsn_t lsn) { this->lsn.store(lsn, std::memory_order_release); } lsn_t get_flushed_lsn(std::memory_order order= std::memory_order_acquire) const noexcept From a091d6ac4e7d2d7873749e685943b3032ccfda57 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marko=20M=C3=A4kel=C3=A4?= Date: Wed, 12 Apr 2023 13:49:57 +0300 Subject: [PATCH 87/92] MDEV-26827 fixup: Do not duplicate io_slots::pending_io_count() os_aio_pending_reads_approx(), os_aio_pending_reads(): Replaces buf_pool.n_pend_reads. os_aio_pending_writes(): Replaces buf_dblwr.pending_writes(). buf_dblwr_t::write_cond, buf_dblwr_t::writes_pending: Remove. --- storage/innobase/btr/btr0cur.cc | 4 +-- storage/innobase/buf/buf0buf.cc | 10 ++----- storage/innobase/buf/buf0dblwr.cc | 42 ++++++++++---------------- storage/innobase/buf/buf0flu.cc | 44 ++++++++++------------------ storage/innobase/buf/buf0rea.cc | 27 +++++------------ storage/innobase/include/buf0buf.h | 16 +--------- storage/innobase/include/buf0dblwr.h | 40 +------------------------ storage/innobase/include/os0file.h | 7 +++++ storage/innobase/log/log0recv.cc | 3 +- storage/innobase/os/os0file.cc | 25 ++++++++++++++++ storage/innobase/srv/srv0start.cc | 24 ++++++++++++--- tpool/tpool_structs.h | 9 ++++-- 12 files changed, 104 insertions(+), 147 deletions(-) diff --git a/storage/innobase/btr/btr0cur.cc b/storage/innobase/btr/btr0cur.cc index b96810400928a..70b0ae4c32cfa 100644 --- a/storage/innobase/btr/btr0cur.cc +++ b/storage/innobase/btr/btr0cur.cc @@ -1058,7 +1058,7 @@ dberr_t btr_cur_t::search_leaf(const dtuple_t *tuple, page_cur_mode_t mode, if (lock_intention == BTR_INTENTION_DELETE) { compress_limit= BTR_CUR_PAGE_COMPRESS_LIMIT(index()); - if (buf_pool.n_pend_reads && + if (os_aio_pending_reads_approx() && trx_sys.history_size_approx() > BTR_CUR_FINE_HISTORY_LENGTH) { /* Most delete-intended operations are due to the purge of history. @@ -1843,7 +1843,7 @@ dberr_t btr_cur_t::open_leaf(bool first, dict_index_t *index, { compress_limit= BTR_CUR_PAGE_COMPRESS_LIMIT(index); - if (buf_pool.n_pend_reads && + if (os_aio_pending_reads_approx() && trx_sys.history_size_approx() > BTR_CUR_FINE_HISTORY_LENGTH) { mtr_x_lock_index(index, mtr); diff --git a/storage/innobase/buf/buf0buf.cc b/storage/innobase/buf/buf0buf.cc index 106569f74b20a..462b1eb634afa 100644 --- a/storage/innobase/buf/buf0buf.cc +++ b/storage/innobase/buf/buf0buf.cc @@ -3539,9 +3539,6 @@ dberr_t buf_page_t::read_complete(const fil_node_t &node) ut_ad(zip_size() == node.space->zip_size()); ut_ad(!!zip.ssize == !!zip.data); - ut_d(auto n=) buf_pool.n_pend_reads--; - ut_ad(n > 0); - const byte *read_frame= zip.data ? zip.data : frame; ut_ad(read_frame); @@ -3841,9 +3838,8 @@ void buf_pool_t::print() << ", modified database pages=" << UT_LIST_GET_LEN(flush_list) << ", n pending decompressions=" << n_pend_unzip - << ", n pending reads=" << n_pend_reads << ", n pending flush LRU=" << n_flush() - << " list=" << buf_dblwr.pending_writes() + << " list=" << os_aio_pending_writes() << ", pages made young=" << stat.n_pages_made_young << ", not young=" << stat.n_pages_not_made_young << ", pages read=" << stat.n_pages_read @@ -3956,11 +3952,11 @@ void buf_stats_get_pool_info(buf_pool_info_t *pool_info) pool_info->n_pend_unzip = UT_LIST_GET_LEN(buf_pool.unzip_LRU); - pool_info->n_pend_reads = buf_pool.n_pend_reads; + pool_info->n_pend_reads = os_aio_pending_reads_approx(); pool_info->n_pending_flush_lru = buf_pool.n_flush(); - pool_info->n_pending_flush_list = buf_dblwr.pending_writes(); + pool_info->n_pending_flush_list = os_aio_pending_writes(); mysql_mutex_unlock(&buf_pool.flush_list_mutex); current_time = time(NULL); diff --git a/storage/innobase/buf/buf0dblwr.cc b/storage/innobase/buf/buf0dblwr.cc index c3f221c6f61ee..c28a9a3337abb 100644 --- a/storage/innobase/buf/buf0dblwr.cc +++ b/storage/innobase/buf/buf0dblwr.cc @@ -53,7 +53,6 @@ void buf_dblwr_t::init() active_slot= &slots[0]; mysql_mutex_init(buf_dblwr_mutex_key, &mutex, nullptr); pthread_cond_init(&cond, nullptr); - pthread_cond_init(&write_cond, nullptr); } } @@ -469,7 +468,6 @@ void buf_dblwr_t::close() ut_ad(!batch_running); pthread_cond_destroy(&cond); - pthread_cond_destroy(&write_cond); for (int i= 0; i < 2; i++) { aligned_free(slots[i].write_buf); @@ -481,38 +479,31 @@ void buf_dblwr_t::close() } /** Update the doublewrite buffer on write completion. */ -void buf_dblwr_t::write_completed(bool with_doublewrite) +void buf_dblwr_t::write_completed() { ut_ad(this == &buf_dblwr); ut_ad(!srv_read_only_mode); mysql_mutex_lock(&mutex); - ut_ad(writes_pending); - if (!--writes_pending) - pthread_cond_broadcast(&write_cond); + ut_ad(is_created()); + ut_ad(srv_use_doublewrite_buf); + ut_ad(batch_running); + slot *flush_slot= active_slot == &slots[0] ? &slots[1] : &slots[0]; + ut_ad(flush_slot->reserved); + ut_ad(flush_slot->reserved <= flush_slot->first_free); - if (with_doublewrite) + if (!--flush_slot->reserved) { - ut_ad(is_created()); - ut_ad(srv_use_doublewrite_buf); - ut_ad(batch_running); - slot *flush_slot= active_slot == &slots[0] ? &slots[1] : &slots[0]; - ut_ad(flush_slot->reserved); - ut_ad(flush_slot->reserved <= flush_slot->first_free); - - if (!--flush_slot->reserved) - { - mysql_mutex_unlock(&mutex); - /* This will finish the batch. Sync data files to the disk. */ - fil_flush_file_spaces(); - mysql_mutex_lock(&mutex); + mysql_mutex_unlock(&mutex); + /* This will finish the batch. Sync data files to the disk. */ + fil_flush_file_spaces(); + mysql_mutex_lock(&mutex); - /* We can now reuse the doublewrite memory buffer: */ - flush_slot->first_free= 0; - batch_running= false; - pthread_cond_broadcast(&cond); - } + /* We can now reuse the doublewrite memory buffer: */ + flush_slot->first_free= 0; + batch_running= false; + pthread_cond_broadcast(&cond); } mysql_mutex_unlock(&mutex); @@ -756,7 +747,6 @@ void buf_dblwr_t::add_to_batch(const IORequest &request, size_t size) const ulint buf_size= 2 * block_size(); mysql_mutex_lock(&mutex); - writes_pending++; for (;;) { diff --git a/storage/innobase/buf/buf0flu.cc b/storage/innobase/buf/buf0flu.cc index 32f39ea08de40..5a9e3cbb34ec3 100644 --- a/storage/innobase/buf/buf0flu.cc +++ b/storage/innobase/buf/buf0flu.cc @@ -246,7 +246,7 @@ void buf_flush_remove_pages(ulint id) if (!deferred) break; - buf_dblwr.wait_for_page_writes(); + os_aio_wait_until_no_pending_writes(); } } @@ -376,9 +376,9 @@ void buf_page_write_complete(const IORequest &request) if (request.is_LRU()) { const bool temp= bpage->oldest_modification() == 2; - if (!temp) - buf_dblwr.write_completed(state < buf_page_t::WRITE_FIX_REINIT && - request.node->space->use_doublewrite()); + if (!temp && state < buf_page_t::WRITE_FIX_REINIT && + request.node->space->use_doublewrite()) + buf_dblwr.write_completed(); /* We must hold buf_pool.mutex while releasing the block, so that no other thread can access it before we have freed it. */ mysql_mutex_lock(&buf_pool.mutex); @@ -390,8 +390,9 @@ void buf_page_write_complete(const IORequest &request) } else { - buf_dblwr.write_completed(state < buf_page_t::WRITE_FIX_REINIT && - request.node->space->use_doublewrite()); + if (state < buf_page_t::WRITE_FIX_REINIT && + request.node->space->use_doublewrite()) + buf_dblwr.write_completed(); bpage->write_complete(false); } } @@ -886,8 +887,6 @@ bool buf_page_t::flush(bool evict, fil_space_t *space) if (lsn > log_sys.get_flushed_lsn()) log_write_up_to(lsn, true); } - if (UNIV_LIKELY(space->purpose != FIL_TYPE_TEMPORARY)) - buf_dblwr.add_unbuffered(); space->io(IORequest{type, this, slot}, physical_offset(), size, write_frame, this); } @@ -1853,7 +1852,7 @@ static void buf_flush_wait(lsn_t lsn) break; } mysql_mutex_unlock(&buf_pool.flush_list_mutex); - buf_dblwr.wait_for_page_writes(); + os_aio_wait_until_no_pending_writes(); mysql_mutex_lock(&buf_pool.flush_list_mutex); } } @@ -1875,8 +1874,6 @@ ATTRIBUTE_COLD void buf_flush_wait_flushed(lsn_t sync_lsn) if (buf_pool.get_oldest_modification(sync_lsn) < sync_lsn) { MONITOR_INC(MONITOR_FLUSH_SYNC_WAITS); - thd_wait_begin(nullptr, THD_WAIT_DISKIO); - tpool::tpool_wait_begin(); #if 1 /* FIXME: remove this, and guarantee that the page cleaner serves us */ if (UNIV_UNLIKELY(!buf_page_cleaner_is_active)) @@ -1891,7 +1888,7 @@ ATTRIBUTE_COLD void buf_flush_wait_flushed(lsn_t sync_lsn) MONITOR_FLUSH_SYNC_COUNT, MONITOR_FLUSH_SYNC_PAGES, n_pages); } - buf_dblwr.wait_for_page_writes(); + os_aio_wait_until_no_pending_writes(); mysql_mutex_lock(&buf_pool.flush_list_mutex); } while (buf_pool.get_oldest_modification(sync_lsn) < sync_lsn); @@ -1900,7 +1897,6 @@ ATTRIBUTE_COLD void buf_flush_wait_flushed(lsn_t sync_lsn) #endif buf_flush_wait(sync_lsn); - tpool::tpool_wait_end(); thd_wait_end(nullptr); } @@ -2335,7 +2331,7 @@ static void buf_flush_page_cleaner() last_activity_count= activity_count; goto maybe_unemployed; } - else if (buf_pool.page_cleaner_idle() && buf_pool.n_pend_reads == 0) + else if (buf_pool.page_cleaner_idle() && !os_aio_pending_reads()) { /* reaching here means 3 things: - last_activity_count == activity_count: suggesting server is idle @@ -2411,7 +2407,7 @@ static void buf_flush_page_cleaner() mysql_mutex_lock(&buf_pool.flush_list_mutex); buf_flush_wait_LRU_batch_end(); mysql_mutex_unlock(&buf_pool.flush_list_mutex); - buf_dblwr.wait_for_page_writes(); + os_aio_wait_until_no_pending_writes(); } mysql_mutex_lock(&buf_pool.flush_list_mutex); @@ -2461,15 +2457,7 @@ ATTRIBUTE_COLD void buf_flush_buffer_pool() { mysql_mutex_unlock(&buf_pool.flush_list_mutex); buf_flush_list(srv_max_io_capacity); - if (const size_t pending= buf_dblwr.pending_writes()) - { - timespec abstime; - service_manager_extend_timeout(INNODB_EXTEND_TIMEOUT_INTERVAL, - "Waiting to write %zu pages", pending); - set_timespec(abstime, INNODB_EXTEND_TIMEOUT_INTERVAL / 2); - buf_dblwr.wait_for_page_writes(abstime); - } - + os_aio_wait_until_no_pending_writes(); mysql_mutex_lock(&buf_pool.flush_list_mutex); service_manager_extend_timeout(INNODB_EXTEND_TIMEOUT_INTERVAL, "Waiting to flush " ULINTPF " pages", @@ -2477,20 +2465,18 @@ ATTRIBUTE_COLD void buf_flush_buffer_pool() } mysql_mutex_unlock(&buf_pool.flush_list_mutex); - ut_ad(!buf_pool.any_io_pending()); + ut_ad(!os_aio_pending_writes()); + ut_ad(!os_aio_pending_reads()); } /** Synchronously flush dirty blocks during recv_sys_t::apply(). NOTE: The calling thread is not allowed to hold any buffer page latches! */ void buf_flush_sync_batch(lsn_t lsn) { - thd_wait_begin(nullptr, THD_WAIT_DISKIO); - tpool::tpool_wait_begin(); + lsn= std::max(lsn, log_sys.get_lsn()); mysql_mutex_lock(&buf_pool.flush_list_mutex); buf_flush_wait(lsn); mysql_mutex_unlock(&buf_pool.flush_list_mutex); - tpool::tpool_wait_end(); - thd_wait_end(nullptr); } /** Synchronously flush dirty blocks. diff --git a/storage/innobase/buf/buf0rea.cc b/storage/innobase/buf/buf0rea.cc index b39a8f4913323..b8fa3055adfec 100644 --- a/storage/innobase/buf/buf0rea.cc +++ b/storage/innobase/buf/buf0rea.cc @@ -227,12 +227,9 @@ static buf_page_t* buf_page_init_for_read(ulint mode, const page_id_t page_id, } buf_pool.stat.n_pages_read++; - mysql_mutex_unlock(&buf_pool.mutex); - buf_pool.n_pend_reads++; - goto func_exit_no_mutex; func_exit: mysql_mutex_unlock(&buf_pool.mutex); -func_exit_no_mutex: + if (mode == BUF_READ_IBUF_PAGES_ONLY) ibuf_mtr_commit(&mtr); @@ -319,8 +316,6 @@ buf_read_page_low( page_id.page_no() * len, len, dst, bpage); if (UNIV_UNLIKELY(fio.err != DB_SUCCESS)) { - ut_d(auto n=) buf_pool.n_pend_reads--; - ut_ad(n > 0); buf_pool.corrupted_evict(bpage, buf_page_t::READ_FIX); } else if (sync) { thd_wait_end(NULL); @@ -367,7 +362,8 @@ buf_read_ahead_random(const page_id_t page_id, ulint zip_size, bool ibuf) read-ahead, as that could break the ibuf page access order */ return 0; - if (buf_pool.n_pend_reads > buf_pool.curr_size / BUF_READ_AHEAD_PEND_LIMIT) + if (os_aio_pending_reads_approx() > + buf_pool.curr_size / BUF_READ_AHEAD_PEND_LIMIT) return 0; fil_space_t* space= fil_space_t::get(page_id.space()); @@ -519,7 +515,8 @@ buf_read_ahead_linear(const page_id_t page_id, ulint zip_size, bool ibuf) /* No read-ahead to avoid thread deadlocks */ return 0; - if (buf_pool.n_pend_reads > buf_pool.curr_size / BUF_READ_AHEAD_PEND_LIMIT) + if (os_aio_pending_reads_approx() > + buf_pool.curr_size / BUF_READ_AHEAD_PEND_LIMIT) return 0; const uint32_t buf_read_ahead_area= buf_pool.read_ahead_area; @@ -689,18 +686,8 @@ void buf_read_recv_pages(ulint space_id, const uint32_t* page_nos, ulint n) limit += buf_pool.chunks[j].size / 2; } - for (ulint count = 0; buf_pool.n_pend_reads >= limit; ) { - std::this_thread::sleep_for( - std::chrono::milliseconds(10)); - - if (!(++count % 1000)) { - - ib::error() - << "Waited for " << count / 100 - << " seconds for " - << buf_pool.n_pend_reads - << " pending reads"; - } + if (os_aio_pending_reads() >= limit) { + os_aio_wait_until_no_pending_reads(); } space->reacquire(); diff --git a/storage/innobase/include/buf0buf.h b/storage/innobase/include/buf0buf.h index 94f8dc2badb24..2b4732a64a010 100644 --- a/storage/innobase/include/buf0buf.h +++ b/storage/innobase/include/buf0buf.h @@ -1693,8 +1693,6 @@ class buf_pool_t /** map of block->frame to buf_block_t blocks that belong to buf_buddy_alloc(); protected by buf_pool.mutex */ hash_table_t zip_hash; - /** number of pending read operations */ - Atomic_counter n_pend_reads; Atomic_counter n_pend_unzip; /*!< number of pending decompressions */ @@ -1721,7 +1719,7 @@ class buf_pool_t /** flush_list size in bytes; protected by flush_list_mutex */ ulint flush_list_bytes; /** possibly modified persistent pages (a subset of LRU); - buf_dblwr.pending_writes() is approximately COUNT(is_write_fixed()) */ + os_aio_pending_writes() is approximately COUNT(is_write_fixed()) */ UT_LIST_BASE_NODE_T(buf_page_t) flush_list; private: static constexpr unsigned PAGE_CLEANER_IDLE= 1; @@ -1874,18 +1872,6 @@ class buf_pool_t /** Reserve a buffer. */ buf_tmp_buffer_t *io_buf_reserve() { return io_buf.reserve(); } - /** @return whether any I/O is pending */ - bool any_io_pending() - { - if (n_pend_reads) - return true; - mysql_mutex_lock(&flush_list_mutex); - const bool any_pending= page_cleaner_status > PAGE_CLEANER_IDLE || - buf_dblwr.pending_writes(); - mysql_mutex_unlock(&flush_list_mutex); - return any_pending; - } - private: /** Remove a block from the flush list. */ inline void delete_from_flush_list_low(buf_page_t *bpage); diff --git a/storage/innobase/include/buf0dblwr.h b/storage/innobase/include/buf0dblwr.h index d9c9239c0b434..92b840d2f4c97 100644 --- a/storage/innobase/include/buf0dblwr.h +++ b/storage/innobase/include/buf0dblwr.h @@ -72,10 +72,6 @@ class buf_dblwr_t ulint writes_completed; /** number of pages written by flush_buffered_writes_completed() */ ulint pages_written; - /** condition variable for !writes_pending */ - pthread_cond_t write_cond; - /** number of pending page writes */ - size_t writes_pending; slot slots[2]; slot *active_slot; @@ -124,7 +120,7 @@ class buf_dblwr_t void recover(); /** Update the doublewrite buffer on data page write completion. */ - void write_completed(bool with_doublewrite); + void write_completed(); /** Flush possible buffered writes to persistent storage. It is very important to call this function after a batch of writes has been posted, and also when we may have to wait for a page latch! @@ -167,40 +163,6 @@ class buf_dblwr_t my_cond_wait(&cond, &mutex.m_mutex); mysql_mutex_unlock(&mutex); } - - /** Register an unbuffered page write */ - void add_unbuffered() - { - mysql_mutex_lock(&mutex); - writes_pending++; - mysql_mutex_unlock(&mutex); - } - - size_t pending_writes() - { - mysql_mutex_lock(&mutex); - const size_t pending{writes_pending}; - mysql_mutex_unlock(&mutex); - return pending; - } - - /** Wait for writes_pending to reach 0 */ - void wait_for_page_writes() - { - mysql_mutex_lock(&mutex); - while (writes_pending) - my_cond_wait(&write_cond, &mutex.m_mutex); - mysql_mutex_unlock(&mutex); - } - - /** Wait for writes_pending to reach 0 */ - void wait_for_page_writes(const timespec &abstime) - { - mysql_mutex_lock(&mutex); - while (writes_pending) - my_cond_timedwait(&write_cond, &mutex.m_mutex, &abstime); - mysql_mutex_unlock(&mutex); - } }; /** The doublewrite buffer */ diff --git a/storage/innobase/include/os0file.h b/storage/innobase/include/os0file.h index 934b30d9515ea..f8ae0f5155741 100644 --- a/storage/innobase/include/os0file.h +++ b/storage/innobase/include/os0file.h @@ -1059,6 +1059,13 @@ void os_aio_free(); @retval DB_IO_ERROR on I/O error */ dberr_t os_aio(const IORequest &type, void *buf, os_offset_t offset, size_t n); +/** @return number of pending reads */ +size_t os_aio_pending_reads(); +/** @return approximate number of pending reads */ +size_t os_aio_pending_reads_approx(); +/** @return number of pending writes */ +size_t os_aio_pending_writes(); + /** Wait until there are no pending asynchronous writes. */ void os_aio_wait_until_no_pending_writes(); diff --git a/storage/innobase/log/log0recv.cc b/storage/innobase/log/log0recv.cc index 44b7e5b2a9222..8d05d6a5f14b0 100644 --- a/storage/innobase/log/log0recv.cc +++ b/storage/innobase/log/log0recv.cc @@ -3384,7 +3384,7 @@ void recv_sys_t::apply(bool last_batch) for (;;) { const bool empty= pages.empty(); - if (empty && !buf_pool.n_pend_reads) + if (empty && !os_aio_pending_reads()) break; if (!is_corrupt_fs() && !is_corrupt_log()) @@ -3398,7 +3398,6 @@ void recv_sys_t::apply(bool last_batch) { mysql_mutex_unlock(&mutex); os_aio_wait_until_no_pending_reads(); - ut_ad(!buf_pool.n_pend_reads); mysql_mutex_lock(&mutex); ut_ad(pages.empty()); } diff --git a/storage/innobase/os/os0file.cc b/storage/innobase/os/os0file.cc index e3de49f443219..12561877c0c62 100644 --- a/storage/innobase/os/os0file.cc +++ b/storage/innobase/os/os0file.cc @@ -131,6 +131,11 @@ class io_slots { wait(); } + + std::mutex& mutex() + { + return m_cache.mutex(); + } }; static io_slots *read_slots; @@ -3660,6 +3665,26 @@ void os_aio_wait_until_no_pending_writes() buf_dblwr.wait_flush_buffered_writes(); } +/** @return number of pending reads */ +size_t os_aio_pending_reads() +{ + std::unique_lock lk(read_slots->mutex()); + return read_slots->pending_io_count(); +} + +/** @return approximate number of pending reads */ +size_t os_aio_pending_reads_approx() +{ + return read_slots->pending_io_count(); +} + +/** @return number of pending writes */ +size_t os_aio_pending_writes() +{ + std::unique_lock lk(write_slots->mutex()); + return write_slots->pending_io_count(); +} + /** Wait until all pending asynchronous reads have completed. */ void os_aio_wait_until_no_pending_reads() { diff --git a/storage/innobase/srv/srv0start.cc b/storage/innobase/srv/srv0start.cc index 872f1fc7e9cc6..a1368c5146cc0 100644 --- a/storage/innobase/srv/srv0start.cc +++ b/storage/innobase/srv/srv0start.cc @@ -249,7 +249,11 @@ static dberr_t create_log_file(bool create_new_db, lsn_t lsn, } DBUG_PRINT("ib_log", ("After innodb_log_abort_6")); - DBUG_ASSERT(!buf_pool.any_io_pending()); + ut_ad(!os_aio_pending_reads()); + ut_ad(!os_aio_pending_writes()); + ut_d(mysql_mutex_lock(&buf_pool.flush_list_mutex)); + ut_ad(!buf_pool.get_oldest_modification(0)); + ut_d(mysql_mutex_unlock(&buf_pool.flush_list_mutex)); DBUG_EXECUTE_IF("innodb_log_abort_7", return DB_ERROR;); DBUG_PRINT("ib_log", ("After innodb_log_abort_7")); @@ -967,7 +971,11 @@ static lsn_t srv_prepare_to_delete_redo_log_file(bool old_exists) } ut_ad(flushed_lsn == log_sys.get_lsn()); - ut_ad(!buf_pool.any_io_pending()); + ut_ad(!os_aio_pending_reads()); + ut_ad(!os_aio_pending_writes()); + ut_d(mysql_mutex_lock(&buf_pool.flush_list_mutex)); + ut_ad(!buf_pool.get_oldest_modification(0)); + ut_d(mysql_mutex_unlock(&buf_pool.flush_list_mutex)); DBUG_RETURN(flushed_lsn); } @@ -1601,7 +1609,11 @@ dberr_t srv_start(bool create_new_db) 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()); + ut_ad(!os_aio_pending_reads()); + ut_ad(!os_aio_pending_writes()); + ut_d(mysql_mutex_lock(&buf_pool.flush_list_mutex)); + ut_ad(!buf_pool.get_oldest_modification(0)); + ut_d(mysql_mutex_unlock(&buf_pool.flush_list_mutex)); log_sys.log.close_file(); if (err == DB_SUCCESS) { bool trunc = srv_operation @@ -1645,7 +1657,11 @@ dberr_t srv_start(bool create_new_db) threads until creating a log checkpoint at the end of create_log_file(). */ ut_d(recv_no_log_write = true); - DBUG_ASSERT(!buf_pool.any_io_pending()); + ut_ad(!os_aio_pending_reads()); + ut_ad(!os_aio_pending_writes()); + ut_d(mysql_mutex_lock(&buf_pool.flush_list_mutex)); + ut_ad(!buf_pool.get_oldest_modification(0)); + ut_d(mysql_mutex_unlock(&buf_pool.flush_list_mutex)); DBUG_EXECUTE_IF("innodb_log_abort_3", return(srv_init_abort(DB_ERROR));); diff --git a/tpool/tpool_structs.h b/tpool/tpool_structs.h index b49204f2d75ac..b6ca3f54016ea 100644 --- a/tpool/tpool_structs.h +++ b/tpool/tpool_structs.h @@ -130,9 +130,12 @@ template class cache return m_cache[m_pos++]; } - /** - Put back an item to cache. - @param item - item to put back + + std::mutex &mutex() { return m_mtx; } + + /** + Put back an element to cache. + @param ele element to put back */ void put(T *ele) { From 2ddfb838078cb0f81b48ef878d97b966c8d9c494 Mon Sep 17 00:00:00 2001 From: Thirunarayanan Balathandayuthapani Date: Wed, 5 Apr 2023 16:55:07 +0530 Subject: [PATCH 88/92] MDEV-29273 Race condition between drop table and closing of table - This issue caused by race condition between drop thread and fil_encrypt_thread. fil_encrypt_thread closes the tablespace if the number of opened files exceeds innodb_open_files. fil_node_open_file() closes the tablespace which are open and it doesn't have pending operations. At that time, InnoDB drop tries to write the redo log for the file delete operation. It throws the bad file descriptor error. - When trying to close the file, InnoDB should check whether the table is going to be dropped. --- storage/innobase/fil/fil0fil.cc | 13 +++++++++++-- storage/innobase/include/fil0fil.h | 3 +-- 2 files changed, 12 insertions(+), 4 deletions(-) diff --git a/storage/innobase/fil/fil0fil.cc b/storage/innobase/fil/fil0fil.cc index eee4bd3eb5874..7e2b04eaa7388 100644 --- a/storage/innobase/fil/fil0fil.cc +++ b/storage/innobase/fil/fil0fil.cc @@ -100,7 +100,13 @@ bool fil_space_t::try_to_close(bool print_info) if (!node->is_open()) continue; - if (const auto n= space.set_closing()) + /* Other thread is trying to do fil_delete_tablespace() + concurrently for the same tablespace. So ignore this + tablespace and try to close the other one */ + const auto n= space.set_closing(); + if (n & STOPPING) + continue; + if (n & (PENDING | NEEDS_FSYNC)) { if (!print_info) continue; @@ -1372,7 +1378,10 @@ void fil_space_t::close_all() for (ulint count= 10000; count--;) { - if (!space.set_closing()) + const auto n= space.set_closing(); + if (n & STOPPING) + goto next; + if (!(n & (PENDING | NEEDS_FSYNC))) { node->close(); goto next; diff --git a/storage/innobase/include/fil0fil.h b/storage/innobase/include/fil0fil.h index ff6ece8a360d0..12ac86dc9beb5 100644 --- a/storage/innobase/include/fil0fil.h +++ b/storage/innobase/include/fil0fil.h @@ -628,8 +628,7 @@ struct fil_space_t final @return number of pending operations, possibly with NEEDS_FSYNC flag */ uint32_t set_closing() { - return n_pending.fetch_or(CLOSING, std::memory_order_acquire) & - (PENDING | NEEDS_FSYNC); + return n_pending.fetch_or(CLOSING, std::memory_order_acquire); } public: From c0eeb72526bb4c6656d84b89ced33880ca1639d1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marko=20M=C3=A4kel=C3=A4?= Date: Thu, 13 Apr 2023 12:25:41 +0300 Subject: [PATCH 89/92] MDEV-28974 fixup: Fix error and warning messages fil_name_process(): Starting with commit 212994f704496d01881f377e34e04bd007e5e298 the name is not guaranteed to be NUL terminated. --- storage/innobase/log/log0recv.cc | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) diff --git a/storage/innobase/log/log0recv.cc b/storage/innobase/log/log0recv.cc index 8d05d6a5f14b0..3b6e3008a9569 100644 --- a/storage/innobase/log/log0recv.cc +++ b/storage/innobase/log/log0recv.cc @@ -1307,7 +1307,8 @@ static void fil_name_process(const char *name, ulint len, uint32_t space_id, } else { ib::error() << "Tablespace " << space_id << " has been found in two places: '" - << f.name << "' and '" << name << "'." + << f.name << "' and '" + << fname.name << "'." " You must delete one of them."; recv_sys.set_corrupt_fs(); } @@ -1333,7 +1334,8 @@ static void fil_name_process(const char *name, ulint len, uint32_t space_id, ib::info() << "At LSN: " << recv_sys.recovered_lsn - << ": unable to open file " << name + << ": unable to open file " + << fname.name << " for tablespace " << space_id; } break; @@ -1350,8 +1352,9 @@ static void fil_name_process(const char *name, ulint len, uint32_t space_id, ut_ad(space == NULL); if (srv_force_recovery == 0) { sql_print_error("InnoDB: Recovery cannot access" - " file %s (tablespace " - UINT32PF ")", name, space_id); + " file %.*s (tablespace " + UINT32PF ")", int(len), name, + space_id); sql_print_information("InnoDB: You may set " "innodb_force_recovery=1" " to ignore this and" @@ -1362,9 +1365,10 @@ static void fil_name_process(const char *name, ulint len, uint32_t space_id, } sql_print_warning("InnoDB: Ignoring changes to" - " file %s (tablespace " UINT32PF ")" + " file %.*s (tablespace " + UINT32PF ")" " due to innodb_force_recovery", - name, space_id); + int(len), name, space_id); } } } From f50abab195168e497f36715b2f0dbdad8183ed4c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marko=20M=C3=A4kel=C3=A4?= Date: Thu, 13 Apr 2023 15:18:26 +0300 Subject: [PATCH 90/92] MDEV-31048 PERFORMANCE_SCHEMA lakcs InnoDB read_slots and write_slots tpool::cache::m_mtx: Add PERFORMANCE_SCHEMA instrumentation (wait/synch/mutex/innodb/tpool_cache_mutex). This covers the InnoDB read_slots and write_slots for asynchronous data page I/O. --- storage/innobase/handler/ha_innodb.cc | 2 + storage/innobase/os/os0file.cc | 14 +++--- tpool/tpool_structs.h | 62 +++++++++++++++++++-------- 3 files changed, 54 insertions(+), 24 deletions(-) diff --git a/storage/innobase/handler/ha_innodb.cc b/storage/innobase/handler/ha_innodb.cc index 04a857ecd0c70..f102789d7ab28 100644 --- a/storage/innobase/handler/ha_innodb.cc +++ b/storage/innobase/handler/ha_innodb.cc @@ -542,6 +542,7 @@ mysql_pfs_key_t trx_pool_manager_mutex_key; mysql_pfs_key_t lock_wait_mutex_key; mysql_pfs_key_t trx_sys_mutex_key; mysql_pfs_key_t srv_threads_mutex_key; +mysql_pfs_key_t tpool_cache_mutex_key; /* all_innodb_mutexes array contains mutexes that are performance schema instrumented if "UNIV_PFS_MUTEX" @@ -577,6 +578,7 @@ static PSI_mutex_info all_innodb_mutexes[] = { PSI_KEY(rtr_match_mutex), PSI_KEY(rtr_path_mutex), PSI_KEY(trx_sys_mutex), + PSI_KEY(tpool_cache_mutex), }; # endif /* UNIV_PFS_MUTEX */ diff --git a/storage/innobase/os/os0file.cc b/storage/innobase/os/os0file.cc index 12561877c0c62..d366c784b96b9 100644 --- a/storage/innobase/os/os0file.cc +++ b/storage/innobase/os/os0file.cc @@ -132,7 +132,7 @@ class io_slots wait(); } - std::mutex& mutex() + mysql_mutex_t& mutex() { return m_cache.mutex(); } @@ -3668,8 +3668,10 @@ void os_aio_wait_until_no_pending_writes() /** @return number of pending reads */ size_t os_aio_pending_reads() { - std::unique_lock lk(read_slots->mutex()); - return read_slots->pending_io_count(); + mysql_mutex_lock(&read_slots->mutex()); + size_t pending= read_slots->pending_io_count(); + mysql_mutex_unlock(&read_slots->mutex()); + return pending; } /** @return approximate number of pending reads */ @@ -3681,8 +3683,10 @@ size_t os_aio_pending_reads_approx() /** @return number of pending writes */ size_t os_aio_pending_writes() { - std::unique_lock lk(write_slots->mutex()); - return write_slots->pending_io_count(); + mysql_mutex_lock(&write_slots->mutex()); + size_t pending= write_slots->pending_io_count(); + mysql_mutex_unlock(&write_slots->mutex()); + return pending; } /** Wait until all pending asynchronous reads have completed. */ diff --git a/tpool/tpool_structs.h b/tpool/tpool_structs.h index b6ca3f54016ea..550a92d6e583c 100644 --- a/tpool/tpool_structs.h +++ b/tpool/tpool_structs.h @@ -14,14 +14,13 @@ along with this program; if not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02111 - 1301 USA*/ #pragma once +#include +#include #include #include -#include -#include #include #include - /* Suppress TSAN warnings, that we believe are not critical. */ #if defined(__has_feature) #define TPOOL_HAS_FEATURE(...) __has_feature(__VA_ARGS__) @@ -37,6 +36,11 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02111 - 1301 USA*/ #define TPOOL_SUPPRESS_TSAN #endif +#ifdef HAVE_PSI_INTERFACE +typedef unsigned int mysql_pfs_key_t; +extern mysql_pfs_key_t tpool_cache_mutex_key; +#endif + namespace tpool { @@ -55,13 +59,13 @@ namespace tpool template class cache { /** Protects updates of m_pos and m_cache members */ - std::mutex m_mtx; + mysql_mutex_t m_mtx; /** Notify waiting threads about "cache full" or "cache not empty" conditions @see get() and wait() */ - std::condition_variable m_cv; + pthread_cond_t m_cv; /** Cached items vector.Does not change after construction */ std::vector m_base; @@ -108,13 +112,22 @@ template class cache Constructor @param size - maximum number of items in cache */ - cache(size_t size) : m_mtx(), m_cv(), m_base(size), m_cache(size), + cache(size_t size) : m_base(size), m_cache(size), m_waiters(), m_pos(0) { + mysql_mutex_init(tpool_cache_mutex_key, &m_mtx, nullptr); + pthread_cond_init(&m_cv, nullptr); + for(size_t i= 0 ; i < size; i++) m_cache[i]= &m_base[i]; } + ~cache() + { + mysql_mutex_destroy(&m_mtx); + pthread_cond_destroy(&m_cv); + } + /** Retrieve an item from cache. Waits for free item, if cache is currently empty. @@ -122,16 +135,17 @@ template class cache */ T* get() { - std::unique_lock lk(m_mtx); - while(is_empty()) - m_cv.wait(lk); + mysql_mutex_lock(&m_mtx); + while (is_empty()) + my_cond_wait(&m_cv, &m_mtx.m_mutex); assert(m_pos < capacity()); // return last element - return m_cache[m_pos++]; + T *t= m_cache[m_pos++]; + mysql_mutex_unlock(&m_mtx); + return t; } - - std::mutex &mutex() { return m_mtx; } + mysql_mutex_t &mutex() { return m_mtx; } /** Put back an element to cache. @@ -139,7 +153,7 @@ template class cache */ void put(T *ele) { - std::unique_lock lk(m_mtx); + mysql_mutex_lock(&m_mtx); assert(!is_full()); // put element to the logical end of the array m_cache[--m_pos] = ele; @@ -147,7 +161,8 @@ template class cache /* Notify waiters when the cache becomes not empty, or when it becomes full */ if (m_pos == 1 || (m_waiters && is_full())) - m_cv.notify_all(); + pthread_cond_broadcast(&m_cv); + mysql_mutex_unlock(&m_mtx); } /** Check if pointer represents cached element */ @@ -157,16 +172,25 @@ template class cache return ele >= &m_base[0] && ele <= &m_base[capacity() - 1]; } - /** Wait until cache is full.*/ - void wait() + /** Wait until cache is full + @param m cache mutex (locked) */ + void wait(mysql_mutex_t &m) { - std::unique_lock lk(m_mtx); + mysql_mutex_assert_owner(&m); m_waiters++; - while(!is_full()) - m_cv.wait(lk); + while (!is_full()) + my_cond_wait(&m_cv, &m.m_mutex); m_waiters--; } + /* Wait until cache is full.*/ + void wait() + { + mysql_mutex_lock(&m_mtx); + wait(m_mtx); + mysql_mutex_unlock(&m_mtx); + } + /** @return approximate number of "borrowed" items. A "dirty" read, not used in any critical functionality. From 1e4eef5c17167f0740182fe69bff30f9416acfc3 Mon Sep 17 00:00:00 2001 From: Tuukka Pasanen Date: Thu, 13 Apr 2023 10:42:34 +0300 Subject: [PATCH 91/92] MDEV-31045: Fix regression building on Ubuntu 18.04 Github PR #2424 regressed Ubuntu 18.04 building other than x86_64 machines. Architecture that are impacted are PPC64 and ARM64. This was because of changes in debian/rules file which caused removing dependency to package 'libpmem-dev' and CMake which '-DWITH_PMEM' removing not working correctly. Package libpmem-dev was removed but it still required to have PMEM with CMake which. Commit make change that -DWITH_PMEM is correctly removed if it's not wanted. --- debian/autobake-deb.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/debian/autobake-deb.sh b/debian/autobake-deb.sh index bad6e6eecf066..e5c5600daf7b2 100755 --- a/debian/autobake-deb.sh +++ b/debian/autobake-deb.sh @@ -64,7 +64,7 @@ replace_uring_with_aio() disable_pmem() { sed '/libpmem-dev/d' -i debian/control - sed '/-DWITH_PMEM=YES/d' -i debian/rules + sed '/-DWITH_PMEM=ON/d' -i debian/rules } architecture=$(dpkg-architecture -q DEB_BUILD_ARCH) From f2fde3f6675dff56e7f46c19c9f041cc7e259d43 Mon Sep 17 00:00:00 2001 From: Tuukka Pasanen Date: Mon, 20 Feb 2023 10:10:09 +0200 Subject: [PATCH 92/92] MDEV-30687: Make small facelifting to autobake-debs.sh Currently autobake-debs.sh does not pass shellcheck it fails making errors: * SC1091 when using shellcheck -x it needs to know where to find ./VERSION. As this is not needed we just specify it as /dev/null as mentioned in shellcheck documentation: https://www.shellcheck.net/wiki/SC1091 * SC2086 make sure that there is no globbing or word splitting in dpkg-buidpackage string. This not big problem or about to happen but now extra parameter parsing is more Bash compliant with using array. Change BUILDPACKAGE_PREPEND to BUILDPACKAGE_DPKGCMD which holds 'eatmydata' if it's available and needed 'dpkg-buildpackage' https://www.shellcheck.net/wiki/SC2086 Fix small script indentation problem. --- debian/autobake-deb.sh | 36 +++++++++++++++++++++++++++--------- 1 file changed, 27 insertions(+), 9 deletions(-) diff --git a/debian/autobake-deb.sh b/debian/autobake-deb.sh index e5c5600daf7b2..cf14eb701b525 100755 --- a/debian/autobake-deb.sh +++ b/debian/autobake-deb.sh @@ -16,6 +16,7 @@ set -e # Buildbot, running the test suite from installed .debs on a clean VM. export DEB_BUILD_OPTIONS="nocheck $DEB_BUILD_OPTIONS" +# shellcheck source=/dev/null source ./VERSION # General CI optimizations to keep build output smaller if [[ $GITLAB_CI ]] @@ -91,20 +92,20 @@ fi # If not known, use 'unknown' in .deb version identifier if [ -z "${LSBID}" ] then - LSBID="unknown" + LSBID="unknown" fi case "${LSBNAME}" in # Debian - buster) + "buster") replace_uring_with_aio if [ ! "$architecture" = amd64 ] then disable_pmem fi ;& - bullseye|bookworm) + "bullseye"|"bookworm") # mariadb-plugin-rocksdb in control is 4 arches covered by the distro rocksdb-tools # so no removal is necessary. if [[ ! "$architecture" =~ amd64|arm64|ppc64el ]] @@ -116,19 +117,19 @@ in replace_uring_with_aio fi ;& - sid) + "sid") # The default packaging should always target Debian Sid, so in this case # there is intentionally no customizations whatsoever. ;; # Ubuntu - bionic) + "bionic") remove_rocksdb_tools [ "$architecture" != amd64 ] && disable_pmem ;& - focal) + "focal") replace_uring_with_aio ;& - impish|jammy|kinetic) + "impish"|"jammy"|"kinetic") # mariadb-plugin-rocksdb s390x not supported by us (yet) # ubuntu doesn't support mips64el yet, so keep this just # in case something changes. @@ -169,17 +170,34 @@ dch -b -D "${LSBNAME}" -v "${VERSION}" "Automatic build with ${LOGSTRING}." --co echo "Creating package version ${VERSION} ... " +BUILDPACKAGE_DPKGCMD="" + # Use eatmydata is available to build faster with less I/O, skipping fsync() # during the entire build process (safe because a build can always be restarted) if which eatmydata > /dev/null then - BUILDPACKAGE_PREPEND=eatmydata + BUILDPACKAGE_DPKGCMD="eatmydata" +fi + +BUILDPACKAGE_DPKGCMD+="dpkg-buildpackage" + +# Using dpkg-buildpackage args +# -us Allow unsigned sources +# -uc Allow unsigned changes +# -I Tar ignore +BUILDPACKAGE_DPKG_ARGS=(-us -uc -I) + +# There can be also extra flags that are appended to args +if [ -n "$BUILDPACKAGE_FLAGS" ] +then + read -ra BUILDPACKAGE_TMP_ARGS <<< "$BUILDPACKAGE_FLAGS" + BUILDPACKAGE_DPKG_ARGS=("${BUILDPACKAGE_DPKG_ARGS[@]} ${BUILDPACKAGE_TMP_ARGS[@]}") fi # Build the package # Pass -I so that .git and other unnecessary temporary and source control files # will be ignored by dpkg-source when creating the tar.gz source package. -fakeroot $BUILDPACKAGE_PREPEND dpkg-buildpackage -us -uc -I $BUILDPACKAGE_FLAGS +fakeroot -- "${BUILDPACKAGE_DPKGCMD}" "${BUILDPACKAGE_DPKG_ARGS[@]}" # If the step above fails due to missing dependencies, you can manually run # sudo mk-build-deps debian/control -r -i