Quelle partition_key_algorithm.result
Sprache: Lisp
# MDEV-9826 better hash algorithms for PARTITION BY KEY
## MDEV-9826 case with NULL
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 values (1 , '2014-04-22' );
insert into t1 values (1 , '2014-04-23' );
insert into t1 values (1 , '2014-04-24' );
insert into t1 values (1 , '2014-04-25' );
insert into t1 values (1 , '2014-04-26' );
insert into t1 values (1 , '2014-04-27' );
insert into t1 values (1 , '2014-04-28' );
insert into t1 values (1 , '2014-04-29' );
insert into t1 values (1 , '2014-04-30' );
select partition_name, table_rows from information_schema.partitions where table_name='t1' ;
partition_name table_rows
p0 3
p1 0
p2 1
p3 0
p4 2
p5 0
p6 4
p7 0
select * from t1;
c1 c2
1 2014 -04 -22
1 2014 -04 -26
1 2014 -04 -30
1 NULL
1 2014 -04 -24
1 2014 -04 -28
1 2014 -04 -23
1 2014 -04 -25
1 2014 -04 -27
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 ;
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
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 ;
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`)
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
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 ;
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`)
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 153
p1 0
p2 542
p3 0
p4 306
p5 1
p6 0
p7 0
drop table t1;
## MDEV-20791 case with INET6
create table t1 (a inet6) partition by key (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
p0 0
p1 5
### here we test hash values using an odd prime number of partitions
alter table t1 partition by key (a) partitions 7 ;
select partition_name, table_rows from information_schema.partitions where table_name='t1' ;
partition_name table_rows
p0 1
p1 1
p2 1
p3 1
p4 1
p5 0
p6 0
### partition by linear key where mask (7 ) > num_parts (6 )
alter table t1 partition by linear key (a) partitions 6 ;
select partition_name, table_rows from information_schema.partitions where table_name='t1' ;
partition_name table_rows
p0 0
p1 4
p2 0
p3 1
p4 0
p5 0
drop table t1;
## MDEV-20791 case with BINARY
CREATE TABLE t1 (a BINARY(16 )) PARTITION BY KEY (a) PARTITIONS 2 ;
INSERT INTO t1 VALUES (X'00000DB8000000000000FF0000428329' );
INSERT INTO t1 VALUES (X'20010DB8000000000000FF0000428329' );
INSERT INTO t1 VALUES (X'00000000000000000000000000000000' );
INSERT INTO t1 VALUES (X'000000000000000000000000C0000280' );
INSERT INTO t1 VALUES (X'00000000000000000000FFFFC0000280' );
select partition_name, table_rows from information_schema.partitions where table_name='t1' ;
partition_name table_rows
p0 0
p1 5
drop table t1;
## MDEV-20791 case with more rows
create table t1 (a inet6) partition by key (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
p0 0
p1 65536
insert into t1 values ('::' );
insert into t1 select concat('::' , hex(seq), ':192.0.2.128' ) from seq_0_to_65535;
select partition_name, table_rows from information_schema.partitions where table_name='t1' ;
partition_name table_rows
p0 16384
p1 114689
drop table t1;
## MDEV-6255 case to test charset/collation
### cp1251_ukrainian_ci: 0 x20 SPACE is equal to 0 x60 GRAVE ACCENT
CREATE TABLE t1 (a VARCHAR(10 ) CHARACTER SET cp1251 COLLATE cp1251_ukrainian_ci);
INSERT INTO t1 VALUES (0 x20),(0 x60),(0 x6060),(0 x606060);
SELECT HEX(a) FROM t1 WHERE a=0 x60;
HEX(a)
20
60
6060
606060
ALTER TABLE t1 PARTITION BY KEY (a) PARTITIONS 3 ;
SELECT HEX(a) FROM t1 WHERE a=0 x60;
HEX(a)
20
60
6060
606060
DROP TABLE t1;
### koi8u_general_ci: 0 x20 SPACE is equal to 0 x60 GRAVE ACCENT
CREATE TABLE t1 (a VARCHAR(10 ) CHARACTER SET koi8u COLLATE koi8u_general_ci);
INSERT INTO t1 VALUES (0 x20),(0 x60),(0 x6060),(0 x606060);
SELECT HEX(a) FROM t1 WHERE a=0 x60;
HEX(a)
20
60
6060
606060
ALTER TABLE t1 PARTITION BY KEY (a) PARTITIONS 3 ;
SELECT HEX(a) FROM t1 WHERE a=0 x60;
HEX(a)
20
60
6060
606060
DROP TABLE t1;
### cp1250_general_ci: 0 x20 SPACE is equal to 0 xA0 NO-BREAK SPACE
CREATE TABLE t1 (a VARCHAR(10 ) CHARACTER SET cp1250 COLLATE cp1250_general_ci);
INSERT INTO t1 VALUES (0 x20),(0 xA0),(0 xA0A0),(0 xA0A0A0);
SELECT HEX(a) FROM t1 WHERE a=0 xA0;
HEX(a)
20
A0
A0A0
A0A0A0
ALTER TABLE t1 PARTITION BY KEY (a) PARTITIONS 3 ;
SELECT HEX(a) FROM t1 WHERE a=0 xA0;
HEX(a)
20
A0
A0A0
A0A0A0
DROP TABLE t1;
## MDEV-38549 MDEV-9826 derived a bug for numeric columns from
## the old hash design
CREATE OR REPLACE TABLE t1 (c1 INT NOT NULL) PARTITION BY KEY (c1) PARTITIONS 16 ;
INSERT INTO t1 VALUES (0 x41),(0 x61);
SELECT table_name, partition_name, table_rows FROM information_schema.partitions
WHERE table_name='t1' AND table_rows>0 ;
table_name partition_name table_rows
t1 p4 2
ALTER TABLE t1 PARTITION BY KEY (c1) PARTITIONS 7 ;
SELECT table_name, partition_name, table_rows FROM information_schema.partitions
WHERE table_name='t1' AND table_rows>0 ;
table_name partition_name table_rows
t1 p5 2
DROP TABLE t1;
Messung V0.5 in Prozent C=66 H=100 G=84
¤ Dauer der Verarbeitung: 0.1 Sekunden
(vorverarbeitet am 2026-10-08)
¤
*© Formatika GbR, Deutschland
2026-10-10
Neuigkeiten
Aktuelles
Motto des Tages
Open Source Software
Jenseits des Üblichen ....
Besucherstatistik
Statistik
#Sources=1126438
#Domains=1867298