*** ../myisam/mi_range.c Tue Feb 13 23:24:00 2007 --- ../../mysql-5.0.bk-orig/myisam/mi_range.c Sat Feb 10 15:13:55 2007 *************** *** 22,30 **** #include "rt_index.h" static ha_rows _mi_record_pos(MI_INFO *info,const byte *key,uint key_len, ! enum ha_rkey_function search_flag, int *xxx); static double _mi_search_pos(MI_INFO *info,MI_KEYDEF *keyinfo,uchar *key, ! uint key_len,uint nextflag,my_off_t pos, int *xxx); static uint _mi_keynr(MI_INFO *info,MI_KEYDEF *keyinfo,uchar *page, uchar *keypos,uint *ret_max_key); --- 22,30 ---- #include "rt_index.h" static ha_rows _mi_record_pos(MI_INFO *info,const byte *key,uint key_len, ! enum ha_rkey_function search_flag); static double _mi_search_pos(MI_INFO *info,MI_KEYDEF *keyinfo,uchar *key, ! uint key_len,uint nextflag,my_off_t pos); static uint _mi_keynr(MI_INFO *info,MI_KEYDEF *keyinfo,uchar *page, uchar *keypos,uint *ret_max_key); *************** *** 52,59 **** key_range *max_key) { ha_rows start_pos,end_pos,res; - int non_key_hit1, non_key_hit2; - int keys_equal; DBUG_ENTER("mi_records_in_range"); if ((inx = _mi_check_index(info,inx)) < 0) --- 52,57 ---- *************** *** 99,147 **** #endif case HA_KEY_ALG_BTREE: default: - - keys_equal = 0; - if( min_key && max_key - && min_key->length == max_key->length - && memcmp(min_key->key, max_key->key, min_key->length) == 0 - && (min_key->flag == HA_READ_KEY_EXACT && max_key->flag == HA_READ_AFTER_KEY) - ) - keys_equal = 1; - - non_key_hit1 = 0; start_pos= (min_key ? _mi_record_pos(info, min_key->key, min_key->length, ! min_key->flag, &non_key_hit1) : (ha_rows) 0); ! ! non_key_hit2 = 0; ! if(keys_equal == 1 && non_key_hit1 == 1 && max_key) { ! end_pos=start_pos; ! non_key_hit2 = 2; // just for the dbug print ! } else { ! end_pos= (max_key ? _mi_record_pos(info, max_key->key, max_key->length, ! max_key->flag, &non_key_hit2) : ! info->state->records+ (ha_rows) 1); ! } ! ! res= ( end_pos < start_pos ! ? (ha_rows) 0 ! : ( end_pos == start_pos ! ? ( keys_equal == 1 && non_key_hit1 >= 1 && non_key_hit2 >= 1 ? (ha_rows) 0 : (ha_rows) 1 ) ! : end_pos-start_pos ! ) ! ); ! ! if (start_pos == HA_POS_ERROR || end_pos == HA_POS_ERROR) ! res=HA_POS_ERROR; } ! ! if (info->s->concurrent_insert) rw_unlock(&info->s->key_root_lock[inx]); fast_mi_writeinfo(info); ! DBUG_PRINT("info",("records: %ld start_pos: %ld end_pos: %ld equal: %d non_hit: %d %d",(ulong) (res),(ulong) (start_pos), (ulong) (end_pos), keys_equal, non_key_hit1, non_key_hit2)); DBUG_RETURN(res); } --- 97,121 ---- #endif case HA_KEY_ALG_BTREE: default: start_pos= (min_key ? _mi_record_pos(info, min_key->key, min_key->length, ! min_key->flag) : (ha_rows) 0); ! end_pos= (max_key ? _mi_record_pos(info, max_key->key, max_key->length, ! max_key->flag) : ! info->state->records+ (ha_rows) 1); ! res= (end_pos < start_pos ? (ha_rows) 0 : ! (end_pos == start_pos ? (ha_rows) 1 : end_pos-start_pos)); ! if (start_pos == HA_POS_ERROR || end_pos == HA_POS_ERROR) ! res=HA_POS_ERROR; } ! ! if (info->s->concurrent_insert) rw_unlock(&info->s->key_root_lock[inx]); fast_mi_writeinfo(info); ! DBUG_PRINT("info",("records: %ld",(ulong) (res))); DBUG_RETURN(res); } *************** *** 149,155 **** /* Find relative position (in records) for key in index-tree */ static ha_rows _mi_record_pos(MI_INFO *info, const byte *key, uint key_len, ! enum ha_rkey_function search_flag, int *non_key_hit) { uint inx=(uint) info->lastinx, nextflag; MI_KEYDEF *keyinfo=info->s->keyinfo+inx; --- 123,129 ---- /* Find relative position (in records) for key in index-tree */ static ha_rows _mi_record_pos(MI_INFO *info, const byte *key, uint key_len, ! enum ha_rkey_function search_flag) { uint inx=(uint) info->lastinx, nextflag; MI_KEYDEF *keyinfo=info->s->keyinfo+inx; *************** *** 172,178 **** pos=_mi_search_pos(info,keyinfo,key_buff,key_len, nextflag | SEARCH_SAVE_BUFF, ! info->s->state.key_root[inx], non_key_hit); if (pos >= 0.0) { DBUG_PRINT("exit",("pos: %ld",(ulong) (pos*info->state->records))); --- 146,152 ---- pos=_mi_search_pos(info,keyinfo,key_buff,key_len, nextflag | SEARCH_SAVE_BUFF, ! info->s->state.key_root[inx]); if (pos >= 0.0) { DBUG_PRINT("exit",("pos: %ld",(ulong) (pos*info->state->records))); *************** *** 188,196 **** static double _mi_search_pos(register MI_INFO *info, register MI_KEYDEF *keyinfo, uchar *key, uint key_len, uint nextflag, ! register my_off_t pos, ! int *non_key_hit ! ) { int flag; uint nod_flag,keynr,max_keynr; --- 162,168 ---- static double _mi_search_pos(register MI_INFO *info, register MI_KEYDEF *keyinfo, uchar *key, uint key_len, uint nextflag, ! register my_off_t pos) { int flag; uint nod_flag,keynr,max_keynr; *************** *** 200,213 **** DBUG_ENTER("_mi_search_pos"); LINT_INIT(max_keynr); ! if (pos == HA_OFFSET_ERROR) { ! *non_key_hit = 1; ! DBUG_RETURN(0.5); ! } if (!(buff=_mi_fetch_keypage(info,keyinfo,pos,DFLT_INIT_HITS,info->buff,1))) goto err; - flag=(*keyinfo->bin_search)(info,keyinfo,buff,key,key_len,nextflag, &keypos,info->lastkey, &after_key); nod_flag=mi_test_if_nod(buff); --- 172,182 ---- DBUG_ENTER("_mi_search_pos"); LINT_INIT(max_keynr); ! if (pos == HA_OFFSET_ERROR) ! DBUG_RETURN(0.5); if (!(buff=_mi_fetch_keypage(info,keyinfo,pos,DFLT_INIT_HITS,info->buff,1))) goto err; flag=(*keyinfo->bin_search)(info,keyinfo,buff,key,key_len,nextflag, &keypos,info->lastkey, &after_key); nod_flag=mi_test_if_nod(buff); *************** *** 222,233 **** Try to find a smaller, better matching key. Matches keynr + [0-1] */ ! if (flag > 0 && ! nod_flag) { ! *non_key_hit = 1; ! offset = 1.0; ! } ! else if ((offset=_mi_search_pos(info, keyinfo, key, key_len, nextflag, ! _mi_kpos(nod_flag,keypos), non_key_hit)) < 0) DBUG_RETURN(offset); } else --- 191,200 ---- Try to find a smaller, better matching key. Matches keynr + [0-1] */ ! if (flag > 0 && ! nod_flag) ! offset= 1.0; ! else if ((offset=_mi_search_pos(info,keyinfo,key,key_len,nextflag, ! _mi_kpos(nod_flag,keypos))) < 0) DBUG_RETURN(offset); } else *************** *** 246,258 **** Matches keynr + [0-1] */ if ((offset=_mi_search_pos(info,keyinfo,key,key_len,SEARCH_FIND, ! _mi_kpos(nod_flag,keypos),non_key_hit)) < 0) DBUG_RETURN(offset); /* Read error */ - *non_key_hit = 0; // we do have a match } } ! DBUG_PRINT("info",("keynr: %d offset: %g max_keynr: %d nod: %d flag: %d nextflag: %d", ! keynr,offset,max_keynr,nod_flag,flag, nextflag)); DBUG_RETURN((keynr+offset)/(max_keynr+1)); err: DBUG_PRINT("exit",("Error: %d",my_errno)); --- 213,224 ---- Matches keynr + [0-1] */ if ((offset=_mi_search_pos(info,keyinfo,key,key_len,SEARCH_FIND, ! _mi_kpos(nod_flag,keypos))) < 0) DBUG_RETURN(offset); /* Read error */ } } ! DBUG_PRINT("info",("keynr: %d offset: %g max_keynr: %d nod: %d flag: %d", ! keynr,offset,max_keynr,nod_flag,flag)); DBUG_RETURN((keynr+offset)/(max_keynr+1)); err: DBUG_PRINT("exit",("Error: %d",my_errno));