~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to storage/myisam/mi_range.c

  • Committer: Jim Winstead
  • Date: 2008-07-19 02:56:45 UTC
  • mto: (202.1.8 codestyle)
  • mto: This revision was merged to the branch mainline in revision 207.
  • Revision ID: jimw@mysql.com-20080719025645-w2pwytebgzusjzjb
Various fixes to enable compilation on Mac OS X, and remove the glib dependency.
Temporarily disables tab-completion in the drizzle client until an appropriate
autoconf check can be added/enabled.

Show diffs side-by-side

added added

removed removed

Lines of Context:
11
11
 
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 */
15
15
 
16
16
/*
17
17
  Gives a approximated number of how many records there is between two keys.
18
18
  Used when optimizing querries.
19
19
 */
20
20
 
21
 
#include "myisam_priv.h"
22
 
 
23
 
using namespace drizzled;
24
 
 
25
 
static ha_rows _mi_record_pos(MI_INFO *, const unsigned char *, key_part_map,
 
21
#include "myisamdef.h"
 
22
 
 
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 *);
29
27
 
30
28
/*
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
46
44
*/
47
 
 
 
45
  
48
46
ha_rows mi_records_in_range(MI_INFO *info, int inx,
49
47
                            key_range *min_key, key_range *max_key)
50
48
{
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]);
59
59
 
60
60
  switch(info->s->keyinfo[inx].key_alg){
61
61
  case HA_KEY_ALG_BTREE:
72
72
      res=HA_POS_ERROR;
73
73
  }
74
74
 
 
75
  if (info->s->concurrent_insert)
 
76
    rw_unlock(&info->s->key_root_lock[inx]);
75
77
  fast_mi_writeinfo(info);
76
78
 
77
79
  return(res);
80
82
 
81
83
        /* Find relative position (in records) for key in index-tree */
82
84
 
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)
86
88
{
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;
 
91
  uchar *key_buff;
90
92
  double pos;
91
93
 
92
94
  assert(keypart_map);
93
95
 
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,
96
98
                       (HA_KEYSEG**) 0);
97
99
  nextflag=myisam_read_vec[search_flag];
98
100
  if (!(nextflag & (SEARCH_FIND | SEARCH_NO_FIND | SEARCH_LAST)))
137
139
                     info->s->state.key_root[inx]);
138
140
  if (pos >= 0.0)
139
141
  {
140
 
    return((uint32_t) (pos*info->state->records+0.5));
 
142
    return((ulong) (pos*info->state->records+0.5));
141
143
  }
142
144
  return(HA_POS_ERROR);
143
145
}
148
150
 
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)
153
155
{
154
156
  int flag;
155
 
  uint32_t nod_flag, keynr, max_keynr= 0;
156
 
  bool after_key;
157
 
  unsigned char *keypos,*buff;
 
157
  uint nod_flag, keynr, max_keynr= 0;
 
158
  my_bool after_key;
 
159
  uchar *keypos,*buff;
158
160
  double offset;
159
161
 
160
162
  if (pos == HA_OFFSET_ERROR)
210
212
 
211
213
        /* Get keynummer of current key and max number of keys in nod */
212
214
 
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)
215
217
{
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;
218
220
 
219
221
  end= page+mi_getint(page);
220
222
  nod_flag=mi_test_if_nod(page);