~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to plugin/myisam/mi_rnext_same.cc

  • Committer: Padraig O'Sullivan
  • Date: 2009-09-13 01:03:01 UTC
  • mto: (1126.9.2 captain-20090915-01)
  • mto: This revision was merged to the branch mainline in revision 1133.
  • Revision ID: osullivan.padraig@gmail.com-20090913010301-tcvvezipx1124acy
Added calls to the dtrace delete begin/end probes.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
/* Copyright (C) 2000-2006 MySQL AB
2
 
 
3
 
   This program is free software; you can redistribute it and/or modify
4
 
   it under the terms of the GNU General Public License as published by
5
 
   the Free Software Foundation; version 2 of the License.
6
 
 
7
 
   This program is distributed in the hope that it will be useful,
8
 
   but WITHOUT ANY WARRANTY; without even the implied warranty of
9
 
   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
10
 
   GNU General Public License for more details.
11
 
 
12
 
   You should have received a copy of the GNU General Public License
13
 
   along with this program; if not, write to the Free Software
14
 
   Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA */
15
 
 
16
 
#include "myisam_priv.h"
17
 
 
18
 
using namespace drizzled;
19
 
 
20
 
        /*
21
 
           Read next row with the same key as previous read, but abort if
22
 
           the key changes.
23
 
           One may have done a write, update or delete of the previous row.
24
 
           NOTE! Even if one changes the previous row, the next read is done
25
 
           based on the position of the last used key!
26
 
        */
27
 
 
28
 
int mi_rnext_same(MI_INFO *info, unsigned char *buf)
29
 
{
30
 
  int error;
31
 
  uint32_t inx,not_used[2];
32
 
  MI_KEYDEF *keyinfo;
33
 
 
34
 
  if ((int) (inx=info->lastinx) < 0 || info->lastpos == HA_OFFSET_ERROR)
35
 
    return(errno=HA_ERR_WRONG_INDEX);
36
 
  keyinfo=info->s->keyinfo+inx;
37
 
  if (fast_mi_readinfo(info))
38
 
    return(errno);
39
 
 
40
 
  if (info->s->concurrent_insert)
41
 
    pthread_rwlock_rdlock(&info->s->key_root_lock[inx]);
42
 
 
43
 
  switch (keyinfo->key_alg)
44
 
  {
45
 
    case HA_KEY_ALG_BTREE:
46
 
    default:
47
 
      if (!(info->update & HA_STATE_RNEXT_SAME))
48
 
      {
49
 
        /* First rnext_same; Store old key */
50
 
        memcpy(info->lastkey2,info->lastkey,info->last_rkey_length);
51
 
      }
52
 
      for (;;)
53
 
      {
54
 
        if ((error=_mi_search_next(info,keyinfo,info->lastkey,
55
 
                               info->lastkey_length,SEARCH_BIGGER,
56
 
                               info->s->state.key_root[inx])))
57
 
          break;
58
 
        if (ha_key_cmp(keyinfo->seg, info->lastkey, info->lastkey2,
59
 
                       info->last_rkey_length, SEARCH_FIND, not_used))
60
 
        {
61
 
          error=1;
62
 
          errno=HA_ERR_END_OF_FILE;
63
 
          info->lastpos= HA_OFFSET_ERROR;
64
 
          break;
65
 
        }
66
 
        /* Skip rows that are inserted by other threads since we got a lock */
67
 
        if (info->lastpos < info->state->data_file_length &&
68
 
            (!info->index_cond_func || mi_check_index_cond(info, inx, buf)))
69
 
          break;
70
 
      }
71
 
  }
72
 
  if (info->s->concurrent_insert)
73
 
    pthread_rwlock_unlock(&info->s->key_root_lock[inx]);
74
 
        /* Don't clear if database-changed */
75
 
  info->update&= (HA_STATE_CHANGED | HA_STATE_ROW_CHANGED);
76
 
  info->update|= HA_STATE_NEXT_FOUND | HA_STATE_RNEXT_SAME;
77
 
 
78
 
  if (error)
79
 
  {
80
 
    if (errno == HA_ERR_KEY_NOT_FOUND)
81
 
      errno=HA_ERR_END_OF_FILE;
82
 
  }
83
 
  else if (!buf)
84
 
  {
85
 
    return(info->lastpos==HA_OFFSET_ERROR ? errno : 0);
86
 
  }
87
 
  else if (!(*info->read_record)(info,info->lastpos,buf))
88
 
  {
89
 
    info->update|= HA_STATE_AKTIV;              /* Record is read */
90
 
    return(0);
91
 
  }
92
 
  return(errno);
93
 
} /* mi_rnext_same */