diff --git a/.github/workflows/nightly.yaml b/.github/workflows/nightly.yaml index bcdbfac34..f8c40ade2 100644 --- a/.github/workflows/nightly.yaml +++ b/.github/workflows/nightly.yaml @@ -38,6 +38,7 @@ jobs: [ -s /tmp/.clang-format-diff ] && exit 1 || true build: + needs: lint runs-on: ubuntu-latest steps: - uses: actions/checkout@v4 @@ -92,4 +93,4 @@ jobs: cd /home/shannon-bin/mysql-test/ sudo chmod -R u+rwx mysql-test-run.pl ./mysql-test-run.pl --suite=main,innodb,binlog,binlog_gtid,binlog_nogtid,secondary_engine,rpl,rpl_gtid,rpl_nogtid \ - --mysqld=--user=$USER --mysqld=--default-storage-engine=innodb --nowarnings --force --nocheck-testcases --retry=0 --parallel=10 \ No newline at end of file + --mysqld=--user=$USER --mysqld=--default-storage-engine=innodb --nowarnings --force --nocheck-testcases --retry=0 --parallel=$(nproc) \ No newline at end of file diff --git a/.github/workflows/pull-requests.yaml b/.github/workflows/pull-requests.yaml index bd0e94671..63559c8f0 100644 --- a/.github/workflows/pull-requests.yaml +++ b/.github/workflows/pull-requests.yaml @@ -36,22 +36,6 @@ defaults: shell: bash jobs: - check-runner-spec: - runs-on: ubuntu-latest - steps: - - name: Checkout repository - uses: actions/checkout@v4 - - - name: Print disk space usage - run: | - echo "Root directory (/):" - df -h / - echo "Home directory (/home/runner):" - df -h /home/runner - echo "Work directory (/home/runner/work):" - df -h /home/runner/work - echo "Temp directory (/tmp):" - df -h /tmp lint: name: lint # if: ${{ contains(github.event.pull_request.labels.*.name, 'ready-for-testing') && github.event.pull_request.merged != true }} @@ -74,7 +58,8 @@ jobs: [ -s /tmp/.clang-format-diff ] && exit 1 || true build: - runs-on: ubuntu-latest + needs: lint + runs-on: self-hosted steps: - uses: actions/checkout@v4 - name: install_lib @@ -89,7 +74,7 @@ jobs: run: | cd /tmp && wget https://boostorg.jfrog.io/artifactory/main/release/1.77.0/source/boost_1_77_0.tar.gz && \ tar zxvf boost_1_77_0.tar.gz && cd boost_1_77_0 && ./bootstrap.sh --prefix=/usr/local/boost && ./b2 -j$(nproc) && sudo ./b2 install && \ - sudo rm ../boost_1_77_0 -rf + sudo rm ../boost_1_77_0 -rf && sudo rm /tmp/boost_1_77_0.tar.gz #sed -i '61s/^/#/' cmake_install.cmake to disable can not find openssl_executeable error. removes it when it fixed. - name: build_shannon_and_install run: | @@ -99,10 +84,10 @@ jobs: cmake ../ \ -DWITH_BOOST=/usr/local/boost/include \ -DCMAKE_BUILD_TYPE=Release \ - -DCMAKE_INSTALL_PREFIX=/home/shannon-bin/ \ - -DMYSQL_DATADIR=/home/shannon-bin/ \ - -DSYSCONFDIR=/home/shannon-bin/ \ - -DMYSQL_UNIX_ADDR=/home/shannon-bin/temp/mysql.sock \ + -DCMAKE_INSTALL_PREFIX=/__w/shannon-bin/ \ + -DMYSQL_DATADIR=/__w/shannon-bin/ \ + -DSYSCONFDIR=/__w/shannon-bin/ \ + -DMYSQL_UNIX_ADDR=/__w/shannon-bin/temp/mysql.sock \ -DWITH_EMBEDDED_SERVER=OFF \ -DWITH_MYISAM_STORAGE_ENGINE=1 \ -DWITH_INNOBASE_STORAGE_ENGINE=1 \ @@ -123,9 +108,9 @@ jobs: sudo rm /__w/ShannonBase/ -rf - name: run_mtr_test run: | - mkdir -p /home/shannon-bin/log - sudo chown -R $USER:$USER /home/shannon-bin/ - cd /home/shannon-bin/mysql-test/ + sudo mkdir -p /__w/shannon-bin/log + sudo chown -R $USER:$USER /__w/shannon-bin/ + cd /__w/shannon-bin/mysql-test/ sudo chmod -R u+rwx mysql-test-run.pl ./mysql-test-run.pl --suite=main,innodb,binlog,binlog_gtid,binlog_nogtid,secondary_engine,rpl,rpl_gtid,rpl_nogtid \ - --mysqld=--user=$USER --mysqld=--default-storage-engine=innodb --nowarnings --force --nocheck-testcases --retry=0 --parallel=10 \ No newline at end of file + --mysqld=--user=$USER --mysqld=--default-storage-engine=innodb --nowarnings --force --nocheck-testcases --retry=0 --parallel=$(nproc) \ No newline at end of file diff --git a/.github/workflows/weekly.yaml b/.github/workflows/weekly.yaml index 24eb4077d..ad6f114d0 100644 --- a/.github/workflows/weekly.yaml +++ b/.github/workflows/weekly.yaml @@ -39,6 +39,7 @@ jobs: [ -s /tmp/.clang-format-diff ] && exit 1 || true build: + needs: lint runs-on: ubuntu-latest steps: - uses: actions/checkout@v4 @@ -93,4 +94,4 @@ jobs: cd /home/shannon-bin/mysql-test/ sudo chmod -R u+rwx mysql-test-run.pl ./mysql-test-run.pl --big-test --mysqld=--user=$USER --mysqld=--default-storage-engine=innodb --nowarnings --force \ - --nocheck-testcases --retry=0 --parallel=10 \ No newline at end of file + --nocheck-testcases --retry=0 --parallel=$(nproc) \ No newline at end of file diff --git a/sql/CMakeLists.txt b/sql/CMakeLists.txt index 8659e7e79..627af5a3d 100644 --- a/sql/CMakeLists.txt +++ b/sql/CMakeLists.txt @@ -348,13 +348,6 @@ SET(SQL_GIS_SOURCES item_geofunc_relchecks.cc options_parser.cc ) -SET(SQL_VECTOR_SOURCES - vector/vector.cpp - vector/bitvector.cpp - vector/vector_comm.cpp - vector/bitvector.cpp - vector/halfutils.cpp -) SET(SQL_SHARED_SOURCES auth/auth_acls.cc @@ -1010,10 +1003,6 @@ TARGET_INCLUDE_DIRECTORIES(sql_ml PUBLIC TARGET_LINK_LIBRARIES(sql_ml _lightgbm) SET_TARGET_PROPERTIES(sql_ml PROPERTIES LINK_INTERFACE_MULTIPLICITY 3) -ADD_LIBRARY(sql_vector STATIC ${SQL_VECTOR_SOURCES}) -TARGET_LINK_LIBRARIES(sql_vector sql_dd sql_main) -SET_TARGET_PROPERTIES(sql_vector PROPERTIES LINK_INTERFACE_MULTIPLICITY 3) - # # On Windows platform we compile in the client-side Windows Native Authentication # plugin which is used by the client connection code included in the server. @@ -1279,7 +1268,7 @@ ENDIF() SET_TARGET_PROPERTIES(mysqld PROPERTIES ENABLE_EXPORTS TRUE) TARGET_LINK_LIBRARIES(mysqld sql_main sql_gis binlog rpl rpl_source rpl_replica sql_dd mysys - minchassis binlogevents_static sql_ml sql_vector ext::icu) + minchassis binlogevents_static sql_ml ext::icu) # Add dependency on ldap library, to ensure it is not unloaded # when we shutdown the authentication plugin. diff --git a/sql/sql_union.cc b/sql/sql_union.cc index d31aa1857..78096b47c 100644 --- a/sql/sql_union.cc +++ b/sql/sql_union.cc @@ -1789,13 +1789,14 @@ bool Query_expression::ExecuteIteratorQuery(THD *thd) { else if (thd->killed) // Aborted by user { thd->send_kill_message(); - return true; + execute_error = true; } - + if (execute_error) break; ++*send_records_ptr; if (query_result->send_data(thd, *fields)) { - return true; + execute_error = true; + break; } thd->get_stmt_da()->inc_current_row_for_condition(); } diff --git a/sql/vector/bitvector.cpp b/sql/vector/bitvector.cpp deleted file mode 100644 index 906bf9948..000000000 --- a/sql/vector/bitvector.cpp +++ /dev/null @@ -1,88 +0,0 @@ -/* Copyright (c) 2018, 2023, Oracle and/or its affiliates. - - This program is free software; you can redistribute it and/or modify - it under the terms of the GNU General Public License, version 2.0, - as published by the Free Software Foundation. - - This program is also distributed with certain software (including - but not limited to OpenSSL) that is licensed under separate terms, - as designated in a particular file or component or in included license - documentation. The authors of MySQL hereby grant you an additional - permission to link the program and your derivative works with the - separately licensed software that they have included with MySQL. - - 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, version 2.0, for more details. - - You should have received a copy of the GNU General Public License - along with this program; if not, write to the Free Software - Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA - - pg_vector - Copyright (c) 2023, Shannon Data AI and/or its affiliates. -*/ -#ifndef __SHANNONBASE_BITVECTOR_H__ -#define __SHANNONBASE_BITVECTOR_H__ - -#include "bitvector.h" - -#include "include/my_sys.h" -#include "mysqld_error.h" - -namespace ShannonBase { -namespace Vector { - -VarBit BitVector::InitBitVector(uint32 dim) { - VarBit result; - uint byte_size = dim / sizeof(sizeof(uint8)); - result.reserve(byte_size); - - return result; -} - -double BitVector::hamming_distance(VarBit *va, VarBit *vb) { - unsigned char *ax = va->data(); - unsigned char *bx = vb->data(); - uint64 distance = 0; - - if (!CheckDims(va, vb)) { - my_error(ER_SECONDARY_ENGINE_PLUGIN, MYF(0), "invalid dims"); - return 0.0f; - } - - /* TODO Improve performance */ - for (uint32 i = 0; i < va->size(); i++) - distance += shannon_number_of_ones[ax[i] ^ bx[i]]; - return ((double)distance); - ; -} - -double BitVector::jaccard_distance(VarBit *va, VarBit *vb) { - unsigned char *ax = va->data(); - unsigned char *bx = vb->data(); - uint64 ab = 0; - uint64 aa; - uint64 bb; - - if (!CheckDims(va, vb)) { - my_error(ER_SECONDARY_ENGINE_PLUGIN, MYF(0), "invalid dims"); - return 0.0f; - } - - /* TODO Improve performance */ - for (uint32 i = 0; i < va->size(); i++) - ab += shannon_number_of_ones[ax[i] & bx[i]]; - - if (ab == 0) return (1.0f); - - aa = Utils::calc_bits_count((char *)ax, va->size()); - bb = Utils::calc_bits_count((char *)bx, vb->size()); - - return (1 - (ab / ((double)(aa + bb - ab)))); -} - -} // namespace Vector -} // namespace ShannonBase -#endif //__SHANNONBASE_BITVECTOR_H__ \ No newline at end of file diff --git a/sql/vector/bitvector.h b/sql/vector/bitvector.h deleted file mode 100644 index eadb3f147..000000000 --- a/sql/vector/bitvector.h +++ /dev/null @@ -1,50 +0,0 @@ -/* Copyright (c) 2018, 2023, Oracle and/or its affiliates. - - This program is free software; you can redistribute it and/or modify - it under the terms of the GNU General Public License, version 2.0, - as published by the Free Software Foundation. - - This program is also distributed with certain software (including - but not limited to OpenSSL) that is licensed under separate terms, - as designated in a particular file or component or in included license - documentation. The authors of MySQL hereby grant you an additional - permission to link the program and your derivative works with the - separately licensed software that they have included with MySQL. - - 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, version 2.0, for more details. - - You should have received a copy of the GNU General Public License - along with this program; if not, write to the Free Software - Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA - - pg_vector - Copyright (c) 2023, Shannon Data AI and/or its affiliates. -*/ -#ifndef __SHANNONBASE_BIT_VECTOR_H__ -#define __SHANNONBASE_BIT_VECTOR_H__ - -#include "vector_comm.h" - -namespace ShannonBase { -namespace Vector { - -class BitVector { - public: - BitVector() = default; - virtual ~BitVector() = default; - - VarBit InitBitVector(uint32 dim); - inline bool CheckDims(VarBit *va, VarBit *vb) { - return (va->size() == vb->size()) ? true : false; - } - - double hamming_distance(VarBit *va, VarBit *vb); - double jaccard_distance(VarBit *va, VarBit *vb); -}; - -} // namespace Vector -} // namespace ShannonBase -#endif //__SHANNONBASE_BIT_VECTOR_H__ \ No newline at end of file diff --git a/sql/vector/halfutils.cpp b/sql/vector/halfutils.cpp deleted file mode 100644 index d1c8d5184..000000000 --- a/sql/vector/halfutils.cpp +++ /dev/null @@ -1,240 +0,0 @@ -/* Copyright (c) 2018, 2023, Oracle and/or its affiliates. - - This program is free software; you can redistribute it and/or modify - it under the terms of the GNU General Public License, version 2.0, - as published by the Free Software Foundation. - - This program is also distributed with certain software (including - but not limited to OpenSSL) that is licensed under separate terms, - as designated in a particular file or component or in included license - documentation. The authors of MySQL hereby grant you an additional - permission to link the program and your derivative works with the - separately licensed software that they have included with MySQL. - - 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, version 2.0, for more details. - - You should have received a copy of the GNU General Public License - along with this program; if not, write to the Free Software - Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA - - pg_vector - Copyright (c) 2023, Shannon Data AI and/or its affiliates. -*/ -#include "halfutils.h" - -#include "halfvec.h" - -#ifdef HALFVEC_DISPATCH -#include - -#if defined(HAVE__GET_CPUID) -#include -#elif defined(HAVE__CPUID) -#include -#endif - -#ifdef _MSC_VER -#define TARGET_F16C_FMA -#else -#define TARGET_F16C_FMA __attribute__((target("f16c,fma"))) -#endif -#endif - -namespace ShannonBase { -namespace Vector { -float (*HalfvecL2SquaredDistance)(int dim, half *ax, half *bx); -float (*HalfvecInnerProduct)(int dim, half *ax, half *bx); -double (*HalfvecCosineSimilarity)(int dim, half *ax, half *bx); - -static float HalfvecL2SquaredDistanceDefault(int dim, half *ax, half *bx) { - float distance = 0.0; - - /* Auto-vectorized */ - for (int i = 0; i < dim; i++) { - float diff = - HalfUtils::HalfToFloat4(ax[i]) - HalfUtils::HalfToFloat4(bx[i]); - - distance += diff * diff; - } - - return distance; -} - -#ifdef HALFVEC_DISPATCH -static float HalfvecL2SquaredDistanceF16cFma(int dim, half *ax, half *bx) { - float distance; - int i; - float s[8]; - int count = (dim / 8) * 8; - __m256 dist = _mm256_setzero_ps(); - - for (i = 0; i < count; i += 8) { - __m128i axi = _mm_loadu_si128((__m128i *)(ax + i)); - __m128i bxi = _mm_loadu_si128((__m128i *)(bx + i)); - __m256 axs = _mm256_cvtph_ps(axi); - __m256 bxs = _mm256_cvtph_ps(bxi); - __m256 diff = _mm256_sub_ps(axs, bxs); - - dist = _mm256_fmadd_ps(diff, diff, dist); - } - - _mm256_storeu_ps(s, dist); - - distance = s[0] + s[1] + s[2] + s[3] + s[4] + s[5] + s[6] + s[7]; - - for (; i < dim; i++) { - float diff = - HalfUtils::HalfToFloat4(ax[i]) - HalfUtils::HalfToFloat4(bx[i]); - - distance += diff * diff; - } - - return distance; -} -#endif - -static float HalfvecInnerProductDefault(int dim, half *ax, half *bx) { - float distance = 0.0; - - /* Auto-vectorized */ - for (int i = 0; i < dim; i++) - distance += HalfUtils::HalfToFloat4(ax[i]) * HalfUtils::HalfToFloat4(bx[i]); - - return distance; -} -#ifdef HALFVEC_DISPATCH -TARGET_F16C_FMA static float HalfvecInnerProductF16cFma(int dim, half *ax, - half *bx) { - float distance; - int i; - float s[8]; - int count = (dim / 8) * 8; - __m256 dist = _mm256_setzero_ps(); - - for (i = 0; i < count; i += 8) { - __m128i axi = _mm_loadu_si128((__m128i *)(ax + i)); - __m128i bxi = _mm_loadu_si128((__m128i *)(bx + i)); - __m256 axs = _mm256_cvtph_ps(axi); - __m256 bxs = _mm256_cvtph_ps(bxi); - - dist = _mm256_fmadd_ps(axs, bxs, dist); - } - - _mm256_storeu_ps(s, dist); - - distance = s[0] + s[1] + s[2] + s[3] + s[4] + s[5] + s[6] + s[7]; - - for (; i < dim; i++) - distance += HalfUtils::HalfToFloat4(ax[i]) * HalfUtils::HalfToFloat4(bx[i]); - - return distance; -} -#endif - -static double HalfvecCosineSimilarityDefault(int dim, half *ax, half *bx) { - float similarity = 0.0; - float norma = 0.0; - float normb = 0.0; - - /* Auto-vectorized */ - for (int i = 0; i < dim; i++) { - float axi = HalfUtils::HalfToFloat4(ax[i]); - float bxi = HalfUtils::HalfToFloat4(bx[i]); - - similarity += axi * bxi; - norma += axi * axi; - normb += bxi * bxi; - } - - /* Use sqrt(a * b) over sqrt(a) * sqrt(b) */ - return (double)similarity / sqrt((double)norma * (double)normb); -} - -#ifdef HALFVEC_DISPATCH -TARGET_F16C_FMA static double HalfvecCosineSimilarityF16cFma(int dim, half *ax, - half *bx) { - float similarity; - float norma; - float normb; - int i; - float s[8]; - int count = (dim / 8) * 8; - __m256 sim = _mm256_setzero_ps(); - __m256 na = _mm256_setzero_ps(); - __m256 nb = _mm256_setzero_ps(); - - for (i = 0; i < count; i += 8) { - __m128i axi = _mm_loadu_si128((__m128i *)(ax + i)); - __m128i bxi = _mm_loadu_si128((__m128i *)(bx + i)); - __m256 axs = _mm256_cvtph_ps(axi); - __m256 bxs = _mm256_cvtph_ps(bxi); - - sim = _mm256_fmadd_ps(axs, bxs, sim); - na = _mm256_fmadd_ps(axs, axs, na); - nb = _mm256_fmadd_ps(bxs, bxs, nb); - } - - _mm256_storeu_ps(s, sim); - similarity = s[0] + s[1] + s[2] + s[3] + s[4] + s[5] + s[6] + s[7]; - - _mm256_storeu_ps(s, na); - norma = s[0] + s[1] + s[2] + s[3] + s[4] + s[5] + s[6] + s[7]; - - _mm256_storeu_ps(s, nb); - normb = s[0] + s[1] + s[2] + s[3] + s[4] + s[5] + s[6] + s[7]; - - /* Auto-vectorized */ - for (; i < dim; i++) { - float axi = HalfUtils::HalfToFloat4(ax[i]); - float bxi = HalfUtils::HalfToFloat4(bx[i]); - - similarity += axi * bxi; - norma += axi * axi; - normb += bxi * bxi; - } - - /* Use sqrt(a * b) over sqrt(a) * sqrt(b) */ - return (double)similarity / sqrt((double)norma * (double)normb); -} -#endif - -#ifdef HALFVEC_DISPATCH -#define CPU_FEATURE_FMA (1 << 12) -#define CPU_FEATURE_F16C (1 << 29) - -static bool SupportsCpuFeature(unsigned int feature) { - unsigned int exx[4] = {0, 0, 0, 0}; - -#if defined(HAVE__GET_CPUID) - __get_cpuid(1, &exx[0], &exx[1], &exx[2], &exx[3]); -#elif defined(HAVE__CPUID) - __cpuid(exx, 1); -#endif - - return (exx[2] & feature) == feature; -} -#endif - -void HalfvecInit(void) { - /* - * Could skip pointer when single function, but no difference in - * performance - */ - HalfvecL2SquaredDistance = HalfvecL2SquaredDistanceDefault; - HalfvecInnerProduct = HalfvecInnerProductDefault; - HalfvecCosineSimilarity = HalfvecCosineSimilarityDefault; - -#ifdef HALFVEC_DISPATCH - if (SupportsCpuFeature(CPU_FEATURE_FMA | CPU_FEATURE_F16C)) { - HalfvecL2SquaredDistance = HalfvecL2SquaredDistanceF16cFma; - HalfvecInnerProduct = HalfvecInnerProductF16cFma; - HalfvecCosineSimilarity = HalfvecCosineSimilarityF16cFma; - } -#endif -} - -} // namespace Vector -} // namespace ShannonBase \ No newline at end of file diff --git a/sql/vector/halfutils.h b/sql/vector/halfutils.h deleted file mode 100644 index 8e5f30aaf..000000000 --- a/sql/vector/halfutils.h +++ /dev/null @@ -1,238 +0,0 @@ -/* Copyright (c) 2018, 2023, Oracle and/or its affiliates. - - This program is free software; you can redistribute it and/or modify - it under the terms of the GNU General Public License, version 2.0, - as published by the Free Software Foundation. - - This program is also distributed with certain software (including - but not limited to OpenSSL) that is licensed under separate terms, - as designated in a particular file or component or in included license - documentation. The authors of MySQL hereby grant you an additional - permission to link the program and your derivative works with the - separately licensed software that they have included with MySQL. - - 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, version 2.0, for more details. - - You should have received a copy of the GNU General Public License - along with this program; if not, write to the Free Software - Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA - - pg_vector - Copyright (c) 2023, Shannon Data AI and/or its affiliates. -*/ -#ifndef __SHANNONBASE_HALFUTILS_H_ -#define __SHANNONBASE_HALFUTILS_H_ - -#include -#ifdef F16C_SUPPORT -#include -#endif - -#include "halfvec.h" -#include "include/my_compiler.h" -#include "vector_comm.h" - -namespace ShannonBase { -namespace Vector { - -extern float (*HalfvecL2SquaredDistance)(int dim, half *ax, half *bx); -extern float (*HalfvecInnerProduct)(int dim, half *ax, half *bx); -extern double (*HalfvecCosineSimilarity)(int dim, half *ax, half *bx); - -class HalfUtils { - public: - static void HalfvecInit(void); - /* * Check if half is NaN */ - static inline bool HalfIsNan(half num) { -#ifdef FLT16_SUPPORT - return isnan(num); -#else - return (num & 0x7C00) == 0x7C00 && (num & 0x7FFF) != 0x7C00; -#endif - } - /* * Check if half is infinite */ - static inline bool HalfIsInf(half num) { -#ifdef FLT16_SUPPORT - return isinf(num); -#else - return (num & 0x7FFF) == 0x7C00; -#endif - } - /* * Check if half is zero */ - static inline bool HalfIsZero(half num) { -#ifdef FLT16_SUPPORT - return num == 0; -#else - return (num & 0x7FFF) == 0x0000; -#endif - } - /* * Convert a half to a float4 */ - static inline float HalfToFloat4(half num) { -#if defined(F16C_SUPPORT) - return _cvtsh_ss(num); -#elif defined(FLT16_SUPPORT) - return (float)num; -#else - /* TODO Improve performance */ - /* Assumes same endianness for floats and integers */ - union { - float f; - uint32 i; - } swapfloat; - union { - half h; - uint16 i; - } swaphalf; - - uint16 bin; - uint32 exponent; - uint32 mantissa; - uint32 result; - - swaphalf.h = num; - bin = swaphalf.i; - exponent = (bin & 0x7C00) >> 10; - mantissa = bin & 0x03FF; - - /* Sign */ - result = (bin & 0x8000) << 16; - - if (unlikely(exponent == 31)) { - if (mantissa == 0) { - /* Infinite */ - result |= 0x7F800000; - } else { - /* NaN */ - result |= 0x7FC00000; - } - } else if (unlikely(exponent == 0)) { - /* Subnormal */ - if (mantissa != 0) { - exponent = -14; - - for (int i = 0; i < 10; i++) { - mantissa <<= 1; - exponent -= 1; - - if ((mantissa >> 10) % 2 == 1) { - mantissa &= 0x03ff; - break; - } - } - - result |= (exponent + 127) << 23; - } - } else { - /* Normal */ - result |= (exponent - 15 + 127) << 23; - } - - result |= mantissa << 13; - swapfloat.i = result; - return swapfloat.f; -#endif - } - - /* - * Convert a float4 to a half - */ - static inline half Float4ToHalfUnchecked(float num) { -#if defined(F16C_SUPPORT) - return _cvtss_sh(num, 0); -#elif defined(FLT16_SUPPORT) - return (_Float16)num; -#else - /* TODO Improve performance */ - - /* Assumes same endianness for floats and integers */ - union { - float f; - uint32 i; - } swapfloat; - - union { - half h; - uint16 i; - } swaphalf; - - uint32 bin; - int exponent; - int mantissa; - uint16 result; - - swapfloat.f = num; - bin = swapfloat.i; - exponent = (bin & 0x7F800000) >> 23; - mantissa = bin & 0x007FFFFF; - - /* Sign */ - result = (bin & 0x80000000) >> 16; - - if (std::isinf(num)) { - /* Infinite */ - result |= 0x7C00; - } else if (std::isnan(num)) { - /* NaN */ - result |= 0x7E00; - result |= mantissa >> 13; - } else if (exponent > 98) { - int m; - int gr; - int s; - - exponent -= 127; - s = mantissa & 0x00000FFF; - - /* Subnormal */ - if (exponent < -14) { - int diff = -exponent - 14; - - mantissa >>= diff; - mantissa += 1 << (23 - diff); - s |= mantissa & 0x00000FFF; - } - - m = mantissa >> 13; - - /* Round */ - gr = (mantissa >> 12) % 4; - if (gr == 3 || (gr == 1 && s != 0)) m += 1; - - if (m == 1024) { - m = 0; - exponent += 1; - } - - if (exponent > 15) { - /* Infinite */ - result |= 0x7C00; - } else { - if (exponent >= -14) result |= (exponent + 15) << 10; - - result |= m; - } - } - - swaphalf.i = result; - return swaphalf.h; -#endif - } - - /* * Convert a float4 to a half */ - inline half Float4ToHalf(float num) { - half result = Float4ToHalfUnchecked(num); - - if (unlikely(HalfIsInf(result)) && !std::isinf(num)) { // error - return 0.0f; - } - - return result; - } -}; - -} // namespace Vector -} // namespace ShannonBase -#endif //__SHANNONBASE_HALFUTILS_H_ diff --git a/sql/vector/halfvec.cpp b/sql/vector/halfvec.cpp deleted file mode 100644 index e69de29bb..000000000 diff --git a/sql/vector/halfvec.h b/sql/vector/halfvec.h deleted file mode 100644 index 9412ad5aa..000000000 --- a/sql/vector/halfvec.h +++ /dev/null @@ -1,54 +0,0 @@ -/* Copyright (c) 2018, 2023, Oracle and/or its affiliates. - - This program is free software; you can redistribute it and/or modify - it under the terms of the GNU General Public License, version 2.0, - as published by the Free Software Foundation. - - This program is also distributed with certain software (including - but not limited to OpenSSL) that is licensed under separate terms, - as designated in a particular file or component or in included license - documentation. The authors of MySQL hereby grant you an additional - permission to link the program and your derivative works with the - separately licensed software that they have included with MySQL. - - 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, version 2.0, for more details. - - You should have received a copy of the GNU General Public License - along with this program; if not, write to the Free Software - Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA - - pg_vector - Copyright (c) 2023, Shannon Data AI and/or its affiliates. -*/ -#ifndef __SHANNONBASE_HALFVECTOR_H_ -#define __SHANNONBASE_HALFVECTOR_H_ - -#include "vector_comm.h" - -#if defined(__x86_64__) || defined(_M_AMD64) -//#define HALFVEC_DISPATCH -#endif -/* F16C has better performance than _Float16 (on x86-64) */ -#if defined(__F16C__) -#define F16C_SUPPORT -#elif defined(__FLT16_MAX__) && !defined(HALFVEC_DISPATCH) -#define FLT16_SUPPORT -#endif - -#ifdef FLT16_SUPPORT -#define half _Float16 -#define HALF_MAX FLT16_MAX -#else -#define half uint16 -#define HALF_MAX 65504 -#endif - -#define HALFVEC_MAX_DIM VECTOR_MAX_DIM - -namespace ShannonBase { -namespace Vector {} // namespace Vector -} // namespace ShannonBase -#endif //__SHANNONBASE_HALFVECTOR_H_ \ No newline at end of file diff --git a/sql/vector/vector.cpp b/sql/vector/vector.cpp deleted file mode 100644 index 978be9369..000000000 --- a/sql/vector/vector.cpp +++ /dev/null @@ -1,207 +0,0 @@ -/* Copyright (c) 2018, 2023, Oracle and/or its affiliates. - - This program is free software; you can redistribute it and/or modify - it under the terms of the GNU General Public License, version 2.0, - as published by the Free Software Foundation. - - This program is also distributed with certain software (including - but not limited to OpenSSL) that is licensed under separate terms, - as designated in a particular file or component or in included license - documentation. The authors of MySQL hereby grant you an additional - permission to link the program and your derivative works with the - separately licensed software that they have included with MySQL. - - 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, version 2.0, for more details. - - You should have received a copy of the GNU General Public License - along with this program; if not, write to the Free Software - Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA - - pg_vector - Copyright (c) 2023, Shannon Data AI and/or its affiliates. -*/ - -#include "vector.h" - -#include -#include - -#include "include/my_sys.h" -#include "mysqld_error.h" - -namespace ShannonBase { -namespace Vector { - -static inline void CheckDims(Vector a, Vector b) { - if (a.size() == b.size()) - my_error(ER_SECONDARY_ENGINE_PLUGIN, MYF(0), "different vector dimensions"); -} - -static inline void CheckExpectedDim(int32 typmod, int dim) { - if (typmod != -1 && typmod != dim) - my_error(ER_SECONDARY_ENGINE_PLUGIN, MYF(0), - "expected dimensions not matched"); -} - -static inline void CheckDim(int dim) { - if (dim < 1) - my_error(ER_SECONDARY_ENGINE_PLUGIN, MYF(0), - "vector must have at least 1 dimension"); - - if (dim > VECTOR_MAX_DIM) - my_error(ER_SECONDARY_ENGINE_PLUGIN, MYF(0), - "vector cannot have more than the max dims"); -} - -/* - * Ensure finite element - */ -static inline void CheckElement(float value) { - if (std::isnan(value)) - my_error(ER_SECONDARY_ENGINE_PLUGIN, MYF(0), "NaN not allowed in vector"); - - if (std::isinf(value)) - my_error(ER_SECONDARY_ENGINE_PLUGIN, MYF(0), - "infinite value not allowed in vector"); -} - -Vector InitVector(uint16 dim) { - Vector vcs; - vcs.reserve(dim); - return vcs; -} - -static inline bool vector_isspace(char ch) { - if (ch == ' ' || ch == '\t' || ch == '\n' || ch == '\r' || ch == '\v' || - ch == '\f') - return true; - return false; -} - -Vector vector_in(uchar *values, int32 type_type) { - uchar *lit = values; - int32 typmod = type_type; - float x[VECTOR_MAX_DIM]; - int dim = 0; - uchar *pt = lit; - Vector result; - - while (vector_isspace(*pt)) pt++; - - if (*pt != '[') - my_error(ER_SECONDARY_ENGINE_PLUGIN, MYF(0), - "invalid input syntax for type vector: Vector contents must start " - "with \"[\"."); - - pt++; - - while (vector_isspace(*pt)) pt++; - - if (*pt == ']') - my_error(ER_SECONDARY_ENGINE_PLUGIN, MYF(0), - "vector must have at least 1 dimension"); - - for (;;) { - float val; - uchar *stringEnd; - - if (dim == VECTOR_MAX_DIM) - my_error(ER_SECONDARY_ENGINE_PLUGIN, MYF(0), - "vector cannot have more than the max dims size"); - - while (vector_isspace(*pt)) pt++; - - /* Check for empty string like float4in */ - if (*pt == '\0') - my_error(ER_SECONDARY_ENGINE_PLUGIN, MYF(0), - "invalid input syntax for type vector"); - - errno = 0; - - /* Use strtof like float4in to avoid a double-rounding problem */ - /* Postgres sets LC_NUMERIC to C on startup */ - val = strtof((const char *)pt, (char **)&stringEnd); - - if (stringEnd == pt) - my_error(ER_SECONDARY_ENGINE_PLUGIN, MYF(0), - "invalid input syntax for type vector"); - - /* Check for range error like float4in */ - if (errno == ERANGE && std::isinf(val)) - my_error(ER_SECONDARY_ENGINE_PLUGIN, MYF(0), - "is out of range for type vector"); - - CheckElement(val); - x[dim++] = val; - - pt = stringEnd; - - while (vector_isspace(*pt)) pt++; - - if (*pt == ',') - pt++; - else if (*pt == ']') { - pt++; - break; - } else - my_error(ER_SECONDARY_ENGINE_PLUGIN, MYF(0), - "invalid input syntax for type vector."); - } - - /* Only whitespace is allowed after the closing brace */ - while (vector_isspace(*pt)) pt++; - - if (*pt != '\0') - my_error(ER_SECONDARY_ENGINE_PLUGIN, MYF(0), - "invalid input syntax for type vector, Junk after closing right " - "brace."); - - CheckDim(dim); - CheckExpectedDim(typmod, dim); - - result = InitVector(dim); - for (int i = 0; i < dim; i++) result.push_back(x[i]); - - return (result); -} - -/* Convert internal representation to textual representation - */ -uchar *vector_out(Vector &vect) { - int dim = vect.size(); - uchar *buf; - uchar *ptr; - - /* - * Need: - * - * dim * (FLOAT_SHORTEST_DECIMAL_LEN - 1) bytes for - * float_to_shortest_decimal_bufn - * - * dim - 1 bytes for separator - * - * 3 bytes for [, ], and \0 - */ - buf = (uchar *)malloc(FLOAT_SHORTEST_DECIMAL_LEN * dim + 2); - ptr = buf; - - AppendChar(ptr, '['); - - for (int i = 0; i < dim; i++) { - if (i > 0) AppendChar(ptr, ','); - - char *chr_ptr = (char *)ptr; - AppendFloat(chr_ptr, vect[i]); - } - - AppendChar(ptr, ']'); - *ptr = '\0'; - - return (buf); -} - -} // namespace Vector -} // namespace ShannonBase \ No newline at end of file diff --git a/sql/vector/vector.h b/sql/vector/vector.h deleted file mode 100644 index 05ca0172c..000000000 --- a/sql/vector/vector.h +++ /dev/null @@ -1,47 +0,0 @@ -/* Copyright (c) 2018, 2023, Oracle and/or its affiliates. - - This program is free software; you can redistribute it and/or modify - it under the terms of the GNU General Public License, version 2.0, - as published by the Free Software Foundation. - - This program is also distributed with certain software (including - but not limited to OpenSSL) that is licensed under separate terms, - as designated in a particular file or component or in included license - documentation. The authors of MySQL hereby grant you an additional - permission to link the program and your derivative works with the - separately licensed software that they have included with MySQL. - - 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, version 2.0, for more details. - - You should have received a copy of the GNU General Public License - along with this program; if not, write to the Free Software - Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA - - pg_vector - Copyright (c) 2023, Shannon Data AI and/or its affiliates. -*/ -#ifndef __SHANNONBASE_VECTOR_H__ -#define __SHANNONBASE_VECTOR_H__ - -#include "vector_comm.h" - -#include - -namespace ShannonBase { -namespace Vector { - -//#define VECTOR_SIZE(_dim) (offsetof(Vector, x) + -// sizeof(float)*(_dim)) #define DatumGetVector(x) ((Vector *) -// PG_DETOAST_DATUM(x)) #define PG_GETARG_VECTOR_P(x) -// DatumGetVector(PG_GETARG_DATUM(x)) #define PG_RETURN_VECTOR_P(x) -// PG_RETURN_POINTER(x) - -Vector InitVector(uint16 dim); -Vector vector_in(uchar *values, int32 type_type); - -} // namespace Vector -} // namespace ShannonBase -#endif //__SHANNONBASE_VECTOR_H__ diff --git a/sql/vector/vector_comm.cpp b/sql/vector/vector_comm.cpp deleted file mode 100644 index 037c84002..000000000 --- a/sql/vector/vector_comm.cpp +++ /dev/null @@ -1,75 +0,0 @@ -/* Copyright (c) 2018, 2023, Oracle and/or its affiliates. - - This program is free software; you can redistribute it and/or modify - it under the terms of the GNU General Public License, version 2.0, - as published by the Free Software Foundation. - - This program is also distributed with certain software (including - but not limited to OpenSSL) that is licensed under separate terms, - as designated in a particular file or component or in included license - documentation. The authors of MySQL hereby grant you an additional - permission to link the program and your derivative works with the - separately licensed software that they have included with MySQL. - - 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, version 2.0, for more details. - - You should have received a copy of the GNU General Public License - along with this program; if not, write to the Free Software - Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA - - Copyright (c) 2023, Shannon Data AI and/or its affiliates. -*/ -#include "vector_comm.h" - -namespace ShannonBase { -namespace Vector { - -bool Utils::f2d_small_int(const uint32 ieeeMantissa, const uint32 ieeeExponent, - floating_decimal_32 *v) { - const int32 e2 = (int32)ieeeExponent - FLOAT_BIAS - FLOAT_MANTISSA_BITS; - - /* - * Avoid using multiple "return false;" here since it tends to provoke the - * compiler into inlining multiple copies of f2d, which is undesirable. - */ - - if (e2 >= -FLOAT_MANTISSA_BITS && e2 <= 0) { - /*---- - * Since 2^23 <= m2 < 2^24 and 0 <= -e2 <= 23: - * 1 <= f = m2 / 2^-e2 < 2^24. - * - * Test if the lower -e2 bits of the significand are 0, i.e. whether - * the fraction is 0. We can use ieeeMantissa here, since the implied - * 1 bit can never be tested by this; the implied 1 can only be part - * of a fraction if e2 < -FLOAT_MANTISSA_BITS which we already - * checked. (e.g. 0.5 gives ieeeMantissa == 0 and e2 == -24) - */ - const uint32 mask = (1U << -e2) - 1; - const uint32 fraction = ieeeMantissa & mask; - - if (fraction == 0) { - /*---- - * f is an integer in the range [1, 2^24). - * Note: mantissa might contain trailing (decimal) 0's. - * Note: since 2^24 < 10^9, there is no need to adjust - * decimalLength(). - */ - const uint32 m2 = (1U << FLOAT_MANTISSA_BITS) | ieeeMantissa; - - v->mantissa = m2 >> -e2; - v->exponent = 0; - return true; - } - } - return false; -} - -int Utils::float_to_shortest_decimal_bufn(float f[[maybe_unused]], char *result[[maybe_unused]]) { - return 0; -} - -} // namespace Vector -} // namespace ShannonBase \ No newline at end of file diff --git a/sql/vector/vector_comm.h b/sql/vector/vector_comm.h deleted file mode 100644 index 47352cc15..000000000 --- a/sql/vector/vector_comm.h +++ /dev/null @@ -1,129 +0,0 @@ -/* Copyright (c) 2018, 2023, Oracle and/or its affiliates. - - This program is free software; you can redistribute it and/or modify - it under the terms of the GNU General Public License, version 2.0, - as published by the Free Software Foundation. - - This program is also distributed with certain software (including - but not limited to OpenSSL) that is licensed under separate terms, - as designated in a particular file or component or in included license - documentation. The authors of MySQL hereby grant you an additional - permission to link the program and your derivative works with the - separately licensed software that they have included with MySQL. - - 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, version 2.0, for more details. - - You should have received a copy of the GNU General Public License - along with this program; if not, write to the Free Software - Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA - - Copyright (c) 2023, Shannon Data AI and/or its affiliates. -*/ -#ifndef __SHANNONBASE_VECTOR_COMMON_H__ -#define __SHANNONBASE_VECTOR_COMMON_H__ - -#include "include/my_inttypes.h" - -#include -#include -#include - -namespace ShannonBase { -namespace Vector { - -#define VECTOR_MAX_DIM 16000 -#define FLEXIBLE_ARRAY_MEMBER /* empty */ - -#define FLOAT_MANTISSA_BITS 23 -#define FLOAT_EXPONENT_BITS 8 -#define FLOAT_BIAS 127 - -#define FLOAT_SHORTEST_DECIMAL_LEN 16 - -/* - * Array giving the number of 1-bits in each possible byte value. - * - * Note: we export this for use by functions in which explicit use - * of the popcount functions seems unlikely to be a win. - */ -const uint8 shannon_number_of_ones[256] = { - 0, 1, 1, 2, 1, 2, 2, 3, 1, 2, 2, 3, 2, 3, 3, 4, 1, 2, 2, 3, 2, 3, 3, 4, - 2, 3, 3, 4, 3, 4, 4, 5, 1, 2, 2, 3, 2, 3, 3, 4, 2, 3, 3, 4, 3, 4, 4, 5, - 2, 3, 3, 4, 3, 4, 4, 5, 3, 4, 4, 5, 4, 5, 5, 6, 1, 2, 2, 3, 2, 3, 3, 4, - 2, 3, 3, 4, 3, 4, 4, 5, 2, 3, 3, 4, 3, 4, 4, 5, 3, 4, 4, 5, 4, 5, 5, 6, - 2, 3, 3, 4, 3, 4, 4, 5, 3, 4, 4, 5, 4, 5, 5, 6, 3, 4, 4, 5, 4, 5, 5, 6, - 4, 5, 5, 6, 5, 6, 6, 7, 1, 2, 2, 3, 2, 3, 3, 4, 2, 3, 3, 4, 3, 4, 4, 5, - 2, 3, 3, 4, 3, 4, 4, 5, 3, 4, 4, 5, 4, 5, 5, 6, 2, 3, 3, 4, 3, 4, 4, 5, - 3, 4, 4, 5, 4, 5, 5, 6, 3, 4, 4, 5, 4, 5, 5, 6, 4, 5, 5, 6, 5, 6, 6, 7, - 2, 3, 3, 4, 3, 4, 4, 5, 3, 4, 4, 5, 4, 5, 5, 6, 3, 4, 4, 5, 4, 5, 5, 6, - 4, 5, 5, 6, 5, 6, 6, 7, 3, 4, 4, 5, 4, 5, 5, 6, 4, 5, 5, 6, 5, 6, 6, 7, - 4, 5, 5, 6, 5, 6, 6, 7, 5, 6, 6, 7, 6, 7, 7, 8}; - -using Vector = std::vector; -using VarBit = std::vector; - -/* A floating decimal representing m * 10^e. */ -typedef struct floating_decimal_32 { - uint32 mantissa; - int32 exponent; -} floating_decimal_32; - -inline uint32 float_to_bits(const float f) { - uint32 bits = 0; - std::memcpy(&bits, &f, sizeof(float)); - return bits; -} - -class Utils { - public: - static inline int copy_special_str(char *const result, const bool sign, - const bool exponent, const bool mantissa) { - if (mantissa) { - std::memcpy(result, "NaN", 3); - return 3; - } - - if (sign) { - result[0] = '-'; - } - if (exponent) { - std::memcpy(result + sign, "Infinity", 8); - return sign + 8; - } - result[sign] = '0'; - return sign + 1; - } - - static inline int calc_bits_count(const char *buf, int bytes) { - int count = 0; - - // Iterate through each byte in the buffer - for (int i = 0; i < bytes; ++i) { - unsigned char byte = buf[i]; // Convert char to unsigned char - - // Count the number of 1-bits in the current byte using bitwise AND - // operation - while (byte != 0) { - count += - (byte & 1); // Increment count if the least significant bit is 1 - byte >>= 1; // Shift byte to the right by 1 bit - } - } - - return count; - } - static bool f2d_small_int(const uint32 ieeeMantissa, - const uint32 ieeeExponent, floating_decimal_32 *v); - static int float_to_shortest_decimal_bufn(float f, char *result); -}; - -#define AppendChar(ptr, c) (*(ptr)++ = (c)) -#define AppendFloat(ptr, f) \ - ((ptr) += Utils::float_to_shortest_decimal_bufn((f), (ptr))) - -} // namespace Vector -} // namespace ShannonBase -#endif //__SHANNONBASE_VECTOR_COMMON_H__ diff --git a/storage/rapid_engine/compress/algorithms.h b/storage/rapid_engine/compress/algorithms.h index ec2769975..3703b07c8 100644 --- a/storage/rapid_engine/compress/algorithms.h +++ b/storage/rapid_engine/compress/algorithms.h @@ -32,6 +32,7 @@ #include #include #include +#include namespace ShannonBase { namespace Compress { diff --git a/storage/rapid_engine/compress/dictionary/dictionary.cpp b/storage/rapid_engine/compress/dictionary/dictionary.cpp index 8f2c9cd0e..2ef12a976 100644 --- a/storage/rapid_engine/compress/dictionary/dictionary.cpp +++ b/storage/rapid_engine/compress/dictionary/dictionary.cpp @@ -29,6 +29,7 @@ #include #include +#include "include/my_inttypes.h" #include "include/ut0dbg.h" #include "storage/rapid_engine/compress/algorithms.h" diff --git a/storage/rapid_engine/handler/ha_shannon_rapid.cc b/storage/rapid_engine/handler/ha_shannon_rapid.cc index fc3d5b4d9..3349609ea 100644 --- a/storage/rapid_engine/handler/ha_shannon_rapid.cc +++ b/storage/rapid_engine/handler/ha_shannon_rapid.cc @@ -701,21 +701,23 @@ int ha_rapid::load_table(const TABLE &table_arg) { context.m_current_table = table_arg.s->table_name.str; context.m_table = const_cast(&table_arg); - /** Any keys exist, set the key info. if any key exists, we also build keys on imcs table. otherwise, dont*/ - if (table_arg.key_info) { - auto key = table_arg.key_info; // first key we care about. - for (uint keyid = 0; keyid < key->user_defined_key_parts; keyid++) { - if (key->key_part[keyid].field->is_flag_set(NOT_SECONDARY_FLAG)) { - my_error(ER_RAPID_DA_PRIMARY_KEY_CAN_NOT_HAVE_NOT_SECONDARY_FLAG, MYF(0), table_arg.s->db.str, - table_arg.s->table_name.str); - return HA_ERR_GENERIC; - } - } + // check if primary key is missing. rapid engine must has at least one PK. + if (table_arg.s->is_missing_primary_key()) { + my_error(ER_REQUIRES_PRIMARY_KEY, MYF(0)); + return HA_ERR_GENERIC; + } - context.m_extra_info.m_key_buff = std::make_unique(key->key_length); - context.m_extra_info.m_key_len = key->key_length; + context.m_extra_info.m_keynr = 0; + auto key = (table_arg.key_info + 0); + for (uint keyid = 0; keyid < key->user_defined_key_parts; keyid++) { + if (key->key_part[keyid].field->is_flag_set(NOT_SECONDARY_FLAG)) { + my_error(ER_RAPID_DA_PRIMARY_KEY_CAN_NOT_HAVE_NOT_SECONDARY_FLAG, MYF(0), table_arg.s->db.str, + table_arg.s->table_name.str); + return HA_ERR_GENERIC; + } } + context.m_extra_info.m_key_buff = std::make_unique(key->key_length); // Scan the primary table and read the records. if (table_arg.file->inited == NONE && table_arg.file->ha_rnd_init(true)) { my_error(ER_NO_SUCH_TABLE, MYF(0), table_arg.s->db.str, table_arg.s->table_name.str); @@ -732,11 +734,11 @@ int ha_rapid::load_table(const TABLE &table_arg) { if (tmp == HA_ERR_KEY_NOT_FOUND) break; auto offset {0}; - for (uint key_partid = 0; key_partid < table_arg.key_info->user_defined_key_parts; key_partid++) { - memcpy(context.m_extra_info.m_key_buff.get() + offset, - table_arg.key_info->key_part[key_partid].field->field_ptr(), - table_arg.key_info->key_part[key_partid].store_length); - offset += table_arg.key_info->key_part[key_partid].store_length; + memset(context.m_extra_info.m_key_buff.get(), 0x0, key->key_length); + for (uint key_partid = 0; key_partid < key->user_defined_key_parts; key_partid++) { + memcpy(context.m_extra_info.m_key_buff.get() + offset, key->key_part[key_partid].field->field_ptr(), + key->key_part[key_partid].store_length); + offset += key->key_part[key_partid].store_length; } context.m_extra_info.m_key_len = offset;