diff options
author | unknown <monty@mysql.com> | 2005-05-14 18:31:22 +0300 |
---|---|---|
committer | unknown <monty@mysql.com> | 2005-05-14 18:31:22 +0300 |
commit | f8f714a2fbd821488aa3d8e39d6c3a944c7b1aa1 (patch) | |
tree | c08ee86cd9f77c3a7dc13b02b09371ccd19f2b88 /sql/unireg.cc | |
parent | bb2b8120615f48cd17682aa810e54b20a7002c77 (diff) | |
parent | 78f2e7b53db62a3bc67dcb5ed20dfe47cf680c66 (diff) | |
download | mariadb-git-f8f714a2fbd821488aa3d8e39d6c3a944c7b1aa1.tar.gz |
Merge with 4.1
BitKeeper/etc/logging_ok:
auto-union
BitKeeper/deleted/.del-errmsg.txt~11edc4db89248c16:
Auto merged
BitKeeper/deleted/.del-errmsg.txt~184eb1f09242dc72:
Auto merged
BitKeeper/deleted/.del-errmsg.txt~2cdeb8d6f80eba72:
Auto merged
BitKeeper/deleted/.del-errmsg.txt~4617575065d612b9:
Auto merged
BitKeeper/deleted/.del-errmsg.txt~587903f9311db2d1:
Auto merged
BitKeeper/deleted/.del-errmsg.txt~606dfaeb9e81aa4e:
Auto merged
BitKeeper/deleted/.del-errmsg.txt~6bbd9eac7f0e6b89:
Auto merged
BitKeeper/deleted/.del-errmsg.txt~7397c423c52c6d2c:
Auto merged
BitKeeper/deleted/.del-errmsg.txt~898865062c970766:
Auto merged
BitKeeper/deleted/.del-errmsg.txt~8ed1999cbd481dc4:
Auto merged
BitKeeper/deleted/.del-errmsg.txt~94a93cc742fca24d:
Auto merged
BitKeeper/deleted/.del-errmsg.txt~9dab24f7fb11b1e1:
Auto merged
BitKeeper/deleted/.del-errmsg.txt~b44a85a177954da0:
Auto merged
BitKeeper/deleted/.del-errmsg.txt~b6181e29d8282b06:
Auto merged
BitKeeper/deleted/.del-errmsg.txt~ba132dc9bc936c8a:
Auto merged
BitKeeper/deleted/.del-errmsg.txt~e2609fdf7870795:
Auto merged
BitKeeper/deleted/.del-errmsg.txt~e3183b99fbba0a9c:
Auto merged
BitKeeper/deleted/.del-errmsg.txt~eeb2c47537ed9c23:
Auto merged
BitKeeper/deleted/.del-errmsg.txt~ef28b592c7591b7:
Auto merged
BitKeeper/deleted/.del-errmsg.txt~ef53c33ac0ff8a84:
Auto merged
BitKeeper/deleted/.del-errmsg.txt~f19bfd5d4c918964:
Auto merged
BitKeeper/deleted/.del-errmsg.txt~f96b7055cac394e:
Auto merged
libmysql/libmysql.c:
Auto merged
myisam/mi_key.c:
Auto merged
mysql-test/r/alter_table.result:
Auto merged
mysql-test/r/auto_increment.result:
Auto merged
mysql-test/r/innodb.result:
Auto merged
mysql-test/r/select.result:
Auto merged
mysql-test/t/alter_table.test:
Auto merged
mysql-test/t/innodb.test:
Auto merged
mysql-test/t/select.test:
Auto merged
sql/handler.h:
Auto merged
sql/item_func.cc:
Auto merged
sql/sql_yacc.yy:
Auto merged
mysql-test/r/insert_update.result:
Auto merged
strings/ctype-ucs2.c:
Auto merged
sql/sql_table.cc:
merge
sql/unireg.cc:
merge
Diffstat (limited to 'sql/unireg.cc')
-rw-r--r-- | sql/unireg.cc | 75 |
1 files changed, 47 insertions, 28 deletions
diff --git a/sql/unireg.cc b/sql/unireg.cc index 00fc80a25fe..82f91d1da68 100644 --- a/sql/unireg.cc +++ b/sql/unireg.cc @@ -32,18 +32,21 @@ static uchar * pack_screens(List<create_field> &create_fields, uint *info_length, uint *screens, bool small_file); -static uint pack_keys(uchar *keybuff,uint key_count, KEY *key_info); +static uint pack_keys(uchar *keybuff,uint key_count, KEY *key_info, + ulong data_offset); static bool pack_header(uchar *forminfo,enum db_type table_type, List<create_field> &create_fields, uint info_length, uint screens, uint table_options, - handler *file); + ulong data_offset, handler *file); static uint get_interval_id(uint *int_count,List<create_field> &create_fields, create_field *last_field); -static bool pack_fields(File file, List<create_field> &create_fields); +static bool pack_fields(File file, List<create_field> &create_fields, + ulong data_offset); static bool make_empty_rec(THD *thd, int file, enum db_type table_type, uint table_options, List<create_field> &create_fields, - uint reclength,uint null_fields); + uint reclength, uint null_fields, + ulong data_offset); /* Create a frm (table definition) file @@ -71,7 +74,7 @@ bool mysql_create_frm(THD *thd, my_string file_name, { uint reclength,info_length,screens,key_info_length,maxlength,null_fields; File file; - ulong filepos; + ulong filepos, data_offset; uchar fileinfo[64],forminfo[288],*keybuff; TYPELIB formnames; uchar *screen_buff; @@ -81,9 +84,16 @@ bool mysql_create_frm(THD *thd, my_string file_name, if (!(screen_buff=pack_screens(create_fields,&info_length,&screens,0))) DBUG_RETURN(1); if (db_file == NULL) - db_file=get_new_handler((TABLE*) 0, create_info->db_type); + db_file= get_new_handler((TABLE*) 0, create_info->db_type); + + /* If fixed row records, we need one bit to check for deleted rows */ + if (!(create_info->table_options & HA_OPTION_PACK_RECORD)) + create_info->null_bits++; + data_offset= (create_info->null_bits + 7) / 8; + if (pack_header(forminfo, create_info->db_type,create_fields,info_length, - screens, create_info->table_options, db_file)) + screens, create_info->table_options, + data_offset, db_file)) { my_free((gptr) screen_buff,MYF(0)); if (thd->net.last_errno != ER_TOO_MANY_FIELDS) @@ -94,7 +104,7 @@ bool mysql_create_frm(THD *thd, my_string file_name, if (!(screen_buff=pack_screens(create_fields,&info_length,&screens,1))) DBUG_RETURN(1); if (pack_header(forminfo, create_info->db_type, create_fields,info_length, - screens, create_info->table_options, db_file)) + screens, create_info->table_options, data_offset, db_file)) { my_free((gptr) screen_buff,MYF(0)); DBUG_RETURN(1); @@ -112,7 +122,7 @@ bool mysql_create_frm(THD *thd, my_string file_name, uint key_buff_length=keys*(7+NAME_LEN+MAX_REF_PARTS*9)+16; 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, data_offset); VOID(get_form_pos(file,fileinfo,&formnames)); if (!(filepos=make_new_entry(file,fileinfo,&formnames,""))) goto err; @@ -135,13 +145,13 @@ bool mysql_create_frm(THD *thd, my_string file_name, (ulong) uint2korr(fileinfo+6)+ (ulong) key_buff_length, MY_SEEK_SET,MYF(0))); if (make_empty_rec(thd,file,create_info->db_type,create_info->table_options, - create_fields,reclength,null_fields)) + create_fields,reclength, null_fields, data_offset)) goto err; VOID(my_seek(file,filepos,MY_SEEK_SET,MYF(0))); if (my_write(file,(byte*) forminfo,288,MYF_RW) || my_write(file,(byte*) screen_buff,info_length,MYF_RW) || - pack_fields(file,create_fields)) + pack_fields(file, create_fields, data_offset)) goto err; #ifdef HAVE_CRYPTED_FRM @@ -313,7 +323,8 @@ static uchar * pack_screens(List<create_field> &create_fields, /* Pack keyinfo and keynames to keybuff for save in form-file. */ -static uint pack_keys(uchar *keybuff,uint key_count,KEY *keyinfo) +static uint pack_keys(uchar *keybuff, uint key_count, KEY *keyinfo, + ulong data_offset) { uint key_parts,length; uchar *pos, *keyname_pos; @@ -340,10 +351,13 @@ static uint pack_keys(uchar *keybuff,uint key_count,KEY *keyinfo) key_part++) { - DBUG_PRINT("loop",("field: %d startpos: %ld length: %ld", - key_part->fieldnr,key_part->offset,key_part->length)); + uint offset; + DBUG_PRINT("loop",("field: %d startpos: %lu length: %ld", + key_part->fieldnr, key_part->offset + data_offset, + key_part->length)); int2store(pos,key_part->fieldnr+1+FIELD_NAME_USED); - int2store(pos+2,key_part->offset+1); + offset= (uint) (key_part->offset+data_offset+1); + int2store(pos+2, offset); pos[4]=0; // Sort order int2store(pos+5,key_part->key_type); int2store(pos+7,key_part->length); @@ -384,8 +398,8 @@ static uint pack_keys(uchar *keybuff,uint key_count,KEY *keyinfo) static bool pack_header(uchar *forminfo, enum db_type table_type, List<create_field> &create_fields, - uint info_length, uint screens,uint table_options, - handler *file) + uint info_length, uint screens, uint table_options, + ulong data_offset, handler *file) { uint length,int_count,int_length,no_empty, int_parts; uint time_stamp_pos,null_fields; @@ -425,10 +439,10 @@ static bool pack_header(uchar *forminfo, enum db_type table_type, if (field->sql_type == FIELD_TYPE_TIMESTAMP && MTYP_TYPENR(field->unireg_check) != Field::NONE && !time_stamp_pos) - time_stamp_pos=(int) field->offset+1; + time_stamp_pos= (uint) field->offset+ (uint) data_offset + 1; length=field->pack_length; - if ((int) field->offset+length > reclength) - reclength=(int) field->offset+length; + if ((uint) field->offset+ (uint) data_offset+ length > reclength) + reclength=(uint) (field->offset+ data_offset + length); n_length+= (ulong) strlen(field->field_name)+1; field->interval_id=0; if (field->interval) @@ -539,7 +553,8 @@ static uint get_interval_id(uint *int_count,List<create_field> &create_fields, /* Save fields, fieldnames and intervals */ -static bool pack_fields(File file,List<create_field> &create_fields) +static bool pack_fields(File file, List<create_field> &create_fields, + ulong data_offset) { reg2 uint i; uint int_count, comment_length=0; @@ -554,11 +569,13 @@ static bool pack_fields(File file,List<create_field> &create_fields) int_count=0; while ((field=it++)) { + uint recpos; buff[0]= (uchar) field->row; buff[1]= (uchar) field->col; buff[2]= (uchar) field->sc_length; int2store(buff+3, field->length); - uint recpos=(uint) field->offset+1; + /* The +1 is here becasue the col offset in .frm file have offset 1 */ + recpos= field->offset+1 + (uint) data_offset; int3store(buff+5,recpos); int2store(buff+8,field->pack_flag); int2store(buff+10,field->unireg_check); @@ -644,11 +661,12 @@ static bool pack_fields(File file,List<create_field> &create_fields) static bool make_empty_rec(THD *thd, File file,enum db_type table_type, uint table_options, List<create_field> &create_fields, - uint reclength, uint null_fields) + uint reclength, uint null_fields, + ulong data_offset) { int error; Field::utype type; - uint null_count; + uint firstpos, null_count; uchar *buff,*null_pos; TABLE table; create_field *field; @@ -675,10 +693,10 @@ static bool make_empty_rec(THD *thd, File file,enum db_type table_type, null_count=0; if (!(table_options & HA_OPTION_PACK_RECORD)) { - null_fields++; // Need one bit for delete mark - null_count++; + null_count++; // Need one bit for delete mark *buff|= 1; } + DBUG_ASSERT(data_offset == ((null_fields + null_count + 7) / 8)); null_pos= buff; List_iterator<create_field> it(create_fields); @@ -688,7 +706,8 @@ static bool make_empty_rec(THD *thd, File file,enum db_type table_type, /* regfield don't have to be deleted as it's allocated with sql_alloc() */ - Field *regfield=make_field((char*) buff+field->offset,field->length, + Field *regfield=make_field((char*) buff+field->offset + data_offset, + field->length, null_pos + null_count / 8, null_count & 7, field->pack_flag, @@ -742,7 +761,7 @@ static bool make_empty_rec(THD *thd, File file,enum db_type table_type, if (null_count) *(null_pos + null_count / 8)|= ~(((uchar) 1 << (null_count & 7)) - 1); - error=(int) my_write(file,(byte*) buff,(uint) reclength,MYF_RW); + error=(int) my_write(file,(byte*) buff, (uint) reclength,MYF_RW); err: my_free((gptr) buff,MYF(MY_FAE)); |