Commit 572e18ae authored by unknown's avatar unknown

>255 keys support in frm

parent 293a61ed
...@@ -156,7 +156,16 @@ int openfrm(const char *name, const char *alias, uint db_stat, uint prgflag, ...@@ -156,7 +156,16 @@ int openfrm(const char *name, const char *alias, uint db_stat, uint prgflag,
VOID(my_seek(file,(ulong) uint2korr(head+6),MY_SEEK_SET,MYF(0))); VOID(my_seek(file,(ulong) uint2korr(head+6),MY_SEEK_SET,MYF(0)));
if (read_string(file,(gptr*) &disk_buff,key_info_length)) if (read_string(file,(gptr*) &disk_buff,key_info_length))
goto err_not_open; /* purecov: inspected */ goto err_not_open; /* purecov: inspected */
outparam->keys=keys= disk_buff[0]; if (disk_buff[1] & 0x80)
{
outparam->keys= keys= uint2korr(disk_buff) & 0x7fff;
outparam->key_parts= key_parts= uint2korr(disk_buff+2);
}
else
{
outparam->keys= keys= disk_buff[0];
outparam->key_parts= key_parts= disk_buff[1];
}
outparam->keys_for_keyread.init().set_prefix(keys); outparam->keys_for_keyread.init().set_prefix(keys);
outparam->keys_in_use.init().set_prefix(keys); outparam->keys_in_use.init().set_prefix(keys);
outparam->read_only_keys.init().clear_all(); outparam->read_only_keys.init().clear_all();
...@@ -164,7 +173,6 @@ int openfrm(const char *name, const char *alias, uint db_stat, uint prgflag, ...@@ -164,7 +173,6 @@ int openfrm(const char *name, const char *alias, uint db_stat, uint prgflag,
outparam->used_keys.init(); outparam->used_keys.init();
outparam->keys_in_use_for_query.init(); outparam->keys_in_use_for_query.init();
outparam->key_parts=key_parts=disk_buff[1];
n_length=keys*sizeof(KEY)+key_parts*sizeof(KEY_PART_INFO); n_length=keys*sizeof(KEY)+key_parts*sizeof(KEY_PART_INFO);
if (!(keyinfo = (KEY*) alloc_root(&outparam->mem_root, if (!(keyinfo = (KEY*) alloc_root(&outparam->mem_root,
n_length+uint2korr(disk_buff+4)))) n_length+uint2korr(disk_buff+4))))
...@@ -269,7 +277,9 @@ int openfrm(const char *name, const char *alias, uint db_stat, uint prgflag, ...@@ -269,7 +277,9 @@ int openfrm(const char *name, const char *alias, uint db_stat, uint prgflag,
record[outparam->reclength]=0; // For purify and ->c_ptr() record[outparam->reclength]=0; // For purify and ->c_ptr()
outparam->rec_buff_length=rec_buff_length; outparam->rec_buff_length=rec_buff_length;
if (my_pread(file,(byte*) record,(uint) outparam->reclength, if (my_pread(file,(byte*) record,(uint) outparam->reclength,
(ulong) (uint2korr(head+6)+uint2korr(head+14)), (ulong) (uint2korr(head+6)+
((uint2korr(head+14) == 0xffff ?
uint4korr(head+10) : uint2korr(head+14)))),
MYF(MY_NABP))) MYF(MY_NABP)))
goto err_not_open; /* purecov: inspected */ goto err_not_open; /* purecov: inspected */
/* HACK: table->record[2] is used instead of table->default_values here */ /* HACK: table->record[2] is used instead of table->default_values here */
...@@ -1114,6 +1124,7 @@ File create_frm(register my_string name, uint reclength, uchar *fileinfo, ...@@ -1114,6 +1124,7 @@ File create_frm(register my_string name, uint reclength, uchar *fileinfo,
key_length=keys*(7+NAME_LEN+MAX_REF_PARTS*9)+16; key_length=keys*(7+NAME_LEN+MAX_REF_PARTS*9)+16;
length=(ulong) next_io_size((ulong) (IO_SIZE+key_length+reclength)); length=(ulong) next_io_size((ulong) (IO_SIZE+key_length+reclength));
int4store(fileinfo+10,length); int4store(fileinfo+10,length);
if (key_length > 0xffff) key_length=0xffff;
int2store(fileinfo+14,key_length); int2store(fileinfo+14,key_length);
int2store(fileinfo+16,reclength); int2store(fileinfo+16,reclength);
int4store(fileinfo+18,create_info->max_rows); int4store(fileinfo+18,create_info->max_rows);
......
...@@ -92,15 +92,15 @@ int rea_create_table(THD *thd, my_string file_name, ...@@ -92,15 +92,15 @@ int rea_create_table(THD *thd, my_string file_name,
DBUG_RETURN(1); DBUG_RETURN(1);
} }
uint key_buff_length=uint2korr(fileinfo+14); uint key_buff_length=keys*(7+NAME_LEN+MAX_REF_PARTS*9)+16;
keybuff=(uchar*) my_alloca(key_buff_length); keybuff=(uchar*) my_malloc(key_buff_length, MYF(0));
key_info_length=pack_keys(keybuff,keys,key_info); key_info_length=pack_keys(keybuff,keys,key_info);
VOID(get_form_pos(file,fileinfo,&formnames)); VOID(get_form_pos(file,fileinfo,&formnames));
if (!(filepos=make_new_entry(file,fileinfo,&formnames,""))) if (!(filepos=make_new_entry(file,fileinfo,&formnames,"")))
goto err; goto err;
maxlength=(uint) next_io_size((ulong) (uint2korr(forminfo)+1000)); maxlength=(uint) next_io_size((ulong) (uint2korr(forminfo)+1000));
int2store(forminfo+2,maxlength); int2store(forminfo+2,maxlength);
int4store(fileinfo+10,(ulong) (filepos+maxlength)); int4store(fileinfo+10,key_buff_length);
fileinfo[26]= (uchar) test((create_info->max_rows == 1) && fileinfo[26]= (uchar) test((create_info->max_rows == 1) &&
(create_info->min_rows == 1) && (keys == 0)); (create_info->min_rows == 1) && (keys == 0));
int2store(fileinfo+28,key_info_length); int2store(fileinfo+28,key_info_length);
...@@ -148,7 +148,7 @@ int rea_create_table(THD *thd, my_string file_name, ...@@ -148,7 +148,7 @@ int rea_create_table(THD *thd, my_string file_name,
#endif #endif
my_free((gptr) screen_buff,MYF(0)); my_free((gptr) screen_buff,MYF(0));
my_afree((gptr) keybuff); my_free((gptr) keybuff, MYF(0));
VOID(my_close(file,MYF(MY_WME))); VOID(my_close(file,MYF(MY_WME)));
if (ha_create_table(file_name,create_info,0)) if (ha_create_table(file_name,create_info,0))
goto err2; goto err2;
...@@ -156,7 +156,7 @@ int rea_create_table(THD *thd, my_string file_name, ...@@ -156,7 +156,7 @@ int rea_create_table(THD *thd, my_string file_name,
err: err:
my_free((gptr) screen_buff,MYF(0)); my_free((gptr) screen_buff,MYF(0));
my_afree((gptr) keybuff); my_free((gptr) keybuff, MYF(0));
VOID(my_close(file,MYF(MY_WME))); VOID(my_close(file,MYF(MY_WME)));
err2: err2:
my_delete(file_name,MYF(0)); my_delete(file_name,MYF(0));
...@@ -291,10 +291,17 @@ static uint pack_keys(uchar *keybuff,uint key_count,KEY *keyinfo) ...@@ -291,10 +291,17 @@ static uint pack_keys(uchar *keybuff,uint key_count,KEY *keyinfo)
} }
*(pos++)=0; *(pos++)=0;
if (key_count > 127 || key_parts > 127)
{
key_count|=0x8000;
int2store(keybuff,key_count);
int2store(keybuff+2,key_parts);
}
else
{
keybuff[0]=(uchar) key_count; keybuff[0]=(uchar) key_count;
keybuff[1]=(uchar) key_parts; keybuff[1]=(uchar) key_parts;
length=(uint) (keyname_pos-keybuff); }
int2store(keybuff+2,length);
length=(uint) (pos-keyname_pos); length=(uint) (pos-keyname_pos);
int2store(keybuff+4,length); int2store(keybuff+4,length);
DBUG_RETURN((uint) (pos-keybuff)); DBUG_RETURN((uint) (pos-keybuff));
......
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