12
12
You should have received a copy of the GNU General Public License
13
13
along with this program; if not, write to the Free Software
14
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA */
14
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */
17
17
Gives a approximated number of how many records there is between two keys.
18
18
Used when optimizing querries.
21
#include "myisam_priv.h"
23
using namespace drizzled;
25
static ha_rows _mi_record_pos(MI_INFO *, const unsigned char *, key_part_map,
21
#include "myisamdef.h"
23
static ha_rows _mi_record_pos(MI_INFO *, const uchar *, key_part_map,
26
24
enum ha_rkey_function);
27
static double _mi_search_pos(MI_INFO *,MI_KEYDEF *,unsigned char *, uint,uint,internal::my_off_t);
28
static uint32_t _mi_keynr(MI_INFO *info,MI_KEYDEF *,unsigned char *, unsigned char *,uint32_t *);
25
static double _mi_search_pos(MI_INFO *,MI_KEYDEF *,uchar *, uint,uint,my_off_t);
26
static uint _mi_keynr(MI_INFO *info,MI_KEYDEF *,uchar *, uchar *,uint *);
31
29
Estimate how many records there is in a given range
44
42
HA_POS_ERROR error (or we can't estimate number of rows)
45
43
number Estimated number of rows
48
46
ha_rows mi_records_in_range(MI_INFO *info, int inx,
49
47
key_range *min_key, key_range *max_key)
56
54
if (fast_mi_readinfo(info))
57
55
return(HA_POS_ERROR);
58
56
info->update&= (HA_STATE_CHANGED+HA_STATE_ROW_CHANGED);
57
if (info->s->concurrent_insert)
58
rw_rdlock(&info->s->key_root_lock[inx]);
60
60
switch(info->s->keyinfo[inx].key_alg){
61
61
case HA_KEY_ALG_BTREE:
81
83
/* Find relative position (in records) for key in index-tree */
83
static ha_rows _mi_record_pos(MI_INFO *info, const unsigned char *key,
85
static ha_rows _mi_record_pos(MI_INFO *info, const uchar *key,
84
86
key_part_map keypart_map,
85
87
enum ha_rkey_function search_flag)
87
uint32_t inx=(uint) info->lastinx, nextflag, key_len;
89
uint inx=(uint) info->lastinx, nextflag, key_len;
88
90
MI_KEYDEF *keyinfo=info->s->keyinfo+inx;
89
unsigned char *key_buff;
92
94
assert(keypart_map);
94
96
key_buff=info->lastkey+info->s->base.max_key_length;
95
key_len=_mi_pack_key(info,inx,key_buff,(unsigned char*) key, keypart_map,
97
key_len=_mi_pack_key(info,inx,key_buff,(uchar*) key, keypart_map,
97
99
nextflag=myisam_read_vec[search_flag];
98
100
if (!(nextflag & (SEARCH_FIND | SEARCH_NO_FIND | SEARCH_LAST)))
149
151
static double _mi_search_pos(register MI_INFO *info,
150
152
register MI_KEYDEF *keyinfo,
151
unsigned char *key, uint32_t key_len, uint32_t nextflag,
152
register internal::my_off_t pos)
153
uchar *key, uint key_len, uint nextflag,
154
register my_off_t pos)
155
uint32_t nod_flag, keynr, max_keynr= 0;
157
unsigned char *keypos,*buff;
157
uint nod_flag, keynr, max_keynr= 0;
160
162
if (pos == HA_OFFSET_ERROR)
211
213
/* Get keynummer of current key and max number of keys in nod */
213
static uint32_t _mi_keynr(MI_INFO *info, register MI_KEYDEF *keyinfo, unsigned char *page,
214
unsigned char *keypos, uint32_t *ret_max_key)
215
static uint _mi_keynr(MI_INFO *info, register MI_KEYDEF *keyinfo, uchar *page,
216
uchar *keypos, uint *ret_max_key)
216
uint32_t nod_flag,keynr,max_key;
217
unsigned char t_buff[MI_MAX_KEY_BUFF],*end;
218
uint nod_flag,keynr,max_key;
219
uchar t_buff[MI_MAX_KEY_BUFF],*end;
219
221
end= page+mi_getint(page);
220
222
nod_flag=mi_test_if_nod(page);