~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to plugin/myisam/mi_rprev.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-2001, 2004 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
 
        /*
19
 
           Read previous row with the same key as previous read
20
 
           One may have done a write, update or delete of the previous row.
21
 
           NOTE! Even if one changes the previous row, the next read is done
22
 
           based on the position of the last used key!
23
 
        */
24
 
 
25
 
int mi_rprev(MI_INFO *info, unsigned char *buf, int inx)
26
 
{
27
 
  int error,changed;
28
 
  register uint32_t flag;
29
 
  MYISAM_SHARE *share=info->s;
30
 
 
31
 
  if ((inx = _mi_check_index(info,inx)) < 0)
32
 
    return(errno);
33
 
  flag=SEARCH_SMALLER;                          /* Read previous */
34
 
  if (info->lastpos == HA_OFFSET_ERROR && info->update & HA_STATE_NEXT_FOUND)
35
 
    flag=0;                                     /* Read last */
36
 
 
37
 
  if (fast_mi_readinfo(info))
38
 
    return(errno);
39
 
  changed=_mi_test_if_changed(info);
40
 
  if (share->concurrent_insert)
41
 
    pthread_rwlock_rdlock(&share->key_root_lock[inx]);
42
 
  if (!flag)
43
 
    error=_mi_search_last(info, share->keyinfo+inx,
44
 
                          share->state.key_root[inx]);
45
 
  else if (!changed)
46
 
    error=_mi_search_next(info,share->keyinfo+inx,info->lastkey,
47
 
                          info->lastkey_length,flag,
48
 
                          share->state.key_root[inx]);
49
 
  else
50
 
    error=_mi_search(info,share->keyinfo+inx,info->lastkey,
51
 
                     USE_WHOLE_KEY, flag, share->state.key_root[inx]);
52
 
 
53
 
  if (share->concurrent_insert)
54
 
  {
55
 
    if (!error)
56
 
    {
57
 
      while (info->lastpos >= info->state->data_file_length)
58
 
      {
59
 
        /* Skip rows that are inserted by other threads since we got a lock */
60
 
        if  ((error=_mi_search_next(info,share->keyinfo+inx,info->lastkey,
61
 
                                    info->lastkey_length,
62
 
                                    SEARCH_SMALLER,
63
 
                                    share->state.key_root[inx])))
64
 
          break;
65
 
      }
66
 
    }
67
 
    pthread_rwlock_unlock(&share->key_root_lock[inx]);
68
 
  }
69
 
  info->update&= (HA_STATE_CHANGED | HA_STATE_ROW_CHANGED);
70
 
  info->update|= HA_STATE_PREV_FOUND;
71
 
  if (error)
72
 
  {
73
 
    if (errno == HA_ERR_KEY_NOT_FOUND)
74
 
      errno=HA_ERR_END_OF_FILE;
75
 
  }
76
 
  else if (!buf)
77
 
  {
78
 
    return(info->lastpos==HA_OFFSET_ERROR ? errno : 0);
79
 
  }
80
 
  else if (!(*info->read_record)(info,info->lastpos,buf))
81
 
  {
82
 
    info->update|= HA_STATE_AKTIV;              /* Record is read */
83
 
    return(0);
84
 
  }
85
 
  return(errno);
86
 
} /* mi_rprev */