~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to storage/myisam/mi_rkey.c

  • Committer: Brian Aker
  • Date: 2008-07-07 14:25:25 UTC
  • mto: (77.1.25 codestyle)
  • mto: This revision was merged to the branch mainline in revision 82.
  • Revision ID: brian@tangent.org-20080707142525-xzy2nl3ie2ebwfln
LL() cleanup

Show diffs side-by-side

added added

removed removed

Lines of Context:
20
20
        /* Read a record using key */
21
21
        /* Ordinary search_flag is 0 ; Give error if no record with key */
22
22
 
23
 
int mi_rkey(MI_INFO *info, unsigned char *buf, int inx, const unsigned char *key,
 
23
int mi_rkey(MI_INFO *info, uchar *buf, int inx, const uchar *key,
24
24
            key_part_map keypart_map, enum ha_rkey_function search_flag)
25
25
{
26
 
  unsigned char *key_buff;
 
26
  uchar *key_buff;
27
27
  MYISAM_SHARE *share=info->s;
28
28
  MI_KEYDEF *keyinfo;
29
29
  HA_KEYSEG *last_used_keyseg;
30
 
  uint32_t pack_key_length, use_key_length, nextflag;
31
 
  uint32_t myisam_search_flag;
 
30
  uint pack_key_length, use_key_length, nextflag;
 
31
  uint myisam_search_flag;
32
32
  int res= 0;
 
33
  DBUG_ENTER("mi_rkey");
 
34
  DBUG_PRINT("enter", ("base: 0x%lx  buf: 0x%lx  inx: %d  search_flag: %d",
 
35
                       (long) info, (long) buf, inx, search_flag));
33
36
 
34
37
  if ((inx = _mi_check_index(info,inx)) < 0)
35
 
    return(my_errno);
 
38
    DBUG_RETURN(my_errno);
36
39
 
37
40
  info->update&= (HA_STATE_CHANGED | HA_STATE_ROW_CHANGED);
38
41
  info->last_key_func= search_flag;
47
50
    */
48
51
    key_buff=info->lastkey+info->s->base.max_key_length;
49
52
    pack_key_length= keypart_map;
50
 
    memcpy(key_buff, key, pack_key_length);
 
53
    bmove(key_buff, key, pack_key_length);
51
54
    last_used_keyseg= info->s->keyinfo[inx].seg + info->last_used_keyseg;
52
55
  }
53
56
  else
54
57
  {
55
 
    assert(keypart_map);
 
58
    DBUG_ASSERT(keypart_map);
56
59
    /* Save the packed key for later use in the second buffer of lastkey. */
57
60
    key_buff=info->lastkey+info->s->base.max_key_length;
58
 
    pack_key_length=_mi_pack_key(info,(uint) inx, key_buff, (unsigned char*) key,
 
61
    pack_key_length=_mi_pack_key(info,(uint) inx, key_buff, (uchar*) key,
59
62
                                 keypart_map, &last_used_keyseg);
60
63
    /* Save packed_key_length for use by the MERGE engine. */
61
64
    info->pack_key_length= pack_key_length;
62
 
    info->last_used_keyseg= (uint16_t) (last_used_keyseg -
 
65
    info->last_used_keyseg= (uint16) (last_used_keyseg -
63
66
                                      info->s->keyinfo[inx].seg);
 
67
    DBUG_EXECUTE("key",_mi_print_key(DBUG_FILE, keyinfo->seg,
 
68
                                     key_buff, pack_key_length););
64
69
  }
65
70
 
66
71
  if (fast_mi_readinfo(info))
104
109
             (info->index_cond_func && 
105
110
              !(res= mi_check_index_cond(info, inx, buf))))
106
111
      {
107
 
        uint32_t not_used[2];
 
112
        uint not_used[2];
108
113
        /*
109
114
          Skip rows that are inserted by other threads since we got a lock
110
115
          Note that this can only happen if we are not searching after an
135
140
        info->lastpos= HA_OFFSET_ERROR;
136
141
        if (share->concurrent_insert)
137
142
          rw_unlock(&share->key_root_lock[inx]);
138
 
        return((my_errno= HA_ERR_KEY_NOT_FOUND));
 
143
        DBUG_RETURN((my_errno= HA_ERR_KEY_NOT_FOUND));
139
144
      }
140
145
      /*
141
146
        Error if no row found within the data file. (Bug #29838)
162
167
 
163
168
  /* Check if we don't want to have record back, only error message */
164
169
  if (!buf)
165
 
    return(info->lastpos == HA_OFFSET_ERROR ? my_errno : 0);
 
170
    DBUG_RETURN(info->lastpos == HA_OFFSET_ERROR ? my_errno : 0);
166
171
 
167
172
  if (!(*info->read_record)(info,info->lastpos,buf))
168
173
  {
169
174
    info->update|= HA_STATE_AKTIV;              /* Record is read */
170
 
    return(0);
 
175
    DBUG_RETURN(0);
171
176
  }
172
177
 
173
178
  info->lastpos = HA_OFFSET_ERROR;              /* Didn't find key */
175
180
  /* Store last used key as a base for read next */
176
181
  memcpy(info->lastkey,key_buff,pack_key_length);
177
182
  info->last_rkey_length= pack_key_length;
178
 
  memset(info->lastkey+pack_key_length, 0, info->s->base.rec_reflength);
 
183
  bzero((char*) info->lastkey+pack_key_length,info->s->base.rec_reflength);
179
184
  info->lastkey_length=pack_key_length+info->s->base.rec_reflength;
180
185
 
181
186
  if (search_flag == HA_READ_AFTER_KEY)
182
187
    info->update|=HA_STATE_NEXT_FOUND;          /* Previous gives last row */
183
188
err:
184
 
  return(my_errno);
 
189
  DBUG_RETURN(my_errno);
185
190
} /* _mi_rkey */