~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to plugin/heap/hp_update.cc

  • Committer: Brian Aker
  • Date: 2010-04-12 19:28:43 UTC
  • mfrom: (1455.5.1 bug561739)
  • Revision ID: brian@gaz-20100412192843-mu6gouk7pq74drts
Merge Jay

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
/* Update current record in heap-database */
17
17
 
24
24
  HP_KEYDEF *keydef, *end, *p_lastinx;
25
25
  unsigned char *pos;
26
26
  bool auto_key_changed= 0;
27
 
  HP_SHARE *share= info->getShare();
 
27
  HP_SHARE *share= info->s;
 
28
  uint32_t old_length, new_length;
 
29
  uint32_t old_chunk_count, new_chunk_count;
28
30
 
29
31
  test_active(info);
30
32
  pos=info->current_ptr;
32
34
  if (info->opt_flag & READ_CHECK_USED && hp_rectest(info,old_record))
33
35
    return(errno);                              /* Record changed */
34
36
 
 
37
  old_length = hp_get_encoded_data_length(share, old_record, &old_chunk_count);
 
38
  new_length = hp_get_encoded_data_length(share, new_record, &new_chunk_count);
 
39
 
 
40
  if (new_chunk_count > old_chunk_count) {
 
41
    /* extend the old chunkset size as necessary, but do not shrink yet */
 
42
    if (hp_reallocate_chunkset(&share->recordspace, new_chunk_count, pos)) {
 
43
      return(errno);                          /* Out of memory or table space */
 
44
    }
 
45
  }
 
46
 
35
47
  if (--(share->records) < share->blength >> 1) share->blength>>= 1;
36
48
  share->changed=1;
37
49
 
40
52
  {
41
53
    if (hp_rec_key_cmp(keydef, old_record, new_record, 0))
42
54
    {
43
 
      if (hp_delete_key(info, keydef, old_record, pos, keydef == p_lastinx) ||
44
 
          hp_write_key(info, keydef, new_record, pos))
45
 
      {
 
55
      if ((*keydef->delete_key)(info, keydef, old_record, pos, keydef == p_lastinx) ||
 
56
          (*keydef->write_key)(info, keydef, new_record, pos))
46
57
        goto err;
47
 
      }
48
58
      if (share->auto_key == (uint) (keydef - share->keydef + 1))
49
59
        auto_key_changed= 1;
50
60
    }
52
62
  hp_copy_record_data_to_chunkset(share, new_record, pos);
53
63
  if (++(share->records) == share->blength) share->blength+= share->blength;
54
64
 
 
65
  if (new_chunk_count < old_chunk_count) {
 
66
    /* Shrink the chunkset to its new size */
 
67
    hp_reallocate_chunkset(&share->recordspace, new_chunk_count, pos);
 
68
  }
 
69
 
55
70
  if (auto_key_changed)
56
71
    heap_update_auto_increment(info, new_record);
57
72
  return(0);
60
75
  if (errno == HA_ERR_FOUND_DUPP_KEY)
61
76
  {
62
77
    info->errkey = (int) (keydef - share->keydef);
 
78
    if (keydef->algorithm == HA_KEY_ALG_BTREE)
 
79
    {
 
80
      /* we don't need to delete non-inserted key from rb-tree */
 
81
      if ((*keydef->write_key)(info, keydef, old_record, pos))
 
82
      {
 
83
        if (++(share->records) == share->blength)
 
84
          share->blength+= share->blength;
 
85
        return(errno);
 
86
      }
 
87
      keydef--;
 
88
    }
63
89
    while (keydef >= share->keydef)
64
90
    {
65
91
      if (hp_rec_key_cmp(keydef, old_record, new_record, 0))
66
92
      {
67
 
        if (hp_delete_key(info, keydef, new_record, pos, 0) ||
68
 
            hp_write_key(info, keydef, old_record, pos))
 
93
        if ((*keydef->delete_key)(info, keydef, new_record, pos, 0) ||
 
94
            (*keydef->write_key)(info, keydef, old_record, pos))
69
95
          break;
70
96
      }
71
97
      keydef--;
75
101
  if (++(share->records) == share->blength)
76
102
    share->blength+= share->blength;
77
103
 
 
104
  if (new_chunk_count > old_chunk_count) {
 
105
    /* Shrink the chunkset to its original size */
 
106
    hp_reallocate_chunkset(&share->recordspace, old_chunk_count, pos);
 
107
  }
 
108
 
78
109
  return(errno);
79
110
} /* heap_update */