From a2d7a21196e69eb1e4c8546d18762afd192a4d31 Mon Sep 17 00:00:00 2001 From: Sergey Zefirov <72864488+mariadb-SergeyZefirov@users.noreply.github.com> Date: Fri, 17 Mar 2023 13:10:53 +0300 Subject: [PATCH] Fix "column1 LIKE column2" for columns from same table (#2776) This WHERE part will be performed with FilterCommand, which did not had LIKE operator implemented until now. --- .../columnstore/basic/r/mcol-5418.result | 12 +++++++++++ mysql-test/columnstore/basic/t/mcol-5418.test | 21 +++++++++++++++++++ primitives/primproc/filtercommand.cpp | 4 ++++ 3 files changed, 37 insertions(+) create mode 100644 mysql-test/columnstore/basic/r/mcol-5418.result create mode 100644 mysql-test/columnstore/basic/t/mcol-5418.test diff --git a/mysql-test/columnstore/basic/r/mcol-5418.result b/mysql-test/columnstore/basic/r/mcol-5418.result new file mode 100644 index 000000000..2fc78dc93 --- /dev/null +++ b/mysql-test/columnstore/basic/r/mcol-5418.result @@ -0,0 +1,12 @@ +DROP DATABASE IF EXISTS mcol5418; +CREATE DATABASE mcol5418; +USE mcol5418; +CREATE TABLE tcs(d1 CHAR(6), d2 CHAR(6)) ENGINE=columnstore; +INSERT INTO tcs(d1, d2) VALUES ('a','a'), ('a', 'b'); +SELECT 'columnstore like', d1, d2 FROM tcs WHERE (d1 LIKE d2); +columnstore like d1 d2 +columnstore like a a +SELECT 'columnstore not like', d1, d2 FROM tcs WHERE (d1 NOT LIKE d2); +columnstore not like d1 d2 +columnstore not like a b +DROP DATABASE mcol5418; diff --git a/mysql-test/columnstore/basic/t/mcol-5418.test b/mysql-test/columnstore/basic/t/mcol-5418.test new file mode 100644 index 000000000..13e303bb2 --- /dev/null +++ b/mysql-test/columnstore/basic/t/mcol-5418.test @@ -0,0 +1,21 @@ +# This test tests the (NOT) LIKE test in filters that is added +# to a FilterCommand in primproc. +# This is a very rare situation, yet somehow I managed to trigger it. + +--disable_warnings +DROP DATABASE IF EXISTS mcol5418; +--enable_warnings + +CREATE DATABASE mcol5418; + +USE mcol5418; + +CREATE TABLE tcs(d1 CHAR(6), d2 CHAR(6)) ENGINE=columnstore; + +INSERT INTO tcs(d1, d2) VALUES ('a','a'), ('a', 'b'); + +SELECT 'columnstore like', d1, d2 FROM tcs WHERE (d1 LIKE d2); + +SELECT 'columnstore not like', d1, d2 FROM tcs WHERE (d1 NOT LIKE d2); + +DROP DATABASE mcol5418; diff --git a/primitives/primproc/filtercommand.cpp b/primitives/primproc/filtercommand.cpp index ba19098ce..88d8fbfa3 100644 --- a/primitives/primproc/filtercommand.cpp +++ b/primitives/primproc/filtercommand.cpp @@ -488,6 +488,10 @@ void StrFilterCmd::setCompareFunc(uint32_t columns) static inline bool compareString(const datatypes::Charset& cs, const utils::ConstString& s0, const utils::ConstString& s1, uint8_t fBOP) { + if (fBOP == COMPARE_LIKE || fBOP == COMPARE_NLIKE) + { + return cs.like(fBOP == COMPARE_NLIKE, s0, s1); + } int cmp = cs.strnncollsp(s0, s1); switch (fBOP) {