MariaDB server is a community developed fork of MySQL server. Started by core members of the original MySQL team, MariaDB actively works with outside developers to deliver the most featureful, stable, and sanely licensed open SQL server in the industry.
Find a file
Marko Mäkelä 4dcb1b575b MDEV-35049: Use CRC-32C and avoid allocating heap
For the adaptive hash index, dtuple_fold() and rec_fold() were employing
a slow rolling hash algorithm, computing hash values ("fold") for one
field and one byte at a time, while depending on calls to
rec_get_offsets().

We already have optimized implementations of CRC-32C and have been
successfully using that function in some other InnoDB tables, but not
yet in the adaptive hash index.

Any linear function such as any CRC will fail the avalanche test that
any cryptographically secure hash function is expected to pass:
any single-bit change in the input key should affect on average half
the bits in the output.

But we always were happy with less than cryptographically secure:
in fact, ut_fold_ulint_pair() or ut_fold_binary() are just about as
linear as any CRC, using a combination of multiplication and addition,
partly carry-less. It is worth noting that exclusive-or corresponds to
carry-less subtraction or addition in a binary Galois field, or GF(2).

We only need some way of reducing key prefixes into hash values.
The CRC-32C should be better than a Rabin–Karp rolling hash algorithm.
Compared to the old hash algorithm, it has the drawback that there will
be only 32 bits of entropy before we choose the hash table cell by a
modulus operation. The size of each adaptive hash index array is
(innodb_buffer_pool_size / 512) / innodb_adaptive_hash_index_parts.
With the maximum number of partitions (512), we would not exceed 1<<32
elements per array until the buffer pool size exceeds 1<<50 bytes (1 PiB).
We would hit other limits before that: the virtual address space on many
contemporary 64-bit processor implementations is only 48 bits (256 TiB).
So, we can simply go for the SIMD accelerated CRC-32C.

rec_fold(): Take a combined parameter n_bytes_fields. Determine the
length of each field on the fly, and compute CRC-32C over a single
contiguous range of bytes, from the start of the record payload area
to the end of the last full or partial field. For secondary index records
in ROW_FORMAT=REDUNDANT, also the data area that is reserved for NULL
values (to facilitate in-place updates between NULL and NOT NULL values)
will be included in the count. Luckily, InnoDB always zero-initialized
such unused area; refer to data_write_sql_null() in
rec_convert_dtuple_to_rec_old(). For other than ROW_FORMAT=REDUNDANT,
no space is allocated for NULL values, and therefore the CRC-32C will
only cover the actual payload of the key prefix.

dtuple_fold(): For ROW_FORMAT=REDUNDANT, include the dummy NULL values
in the CRC-32C, so that the values will be comparable with rec_fold().

innodb_ahi-t: A unit test for rec_fold() and dtuple_fold().

btr_search_build_page_hash_index(), btr_search_drop_page_hash_index():
Use a fixed-size stack buffer for computing the fold values, to avoid
dynamic memory allocation.

btr_search_drop_page_hash_index(): Do not release part.latch if we
need to invoke multiple batches of rec_fold().

dtuple_t: Allocate fewer bits for the fields. The maximum number of
data fields is about 1023, so uint16_t will be fine for them. The
info_bits is stored in less than 1 byte.

ut_pair_min(), ut_pair_cmp(): Remove. We can actually combine and compare
int(n_fields << 16 | n_bytes).

PAGE_CUR_LE_OR_EXTENDS, PAGE_CUR_DBG: Remove. These were never defined,
because they would only work with latin1_swedish_ci if at all.

btr_cur_t::check_mismatch(): Replaces !btr_search_check_guess().

cmp_dtuple_rec_bytes(): Replaces cmp_dtuple_rec_with_match_bytes().
Determine the offsets of fields on the fly.

page_cur_try_search_shortcut_bytes(): This caller of
cmp_dtuple_rec_bytes() will not be invoked on the change buffer tree.

cmp_dtuple_rec_leaf(): Replaces cmp_dtuple_rec_with_match()
for comparing leaf-page records.

buf_block_t::ahi_left_bytes_fields: Consolidated Atomic_relaxed<uint32_t>
of curr_left_side << 31 | curr_n_bytes << 16 | curr_n_fields.
The other set of parameters (n_fields, n_bytes, left_side) was removed
as redundant.

btr_search_update_hash_node_on_insert(): Merged to
btr_search_update_hash_on_insert().

btr_search_build_page_hash_index(): Take combined left_bytes_fields
instead of n_fields, n_bytes, left_side.

btr_search_update_block_hash_info(), btr_search_update_hash_ref():
Merged to btr_search_info_update_hash().

btr_cur_t::n_bytes_fields: Replaces n_bytes << 16 | n_fields.

We also remove many redundant checks of btr_search.enabled.
If we are holding any btr_sea::partition::latch, then a nonnull pointer
in buf_block_t::index must imply that the adaptive hash index is enabled.

Reviewed by: Vladislav Lesin
2025-01-10 16:39:44 +02:00
.github Create FUNDING.yml 2024-11-26 17:39:37 +02:00
BUILD Merge branch '10.6' into 10.11 2024-04-26 08:02:49 +02:00
client Merge 11.7 into main 2025-01-09 13:46:06 +02:00
cmake Merge 11.4 into 11.7 2025-01-09 09:41:38 +02:00
dbug
debian 11.8 branch 2024-11-14 19:09:01 +01:00
Docs
extra MDEV-35049: btr_search_check_free_space_in_heap() is a bottleneck 2025-01-10 16:30:42 +02:00
include Merge 11.4 into 11.7 2025-01-09 09:41:38 +02:00
libmariadb@52d0a38ed1 MDEV-20912 Add support for utf8mb4_0900_* collations in MariaDB Server 2024-12-28 10:23:49 +02:00
libmysqld MDEV-34911 Sargable substr(col, 1, n) = str 2024-12-20 13:25:28 +11:00
libservices Merge 10.6 into 10.11 2024-02-08 15:04:46 +02:00
man MariaDB 11.4.4 release 2024-11-08 07:17:00 +01:00
mysql-test Merge 11.7 into main 2025-01-09 13:46:06 +02:00
mysys Merge 11.4 into 11.7 2025-01-09 09:41:38 +02:00
mysys_ssl post-merge changes 2024-10-29 14:47:32 +01:00
plugin Merge 11.4 into 11.7 2025-01-09 09:41:38 +02:00
randgen/conf
scripts Merge 11.7 into main 2025-01-09 13:46:06 +02:00
sql Merge 11.7 into main 2025-01-09 13:46:06 +02:00
sql-bench Updated sql-bench to run with PostgreSQL 14.9 2023-09-09 15:14:45 +03:00
sql-common Merge 11.4 into 11.7 2024-12-02 17:51:17 +02:00
storage MDEV-35049: Use CRC-32C and avoid allocating heap 2025-01-10 16:39:44 +02:00
strings Merge 11.4 into 11.7 2025-01-09 09:41:38 +02:00
support-files Merge 11.4 into 11.7 2024-12-02 17:51:17 +02:00
tests Merge 11.4 into 11.7 2025-01-09 09:41:38 +02:00
tpool Merge 11.4 into 11.7 2025-01-09 09:41:38 +02:00
unittest Merge 11.7 into main 2025-01-09 13:46:06 +02:00
vio Merge 11.2 into 11.4 2024-10-03 14:32:14 +03:00
win Merge 11.2 into 11.4 2024-10-03 14:32:14 +03:00
wsrep-lib@70cd967f5e galera: wsrep-lib submodule update 2024-12-17 09:53:19 +01:00
zlib Merge branch 'merge-zlib' (1.3.1) into 10.4 2024-04-26 13:50:03 +02:00
.clang-format Remove duplicate key "Language" from .clang-format 2024-04-17 16:52:37 +02:00
.gitattributes
.gitignore Merge 11.2 into 11.4 2024-10-03 14:32:14 +03:00
.gitlab-ci.yml Merge branch '11.4' into 11.5 2024-08-05 17:50:18 +02:00
.gitmodules
appveyor.yml Merge remote-tracking branch 'origin/11.2' into 11.4 2024-06-17 15:46:39 +04:00
BUILD-CMAKE
CMakeLists.txt Merge 10.11 into 11.4 2025-01-09 07:58:08 +02:00
CODING_STANDARDS.md Update markdown files for main branch 2024-08-28 11:49:07 +10:00
config.h.cmake Merge branch '11.6' into 11.7 2024-11-10 19:22:21 +01:00
configure.cmake Merge branch '11.6' into 11.7 2024-11-10 19:22:21 +01:00
CONTRIBUTING.md
COPYING
CREDITS Update sponsors 2024-08-12 09:32:30 +01:00
INSTALL-SOURCE
INSTALL-WIN-SOURCE
KNOWN_BUGS.txt
README.md Merge branch '10.11' into 11.1 2024-05-31 10:54:31 +10:00
SECURITY.md
THIRDPARTY Merge branch '10.6' into 10.11 2024-02-01 18:36:14 +01:00
VERSION 11.8 branch 2024-11-14 19:09:01 +01:00

Code status:

  • Appveyor CI status ci.appveyor.com

MariaDB: The innovative open source database

MariaDB was designed as a drop-in replacement of MySQL(R) with more features, new storage engines, fewer bugs, and better performance.

MariaDB is brought to you by the MariaDB Foundation and the MariaDB Corporation. Please read the CREDITS file for details about the MariaDB Foundation, and who is developing MariaDB.

MariaDB is developed by many of the original developers of MySQL who now work for the MariaDB Corporation, the MariaDB Foundation and by many people in the community.

MySQL, which is the base of MariaDB, is a product and trademark of Oracle Corporation, Inc. For a list of developers and other contributors, see the Credits appendix. You can also run 'SHOW authors' to get a list of active contributors.

A description of the MariaDB project and a manual can be found at:

https://mariadb.org

https://mariadb.com/kb/en/

https://mariadb.com/kb/en/mariadb-vs-mysql-features/

https://mariadb.com/kb/en/mariadb-versus-mysql-compatibility/

https://mariadb.com/kb/en/new-and-old-releases/

Getting the code, building it and testing it

Refer to the following guide: https://mariadb.org/get-involved/getting-started-for-developers/get-code-build-test/ which outlines how to build the source code correctly and run the MariaDB testing framework, as well as which branch to target for your contributions.

Help

More help is available from the Maria Discuss mailing list https://lists.mariadb.org/postorius/lists/discuss.lists.mariadb.org/ and MariaDB's Zulip instance, https://mariadb.zulipchat.com/

Licensing


MariaDB is specifically available only under version 2 of the GNU General Public License (GPLv2). (I.e. Without the "any later version" clause.) This is inherited from MySQL. Please see the README file in the MySQL distribution for more information.

License information can be found in the COPYING file. Third party license information can be found in the THIRDPARTY file.


Bug Reports

Bug and/or error reports regarding MariaDB should be submitted at: https://jira.mariadb.org

For reporting security vulnerabilities, see our security-policy.

The code for MariaDB, including all revision history, can be found at: https://github.com/MariaDB/server