Commit aa2a74a6 authored by marko's avatar marko

branches/zip: Minor cleanup.

innobase_create_index_def(): Add parameter new_primary.

innobase_copy_index_def(): Simplify the documented algorithm,
and try to implement it properly.

innodb-index.test: Replace CHECKSUM TABLE with something more stable and
useful.  The test passes on an older BitKeeper snapshot:

ChangeSet@1.2475.18.9, 2007-05-08 11:16:41+02:00, jbruehe@mysql.com +1 -0
  Raise version number after cloning 5.1.18-beta

But it fails on a newer one where the statement
	alter table t1 add primary key (a), add key (b(20));
results in fast index creation:

ChangeSet@1.2500.1.40, 2007-06-01 20:06:13+04:00, kostja@bodhi.(none) +2 -0
  Merge bodhi.(none):/opt/local/work/mysql-5.0-runtime
  into  bodhi.(none):/opt/local/work/mysql-5.1-runtime
  MERGE: 1.1810.2984.14
parent 0e14cb55
...@@ -7892,9 +7892,12 @@ static ...@@ -7892,9 +7892,12 @@ static
merge_index_def_t* merge_index_def_t*
innobase_create_index_def( innobase_create_index_def(
/*======================*/ /*======================*/
/* out: Index definition */ /* out: Index definition */
KEY* key, /* in: key definition */ KEY* key, /* in: key definition */
mem_heap_t* heap) /* in: heap where memory is allocated */ bool new_primary, /* in: TRUE=generating
a new primary key */
mem_heap_t* heap) /* in: heap where memory
is allocated */
{ {
ulint len; ulint len;
merge_index_def_t* index; merge_index_def_t* index;
...@@ -7902,8 +7905,6 @@ innobase_create_index_def( ...@@ -7902,8 +7905,6 @@ innobase_create_index_def(
DBUG_ENTER("innobase_create_index_def"); DBUG_ENTER("innobase_create_index_def");
ut_a(key && heap);
index = (merge_index_def_t*) mem_heap_alloc_noninline( index = (merge_index_def_t*) mem_heap_alloc_noninline(
heap, sizeof(merge_index_def_t)); heap, sizeof(merge_index_def_t));
...@@ -7917,7 +7918,7 @@ innobase_create_index_def( ...@@ -7917,7 +7918,7 @@ innobase_create_index_def(
--len; --len;
if (my_strcasecmp(system_charset_info, key->name, "PRIMARY")) { if (UNIV_LIKELY(!new_primary)) {
*index->name = TEMP_TABLE_PREFIX; *index->name = TEMP_TABLE_PREFIX;
memcpy(index->name + 1, key->name, len); memcpy(index->name + 1, key->name, len);
} else { } else {
...@@ -7925,11 +7926,11 @@ innobase_create_index_def( ...@@ -7925,11 +7926,11 @@ innobase_create_index_def(
} }
if (key->flags & HA_NOSAME) { if (key->flags & HA_NOSAME) {
index->ind_type = index->ind_type | DICT_UNIQUE; index->ind_type |= DICT_UNIQUE;
} }
if (!my_strcasecmp(system_charset_info, key->name, "PRIMARY")) { if (!my_strcasecmp(system_charset_info, key->name, "PRIMARY")) {
index->ind_type = index->ind_type | DICT_CLUSTERED; index->ind_type |= DICT_CLUSTERED;
} }
for (ulint i = 0; i < n_fields; i++) { for (ulint i = 0; i < n_fields; i++) {
...@@ -7979,7 +7980,7 @@ innobase_copy_index_def( ...@@ -7979,7 +7980,7 @@ innobase_copy_index_def(
ut_a(index && heap); ut_a(index && heap);
if (!(index->type & DICT_CLUSTERED)) { if (!dict_index_is_clust(index)) {
/* Note that from the secondary index we take only /* Note that from the secondary index we take only
those fields that user defined to be in the index. those fields that user defined to be in the index.
In the internal representation more colums were In the internal representation more colums were
...@@ -8011,13 +8012,11 @@ innobase_copy_index_def( ...@@ -8011,13 +8012,11 @@ innobase_copy_index_def(
/*********************************************************************** /***********************************************************************
Create an index table where indexes are ordered as follows: Create an index table where indexes are ordered as follows:
IF a primary key is defined for the table THEN IF a new primary key is defined for the table THEN
1) New primary key 1) New primary key
2) Original unique secondary indexes 2) Original secondary indexes
3) New unique secondary indexes 3) New secondary indexes
4) Original secondary indexes
5) New secondary indexes
ELSE ELSE
...@@ -8036,31 +8035,35 @@ innobase_create_key_def( ...@@ -8036,31 +8035,35 @@ innobase_create_key_def(
mem_heap_t* heap, /* in: heap where space for key mem_heap_t* heap, /* in: heap where space for key
definitions are allocated */ definitions are allocated */
KEY* key_info, /* in: Indexes to be created */ KEY* key_info, /* in: Indexes to be created */
ulint* n_keys) /* in/out: Number of indexes to ulint& n_keys) /* in/out: Number of indexes to
be created */ be created */
{ {
ulint n_indexes; /* Number of indexes */ ulint i = 0;
merge_index_def_t** indexdef; /* Index definition */ merge_index_def_t** indexdef;
merge_index_def_t** indexdefs; /* Index definitions */ merge_index_def_t** indexdefs;
bool new_primary;
DBUG_ENTER("innobase_create_key_def"); DBUG_ENTER("innobase_create_key_def");
ut_a(trx && table && heap && key_info && n_keys && *n_keys);
/* We do not need to count the original primary key */ /* We do not need to count the original primary key */
n_indexes = *n_keys + UT_LIST_GET_LEN(table->indexes) - 1; const ulint n_indexes = n_keys + UT_LIST_GET_LEN(table->indexes) - 1;
indexdef = indexdefs = (merge_index_def_t**)
mem_heap_alloc_noninline(heap, sizeof *indexdef * n_indexes);
indexdef = indexdefs = (merge_index_def_t**) mem_heap_alloc_noninline(
heap, sizeof(merge_index_def_t*) * n_indexes);
/* Primary key if defined is always the first index defined for /* Primary key if defined is always the first index defined for
the table */ the table */
if (!my_strcasecmp(system_charset_info, key_info->name, "PRIMARY")) { new_primary = !my_strcasecmp(system_charset_info,
key_info->name, "PRIMARY");
if (new_primary) {
dict_index_t* index; dict_index_t* index;
/* Create the PRIMARY key index definition */ /* Create the PRIMARY key index definition */
*indexdef = innobase_create_index_def(key_info, heap); *indexdef = innobase_create_index_def(key_info,
new_primary, heap);
row_mysql_lock_data_dictionary(trx); row_mysql_lock_data_dictionary(trx);
...@@ -8069,34 +8072,33 @@ innobase_create_key_def( ...@@ -8069,34 +8072,33 @@ innobase_create_key_def(
index = dict_table_get_next_index_noninline( index = dict_table_get_next_index_noninline(
dict_table_get_first_index_noninline(table)); dict_table_get_first_index_noninline(table));
/* Copy the definitions of all the secondary indexes */ /* Copy the definitions of old secondary indexes */
++indexdef; /* Since we've copied the primary key info */ ++indexdef; /* Since we've copied the primary key info */
*n_keys = 1;
while (index) { while (index) {
ut_a(!(index->type & DICT_CLUSTERED)); ut_a(!dict_index_is_clust(index));
*indexdef = innobase_copy_index_def(index, heap); *indexdef++ = innobase_copy_index_def(index, heap);
index = dict_table_get_next_index_noninline(index); index = dict_table_get_next_index_noninline(index);
++*n_keys;
++indexdef;
} }
row_mysql_unlock_data_dictionary(trx); row_mysql_unlock_data_dictionary(trx);
} else { /* Skip the primary key */
ulint i = 0; i = 1;
}
/* Create definitions for new unique secondary indexes */ /* Create definitions for added secondary indexes. */
for (KEY* key = key_info; i < *n_keys; ++key, ++i, ++indexdef) { while (i < n_keys) {
*indexdef = innobase_create_index_def(key, heap); *indexdef++ = innobase_create_index_def(&key_info[i++],
} new_primary, heap);
} }
n_keys = indexdef - indexdefs;
DBUG_RETURN(indexdefs); DBUG_RETURN(indexdefs);
} }
...@@ -8197,7 +8199,7 @@ ha_innobase::add_index( ...@@ -8197,7 +8199,7 @@ ha_innobase::add_index(
num_of_idx = num_of_keys; num_of_idx = num_of_keys;
index_defs = innobase_create_key_def( index_defs = innobase_create_key_def(
trx, innodb_table, heap, key_info, &num_of_idx); trx, innodb_table, heap, key_info, num_of_idx);
/* If a new primary key is defined for the table we need /* If a new primary key is defined for the table we need
to drop all original secondary indexes from the table. These to drop all original secondary indexes from the table. These
......
...@@ -936,29 +936,35 @@ id select_type table type possible_keys key key_len ref rows Extra ...@@ -936,29 +936,35 @@ id select_type table type possible_keys key key_len ref rows Extra
explain select * from t1 order by a; explain select * from t1 order by a;
id select_type table type possible_keys key key_len ref rows Extra id select_type table type possible_keys key key_len ref rows Extra
1 SIMPLE t1 index NULL PRIMARY 4 NULL 2 Using index 1 SIMPLE t1 index NULL PRIMARY 4 NULL 2 Using index
checksum table t1;
Table Checksum
test.t1 1531596814
drop table t1; drop table t1;
create table t1(a int, b blob,c text) engine=innodb default charset = utf8; create table t1(a int, b blob, c text, d text not null) engine=innodb default charset = utf8;
insert into t1 values (1,repeat('jejdkrun87',220),repeat('jejdkrun87',440)); insert into t1 values (22,repeat('jejdkrun87',220),repeat('jejdkrun87',440),'jejdkrun87');
insert into t1 values (2,repeat('adfd72nh9k',440),repeat('adfd72nh9k',1100)); insert into t1 values (44,repeat('adfd72nh9k',440),repeat('adfd72nh9k',880),'adfd72nh9k');
checksum table t1; select count(*) from t1 where a=44;
Table Checksum count(*)
test.t1 1121933170 1
select a,b=repeat(d,10*a),c=repeat(d,20*a) from t1;
a b=repeat(d,10*a) c=repeat(d,20*a)
22 1 1
44 1 1
alter table t1 add primary key (a), add key (b(20)); alter table t1 add primary key (a), add key (b(20));
checksum table t1; select count(*) from t1 where a=44;
Table Checksum count(*)
test.t1 335046842 1
insert into t1 values (3,repeat('adfdpplkeock',440),repeat('adfdpplkeock',1100)); select a,b=repeat(d,10*a),c=repeat(d,20*a) from t1;
insert into t1 values (4,repeat('adfdijnmnb78k',440),repeat('adfdijnmnb78k',1100)); a b=repeat(d,10*a) c=repeat(d,20*a)
insert into t1 values (5,repeat('adfdijn0loKNHJik',440),repeat('adfdijn0loKNHJik',1100)); 22 1 1
44 1 1
insert into t1 values (33,repeat('adfdpplkeock',330),repeat('adfdpplkeock',660),'adfdpplkeock');
insert into t1 values (55,repeat('adfdijnmnb78k',550),repeat('adfdijnmnb78k',1100),'adfdijnmnb78k');
insert into t1 values (66,repeat('adfdijn0loKNHJik',660),repeat('adfdijn0loKNHJik',1320),'adfdijn0loKNHJik');
show create table t1; show create table t1;
Table Create Table Table Create Table
t1 CREATE TABLE `t1` ( t1 CREATE TABLE `t1` (
`a` int(11) NOT NULL DEFAULT '0', `a` int(11) NOT NULL DEFAULT '0',
`b` blob, `b` blob,
`c` text, `c` text,
`d` text NOT NULL,
PRIMARY KEY (`a`), PRIMARY KEY (`a`),
KEY `b` (`b`(20)) KEY `b` (`b`(20))
) ENGINE=InnoDB DEFAULT CHARSET=utf8 ) ENGINE=InnoDB DEFAULT CHARSET=utf8
...@@ -968,7 +974,11 @@ test.t1 check status OK ...@@ -968,7 +974,11 @@ test.t1 check status OK
explain select * from t1 where b like 'adfd%'; explain select * from t1 where b like 'adfd%';
id select_type table type possible_keys key key_len ref rows Extra id select_type table type possible_keys key key_len ref rows Extra
1 SIMPLE t1 range b b 23 NULL 2 Using where 1 SIMPLE t1 range b b 23 NULL 2 Using where
checksum table t1; select a,b=repeat(d,10*a),c=repeat(d,20*a) from t1;
Table Checksum a b=repeat(d,10*a) c=repeat(d,20*a)
test.t1 1008226368 22 1 1
33 1 1
44 1 1
55 1 1
66 1 1
drop table t1; drop table t1;
...@@ -263,20 +263,22 @@ commit; ...@@ -263,20 +263,22 @@ commit;
select * from t1; select * from t1;
explain select * from t1; explain select * from t1;
explain select * from t1 order by a; explain select * from t1 order by a;
checksum table t1;
drop table t1; drop table t1;
create table t1(a int, b blob,c text) engine=innodb default charset = utf8; create table t1(a int, b blob, c text, d text not null) engine=innodb default charset = utf8;
insert into t1 values (1,repeat('jejdkrun87',220),repeat('jejdkrun87',440)); insert into t1 values (22,repeat('jejdkrun87',220),repeat('jejdkrun87',440),'jejdkrun87');
insert into t1 values (2,repeat('adfd72nh9k',440),repeat('adfd72nh9k',1100)); insert into t1 values (44,repeat('adfd72nh9k',440),repeat('adfd72nh9k',880),'adfd72nh9k');
checksum table t1;
select count(*) from t1 where a=44;
select a,b=repeat(d,10*a),c=repeat(d,20*a) from t1;
alter table t1 add primary key (a), add key (b(20)); alter table t1 add primary key (a), add key (b(20));
checksum table t1; select count(*) from t1 where a=44;
insert into t1 values (3,repeat('adfdpplkeock',440),repeat('adfdpplkeock',1100)); select a,b=repeat(d,10*a),c=repeat(d,20*a) from t1;
insert into t1 values (4,repeat('adfdijnmnb78k',440),repeat('adfdijnmnb78k',1100)); insert into t1 values (33,repeat('adfdpplkeock',330),repeat('adfdpplkeock',660),'adfdpplkeock');
insert into t1 values (5,repeat('adfdijn0loKNHJik',440),repeat('adfdijn0loKNHJik',1100)); insert into t1 values (55,repeat('adfdijnmnb78k',550),repeat('adfdijnmnb78k',1100),'adfdijnmnb78k');
insert into t1 values (66,repeat('adfdijn0loKNHJik',660),repeat('adfdijn0loKNHJik',1320),'adfdijn0loKNHJik');
show create table t1; show create table t1;
check table t1; check table t1;
explain select * from t1 where b like 'adfd%'; explain select * from t1 where b like 'adfd%';
checksum table t1; select a,b=repeat(d,10*a),c=repeat(d,20*a) from t1;
drop table t1; drop table t1;
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment