1
0
mirror of https://github.com/MariaDB/server.git synced 2025-07-29 05:21:33 +03:00

Long Index is only allowed for unique keys not normal index.

This commit is contained in:
sachin
2019-02-25 00:46:48 +05:30
committed by Sergei Golubchik
parent 8084eeaa66
commit 0477e80522
3 changed files with 92 additions and 3 deletions

View File

@ -1405,4 +1405,61 @@ insert into t1 values( 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16,
insert into t1 values( 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 51, 52, 53, 54, 55, 56, 57, 58, 59, 60, 61, 62, 63);; insert into t1 values( 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 51, 52, 53, 54, 55, 56, 57, 58, 59, 60, 61, 62, 63);;
ERROR 23000: Duplicate entry '0' for key 'a63' ERROR 23000: Duplicate entry '0' for key 'a63'
drop table t1; drop table t1;
create table t1(a blob , key(a));
Warnings:
Note 1071 Specified key was too long; max key length is 1000 bytes
show create table t1;
Table Create Table
t1 CREATE TABLE `t1` (
`a` blob DEFAULT NULL,
KEY `a` (`a`(1000))
) ENGINE=MyISAM DEFAULT CHARSET=latin1
drop table t1;
create table t1(a blob);
alter table t1 add index(a);
Warnings:
Note 1071 Specified key was too long; max key length is 1000 bytes
show create table t1;
Table Create Table
t1 CREATE TABLE `t1` (
`a` blob DEFAULT NULL,
KEY `a` (`a`(1000))
) ENGINE=MyISAM DEFAULT CHARSET=latin1
drop table t1;
create table t1(a text, key(a));
Warnings:
Note 1071 Specified key was too long; max key length is 1000 bytes
show create table t1;
Table Create Table
t1 CREATE TABLE `t1` (
`a` text DEFAULT NULL,
KEY `a` (`a`(1000))
) ENGINE=MyISAM DEFAULT CHARSET=latin1
drop table t1;
create table t1(a varchar(4000));
alter table t1 add index(a);
Warnings:
Warning 1071 Specified key was too long; max key length is 1000 bytes
show create table t1;
Table Create Table
t1 CREATE TABLE `t1` (
`a` varchar(4000) DEFAULT NULL,
KEY `a` (`a`(1000))
) ENGINE=MyISAM DEFAULT CHARSET=latin1
drop table t1;
create table t1 (pk int, a int, b int, primary key(pk), key(pk,a));
alter table t1 modify a text;
ERROR 42000: Specified key was too long; max key length is 1000 bytes
alter table t1 modify a varchar(1000);
ERROR 42000: Specified key was too long; max key length is 1000 bytes
show create table t1;
Table Create Table
t1 CREATE TABLE `t1` (
`pk` int(11) NOT NULL,
`a` int(11) DEFAULT NULL,
`b` int(11) DEFAULT NULL,
PRIMARY KEY (`pk`),
KEY `pk` (`pk`,`a`)
) ENGINE=MyISAM DEFAULT CHARSET=latin1
drop table t1;
set @@GLOBAL.max_allowed_packet= @allowed_packet; set @@GLOBAL.max_allowed_packet= @allowed_packet;

View File

@ -512,4 +512,34 @@ while ($count)
--eval $insert_data_2 --eval $insert_data_2
drop table t1; drop table t1;
#
# non-unique long indexes are automatically shortened
#
create table t1(a blob , key(a));
show create table t1;
drop table t1;
create table t1(a blob);
alter table t1 add index(a);
show create table t1;
drop table t1;
create table t1(a text, key(a));
show create table t1;
drop table t1;
create table t1(a varchar(4000));
alter table t1 add index(a);
show create table t1;
drop table t1;
#
# somewhat inconsistently, the following is an error
#
create table t1 (pk int, a int, b int, primary key(pk), key(pk,a));
--error ER_TOO_LONG_KEY
alter table t1 modify a text;
--error ER_TOO_LONG_KEY
alter table t1 modify a varchar(1000);
show create table t1;
drop table t1;
set @@GLOBAL.max_allowed_packet= @allowed_packet; set @@GLOBAL.max_allowed_packet= @allowed_packet;

View File

@ -3941,13 +3941,15 @@ mysql_prepare_create_table(THD *thd, HA_CREATE_INFO *create_info,
column->length= MAX_LEN_GEOM_POINT_FIELD; column->length= MAX_LEN_GEOM_POINT_FIELD;
if (!column->length) if (!column->length)
{ {
if (key->type == Key::PRIMARY) if (key->type == Key::UNIQUE)
is_hash_field_needed= true;
else if (key->type == Key::MULTIPLE)
column->length= file->max_key_length() + 1;
else
{ {
my_error(ER_BLOB_KEY_WITHOUT_LENGTH, MYF(0), column->field_name.str); my_error(ER_BLOB_KEY_WITHOUT_LENGTH, MYF(0), column->field_name.str);
DBUG_RETURN(TRUE); DBUG_RETURN(TRUE);
} }
else
is_hash_field_needed= true;
} }
} }
#ifdef HAVE_SPATIAL #ifdef HAVE_SPATIAL