~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to storage/heap/hp_update.c

  • Committer: Monty Taylor
  • Date: 2008-10-16 06:32:30 UTC
  • mto: (511.1.5 codestyle)
  • mto: This revision was merged to the branch mainline in revision 521.
  • Revision ID: monty@inaugust.com-20081016063230-4brxsra0qsmsg84q
Added -Wunused-macros.

Show diffs side-by-side

added added

removed removed

Lines of Context:
17
17
 
18
18
#include "heapdef.h"
19
19
 
20
 
int heap_update(HP_INFO *info, const uchar *old, const uchar *heap_new)
 
20
int heap_update(HP_INFO *info, const unsigned char *old_record, const unsigned char *new_record)
21
21
{
22
22
  HP_KEYDEF *keydef, *end, *p_lastinx;
23
 
  uchar *pos;
24
 
  my_bool auto_key_changed= 0;
 
23
  unsigned char *pos;
 
24
  bool auto_key_changed= 0;
25
25
  HP_SHARE *share= info->s;
26
 
  DBUG_ENTER("heap_update");
 
26
  uint32_t old_length, new_length;
 
27
  uint32_t old_chunk_count, new_chunk_count;
27
28
 
28
29
  test_active(info);
29
30
  pos=info->current_ptr;
30
31
 
31
 
  if (info->opt_flag & READ_CHECK_USED && hp_rectest(info,old))
32
 
    DBUG_RETURN(my_errno);                              /* Record changed */
 
32
  if (info->opt_flag & READ_CHECK_USED && hp_rectest(info,old_record))
 
33
    return(my_errno);                           /* Record changed */
 
34
 
 
35
  old_length = hp_get_encoded_data_length(share, old_record, &old_chunk_count);
 
36
  new_length = hp_get_encoded_data_length(share, new_record, &new_chunk_count);
 
37
 
 
38
  if (new_chunk_count > old_chunk_count) {
 
39
    /* extend the old chunkset size as necessary, but do not shrink yet */
 
40
    if (hp_reallocate_chunkset(&share->recordspace, new_chunk_count, pos)) {
 
41
      return(my_errno);                          /* Out of memory or table space */
 
42
    }
 
43
  }
 
44
 
33
45
  if (--(share->records) < share->blength >> 1) share->blength>>= 1;
34
46
  share->changed=1;
35
47
 
36
48
  p_lastinx= share->keydef + info->lastinx;
37
49
  for (keydef= share->keydef, end= keydef + share->keys; keydef < end; keydef++)
38
50
  {
39
 
    if (hp_rec_key_cmp(keydef, old, heap_new, 0))
 
51
    if (hp_rec_key_cmp(keydef, old_record, new_record, 0))
40
52
    {
41
 
      if ((*keydef->delete_key)(info, keydef, old, pos, keydef == p_lastinx) ||
42
 
          (*keydef->write_key)(info, keydef, heap_new, pos))
 
53
      if ((*keydef->delete_key)(info, keydef, old_record, pos, keydef == p_lastinx) ||
 
54
          (*keydef->write_key)(info, keydef, new_record, pos))
43
55
        goto err;
44
56
      if (share->auto_key == (uint) (keydef - share->keydef + 1))
45
57
        auto_key_changed= 1;
46
58
    }
47
59
  }
48
 
 
49
 
  memcpy(pos,heap_new,(size_t) share->reclength);
 
60
  hp_copy_record_data_to_chunkset(share, new_record, pos);
50
61
  if (++(share->records) == share->blength) share->blength+= share->blength;
51
62
 
52
 
#if !defined(DBUG_OFF) && defined(EXTRA_HEAP_DEBUG)
53
 
  DBUG_EXECUTE("check_heap",heap_check_heap(info, 0););
54
 
#endif
 
63
  if (new_chunk_count < old_chunk_count) {
 
64
    /* Shrink the chunkset to its new size */
 
65
    hp_reallocate_chunkset(&share->recordspace, new_chunk_count, pos);
 
66
  }
 
67
 
55
68
  if (auto_key_changed)
56
 
    heap_update_auto_increment(info, heap_new);
57
 
  DBUG_RETURN(0);
 
69
    heap_update_auto_increment(info, new_record);
 
70
  return(0);
58
71
 
59
72
 err:
60
73
  if (my_errno == HA_ERR_FOUND_DUPP_KEY)
63
76
    if (keydef->algorithm == HA_KEY_ALG_BTREE)
64
77
    {
65
78
      /* we don't need to delete non-inserted key from rb-tree */
66
 
      if ((*keydef->write_key)(info, keydef, old, pos))
 
79
      if ((*keydef->write_key)(info, keydef, old_record, pos))
67
80
      {
68
81
        if (++(share->records) == share->blength)
69
82
          share->blength+= share->blength;
70
 
        DBUG_RETURN(my_errno);
 
83
        return(my_errno);
71
84
      }
72
85
      keydef--;
73
86
    }
74
87
    while (keydef >= share->keydef)
75
88
    {
76
 
      if (hp_rec_key_cmp(keydef, old, heap_new, 0))
 
89
      if (hp_rec_key_cmp(keydef, old_record, new_record, 0))
77
90
      {
78
 
        if ((*keydef->delete_key)(info, keydef, heap_new, pos, 0) ||
79
 
            (*keydef->write_key)(info, keydef, old, pos))
 
91
        if ((*keydef->delete_key)(info, keydef, new_record, pos, 0) ||
 
92
            (*keydef->write_key)(info, keydef, old_record, pos))
80
93
          break;
81
94
      }
82
95
      keydef--;
83
96
    }
84
97
  }
 
98
 
85
99
  if (++(share->records) == share->blength)
86
100
    share->blength+= share->blength;
87
 
  DBUG_RETURN(my_errno);
 
101
 
 
102
  if (new_chunk_count > old_chunk_count) {
 
103
    /* Shrink the chunkset to its original size */
 
104
    hp_reallocate_chunkset(&share->recordspace, old_chunk_count, pos);
 
105
  }
 
106
 
 
107
  return(my_errno);
88
108
} /* heap_update */