*** myisam/mi_range.c Sun Feb 11 00:10:49 2007 --- ../mysql-5.0.34/myisam/mi_range.c Wed Jan 17 09:51:56 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,58 **** key_range *max_key) { ha_rows start_pos,end_pos,res; - int non_key_hit; DBUG_ENTER("mi_records_in_range"); if ((inx = _mi_check_index(info,inx)) < 0) --- 52,57 ---- *************** *** 98,117 **** #endif case HA_KEY_ALG_BTREE: default: - - non_key_hit = 0; start_pos= (min_key ? _mi_record_pos(info, min_key->key, min_key->length, ! min_key->flag, &non_key_hit) : (ha_rows) 0); end_pos= (max_key ? ! _mi_record_pos(info, max_key->key, max_key->length, ! max_key->flag, &non_key_hit) ! : info->state->records+ (ha_rows) 1); ! res= ( end_pos < start_pos ! ? (ha_rows) 0 ! : ( end_pos == start_pos ? ( non_key_hit == 2 ? (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; } --- 97,112 ---- #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; } *************** *** 128,134 **** /* 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; *************** *** 151,157 **** 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))); *************** *** 167,175 **** 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; *************** *** 179,188 **** DBUG_ENTER("_mi_search_pos"); LINT_INIT(max_keynr); ! if (pos == HA_OFFSET_ERROR) { ! *non_key_hit = (*non_key_hit) +1; ! DBUG_RETURN(0.5); ! } if (!(buff=_mi_fetch_keypage(info,keyinfo,pos,DFLT_INIT_HITS,info->buff,1))) goto err; --- 172,179 ---- 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; *************** *** 200,211 **** Try to find a smaller, better matching key. Matches keynr + [0-1] */ ! if (flag > 0 && ! nod_flag) { ! // *non_key_hit = (*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 *************** *** 224,230 **** 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 */ } } --- 213,219 ---- 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 */ } }