~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to storage/heap/hp_update.c

  • Committer: Monty Taylor
  • Date: 2008-07-22 05:48:51 UTC
  • mto: (202.1.3 toru)
  • mto: This revision was merged to the branch mainline in revision 204.
  • Revision ID: monty@inaugust.com-20080722054851-airxt73370725p7x
Re-enabled optimizations for the normal build, and added back the --with-debug option to turn them off. 

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 unsigned char *old_record, const unsigned char *new_record)
 
20
int heap_update(HP_INFO *info, const uchar *old, const uchar *heap_new)
21
21
{
22
22
  HP_KEYDEF *keydef, *end, *p_lastinx;
23
 
  unsigned char *pos;
24
 
  bool auto_key_changed= 0;
 
23
  uchar *pos;
 
24
  my_bool auto_key_changed= 0;
25
25
  HP_SHARE *share= info->s;
26
 
  uint32_t old_length, new_length;
27
 
  uint32_t old_chunk_count, new_chunk_count;
28
26
 
29
27
  test_active(info);
30
28
  pos=info->current_ptr;
31
29
 
32
 
  if (info->opt_flag & READ_CHECK_USED && hp_rectest(info,old_record))
 
30
  if (info->opt_flag & READ_CHECK_USED)
33
31
    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
 
 
45
32
  if (--(share->records) < share->blength >> 1) share->blength>>= 1;
46
33
  share->changed=1;
47
34
 
48
35
  p_lastinx= share->keydef + info->lastinx;
49
36
  for (keydef= share->keydef, end= keydef + share->keys; keydef < end; keydef++)
50
37
  {
51
 
    if (hp_rec_key_cmp(keydef, old_record, new_record, 0))
 
38
    if (hp_rec_key_cmp(keydef, old, heap_new, 0))
52
39
    {
53
 
      if ((*keydef->delete_key)(info, keydef, old_record, pos, keydef == p_lastinx) ||
54
 
          (*keydef->write_key)(info, keydef, new_record, pos))
 
40
      if ((*keydef->delete_key)(info, keydef, old, pos, keydef == p_lastinx) ||
 
41
          (*keydef->write_key)(info, keydef, heap_new, pos))
55
42
        goto err;
56
43
      if (share->auto_key == (uint) (keydef - share->keydef + 1))
57
44
        auto_key_changed= 1;
58
45
    }
59
46
  }
60
 
  hp_copy_record_data_to_chunkset(share, new_record, pos);
 
47
 
 
48
  memcpy(pos,heap_new,(size_t) share->reclength);
61
49
  if (++(share->records) == share->blength) share->blength+= share->blength;
62
50
 
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
 
 
68
51
  if (auto_key_changed)
69
 
    heap_update_auto_increment(info, new_record);
 
52
    heap_update_auto_increment(info, heap_new);
70
53
  return(0);
71
54
 
72
55
 err:
76
59
    if (keydef->algorithm == HA_KEY_ALG_BTREE)
77
60
    {
78
61
      /* we don't need to delete non-inserted key from rb-tree */
79
 
      if ((*keydef->write_key)(info, keydef, old_record, pos))
 
62
      if ((*keydef->write_key)(info, keydef, old, pos))
80
63
      {
81
64
        if (++(share->records) == share->blength)
82
65
          share->blength+= share->blength;
86
69
    }
87
70
    while (keydef >= share->keydef)
88
71
    {
89
 
      if (hp_rec_key_cmp(keydef, old_record, new_record, 0))
 
72
      if (hp_rec_key_cmp(keydef, old, heap_new, 0))
90
73
      {
91
 
        if ((*keydef->delete_key)(info, keydef, new_record, pos, 0) ||
92
 
            (*keydef->write_key)(info, keydef, old_record, pos))
 
74
        if ((*keydef->delete_key)(info, keydef, heap_new, pos, 0) ||
 
75
            (*keydef->write_key)(info, keydef, old, pos))
93
76
          break;
94
77
      }
95
78
      keydef--;
96
79
    }
97
80
  }
98
 
 
99
81
  if (++(share->records) == share->blength)
100
82
    share->blength+= share->blength;
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
83
  return(my_errno);
108
84
} /* heap_update */