*** ../myisam/mi_range.c Sun Feb 11 20:08:43 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_hit; - int keys_equal; DBUG_ENTER("mi_records_in_range"); if ((inx = _mi_check_index(info,inx)) < 0) --- 52,57 ---- *************** *** 99,136 **** #endif case HA_KEY_ALG_BTREE: default: - - non_key_hit = 0; - 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 ) - keys_equal = 1; - 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); ! ! DBUG_PRINT("info",("XXX 2nd non hit: %d / %d ", non_key_hit, keys_equal)); ! ! res= ( end_pos < start_pos ! ? (ha_rows) 0 ! : ( end_pos == start_pos ! ? ( keys_equal == 1 && 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; } - - DBUG_PRINT("info",("XXX records: %ld start_pos: %ld end_pos: %ld non_hit: %d",(ulong) (res),(ulong) (start_pos), (ulong) (end_pos), non_key_hit)); - - if (info->s->concurrent_insert) rw_unlock(&info->s->key_root_lock[inx]); --- 97,115 ---- #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]); *************** *** 144,150 **** /* 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; *************** *** 167,173 **** 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))); *************** *** 183,191 **** 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; *************** *** 195,204 **** 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; *************** *** 216,227 **** 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 *************** *** 240,246 **** 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 */ } }