~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to storage/myisam/mi_unique.c

  • Committer: Brian Aker
  • Date: 2008-07-07 14:25:25 UTC
  • mto: (77.1.25 codestyle)
  • mto: This revision was merged to the branch mainline in revision 82.
  • Revision ID: brian@tangent.org-20080707142525-xzy2nl3ie2ebwfln
LL() cleanup

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