~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to storage/myisam/mi_unique.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:
16
16
/* Functions to check if a row is unique */
17
17
 
18
18
#include "myisamdef.h"
19
 
#include <m_ctype.h>
 
19
#include <mystrings/m_ctype.h>
20
20
 
21
 
my_bool mi_check_unique(MI_INFO *info, MI_UNIQUEDEF *def, uchar *record,
 
21
bool mi_check_unique(MI_INFO *info, MI_UNIQUEDEF *def, unsigned char *record,
22
22
                        ha_checksum unique_hash, my_off_t disk_pos)
23
23
{
24
24
  my_off_t lastpos=info->lastpos;
25
25
  MI_KEYDEF *key= &info->s->keyinfo[def->key];
26
 
  uchar *key_buff=info->lastkey2;
27
 
  DBUG_ENTER("mi_check_unique");
 
26
  unsigned char *key_buff=info->lastkey2;
28
27
 
29
28
  mi_unique_store(record+key->seg->start, unique_hash);
30
29
  _mi_make_key(info,def->key,key_buff,record,0);
37
36
  {
38
37
    info->page_changed=1;                       /* Can't optimize read next */
39
38
    info->lastpos= lastpos;
40
 
    DBUG_RETURN(0);                             /* No matching rows */
 
39
    return(0);                          /* No matching rows */
41
40
  }
42
41
 
43
42
  for (;;)
50
49
      info->dupp_key_pos= info->lastpos;
51
50
      info->page_changed=1;                     /* Can't optimize read next */
52
51
      info->lastpos=lastpos;
53
 
      DBUG_PRINT("info",("Found duplicate"));
54
 
      DBUG_RETURN(1);                           /* Found identical  */
 
52
      return(1);                                /* Found identical  */
55
53
    }
56
54
    if (_mi_search_next(info,info->s->keyinfo+def->key, info->lastkey,
57
55
                        MI_UNIQUE_HASH_LENGTH, SEARCH_BIGGER,
58
56
                        info->s->state.key_root[def->key]) ||
59
 
        bcmp((char*) info->lastkey, (char*) key_buff, MI_UNIQUE_HASH_LENGTH))
 
57
        memcmp(info->lastkey, key_buff, MI_UNIQUE_HASH_LENGTH))
60
58
    {
61
59
      info->page_changed=1;                     /* Can't optimize read next */
62
60
      info->lastpos=lastpos;
63
 
      DBUG_RETURN(0);                           /* end of tree */
 
61
      return(0);                                /* end of tree */
64
62
    }
65
63
  }
66
64
}
73
71
    Add support for bit fields
74
72
*/
75
73
 
76
 
ha_checksum mi_unique_hash(MI_UNIQUEDEF *def, const uchar *record)
 
74
ha_checksum mi_unique_hash(MI_UNIQUEDEF *def, const unsigned char *record)
77
75
{
78
 
  const uchar *pos, *end;
 
76
  const unsigned char *pos, *end;
79
77
  ha_checksum crc= 0;
80
 
  ulong seed1=0, seed2= 4;
 
78
  uint32_t seed1=0, seed2= 4;
81
79
  HA_KEYSEG *keyseg;
82
80
 
83
81
  for (keyseg=def->seg ; keyseg < def->end ; keyseg++)
84
82
  {
85
83
    enum ha_base_keytype type=(enum ha_base_keytype) keyseg->type;
86
 
    uint length=keyseg->length;
 
84
    uint32_t length=keyseg->length;
87
85
 
88
86
    if (keyseg->null_bit)
89
87
    {
102
100
    pos= record+keyseg->start;
103
101
    if (keyseg->flag & HA_VAR_LENGTH_PART)
104
102
    {
105
 
      uint pack_length=  keyseg->bit_start;
106
 
      uint tmp_length= (pack_length == 1 ? (uint) *(uchar*) pos :
 
103
      uint32_t pack_length=  keyseg->bit_start;
 
104
      uint32_t tmp_length= (pack_length == 1 ? (uint) *(unsigned char*) pos :
107
105
                        uint2korr(pos));
108
106
      pos+= pack_length;                        /* Skip VARCHAR length */
109
107
      set_if_smaller(length,tmp_length);
110
108
    }
111
109
    else if (keyseg->flag & HA_BLOB_PART)
112
110
    {
113
 
      uint tmp_length=_mi_calc_blob_length(keyseg->bit_start,pos);
114
 
      memcpy_fixed((uchar*) &pos,pos+keyseg->bit_start,sizeof(char*));
 
111
      uint32_t tmp_length=_mi_calc_blob_length(keyseg->bit_start,pos);
 
112
      memcpy(&pos,pos+keyseg->bit_start,sizeof(char*));
115
113
      if (!length || length > tmp_length)
116
114
        length=tmp_length;                      /* The whole blob */
117
115
    }
120
118
        type == HA_KEYTYPE_VARTEXT2)
121
119
    {
122
120
      keyseg->charset->coll->hash_sort(keyseg->charset,
123
 
                                       (const uchar*) pos, length, &seed1,
 
121
                                       (const unsigned char*) pos, length, &seed1,
124
122
                                       &seed2);
125
123
      crc^= seed1;
126
124
    }
127
125
    else
128
126
      while (pos != end)
129
127
        crc=((crc << 8) +
130
 
             (((uchar)  *(uchar*) pos++))) +
 
128
             (((unsigned char)  *(unsigned char*) pos++))) +
131
129
          (crc >> (8*sizeof(ha_checksum)-8));
132
130
  }
133
131
  return crc;
145
143
    #   Rows are different
146
144
*/
147
145
 
148
 
int mi_unique_comp(MI_UNIQUEDEF *def, const uchar *a, const uchar *b,
149
 
                   my_bool null_are_equal)
 
146
int mi_unique_comp(MI_UNIQUEDEF *def, const unsigned char *a, const unsigned char *b,
 
147
                   bool null_are_equal)
150
148
{
151
 
  const uchar *pos_a, *pos_b, *end;
 
149
  const unsigned char *pos_a, *pos_b, *end;
152
150
  HA_KEYSEG *keyseg;
153
151
 
154
152
  for (keyseg=def->seg ; keyseg < def->end ; keyseg++)
155
153
  {
156
154
    enum ha_base_keytype type=(enum ha_base_keytype) keyseg->type;
157
 
    uint a_length, b_length;
 
155
    uint32_t a_length, b_length;
158
156
    a_length= b_length= keyseg->length;
159
157
 
160
158
    /* If part is NULL it's regarded as different */
161
159
    if (keyseg->null_bit)
162
160
    {
163
 
      uint tmp;
 
161
      uint32_t tmp;
164
162
      if ((tmp=(a[keyseg->null_pos] & keyseg->null_bit)) !=
165
163
          (uint) (b[keyseg->null_pos] & keyseg->null_bit))
166
164
        return 1;
175
173
    pos_b= b+keyseg->start;
176
174
    if (keyseg->flag & HA_VAR_LENGTH_PART)
177
175
    {
178
 
      uint pack_length= keyseg->bit_start;
 
176
      uint32_t pack_length= keyseg->bit_start;
179
177
      if (pack_length == 1)
180
178
      {
181
 
        a_length= (uint) *(uchar*) pos_a++;
182
 
        b_length= (uint) *(uchar*) pos_b++;
 
179
        a_length= (uint) *(unsigned char*) pos_a++;
 
180
        b_length= (uint) *(unsigned char*) pos_b++;
183
181
      }
184
182
      else
185
183
      {
206
204
        set_if_smaller(a_length, keyseg->length);
207
205
        set_if_smaller(b_length, keyseg->length);
208
206
      }
209
 
      memcpy_fixed((uchar*) &pos_a,pos_a+keyseg->bit_start,sizeof(char*));
210
 
      memcpy_fixed((uchar*) &pos_b,pos_b+keyseg->bit_start,sizeof(char*));
 
207
      memcpy(&pos_a,pos_a+keyseg->bit_start,sizeof(char*));
 
208
      memcpy(&pos_b,pos_b+keyseg->bit_start,sizeof(char*));
211
209
    }
212
210
    if (type == HA_KEYTYPE_TEXT || type == HA_KEYTYPE_VARTEXT1 ||
213
211
        type == HA_KEYTYPE_VARTEXT2)
214
212
    {
215
 
      if (ha_compare_text(keyseg->charset, (uchar *) pos_a, a_length,
216
 
                                           (uchar *) pos_b, b_length, 0, 1))
 
213
      if (ha_compare_text(keyseg->charset, (unsigned char *) pos_a, a_length,
 
214
                                           (unsigned char *) pos_b, b_length, 0, 1))
217
215
        return 1;
218
216
    }
219
217
    else