Skip to content
/ server Public
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
75 changes: 53 additions & 22 deletions include/m_ctype.h
Original file line number Diff line number Diff line change
Expand Up @@ -495,6 +495,38 @@ typedef struct my_charset_loader_st

extern int (*my_string_stack_guard)(int);

typedef struct my_hasher_st
{
ulong m_nr1; /* mysql5x hash value */
ulong m_nr2; /* mysql5x aux value */
uint32 m_nr; /* The hash value */
/* Whether a streaming algorithm has been in use */
my_bool m_streaming;
/* One-shot string hash function */
void (*m_hash_str)(struct my_hasher_st *hasher, const uchar* str,
size_t len);
/*
Byte-streaming hash function, fallback to m_hash_str on one byte
if NULL
*/
void (*m_hash_byte)(struct my_hasher_st *hasher, uchar value);
/* Function to clean up and return the hash value */
uint32 (*m_finalize)(struct my_hasher_st *hasher);
/* Custom pointer e.g. to a state */
void *m_specific;
} my_hasher_st;

/* Defined in hasher-xxx.c files */
extern my_hasher_st my_hasher_mysql5x();
extern my_hasher_st my_hasher_mysql5x_for_unique();
extern my_hasher_st my_hasher_base31();
extern my_hasher_st my_hasher_crc32c();
extern my_hasher_st my_hasher_xxh32();
extern my_hasher_st my_hasher_xxh3();

#define MY_HASH_ADD_MARIADB(A, B, value) \
do { A^= (((A & 63)+B)*((value)))+ (A << 8); B+=3; } while(0)

/* See strings/CHARSET_INFO.txt for information about this structure */
struct my_collation_handler_st
{
Expand Down Expand Up @@ -580,8 +612,8 @@ struct my_collation_handler_st
my_match_t *match, uint nmatch);

/* Hash calculation */
void (*hash_sort)(CHARSET_INFO *cs, const uchar *key, size_t len,
ulong *nr1, ulong *nr2);
void (*hash_sort)(my_hasher_st *hasher, CHARSET_INFO *cs, const uchar *key,
size_t len);
my_bool (*propagate)(CHARSET_INFO *cs, const uchar *str, size_t len);
/*
Make minimum and maximum strings for the collation.
Expand Down Expand Up @@ -1182,9 +1214,9 @@ struct charset_info_st
return (coll->instr)(this, b, b_length, s, s_length, match, nmatch);
}

void hash_sort(const uchar *key, size_t len, ulong *nr1, ulong *nr2) const
void hash_sort(my_hasher_st *hasher, const uchar *key, size_t len) const
{
(coll->hash_sort)(this, key, len, nr1, nr2);
(coll->hash_sort)(hasher, this, key, len);
}

my_bool propagate(const uchar *str, size_t len) const
Expand Down Expand Up @@ -1462,11 +1494,10 @@ my_ci_instr(CHARSET_INFO *ci,


static inline void
my_ci_hash_sort(CHARSET_INFO *ci,
const uchar *key, size_t len,
ulong *nr1, ulong *nr2)
my_ci_hash_sort(my_hasher_st *hasher, CHARSET_INFO *ci,
const uchar *key, size_t len)
{
(ci->coll->hash_sort)(ci, key, len, nr1, nr2);
(ci->coll->hash_sort)(hasher, ci, key, len);
}


Expand Down Expand Up @@ -1585,17 +1616,16 @@ extern int my_strnncoll_simple(CHARSET_INFO *, const uchar *, size_t,
extern int my_strnncollsp_simple(CHARSET_INFO *, const uchar *, size_t,
const uchar *, size_t);

extern void my_hash_sort_simple(CHARSET_INFO *cs,
const uchar *key, size_t len,
ulong *nr1, ulong *nr2);
extern void my_hash_sort_simple(my_hasher_st *hasher,
CHARSET_INFO *cs,
const uchar *key, size_t len);

extern void my_hash_sort_simple_nopad(CHARSET_INFO *cs,
const uchar *key, size_t len,
ulong *nr1, ulong *nr2);
extern void my_hash_sort_simple_nopad(my_hasher_st *hasher,
CHARSET_INFO *cs,
const uchar *key, size_t len);

extern void my_hash_sort_bin(CHARSET_INFO *cs,
const uchar *key, size_t len, ulong *nr1,
ulong *nr2);
extern void my_hash_sort_bin(my_hasher_st *hasher, CHARSET_INFO *cs,
const uchar *key, size_t len);

/**
Compare a string to an array of spaces, for PAD SPACE comparison.
Expand Down Expand Up @@ -1761,12 +1791,13 @@ int my_wildcmp_mb_bin(CHARSET_INFO *cs,
const char *wildstr,const char *wildend,
int escape, int w_one, int w_many);

void my_hash_sort_mb_bin(CHARSET_INFO *cs __attribute__((unused)),
const uchar *key, size_t len,ulong *nr1, ulong *nr2);
void my_hash_sort_mb_bin(my_hasher_st *hasher,
CHARSET_INFO *cs __attribute__((unused)),
const uchar *key, size_t len);

void my_hash_sort_mb_nopad_bin(CHARSET_INFO *cs __attribute__((unused)),
const uchar *key, size_t len,
ulong *nr1, ulong *nr2);
void my_hash_sort_mb_nopad_bin(my_hasher_st *hasher,
CHARSET_INFO *cs __attribute__((unused)),
const uchar *key, size_t len);


extern my_bool my_parse_charset_xml(MY_CHARSET_LOADER *loader,
Expand Down
31 changes: 31 additions & 0 deletions mysql-test/main/func_xxh.result
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
# Testing XXH SQL functions
SELECT XXH32('abc') = 852579327 AS xxh32_expected;
xxh32_expected
1
SELECT XXH32(11223344) = 408040606 AS xxh32_expected;
xxh32_expected
1
SELECT XXH32('abc') = XXH32('abc') AS xxh32_eq;
xxh32_eq
1
SELECT XXH32(NULL) IS NULL AS xxh32_null;
xxh32_null
1
SELECT XXH32('') IS NULL AS xxh32_null;
xxh32_null
1
SELECT XXH3('abc') = 8696274497037089104 AS xxh3_expected;
xxh3_expected
1
SELECT XXH3(11223344) = 9329478082249925753 AS xxh3_expected;
xxh3_expected
1
SELECT XXH3('abc') = XXH32('abc') AS xxh3_eq;
xxh3_eq
0
SELECT XXH3(NULL) IS NULL AS xxh3_null;
xxh3_null
1
SELECT XXH3('') IS NULL AS xxh3_null;
xxh3_null
1
13 changes: 13 additions & 0 deletions mysql-test/main/func_xxh.test
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
--echo # Testing XXH SQL functions

SELECT XXH32('abc') = 852579327 AS xxh32_expected;
SELECT XXH32(11223344) = 408040606 AS xxh32_expected;
SELECT XXH32('abc') = XXH32('abc') AS xxh32_eq;
SELECT XXH32(NULL) IS NULL AS xxh32_null;
SELECT XXH32('') IS NULL AS xxh32_null;

SELECT XXH3('abc') = 8696274497037089104 AS xxh3_expected;
SELECT XXH3(11223344) = 9329478082249925753 AS xxh3_expected;
SELECT XXH3('abc') = XXH32('abc') AS xxh3_eq;
SELECT XXH3(NULL) IS NULL AS xxh3_null;
SELECT XXH3('') IS NULL AS xxh3_null;
46 changes: 46 additions & 0 deletions mysql-test/main/partition_alter.result
Original file line number Diff line number Diff line change
Expand Up @@ -391,3 +391,49 @@ partitio values in (2, 3, 4),
pn values in (52, 53, 54));
drop table t1;
# End of 10.7 tests
# MDEV-9826 change the hash algorithm for PARTITION BY KEY
create table t1(c1 int, c2 date) partition by key (c2) partitions 8;
show create table t1;
Table Create Table
t1 CREATE TABLE `t1` (
`c1` int(11) DEFAULT NULL,
`c2` date DEFAULT NULL
) ENGINE=MyISAM DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_uca1400_ai_ci
PARTITION BY KEY (`c2`)
PARTITIONS 8
insert into t1 values (1, NULL);
insert into t1 select 1, from_days(seq) from seq_735000_to_736000;
select partition_name, table_rows from information_schema.partitions where table_name='t1';
partition_name table_rows
p0 297
p1 0
p2 1
p3 0
p4 428
p5 0
p6 276
p7 0
alter table t1 partition by key algorithm=crc32c (c2) partitions 8;
select partition_name, table_rows from information_schema.partitions where table_name='t1';
partition_name table_rows
p0 126
p1 127
p2 126
p3 126
p4 126
p5 125
p6 122
p7 124
alter table t1 partition by key algorithm=xxh3 (c2) partitions 8;
select partition_name, table_rows from information_schema.partitions where table_name='t1';
partition_name table_rows
p0 122
p1 132
p2 151
p3 121
p4 113
p5 125
p6 128
p7 110
drop table t1;
# End of 12.3 tests
15 changes: 15 additions & 0 deletions mysql-test/main/partition_alter.test
Original file line number Diff line number Diff line change
Expand Up @@ -323,3 +323,18 @@ partition by list(x) (
drop table t1;

--echo # End of 10.7 tests

--echo # MDEV-9826 change the hash algorithm for PARTITION BY KEY
--source include/have_sequence.inc
create table t1(c1 int, c2 date) partition by key (c2) partitions 8;
show create table t1;
insert into t1 values (1, NULL);
insert into t1 select 1, from_days(seq) from seq_735000_to_736000;
select partition_name, table_rows from information_schema.partitions where table_name='t1';
alter table t1 partition by key algorithm=crc32c (c2) partitions 8;
select partition_name, table_rows from information_schema.partitions where table_name='t1';
alter table t1 partition by key algorithm=xxh3 (c2) partitions 8;
select partition_name, table_rows from information_schema.partitions where table_name='t1';
drop table t1;

--echo # End of 12.3 tests
123 changes: 123 additions & 0 deletions mysql-test/main/partition_key_algorithm,1.rdiff
Original file line number Diff line number Diff line change
@@ -0,0 +1,123 @@
--- ../src/mysql-test/main/partition_key_algorithm.result 2025-12-08 13:49:44.869944988 +1100
+++ ../src/mysql-test/main/partition_key_algorithm,1.reject 2025-12-08 13:51:13.221162943 +1100
@@ -1,13 +1,13 @@
# MDEV-9826 change the hash algorithm for PARTITION BY KEY
## MDEV-9826 case with NULL
-create table t1(c1 int, c2 date) partition by key (c2) partitions 8;
+create table t1(c1 int, c2 date) partition by key ALGORITHM=1 (c2) partitions 8;
show create table t1;
Table Create Table
t1 CREATE TABLE `t1` (
`c1` int(11) DEFAULT NULL,
`c2` date DEFAULT NULL
) ENGINE=MyISAM DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_uca1400_ai_ci
- PARTITION BY KEY (`c2`)
+ PARTITION BY KEY ALGORITHM = MYSQL51 (`c2`)
PARTITIONS 8
insert into t1 values (1, NULL);
insert into t1 values (1, '2014-04-22');
@@ -43,14 +43,14 @@
1 2014-04-29
drop table t1;
## MDEV-9826 case with more dates
-create table t1(c1 int, c2 date) partition by key (c2) partitions 8;
+create table t1(c1 int, c2 date) partition by key ALGORITHM=1 (c2) partitions 8;
show create table t1;
Table Create Table
t1 CREATE TABLE `t1` (
`c1` int(11) DEFAULT NULL,
`c2` date DEFAULT NULL
) ENGINE=MyISAM DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_uca1400_ai_ci
- PARTITION BY KEY (`c2`)
+ PARTITION BY KEY ALGORITHM = MYSQL51 (`c2`)
PARTITIONS 8
insert into t1 values (1, NULL);
insert into t1 select 1, from_days(seq) from seq_735000_to_736000;
@@ -66,14 +66,14 @@
p7 0
drop table t1;
## MDEV-9826 case with more dates and linear key
-create table t1(c1 int, c2 date) partition by linear key (c2) partitions 8;
+create table t1(c1 int, c2 date) partition by linear key ALGORITHM=1 (c2) partitions 8;
show create table t1;
Table Create Table
t1 CREATE TABLE `t1` (
`c1` int(11) DEFAULT NULL,
`c2` date DEFAULT NULL
) ENGINE=MyISAM DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_uca1400_ai_ci
- PARTITION BY LINEAR KEY (`c2`)
+ PARTITION BY LINEAR KEY ALGORITHM = MYSQL51 (`c2`)
PARTITIONS 8
insert into t1 values (1, NULL);
insert into t1 select 1, from_days(seq) from seq_735000_to_736000;
@@ -89,14 +89,14 @@
p7 0
drop table t1;
## MDEV-9826 case with more dates and multiple keys
-create table t1(c1 int, c2 date) partition by key (c1, c2) partitions 8;
+create table t1(c1 int, c2 date) partition by key ALGORITHM=1 (c1, c2) partitions 8;
show create table t1;
Table Create Table
t1 CREATE TABLE `t1` (
`c1` int(11) DEFAULT NULL,
`c2` date DEFAULT NULL
) ENGINE=MyISAM DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_uca1400_ai_ci
- PARTITION BY KEY (`c1`,`c2`)
+ PARTITION BY KEY ALGORITHM = MYSQL51 (`c1`,`c2`)
PARTITIONS 8
insert into t1 values (1, NULL);
insert into t1 select 1, from_days(seq) from seq_735000_to_736000;
@@ -112,7 +112,7 @@
p7 0
drop table t1;
## MDEV-20791 case with INET6
-create table t1 (a inet6) partition by key (a) partitions 2;
+create table t1 (a inet6) partition by key ALGORITHM=1 (a) partitions 2;
insert into t1 values ('0:db8::ff00:42:8329'),('2001:db8::ff00:42:8329'),('::'),('::192.0.2.128'),('::ffff:192.0.2.128');
select partition_name, table_rows from information_schema.partitions where table_name='t1';
partition_name table_rows
@@ -120,7 +120,7 @@
p1 5
drop table t1;
## MDEV-20791 case with BINARY
-CREATE TABLE t1 (a BINARY(16)) PARTITION BY KEY (a) PARTITIONS 2;
+CREATE TABLE t1 (a BINARY(16)) PARTITION BY KEY ALGORITHM=1 (a) PARTITIONS 2;
INSERT INTO t1 VALUES (X'00000DB8000000000000FF0000428329');
INSERT INTO t1 VALUES (X'20010DB8000000000000FF0000428329');
INSERT INTO t1 VALUES (X'00000000000000000000000000000000');
@@ -132,7 +132,7 @@
p1 5
drop table t1;
## MDEV-20791 case with more rows
-create table t1 (a inet6) partition by key (a) partitions 2;
+create table t1 (a inet6) partition by key ALGORITHM=1 (a) partitions 2;
insert into t1 select concat(hex(seq), ':db8::ff00:42:8329') from seq_0_to_65535;
select partition_name, table_rows from information_schema.partitions where table_name='t1';
partition_name table_rows
@@ -155,7 +155,7 @@
60
6060
606060
-ALTER TABLE t1 PARTITION BY KEY (a) PARTITIONS 3;
+ALTER TABLE t1 PARTITION BY KEY ALGORITHM=1 (a) PARTITIONS 3;
SELECT HEX(a) FROM t1 WHERE a=0x60;
HEX(a)
20
@@ -172,7 +172,7 @@
60
6060
606060
-ALTER TABLE t1 PARTITION BY KEY (a) PARTITIONS 3;
+ALTER TABLE t1 PARTITION BY KEY ALGORITHM=1 (a) PARTITIONS 3;
SELECT HEX(a) FROM t1 WHERE a=0x60;
HEX(a)
20
@@ -189,7 +189,7 @@
A0
A0A0
A0A0A0
-ALTER TABLE t1 PARTITION BY KEY (a) PARTITIONS 3;
+ALTER TABLE t1 PARTITION BY KEY ALGORITHM=1 (a) PARTITIONS 3;
SELECT HEX(a) FROM t1 WHERE a=0xA0;
HEX(a)
20
Loading