22 uchar *key,uint key_length,my_off_t
page,uchar *anc_buff);
24 my_off_t leaf_page,uchar *leaf_buff,uchar *keypos,
25 my_off_t next_block,uchar *ret_key);
27 my_off_t leaf_page,uchar *leaf_buff,uchar *keypos);
28 static uint remove_key(
MI_KEYDEF *keyinfo,uint nod_flag,uchar *keypos,
29 uchar *lastkey,uchar *page_end,
30 my_off_t *next_block);
32 uchar *key, uint key_length, my_off_t *root);
43 DBUG_ENTER(
"mi_delete");
47 DBUG_EXECUTE_IF(
"myisam_pretend_crashed_table_on_usage",
48 mi_print_error(info->s, HA_ERR_CRASHED);
49 DBUG_RETURN(my_errno= HA_ERR_CRASHED););
50 DBUG_EXECUTE_IF(
"my_error_test_undefined_error",
51 mi_print_error(info->s, INT_MAX);
52 DBUG_RETURN(my_errno= INT_MAX););
53 if (!(info->update & HA_STATE_AKTIV))
55 DBUG_RETURN(my_errno=HA_ERR_KEY_NOT_FOUND);
57 if (share->options & HA_OPTION_READ_ONLY_DATA)
59 DBUG_RETURN(my_errno=EACCES);
61 if (_mi_readinfo(info,F_WRLCK,1))
62 DBUG_RETURN(my_errno);
63 if (info->s->calc_checksum)
64 info->checksum=(*info->s->calc_checksum)(info,record);
65 if ((*share->compare_record)(info,record))
68 if (_mi_mark_file_changed(info))
73 old_key=info->lastkey2;
74 for (i=0 ; i < share->base.keys ; i++ )
76 if (mi_is_key_active(info->s->state.key_map, i))
78 info->s->keyinfo[
i].version++;
79 if (info->s->keyinfo[i].flag & HA_FULLTEXT )
81 if (_mi_ft_del(info,i, old_key,record,info->lastpos))
86 if (info->s->keyinfo[i].ck_delete(info,i,old_key,
87 _mi_make_key(info,i,old_key,record,info->lastpos)))
91 info->update&= ~HA_STATE_RNEXT_SAME;
95 if ((*share->delete_record)(info))
97 info->state->checksum-=info->checksum;
99 info->update= HA_STATE_CHANGED+HA_STATE_DELETED+HA_STATE_ROW_CHANGED;
100 info->state->records--;
102 mi_sizestore(lastpos,info->lastpos);
103 myisam_log_command(MI_LOG_DELETE,info,(uchar*) lastpos,
sizeof(lastpos),0);
104 (void) _mi_writeinfo(info,WRITEINFO_UPDATE_KEYFILE);
106 if (info->invalidator != 0)
108 DBUG_PRINT(
"info", (
"invalidator... '%s' (delete)", info->filename));
109 (*info->invalidator)(info->filename);
116 mi_sizestore(lastpos,info->lastpos);
117 myisam_log_command(MI_LOG_DELETE,info,(uchar*) lastpos,
sizeof(lastpos),0);
118 if (save_errno != HA_ERR_RECORD_CHANGED)
120 mi_print_error(info->s, HA_ERR_CRASHED);
121 mi_mark_crashed(info);
123 (void) _mi_writeinfo(info,WRITEINFO_UPDATE_KEYFILE);
124 info->update|=HA_STATE_WRITTEN;
126 if (save_errno == HA_ERR_KEY_NOT_FOUND)
128 mi_print_error(info->s, HA_ERR_CRASHED);
129 my_errno=HA_ERR_CRASHED;
132 DBUG_RETURN(my_errno);
138 int _mi_ck_delete(
register MI_INFO *info, uint keynr, uchar *key,
141 return _mi_ck_real_delete(info, info->s->keyinfo+keynr, key, key_length,
142 &info->s->state.key_root[keynr]);
147 uchar *key, uint key_length, my_off_t *root)
153 DBUG_ENTER(
"_mi_ck_real_delete");
155 if ((old_root=*root) == HA_OFFSET_ERROR)
157 mi_print_error(info->s, HA_ERR_CRASHED);
158 DBUG_RETURN(my_errno=HA_ERR_CRASHED);
160 if (!(root_buff= (uchar*) my_alloca((uint) keyinfo->block_length+
163 DBUG_PRINT(
"error",(
"Couldn't allocate memory"));
164 DBUG_RETURN(my_errno=ENOMEM);
166 DBUG_PRINT(
"info",(
"root_page: %ld", (
long) old_root));
167 if (!_mi_fetch_keypage(info,keyinfo,old_root,DFLT_INIT_HITS,root_buff,0))
172 if ((error=d_search(info,keyinfo,
173 (keyinfo->flag & HA_FULLTEXT ? SEARCH_FIND | SEARCH_UPDATE
175 key,key_length,old_root,root_buff)) >0)
179 DBUG_PRINT(
"test",(
"Enlarging of root when deleting"));
180 error=_mi_enlarge_root(info,keyinfo,key,root);
184 if (mi_getint(root_buff) <= (nod_flag=mi_test_if_nod(root_buff))+3)
188 *root=_mi_kpos(nod_flag,root_buff+2+nod_flag);
190 *root=HA_OFFSET_ERROR;
191 if (_mi_dispose(info,keyinfo,old_root,DFLT_INIT_HITS))
195 error=_mi_write_keypage(info,keyinfo,old_root,
196 DFLT_INIT_HITS,root_buff);
200 my_afree((uchar*) root_buff);
201 DBUG_PRINT(
"exit",(
"Return: %d",error));
215 uint comp_flag, uchar *key, uint key_length,
216 my_off_t
page, uchar *anc_buff)
218 int flag,ret_value,save_flag;
219 uint length,nod_flag,search_key_length;
221 uchar *leaf_buff,*keypos;
222 my_off_t UNINIT_VAR(leaf_page),next_block;
223 uchar lastkey[MI_MAX_KEY_BUFF];
224 DBUG_ENTER(
"d_search");
225 DBUG_DUMP(
"page",(uchar*) anc_buff,mi_getint(anc_buff));
227 search_key_length= (comp_flag & SEARCH_FIND) ? key_length : USE_WHOLE_KEY;
228 flag=(*keyinfo->bin_search)(info,keyinfo,anc_buff,key, search_key_length,
229 comp_flag, &keypos, lastkey, &last_key);
230 if (flag == MI_FOUND_WRONG_KEY)
232 DBUG_PRINT(
"error",(
"Found wrong key"));
235 nod_flag=mi_test_if_nod(anc_buff);
237 if (!flag && keyinfo->flag & HA_FULLTEXT)
242 get_key_full_length_rdonly(off, lastkey);
243 subkeys=ft_sintXkorr(lastkey+off);
244 DBUG_ASSERT(info->ft1_to_ft2==0 || subkeys >=0);
245 comp_flag=SEARCH_SAME;
249 if (info->ft1_to_ft2)
252 if (insert_dynamic(info->ft1_to_ft2, (lastkey+off)))
254 DBUG_PRINT(
"error",(
"Out of memory"));
261 flag=(*keyinfo->bin_search)(info,keyinfo,anc_buff,key,USE_WHOLE_KEY,
262 comp_flag, &keypos, lastkey, &last_key);
273 if (!(tmp_key_length=(*keyinfo->get_key)(keyinfo,nod_flag,&kpos,lastkey)))
275 mi_print_error(info->s, HA_ERR_CRASHED);
276 my_errno= HA_ERR_CRASHED;
279 root=_mi_dpos(info,nod_flag,kpos);
283 if (_mi_dispose(info, keyinfo, root,DFLT_INIT_HITS))
289 keyinfo=&info->s->ft2_keyinfo;
290 kpos-=keyinfo->keylength+nod_flag;
291 get_key_full_length_rdonly(off, key);
293 ret_value=_mi_ck_real_delete(info, &info->s->ft2_keyinfo,
294 key, HA_FT_WLEN, &root);
295 _mi_dpointer(info, kpos+HA_FT_WLEN, root);
297 ft_intXstore(kpos, subkeys);
299 ret_value=_mi_write_keypage(info,keyinfo,page,
300 DFLT_INIT_HITS,anc_buff);
301 DBUG_PRINT(
"exit",(
"Return: %d",ret_value));
302 DBUG_RETURN(ret_value);
307 LINT_INIT(leaf_page);
310 leaf_page=_mi_kpos(nod_flag,keypos);
311 if (!(leaf_buff= (uchar*) my_alloca((uint) keyinfo->block_length+
314 DBUG_PRINT(
"error",(
"Couldn't allocate memory"));
316 DBUG_PRINT(
"exit",(
"Return: %d",-1));
319 if (!_mi_fetch_keypage(info,keyinfo,leaf_page,DFLT_INIT_HITS,leaf_buff,0))
327 DBUG_PRINT(
"error",(
"Didn't find key"));
328 mi_print_error(info->s, HA_ERR_CRASHED);
329 my_errno=HA_ERR_CRASHED;
333 ret_value=d_search(info,keyinfo,comp_flag,key,key_length,
334 leaf_page,leaf_buff);
339 length=mi_getint(anc_buff);
340 if (!(tmp= remove_key(keyinfo,nod_flag,keypos,lastkey,anc_buff+length,
346 mi_putint(anc_buff,length,nod_flag);
349 if (_mi_write_keypage(info,keyinfo,page,DFLT_INIT_HITS,anc_buff))
351 DBUG_PRINT(
"exit",(
"Return: %d",-1));
355 DBUG_RETURN(
test(length <= (info->quick_mode ? MI_MIN_KEYBLOCK_LENGTH :
356 (uint) keyinfo->underflow_block_length)));
359 ret_value=del(info,keyinfo,key,anc_buff,leaf_page,leaf_buff,keypos,
366 ret_value= underflow(info,keyinfo,anc_buff,leaf_page,leaf_buff,keypos);
369 DBUG_PRINT(
"test",(
"Enlarging of key when deleting"));
370 if (!_mi_get_last_key(info,keyinfo,anc_buff,lastkey,keypos,&length))
374 ret_value=_mi_insert(info,keyinfo,key,anc_buff,keypos,lastkey,
375 (uchar*) 0,(uchar*) 0,(my_off_t) 0,(my_bool) 0);
378 if (ret_value == 0 && mi_getint(anc_buff) > keyinfo->block_length)
381 ret_value=_mi_split_page(info,keyinfo,key,anc_buff,lastkey,0) | 2;
383 if (save_flag && ret_value != 1)
384 ret_value|=_mi_write_keypage(info,keyinfo,page,DFLT_INIT_HITS,anc_buff);
387 DBUG_DUMP(
"page",(uchar*) anc_buff,mi_getint(anc_buff));
389 my_afree((uchar*) leaf_buff);
390 DBUG_PRINT(
"exit",(
"Return: %d",ret_value));
391 DBUG_RETURN(ret_value);
394 my_afree((uchar*) leaf_buff);
395 DBUG_PRINT(
"exit",(
"Error: %d",my_errno));
402 static int del(
register MI_INFO *info,
register MI_KEYDEF *keyinfo, uchar *key,
403 uchar *anc_buff, my_off_t leaf_page, uchar *leaf_buff,
408 int ret_value,length;
409 uint a_length,nod_flag,tmp;
411 uchar keybuff[MI_MAX_KEY_BUFF],*endpos,*next_buff,*key_start, *prev_key;
415 DBUG_PRINT(
"enter",(
"leaf_page: %ld keypos: 0x%lx", (
long) leaf_page,
417 DBUG_DUMP(
"leaf_buff",(uchar*) leaf_buff,mi_getint(leaf_buff));
419 endpos=leaf_buff+mi_getint(leaf_buff);
420 if (!(key_start=_mi_get_last_key(info,keyinfo,leaf_buff,keybuff,endpos,
424 if ((nod_flag=mi_test_if_nod(leaf_buff)))
426 next_page= _mi_kpos(nod_flag,endpos);
427 if (!(next_buff= (uchar*) my_alloca((uint) keyinfo->block_length+
430 if (!_mi_fetch_keypage(info,keyinfo,next_page,DFLT_INIT_HITS,next_buff,0))
434 DBUG_DUMP(
"next_page",(uchar*) next_buff,mi_getint(next_buff));
435 if ((ret_value=del(info,keyinfo,key,anc_buff,next_page,next_buff,
436 keypos,next_block,ret_key)) >0)
438 endpos=leaf_buff+mi_getint(leaf_buff);
441 ret_value=underflow(info,keyinfo,leaf_buff,next_page,
443 if (ret_value == 0 && mi_getint(leaf_buff) > keyinfo->block_length)
445 ret_value=_mi_split_page(info,keyinfo,key,leaf_buff,ret_key,0) | 2;
450 DBUG_PRINT(
"test",(
"Inserting of key when deleting"));
451 if (!_mi_get_last_key(info,keyinfo,leaf_buff,keybuff,endpos,
454 ret_value=_mi_insert(info,keyinfo,key,leaf_buff,endpos,keybuff,
455 (uchar*) 0,(uchar*) 0,(my_off_t) 0,0);
458 if (_mi_write_keypage(info,keyinfo,leaf_page,DFLT_INIT_HITS,leaf_buff))
461 my_afree((uchar*) next_buff);
462 DBUG_RETURN(ret_value);
467 mi_putint(leaf_buff,key_start-leaf_buff,nod_flag);
468 if (_mi_write_keypage(info,keyinfo,leaf_page,DFLT_INIT_HITS,leaf_buff))
473 a_length=mi_getint(anc_buff);
474 endpos=anc_buff+a_length;
475 if (keypos != anc_buff+2+share->base.key_reflength &&
476 !_mi_get_last_key(info,keyinfo,anc_buff,ret_key,keypos,&tmp))
478 prev_key=(keypos == anc_buff+2+share->base.key_reflength ?
480 length=(*keyinfo->pack_key)(keyinfo,share->base.key_reflength,
481 keypos == endpos ? (uchar*) 0 : keypos,
485 bmove_upp((uchar*) endpos+length,(uchar*) endpos,(uint) (endpos-keypos));
487 bmove(keypos,keypos-length, (
int) (endpos-keypos)+length);
488 (*keyinfo->store_key)(keyinfo,keypos,&s_temp);
490 if (!(*keyinfo->get_key)(keyinfo,share->base.key_reflength,&keypos,ret_key))
492 _mi_kpointer(info,keypos - share->base.key_reflength,next_block);
493 mi_putint(anc_buff,a_length+length,share->base.key_reflength);
495 DBUG_RETURN( mi_getint(leaf_buff) <=
496 (info->quick_mode ? MI_MIN_KEYBLOCK_LENGTH :
497 (uint) keyinfo->underflow_block_length));
512 uint length,anc_length,buff_length,leaf_length,p_length,s_length,nod_flag,
513 key_reflength,key_length;
515 uchar anc_key[MI_MAX_KEY_BUFF],leaf_key[MI_MAX_KEY_BUFF],
516 *buff,*endpos,*next_keypos,*anc_pos,*half_pos,*temp_pos,*prev_key,
520 DBUG_ENTER(
"underflow");
521 DBUG_PRINT(
"enter",(
"leaf_page: %ld keypos: 0x%lx",(
long) leaf_page,
523 DBUG_DUMP(
"anc_buff",(uchar*) anc_buff,mi_getint(anc_buff));
524 DBUG_DUMP(
"leaf_buff",(uchar*) leaf_buff,mi_getint(leaf_buff));
529 nod_flag=mi_test_if_nod(leaf_buff);
531 anc_length=mi_getint(anc_buff);
532 leaf_length=mi_getint(leaf_buff);
533 key_reflength=share->base.key_reflength;
534 if (info->s->keyinfo+info->lastinx == keyinfo)
535 info->page_changed=1;
537 if ((keypos < anc_buff+anc_length && (info->state->records & 1)) ||
538 keypos == anc_buff+2+key_reflength)
540 DBUG_PRINT(
"test",(
"use right page"));
542 if (keyinfo->flag & HA_BINARY_PACK_KEY)
544 if (!(next_keypos=_mi_get_key(info, keyinfo,
545 anc_buff, buff, keypos, &length)))
552 if (!(*keyinfo->get_key)(keyinfo,key_reflength,&next_keypos,
556 next_page= _mi_kpos(key_reflength,next_keypos);
557 if (!_mi_fetch_keypage(info,keyinfo,next_page,DFLT_INIT_HITS,buff,0))
559 buff_length=mi_getint(buff);
560 DBUG_DUMP(
"next",(uchar*) buff,buff_length);
563 bmove((uchar*) next_keypos-key_reflength,(uchar*) buff+2,
565 if (!_mi_get_last_key(info,keyinfo,anc_buff,anc_key,next_keypos,&length)
566 || !_mi_get_last_key(info,keyinfo,leaf_buff,leaf_key,
567 leaf_buff+leaf_length,&length))
571 prev_key=(leaf_length == p_length ? (uchar*) 0 : leaf_key);
572 t_length=(*keyinfo->pack_key)(keyinfo,nod_flag,buff+p_length,
575 length=buff_length-p_length;
576 endpos=buff+length+leaf_length+t_length;
578 bmove_upp((uchar*) endpos, (uchar*) buff+buff_length,length);
579 memcpy((uchar*) buff, (uchar*) leaf_buff,(
size_t) leaf_length);
580 (*keyinfo->store_key)(keyinfo,buff+leaf_length,&s_temp);
581 buff_length=(uint) (endpos-buff);
582 mi_putint(buff,buff_length,nod_flag);
586 if (!(s_length=remove_key(keyinfo,key_reflength,keypos,anc_key,
587 anc_buff+anc_length,(my_off_t *) 0)))
590 anc_length-=s_length;
591 mi_putint(anc_buff,anc_length,key_reflength);
593 if (buff_length <= keyinfo->block_length)
595 memcpy((uchar*) leaf_buff,(uchar*) buff,(
size_t) buff_length);
596 if (_mi_dispose(info,keyinfo,next_page,DFLT_INIT_HITS))
601 endpos=anc_buff+anc_length;
602 DBUG_PRINT(
"test",(
"anc_buff: 0x%lx endpos: 0x%lx",
603 (
long) anc_buff, (
long) endpos));
604 if (keypos != anc_buff+2+key_reflength &&
605 !_mi_get_last_key(info,keyinfo,anc_buff,anc_key,keypos,&length))
607 if (!(half_pos=_mi_find_half_pos(nod_flag, keyinfo, buff, leaf_key,
608 &key_length, &after_key)))
610 length=(uint) (half_pos-buff);
611 memcpy((uchar*) leaf_buff,(uchar*) buff,(
size_t) length);
612 mi_putint(leaf_buff,length,nod_flag);
616 _mi_kpointer(info,leaf_key+key_length,next_page);
618 prev_key=(keypos == anc_buff+2+key_reflength ? (uchar*) 0 : anc_key),
619 t_length=(*keyinfo->pack_key)(keyinfo,key_reflength,
620 (keypos == endpos ? (uchar*) 0 :
625 bmove_upp((uchar*) endpos+t_length,(uchar*) endpos,
626 (uint) (endpos-keypos));
628 bmove(keypos,keypos-t_length,(uint) (endpos-keypos)+t_length);
629 (*keyinfo->store_key)(keyinfo,keypos,&s_temp);
630 mi_putint(anc_buff,(anc_length+=t_length),key_reflength);
634 bmove((uchar*) buff+2,(uchar*) half_pos-nod_flag,(
size_t) nod_flag);
635 if (!(*keyinfo->get_key)(keyinfo,nod_flag,&half_pos,leaf_key))
637 t_length=(int) (*keyinfo->pack_key)(keyinfo, nod_flag, (uchar*) 0,
638 (uchar*) 0, (uchar *) 0,
641 length=(uint) ((buff+mi_getint(buff))-half_pos);
642 bmove((uchar*) buff+p_length+t_length,(uchar*) half_pos,(
size_t) length);
643 (*keyinfo->store_key)(keyinfo,buff+p_length,&s_temp);
644 mi_putint(buff,length+t_length+p_length,nod_flag);
646 if (_mi_write_keypage(info,keyinfo,next_page,DFLT_INIT_HITS,buff))
649 if (_mi_write_keypage(info,keyinfo,leaf_page,DFLT_INIT_HITS,leaf_buff))
651 DBUG_RETURN(anc_length <= ((info->quick_mode ? MI_MIN_BLOCK_LENGTH :
652 (uint) keyinfo->underflow_block_length)));
655 DBUG_PRINT(
"test",(
"use left page"));
657 keypos=_mi_get_last_key(info,keyinfo,anc_buff,anc_key,keypos,&length);
660 next_page= _mi_kpos(key_reflength,keypos);
661 if (!_mi_fetch_keypage(info,keyinfo,next_page,DFLT_INIT_HITS,buff,0))
663 buff_length=mi_getint(buff);
664 endpos=buff+buff_length;
665 DBUG_DUMP(
"prev",(uchar*) buff,buff_length);
668 bmove((uchar*) next_keypos - key_reflength,(uchar*) leaf_buff+2,
671 if (!(*keyinfo->get_key)(keyinfo,key_reflength,&next_keypos,
674 if (!_mi_get_last_key(info,keyinfo,buff,leaf_key,endpos,&length))
678 prev_key=(leaf_length == p_length ? (uchar*) 0 : leaf_key);
679 t_length=(*keyinfo->pack_key)(keyinfo,nod_flag,
680 (leaf_length == p_length ?
681 (uchar*) 0 : leaf_buff+p_length),
685 bmove((uchar*) endpos+t_length,(uchar*) leaf_buff+p_length,
686 (
size_t) (leaf_length-p_length));
688 bmove((uchar*) endpos,(uchar*) leaf_buff+((
int) p_length-t_length),
689 (
size_t) (leaf_length-p_length+t_length));
691 (*keyinfo->store_key)(keyinfo,endpos,&s_temp);
692 buff_length=buff_length+leaf_length-p_length+t_length;
693 mi_putint(buff,buff_length,nod_flag);
696 if (!(s_length= remove_key(keyinfo,key_reflength,keypos,anc_key,
697 anc_buff+anc_length,(my_off_t *) 0)))
700 anc_length-=s_length;
701 mi_putint(anc_buff,anc_length,key_reflength);
703 if (buff_length <= keyinfo->block_length)
705 if (_mi_dispose(info,keyinfo,leaf_page,DFLT_INIT_HITS))
710 if (keypos == anc_buff+2+key_reflength)
712 else if (!_mi_get_last_key(info,keyinfo,anc_buff,anc_pos=anc_key,keypos,
715 endpos=_mi_find_half_pos(nod_flag,keyinfo,buff,leaf_key,
716 &key_length, &half_pos);
719 _mi_kpointer(info,leaf_key+key_length,leaf_page);
721 DBUG_DUMP(
"anc_buff",(uchar*) anc_buff,anc_length);
722 DBUG_DUMP(
"key_to_anc",(uchar*) leaf_key,key_length);
724 temp_pos=anc_buff+anc_length;
725 t_length=(*keyinfo->pack_key)(keyinfo,key_reflength,
726 keypos == temp_pos ? (uchar*) 0
731 bmove_upp((uchar*) temp_pos+t_length,(uchar*) temp_pos,
732 (uint) (temp_pos-keypos));
734 bmove(keypos,keypos-t_length,(uint) (temp_pos-keypos)+t_length);
735 (*keyinfo->store_key)(keyinfo,keypos,&s_temp);
736 mi_putint(anc_buff,(anc_length+=t_length),key_reflength);
740 bmove((uchar*) leaf_buff+2,(uchar*) half_pos-nod_flag,(
size_t) nod_flag);
741 if (!(length=(*keyinfo->get_key)(keyinfo,nod_flag,&half_pos,leaf_key)))
743 DBUG_DUMP(
"key_to_leaf",(uchar*) leaf_key,length);
744 t_length=(*keyinfo->pack_key)(keyinfo,nod_flag, (uchar*) 0,
745 (uchar*) 0, (uchar*) 0, leaf_key, &s_temp);
746 length=(uint) ((buff+buff_length)-half_pos);
747 DBUG_PRINT(
"info",(
"t_length: %d length: %d",t_length,(
int) length));
748 bmove((uchar*) leaf_buff+p_length+t_length,(uchar*) half_pos,
750 (*keyinfo->store_key)(keyinfo,leaf_buff+p_length,&s_temp);
751 mi_putint(leaf_buff,length+t_length+p_length,nod_flag);
752 if (_mi_write_keypage(info,keyinfo,leaf_page,DFLT_INIT_HITS,leaf_buff))
754 mi_putint(buff,endpos-buff,nod_flag);
756 if (_mi_write_keypage(info,keyinfo,next_page,DFLT_INIT_HITS,buff))
758 DBUG_RETURN(anc_length <= (uint) keyinfo->block_length/2);
772 static uint remove_key(
MI_KEYDEF *keyinfo, uint nod_flag,
776 my_off_t *next_block)
780 DBUG_ENTER(
"remove_key");
781 DBUG_PRINT(
"enter",(
"keypos: 0x%lx page_end: 0x%lx",(
long) keypos, (
long) page_end));
784 if (!(keyinfo->flag &
785 (HA_PACK_KEY | HA_SPACE_PACK_USED | HA_VAR_LENGTH_KEY |
786 HA_BINARY_PACK_KEY)))
788 s_length=(int) (keyinfo->keylength+nod_flag);
789 if (next_block && nod_flag)
790 *next_block= _mi_kpos(nod_flag,keypos+s_length);
795 if (!(*keyinfo->get_key)(keyinfo,nod_flag,&keypos,lastkey))
798 if (next_block && nod_flag)
799 *next_block= _mi_kpos(nod_flag,keypos);
800 s_length=(int) (keypos-start);
801 if (keypos != page_end)
803 if (keyinfo->flag & HA_BINARY_PACK_KEY)
805 uchar *old_key=start;
806 uint next_length,prev_length,prev_pack_length;
807 get_key_length(next_length,keypos);
808 get_key_pack_length(prev_length,prev_pack_length,old_key);
809 if (next_length > prev_length)
812 bmove_upp(keypos, (lastkey+next_length),
813 (next_length-prev_length));
814 keypos-=(next_length-prev_length)+prev_pack_length;
815 store_key_length(keypos,prev_length);
816 s_length=(int) (keypos-start);
822 if ((keyinfo->seg->flag & HA_PACK_KEY) && *keypos & 128)
825 uint next_length,prev_length,prev_pack_length,lastkey_length,
827 if (keyinfo->seg[0].length >= 127)
829 if (!(prev_length=mi_uint2korr(start) & 32767))
831 next_length=mi_uint2korr(keypos) & 32767;
837 if (!(prev_length= *start & 127))
839 next_length= *keypos & 127;
845 if (keyinfo->seg[0].flag & HA_NULL_PART)
847 get_key_length(lastkey_length,lastkey);
850 next_length=lastkey_length;
854 get_key_length(rest_length,keypos);
856 if (next_length >= prev_length)
858 uint pack_length,tmp;
859 bmove_upp(keypos, (lastkey+next_length),
860 tmp=(next_length-prev_length));
862 pack_length= prev_length ? get_pack_length(rest_length): 0;
863 keypos-=tmp+pack_length+prev_pack_length;
864 s_length=(int) (keypos-start);
868 if (prev_pack_length == 2)
870 store_key_length(keypos,rest_length);
875 if (keyinfo->seg[0].flag & HA_NULL_PART)
879 if (prev_pack_length == 2)
881 mi_int2store(keypos,rest_length);
884 *keypos= rest_length;
892 bmove((uchar*) start,(uchar*) start+s_length,
893 (uint) (page_end-start-s_length));
894 DBUG_RETURN((uint) s_length);