Commit f0c4bdbc 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 c09c8a27
......@@ -7894,7 +7894,10 @@ innobase_create_index_def(
/*======================*/
/* out: Index 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;
merge_index_def_t* index;
......@@ -7902,8 +7905,6 @@ innobase_create_index_def(
DBUG_ENTER("innobase_create_index_def");
ut_a(key && heap);
index = (merge_index_def_t*) mem_heap_alloc_noninline(
heap, sizeof(merge_index_def_t));
......@@ -7917,7 +7918,7 @@ innobase_create_index_def(
--len;
if (my_strcasecmp(system_charset_info, key->name, "PRIMARY")) {
if (UNIV_LIKELY(!new_primary)) {
*index->name = TEMP_TABLE_PREFIX;
memcpy(index->name + 1, key->name, len);
} else {
......@@ -7925,11 +7926,11 @@ innobase_create_index_def(
}
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")) {
index->ind_type = index->ind_type | DICT_CLUSTERED;
index->ind_type |= DICT_CLUSTERED;
}
for (ulint i = 0; i < n_fields; i++) {
......@@ -7979,7 +7980,7 @@ innobase_copy_index_def(
ut_a(index && heap);
if (!(index->type & DICT_CLUSTERED)) {
if (!dict_index_is_clust(index)) {
/* Note that from the secondary index we take only
those fields that user defined to be in the index.
In the internal representation more colums were
......@@ -8011,13 +8012,11 @@ innobase_copy_index_def(
/***********************************************************************
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
2) Original unique secondary indexes
3) New unique secondary indexes
4) Original secondary indexes
5) New secondary indexes
2) Original secondary indexes
3) New secondary indexes
ELSE
......@@ -8036,31 +8035,35 @@ innobase_create_key_def(
mem_heap_t* heap, /* in: heap where space for key
definitions are allocated */
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 */
{
ulint n_indexes; /* Number of indexes */
merge_index_def_t** indexdef; /* Index definition */
merge_index_def_t** indexdefs; /* Index definitions */
ulint i = 0;
merge_index_def_t** indexdef;
merge_index_def_t** indexdefs;
bool new_primary;
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 */
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
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;
/* 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);
......@@ -8069,34 +8072,33 @@ innobase_create_key_def(
index = dict_table_get_next_index_noninline(
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 */
*n_keys = 1;
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);
++*n_keys;
++indexdef;
}
row_mysql_unlock_data_dictionary(trx);
} else {
ulint i = 0;
/* Skip the primary key */
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) {
*indexdef = innobase_create_index_def(key, heap);
}
while (i < n_keys) {
*indexdef++ = innobase_create_index_def(&key_info[i++],
new_primary, heap);
}
n_keys = indexdef - indexdefs;
DBUG_RETURN(indexdefs);
}
......@@ -8197,7 +8199,7 @@ ha_innobase::add_index(
num_of_idx = num_of_keys;
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
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
explain select * from t1 order by a;
id select_type table type possible_keys key key_len ref rows Extra
1 SIMPLE t1 index NULL PRIMARY 4 NULL 2 Using index
checksum table t1;
Table Checksum
test.t1 1531596814
drop table t1;
create table t1(a int, b blob,c text) engine=innodb default charset = utf8;
insert into t1 values (1,repeat('jejdkrun87',220),repeat('jejdkrun87',440));
insert into t1 values (2,repeat('adfd72nh9k',440),repeat('adfd72nh9k',1100));
checksum table t1;
Table Checksum
test.t1 1121933170
create table t1(a int, b blob, c text, d text not null) engine=innodb default charset = utf8;
insert into t1 values (22,repeat('jejdkrun87',220),repeat('jejdkrun87',440),'jejdkrun87');
insert into t1 values (44,repeat('adfd72nh9k',440),repeat('adfd72nh9k',880),'adfd72nh9k');
select count(*) from t1 where a=44;
count(*)
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));
checksum table t1;
Table Checksum
test.t1 335046842
insert into t1 values (3,repeat('adfdpplkeock',440),repeat('adfdpplkeock',1100));
insert into t1 values (4,repeat('adfdijnmnb78k',440),repeat('adfdijnmnb78k',1100));
insert into t1 values (5,repeat('adfdijn0loKNHJik',440),repeat('adfdijn0loKNHJik',1100));
select count(*) from t1 where a=44;
count(*)
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
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;
Table Create Table
t1 CREATE TABLE `t1` (
`a` int(11) NOT NULL DEFAULT '0',
`b` blob,
`c` text,
`d` text NOT NULL,
PRIMARY KEY (`a`),
KEY `b` (`b`(20))
) ENGINE=InnoDB DEFAULT CHARSET=utf8
......@@ -968,7 +974,11 @@ test.t1 check status OK
explain select * from t1 where b like 'adfd%';
id select_type table type possible_keys key key_len ref rows Extra
1 SIMPLE t1 range b b 23 NULL 2 Using where
checksum table t1;
Table Checksum
test.t1 1008226368
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
33 1 1
44 1 1
55 1 1
66 1 1
drop table t1;
......@@ -263,20 +263,22 @@ commit;
select * from t1;
explain select * from t1;
explain select * from t1 order by a;
checksum table t1;
drop table t1;
create table t1(a int, b blob,c text) engine=innodb default charset = utf8;
insert into t1 values (1,repeat('jejdkrun87',220),repeat('jejdkrun87',440));
insert into t1 values (2,repeat('adfd72nh9k',440),repeat('adfd72nh9k',1100));
checksum table t1;
create table t1(a int, b blob, c text, d text not null) engine=innodb default charset = utf8;
insert into t1 values (22,repeat('jejdkrun87',220),repeat('jejdkrun87',440),'jejdkrun87');
insert into t1 values (44,repeat('adfd72nh9k',440),repeat('adfd72nh9k',880),'adfd72nh9k');
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));
checksum table t1;
insert into t1 values (3,repeat('adfdpplkeock',440),repeat('adfdpplkeock',1100));
insert into t1 values (4,repeat('adfdijnmnb78k',440),repeat('adfdijnmnb78k',1100));
insert into t1 values (5,repeat('adfdijn0loKNHJik',440),repeat('adfdijn0loKNHJik',1100));
select count(*) from t1 where a=44;
select a,b=repeat(d,10*a),c=repeat(d,20*a) from t1;
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;
check table t1;
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;
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