create table t1 (id int unsigned not null auto_increment, code tinyint unsigned not null, name char(20) not null, primary key (id), key (code), unique (name)) type=bdb;
update ignore t1 set id = 8, name = 'Sinisa' where id < 3;
select id, code, name from t1 order by id;
id code name
id code name
2 1 Monty
2 1 Monty
3 2 David
3 2 David
...
@@ -14,6 +20,8 @@ id code name
...
@@ -14,6 +20,8 @@ id code name
6 3 Jeremy
6 3 Jeremy
7 4 Matt
7 4 Matt
8 1 Sinisa
8 1 Sinisa
update ignore t1 set id = id + 10, name = 'Ralph' where id < 4;
select id, code, name from t1 order by id;
id code name
id code name
3 2 David
3 2 David
4 2 Erik
4 2 Erik
...
@@ -22,10 +30,26 @@ id code name
...
@@ -22,10 +30,26 @@ id code name
7 4 Matt
7 4 Matt
8 1 Sinisa
8 1 Sinisa
12 1 Ralph
12 1 Ralph
drop table t1;
CREATE TABLE t1 (
id int(11) NOT NULL auto_increment,
parent_id int(11) DEFAULT '0' NOT NULL,
level tinyint(4) DEFAULT '0' NOT NULL,
PRIMARY KEY (id),
KEY parent_id (parent_id),
KEY level (level)
) type=bdb;
INSERT INTO t1 VALUES (1,0,0),(3,1,1),(4,1,1),(8,2,2),(9,2,2),(17,3,2),(22,4,2),(24,4,2),(28,5,2),(29,5,2),(30,5,2),(31,6,2),(32,6,2),(33,6,2),(203,7,2),(202,7,2),(20,3,2),(157,0,0),(193,5,2),(40,7,2),(2,1,1),(15,2,2),(6,1,1),(34,6,2),(35,6,2),(16,3,2),(7,1,1),(36,7,2),(18,3,2),(26,5,2),(27,5,2),(183,4,2),(38,7,2),(25,5,2),(37,7,2),(21,4,2),(19,3,2),(5,1,1),(179,5,2);
update t1 set parent_id=parent_id+100;
select * from t1 where parent_id=102;
id parent_id level
id parent_id level
8 102 2
8 102 2
9 102 2
9 102 2
15 102 2
15 102 2
update t1 set id=id+1000;
update t1 set id=1024 where id=1009;
Duplicate entry '1024' for key 1
select * from t1;
id parent_id level
id parent_id level
1001 100 0
1001 100 0
1002 101 1
1002 101 1
...
@@ -66,6 +90,8 @@ id parent_id level
...
@@ -66,6 +90,8 @@ id parent_id level
1193 105 2
1193 105 2
1202 107 2
1202 107 2
1203 107 2
1203 107 2
update ignore t1 set id=id+1;
select * from t1;
id parent_id level
id parent_id level
1001 100 0
1001 100 0
1002 101 1
1002 101 1
...
@@ -106,16 +132,22 @@ id parent_id level
...
@@ -106,16 +132,22 @@ id parent_id level
1194 105 2
1194 105 2
1202 107 2
1202 107 2
1204 107 2
1204 107 2
update ignore t1 set id=1023 where id=1010;
select * from t1 where parent_id=102;
id parent_id level
id parent_id level
1008 102 2
1008 102 2
1015 102 2
1015 102 2
1010 102 2
1010 102 2
explain select level from t1 where level=1;
table type possible_keys key key_len ref rows Extra
table type possible_keys key key_len ref rows Extra
t1 ref level level 1 const 1 where used; Using index
t1 ref level level 1 const 1 where used; Using index
explain select level,id from t1 where level=1;
table type possible_keys key key_len ref rows Extra
table type possible_keys key key_len ref rows Extra
t1 ref level level 1 const 1 where used; Using index
t1 ref level level 1 const 1 where used; Using index
explain select level,id,parent_id from t1 where level=1;
table type possible_keys key key_len ref rows Extra
table type possible_keys key key_len ref rows Extra
SELECT _userid FROM t1 WHERE _userid='marc@anyware.co.uk';
_userid
_userid
marc@anyware.co.uk
marc@anyware.co.uk
drop table t1;
set autocommit=1;
CREATE TABLE t1 (
user_id int(10) DEFAULT '0' NOT NULL,
name varchar(100),
phone varchar(100),
ref_email varchar(100) DEFAULT '' NOT NULL,
detail varchar(200),
PRIMARY KEY (user_id,ref_email)
)type=bdb;
INSERT INTO t1 VALUES (10292,'sanjeev','29153373','sansh777@hotmail.com','xxx'),(10292,'shirish','2333604','shirish@yahoo.com','ddsds'),(10292,'sonali','323232','sonali@bolly.com','filmstar');
select * from t1 where user_id=10292;
user_id name phone ref_email detail
user_id name phone ref_email detail
10292 sanjeev 29153373 sansh777@hotmail.com xxx
10292 sanjeev 29153373 sansh777@hotmail.com xxx
10292 shirish 2333604 shirish@yahoo.com ddsds
10292 shirish 2333604 shirish@yahoo.com ddsds
10292 sonali 323232 sonali@bolly.com filmstar
10292 sonali 323232 sonali@bolly.com filmstar
INSERT INTO t1 VALUES (10291,'sanjeev','29153373','sansh777@hotmail.com','xxx'),(10293,'shirish','2333604','shirish@yahoo.com','ddsds');
select * from t1 where user_id=10292;
user_id name phone ref_email detail
user_id name phone ref_email detail
10292 sanjeev 29153373 sansh777@hotmail.com xxx
10292 sanjeev 29153373 sansh777@hotmail.com xxx
10292 shirish 2333604 shirish@yahoo.com ddsds
10292 shirish 2333604 shirish@yahoo.com ddsds
10292 sonali 323232 sonali@bolly.com filmstar
10292 sonali 323232 sonali@bolly.com filmstar
select * from t1 where user_id>=10292;
user_id name phone ref_email detail
user_id name phone ref_email detail
10292 sanjeev 29153373 sansh777@hotmail.com xxx
10292 sanjeev 29153373 sansh777@hotmail.com xxx
10292 shirish 2333604 shirish@yahoo.com ddsds
10292 shirish 2333604 shirish@yahoo.com ddsds
10292 sonali 323232 sonali@bolly.com filmstar
10292 sonali 323232 sonali@bolly.com filmstar
10293 shirish 2333604 shirish@yahoo.com ddsds
10293 shirish 2333604 shirish@yahoo.com ddsds
select * from t1 where user_id>10292;
user_id name phone ref_email detail
user_id name phone ref_email detail
10293 shirish 2333604 shirish@yahoo.com ddsds
10293 shirish 2333604 shirish@yahoo.com ddsds
select * from t1 where user_id<10292;
user_id name phone ref_email detail
user_id name phone ref_email detail
10291 sanjeev 29153373 sansh777@hotmail.com xxx
10291 sanjeev 29153373 sansh777@hotmail.com xxx
drop table t1;
CREATE TABLE t1 (a int not null, b int not null,c int not null,
INSERT INTO t1 VALUES (1,0,0),(3,1,1),(4,1,1),(8,2,2),(9,2,2),(17,3,2),(22,4,2),(24,4,2),(28,5,2),(29,5,2),(30,5,2),(31,6,2),(32,6,2),(33,6,2),(203,7,2),(202,7,2),(20,3,2),(157,0,0),(193,5,2),(40,7,2),(2,1,1),(15,2,2),(6,1,1),(34,6,2),(35,6,2),(16,3,2),(7,1,1),(36,7,2),(18,3,2),(26,5,2),(27,5,2),(183,4,2),(38,7,2),(25,5,2),(37,7,2),(21,4,2),(19,3,2),(5,1,1);
INSERT INTO t1 values (179,5,2);
update t1 set parent_id=parent_id+100;
select * from t1 where parent_id=102;
id parent_id level
id parent_id level
8 102 2
8 102 2
9 102 2
9 102 2
15 102 2
15 102 2
update t1 set id=id+1000;
update t1 set id=1024 where id=1009;
select * from t1;
id parent_id level
id parent_id level
1001 100 0
1001 100 0
1003 101 1
1003 101 1
...
@@ -327,6 +575,8 @@ id parent_id level
...
@@ -327,6 +575,8 @@ id parent_id level
1019 103 2
1019 103 2
1005 101 1
1005 101 1
1179 105 2
1179 105 2
update ignore t1 set id=id+1;
select * from t1;
id parent_id level
id parent_id level
1002 100 0
1002 100 0
1004 101 1
1004 101 1
...
@@ -367,12 +617,16 @@ id parent_id level
...
@@ -367,12 +617,16 @@ id parent_id level
1020 103 2
1020 103 2
1006 101 1
1006 101 1
1180 105 2
1180 105 2
update ignore t1 set id=1023 where id=1010;
select * from t1 where parent_id=102;
id parent_id level
id parent_id level
1009 102 2
1009 102 2
1025 102 2
1025 102 2
1016 102 2
1016 102 2
explain select level from t1 where level=1;
table type possible_keys key key_len ref rows Extra
table type possible_keys key key_len ref rows Extra
t1 ref level level 1 const 1 where used; Using index
t1 ref level level 1 const 1 where used; Using index
select level,id from t1 where level=1;
level id
level id
1 1004
1 1004
1 1005
1 1005
...
@@ -380,6 +634,7 @@ level id
...
@@ -380,6 +634,7 @@ level id
1 1007
1 1007
1 1008
1 1008
1 1006
1 1006
select level,id,parent_id from t1 where level=1;
level id parent_id
level id parent_id
1 1004 101
1 1004 101
1 1005 101
1 1005 101
...
@@ -387,6 +642,7 @@ level id parent_id
...
@@ -387,6 +642,7 @@ level id parent_id
1 1007 101
1 1007 101
1 1008 101
1 1008 101
1 1006 101
1 1006 101
select level,id from t1 where level=1 order by id;
create table t1 (id int unsigned not null auto_increment, code tinyint unsigned not null, name char(20) not null, primary key (id), key (code), unique (name)) type=innodb;
update ignore t1 set id = 8, name = 'Sinisa' where id < 3;
select id, code, name from t1 order by id;
id code name
id code name
2 1 Monty
2 1 Monty
3 2 David
3 2 David
...
@@ -14,6 +20,8 @@ id code name
...
@@ -14,6 +20,8 @@ id code name
6 3 Jeremy
6 3 Jeremy
7 4 Matt
7 4 Matt
8 1 Sinisa
8 1 Sinisa
update ignore t1 set id = id + 10, name = 'Ralph' where id < 4;
select id, code, name from t1 order by id;
id code name
id code name
3 2 David
3 2 David
4 2 Erik
4 2 Erik
...
@@ -22,10 +30,26 @@ id code name
...
@@ -22,10 +30,26 @@ id code name
7 4 Matt
7 4 Matt
8 1 Sinisa
8 1 Sinisa
12 1 Ralph
12 1 Ralph
drop table t1;
CREATE TABLE t1 (
id int(11) NOT NULL auto_increment,
parent_id int(11) DEFAULT '0' NOT NULL,
level tinyint(4) DEFAULT '0' NOT NULL,
PRIMARY KEY (id),
KEY parent_id (parent_id),
KEY level (level)
) type=innodb;
INSERT INTO t1 VALUES (1,0,0),(3,1,1),(4,1,1),(8,2,2),(9,2,2),(17,3,2),(22,4,2),(24,4,2),(28,5,2),(29,5,2),(30,5,2),(31,6,2),(32,6,2),(33,6,2),(203,7,2),(202,7,2),(20,3,2),(157,0,0),(193,5,2),(40,7,2),(2,1,1),(15,2,2),(6,1,1),(34,6,2),(35,6,2),(16,3,2),(7,1,1),(36,7,2),(18,3,2),(26,5,2),(27,5,2),(183,4,2),(38,7,2),(25,5,2),(37,7,2),(21,4,2),(19,3,2),(5,1,1),(179,5,2);
update t1 set parent_id=parent_id+100;
select * from t1 where parent_id=102;
id parent_id level
id parent_id level
8 102 2
8 102 2
9 102 2
9 102 2
15 102 2
15 102 2
update t1 set id=id+1000;
update t1 set id=1024 where id=1009;
Duplicate entry '1024' for key 1
select * from t1;
id parent_id level
id parent_id level
1001 100 0
1001 100 0
1002 101 1
1002 101 1
...
@@ -66,6 +90,8 @@ id parent_id level
...
@@ -66,6 +90,8 @@ id parent_id level
1193 105 2
1193 105 2
1202 107 2
1202 107 2
1203 107 2
1203 107 2
update ignore t1 set id=id+1;
select * from t1;
id parent_id level
id parent_id level
1001 100 0
1001 100 0
1002 101 1
1002 101 1
...
@@ -106,16 +132,22 @@ id parent_id level
...
@@ -106,16 +132,22 @@ id parent_id level
1194 105 2
1194 105 2
1202 107 2
1202 107 2
1204 107 2
1204 107 2
update ignore t1 set id=1023 where id=1010;
select * from t1 where parent_id=102;
id parent_id level
id parent_id level
1008 102 2
1008 102 2
1010 102 2
1010 102 2
1015 102 2
1015 102 2
explain select level from t1 where level=1;
table type possible_keys key key_len ref rows Extra
table type possible_keys key key_len ref rows Extra
t1 index level level 1 NULL 39 where used; Using index
t1 index level level 1 NULL 39 where used; Using index
explain select level,id from t1 where level=1;
table type possible_keys key key_len ref rows Extra
table type possible_keys key key_len ref rows Extra
t1 index level level 1 NULL 39 where used; Using index
t1 index level level 1 NULL 39 where used; Using index
explain select level,id,parent_id from t1 where level=1;
table type possible_keys key key_len ref rows Extra
table type possible_keys key key_len ref rows Extra
t1 ALL level NULL NULL NULL 39 where used
t1 ALL level NULL NULL NULL 39 where used
select level,id from t1 where level=1;
level id
level id
1 1002
1 1002
1 1003
1 1003
...
@@ -123,6 +155,7 @@ level id
...
@@ -123,6 +155,7 @@ level id
1 1005
1 1005
1 1006
1 1006
1 1007
1 1007
select level,id,parent_id from t1 where level=1;
level id parent_id
level id parent_id
1 1002 101
1 1002 101
1 1003 101
1 1003 101
...
@@ -130,72 +163,196 @@ level id parent_id
...
@@ -130,72 +163,196 @@ level id parent_id
1 1005 101
1 1005 101
1 1006 101
1 1006 101
1 1007 101
1 1007 101
optimize table t1;
Table Op Msg_type Msg_text
Table Op Msg_type Msg_text
test.t1 optimize error The handler for the table doesn't support check/repair
test.t1 optimize error The handler for the table doesn't support check/repair
SELECT _userid FROM t1 WHERE _userid='marc@anyware.co.uk';
_userid
_userid
marc@anyware.co.uk
marc@anyware.co.uk
drop table t1;
set autocommit=1;
CREATE TABLE t1 (
user_id int(10) DEFAULT '0' NOT NULL,
name varchar(100),
phone varchar(100),
ref_email varchar(100) DEFAULT '' NOT NULL,
detail varchar(200),
PRIMARY KEY (user_id,ref_email)
)type=innodb;
INSERT INTO t1 VALUES (10292,'sanjeev','29153373','sansh777@hotmail.com','xxx'),(10292,'shirish','2333604','shirish@yahoo.com','ddsds'),(10292,'sonali','323232','sonali@bolly.com','filmstar');
select * from t1 where user_id=10292;
user_id name phone ref_email detail
user_id name phone ref_email detail
10292 sanjeev 29153373 sansh777@hotmail.com xxx
10292 sanjeev 29153373 sansh777@hotmail.com xxx
10292 shirish 2333604 shirish@yahoo.com ddsds
10292 shirish 2333604 shirish@yahoo.com ddsds
10292 sonali 323232 sonali@bolly.com filmstar
10292 sonali 323232 sonali@bolly.com filmstar
INSERT INTO t1 VALUES (10291,'sanjeev','29153373','sansh777@hotmail.com','xxx'),(10293,'shirish','2333604','shirish@yahoo.com','ddsds');
select * from t1 where user_id=10292;
user_id name phone ref_email detail
user_id name phone ref_email detail
10292 sanjeev 29153373 sansh777@hotmail.com xxx
10292 sanjeev 29153373 sansh777@hotmail.com xxx
10292 shirish 2333604 shirish@yahoo.com ddsds
10292 shirish 2333604 shirish@yahoo.com ddsds
10292 sonali 323232 sonali@bolly.com filmstar
10292 sonali 323232 sonali@bolly.com filmstar
select * from t1 where user_id>=10292;
user_id name phone ref_email detail
user_id name phone ref_email detail
10292 sanjeev 29153373 sansh777@hotmail.com xxx
10292 sanjeev 29153373 sansh777@hotmail.com xxx
10292 shirish 2333604 shirish@yahoo.com ddsds
10292 shirish 2333604 shirish@yahoo.com ddsds
10292 sonali 323232 sonali@bolly.com filmstar
10292 sonali 323232 sonali@bolly.com filmstar
10293 shirish 2333604 shirish@yahoo.com ddsds
10293 shirish 2333604 shirish@yahoo.com ddsds
select * from t1 where user_id>10292;
user_id name phone ref_email detail
user_id name phone ref_email detail
10293 shirish 2333604 shirish@yahoo.com ddsds
10293 shirish 2333604 shirish@yahoo.com ddsds
select * from t1 where user_id<10292;
user_id name phone ref_email detail
user_id name phone ref_email detail
10291 sanjeev 29153373 sansh777@hotmail.com xxx
10291 sanjeev 29153373 sansh777@hotmail.com xxx
drop table t1;
CREATE TABLE t1 (a int not null, b int not null,c int not null,
INSERT INTO t1 VALUES (1,0,0),(3,1,1),(4,1,1),(8,2,2),(9,2,2),(17,3,2),(22,4,2),(24,4,2),(28,5,2),(29,5,2),(30,5,2),(31,6,2),(32,6,2),(33,6,2),(203,7,2),(202,7,2),(20,3,2),(157,0,0),(193,5,2),(40,7,2),(2,1,1),(15,2,2),(6,1,1),(34,6,2),(35,6,2),(16,3,2),(7,1,1),(36,7,2),(18,3,2),(26,5,2),(27,5,2),(183,4,2),(38,7,2),(25,5,2),(37,7,2),(21,4,2),(19,3,2),(5,1,1);
INSERT INTO t1 values (179,5,2);
update t1 set parent_id=parent_id+100;
select * from t1 where parent_id=102;
id parent_id level
id parent_id level
8 102 2
8 102 2
9 102 2
9 102 2
15 102 2
15 102 2
update t1 set id=id+1000;
update t1 set id=1024 where id=1009;
select * from t1;
id parent_id level
id parent_id level
1001 100 0
1001 100 0
1003 101 1
1003 101 1
...
@@ -306,6 +547,8 @@ id parent_id level
...
@@ -306,6 +547,8 @@ id parent_id level
1019 103 2
1019 103 2
1005 101 1
1005 101 1
1179 105 2
1179 105 2
update ignore t1 set id=id+1;
select * from t1;
id parent_id level
id parent_id level
1002 100 0
1002 100 0
1004 101 1
1004 101 1
...
@@ -346,12 +589,16 @@ id parent_id level
...
@@ -346,12 +589,16 @@ id parent_id level
1020 103 2
1020 103 2
1006 101 1
1006 101 1
1180 105 2
1180 105 2
update ignore t1 set id=1023 where id=1010;
select * from t1 where parent_id=102;
id parent_id level
id parent_id level
1009 102 2
1009 102 2
1025 102 2
1025 102 2
1016 102 2
1016 102 2
explain select level from t1 where level=1;
table type possible_keys key key_len ref rows Extra
table type possible_keys key key_len ref rows Extra
t1 ref level level 1 const 6 where used; Using index
t1 ref level level 1 const 6 where used; Using index
select level,id from t1 where level=1;
level id
level id
1 1004
1 1004
1 1005
1 1005
...
@@ -359,6 +606,7 @@ level id
...
@@ -359,6 +606,7 @@ level id
1 1007
1 1007
1 1008
1 1008
1 1006
1 1006
select level,id,parent_id from t1 where level=1;
level id parent_id
level id parent_id
1 1004 101
1 1004 101
1 1005 101
1 1005 101
...
@@ -366,6 +614,7 @@ level id parent_id
...
@@ -366,6 +614,7 @@ level id parent_id
1 1007 101
1 1007 101
1 1008 101
1 1008 101
1 1006 101
1 1006 101
select level,id from t1 where level=1 order by id;
CREATE TABLE t1 (a int unsigned NOT NULL) type=innodb;
INSERT INTO t1 VALUES (1);
SELECT * FROM t1;
a
a
1
1
DROP TABLE t1;
create table t1 (a int primary key,b int, c int, d int, e int, f int, g int, h int, i int, j int, k int, l int, m int, n int, o int, p int, q int, r int, s int, t int, u int, v int, w int, x int, y int, z int, a1 int, a2 int, a3 int, a4 int, a5 int, a6 int, a7 int, a8 int, a9 int, b1 int, b2 int, b3 int, b4 int, b5 int, b6 int) type = innodb;
insert into t1 values (1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1);
explain select * from t1 where a > 0 and a < 50;
table type possible_keys key key_len ref rows Extra
table type possible_keys key key_len ref rows Extra
t1 range PRIMARY PRIMARY 4 NULL 1 where used
t1 range PRIMARY PRIMARY 4 NULL 1 where used
drop table t1;
create table t1 (id int NOT NULL,id2 int NOT NULL,id3 int NOT NULL,dummy1 char(30),primary key (id,id2),index index_id3 (id3)) type=innodb;
insert into t1 values (0,0,0,'ABCDEFGHIJ'),(2,2,2,'BCDEFGHIJK'),(1,1,1,'CDEFGHIJKL');
LOCK TABLES t1 WRITE;
insert into t1 values (99,1,2,'D'),(1,1,2,'D');
Duplicate entry '1-1' for key 1
select id from t1;
id
id
0
0
1
1
2
2
select id from t1;
id
id
0
0
1
1
2
2
UNLOCK TABLES;
DROP TABLE t1;
create table t1 (id int NOT NULL,id2 int NOT NULL,id3 int NOT NULL,dummy1 char(30),primary key (id,id2),index index_id3 (id3)) type=innodb;
insert into t1 values (0,0,0,'ABCDEFGHIJ'),(2,2,2,'BCDEFGHIJK'),(1,1,1,'CDEFGHIJKL');
LOCK TABLES t1 WRITE;
begin;
insert into t1 values (99,1,2,'D'),(1,1,2,'D');
Duplicate entry '1-1' for key 1
select id from t1;
id
id
0
0
1
1
2
2
insert ignore into t1 values (100,1,2,'D'),(1,1,99,'D');
commit;
select id,id3 from t1;
id id3
id id3
0 0
0 0
1 1
1 1
2 2
2 2
100 2
100 2
UNLOCK TABLES;
DROP TABLE t1;
create table t1 (a char(20), unique (a(5))) type=innodb;
Incorrect sub part key. The used key part isn't a string, the used length is longer than the key part or the table handler doesn't support unique sub keys
create table t1 (a char(20), index (a(5))) type=innodb;
show create table t1;
Table Create Table
Table Create Table
t1 CREATE TABLE `t1` (
t1 CREATE TABLE `t1` (
`a` char(20) default NULL,
`a` char(20) default NULL,
KEY `a` (`a`)
KEY `a` (`a`)
) TYPE=InnoDB
) TYPE=InnoDB
drop table t1;
create temporary table t1 (a int not null auto_increment, primary key(a)) type=innodb;