~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to storage/myisam/mi_range.c

  • Committer: Brian Aker
  • Date: 2008-07-16 01:30:24 UTC
  • Revision ID: brian@tangent.org-20080716013024-nmnogwdpa459jrch
First pass of cleanup

Show diffs side-by-side

added added

removed removed

Lines of Context:
20
20
 
21
21
#include "myisamdef.h"
22
22
 
23
 
static ha_rows _mi_record_pos(MI_INFO *, const unsigned char *, key_part_map,
 
23
static ha_rows _mi_record_pos(MI_INFO *, const uchar *, key_part_map,
24
24
                              enum ha_rkey_function);
25
 
static double _mi_search_pos(MI_INFO *,MI_KEYDEF *,unsigned char *, uint,uint,my_off_t);
26
 
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 *);
27
27
 
28
28
/*
29
29
  Estimate how many records there is in a given range
47
47
                            key_range *min_key, key_range *max_key)
48
48
{
49
49
  ha_rows start_pos,end_pos,res;
 
50
  DBUG_ENTER("mi_records_in_range");
50
51
 
51
52
  if ((inx = _mi_check_index(info,inx)) < 0)
52
 
    return(HA_POS_ERROR);
 
53
    DBUG_RETURN(HA_POS_ERROR);
53
54
 
54
55
  if (fast_mi_readinfo(info))
55
 
    return(HA_POS_ERROR);
 
56
    DBUG_RETURN(HA_POS_ERROR);
56
57
  info->update&= (HA_STATE_CHANGED+HA_STATE_ROW_CHANGED);
57
58
  if (info->s->concurrent_insert)
58
59
    rw_rdlock(&info->s->key_root_lock[inx]);
76
77
    rw_unlock(&info->s->key_root_lock[inx]);
77
78
  fast_mi_writeinfo(info);
78
79
 
79
 
  return(res);
 
80
  DBUG_PRINT("info",("records: %ld",(ulong) (res)));
 
81
  DBUG_RETURN(res);
80
82
}
81
83
 
82
84
 
83
85
        /* Find relative position (in records) for key in index-tree */
84
86
 
85
 
static ha_rows _mi_record_pos(MI_INFO *info, const unsigned char *key,
 
87
static ha_rows _mi_record_pos(MI_INFO *info, const uchar *key,
86
88
                              key_part_map keypart_map,
87
89
                              enum ha_rkey_function search_flag)
88
90
{
89
 
  uint32_t inx=(uint) info->lastinx, nextflag, key_len;
 
91
  uint inx=(uint) info->lastinx, nextflag, key_len;
90
92
  MI_KEYDEF *keyinfo=info->s->keyinfo+inx;
91
 
  unsigned char *key_buff;
 
93
  uchar *key_buff;
92
94
  double pos;
93
95
 
94
 
  assert(keypart_map);
 
96
  DBUG_ENTER("_mi_record_pos");
 
97
  DBUG_PRINT("enter",("search_flag: %d",search_flag));
 
98
  DBUG_ASSERT(keypart_map);
95
99
 
96
100
  key_buff=info->lastkey+info->s->base.max_key_length;
97
 
  key_len=_mi_pack_key(info,inx,key_buff,(unsigned char*) key, keypart_map,
 
101
  key_len=_mi_pack_key(info,inx,key_buff,(uchar*) key, keypart_map,
98
102
                       (HA_KEYSEG**) 0);
 
103
  DBUG_EXECUTE("key",_mi_print_key(DBUG_FILE,keyinfo->seg,
 
104
                                    (uchar*) key_buff,key_len););
99
105
  nextflag=myisam_read_vec[search_flag];
100
106
  if (!(nextflag & (SEARCH_FIND | SEARCH_NO_FIND | SEARCH_LAST)))
101
107
    key_len=USE_WHOLE_KEY;
139
145
                     info->s->state.key_root[inx]);
140
146
  if (pos >= 0.0)
141
147
  {
142
 
    return((uint32_t) (pos*info->state->records+0.5));
 
148
    DBUG_PRINT("exit",("pos: %ld",(ulong) (pos*info->state->records)));
 
149
    DBUG_RETURN((ulong) (pos*info->state->records+0.5));
143
150
  }
144
 
  return(HA_POS_ERROR);
 
151
  DBUG_RETURN(HA_POS_ERROR);
145
152
}
146
153
 
147
154
 
150
157
 
151
158
static double _mi_search_pos(register MI_INFO *info,
152
159
                             register MI_KEYDEF *keyinfo,
153
 
                             unsigned char *key, uint32_t key_len, uint32_t nextflag,
 
160
                             uchar *key, uint key_len, uint nextflag,
154
161
                             register my_off_t pos)
155
162
{
156
163
  int flag;
157
 
  uint32_t nod_flag, keynr, max_keynr= 0;
158
 
  bool after_key;
159
 
  unsigned char *keypos,*buff;
 
164
  uint nod_flag, keynr, max_keynr= 0;
 
165
  my_bool after_key;
 
166
  uchar *keypos,*buff;
160
167
  double offset;
 
168
  DBUG_ENTER("_mi_search_pos");
161
169
 
162
170
  if (pos == HA_OFFSET_ERROR)
163
 
    return(0.5);
 
171
    DBUG_RETURN(0.5);
164
172
 
165
173
  if (!(buff=_mi_fetch_keypage(info,keyinfo,pos,DFLT_INIT_HITS,info->buff,1)))
166
174
    goto err;
172
180
  if (flag)
173
181
  {
174
182
    if (flag == MI_FOUND_WRONG_KEY)
175
 
      return(-1);                               /* error */
 
183
      DBUG_RETURN(-1);                          /* error */
176
184
    /*
177
185
      Didn't found match. keypos points at next (bigger) key
178
186
      Try to find a smaller, better matching key.
182
190
      offset= 1.0;
183
191
    else if ((offset=_mi_search_pos(info,keyinfo,key,key_len,nextflag,
184
192
                                    _mi_kpos(nod_flag,keypos))) < 0)
185
 
      return(offset);
 
193
      DBUG_RETURN(offset);
186
194
  }
187
195
  else
188
196
  {
201
209
      */
202
210
      if ((offset=_mi_search_pos(info,keyinfo,key,key_len,SEARCH_FIND,
203
211
                                 _mi_kpos(nod_flag,keypos))) < 0)
204
 
        return(offset);                 /* Read error */
 
212
        DBUG_RETURN(offset);                    /* Read error */
205
213
    }
206
214
  }
207
 
  return((keynr+offset)/(max_keynr+1));
 
215
  DBUG_PRINT("info",("keynr: %d  offset: %g  max_keynr: %d  nod: %d  flag: %d",
 
216
                     keynr,offset,max_keynr,nod_flag,flag));
 
217
  DBUG_RETURN((keynr+offset)/(max_keynr+1));
208
218
err:
209
 
  return (-1.0);
 
219
  DBUG_PRINT("exit",("Error: %d",my_errno));
 
220
  DBUG_RETURN (-1.0);
210
221
}
211
222
 
212
223
 
213
224
        /* Get keynummer of current key and max number of keys in nod */
214
225
 
215
 
static uint32_t _mi_keynr(MI_INFO *info, register MI_KEYDEF *keyinfo, unsigned char *page,
216
 
                      unsigned char *keypos, uint32_t *ret_max_key)
 
226
static uint _mi_keynr(MI_INFO *info, register MI_KEYDEF *keyinfo, uchar *page,
 
227
                      uchar *keypos, uint *ret_max_key)
217
228
{
218
 
  uint32_t nod_flag,keynr,max_key;
219
 
  unsigned char t_buff[MI_MAX_KEY_BUFF],*end;
 
229
  uint nod_flag,keynr,max_key;
 
230
  uchar t_buff[MI_MAX_KEY_BUFF],*end;
220
231
 
221
232
  end= page+mi_getint(page);
222
233
  nod_flag=mi_test_if_nod(page);