~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to plugin/myisam/my_handler.cc

  • Committer: Monty Taylor
  • Date: 2009-10-06 19:37:52 UTC
  • mto: This revision was merged to the branch mainline in revision 1184.
  • Revision ID: mordred@inaugust.com-20091006193752-4dx2c8u35j4em79g
Removed more server_includes.h from headers.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
/* Copyright (C) 2002-2006 MySQL AB
2
 
   
3
 
   This library is free software; you can redistribute it and/or
4
 
   modify it under the terms of the GNU Library General Public
5
 
   License as published by the Free Software Foundation; version 2
6
 
   of the License.
7
 
   
8
 
   This library is distributed in the hope that it will be useful,
9
 
   but WITHOUT ANY WARRANTY; without even the implied warranty of
10
 
   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
11
 
   Library General Public License for more details.
12
 
 
13
 
   You should have received a copy of the GNU Library General Public
14
 
   License along with this library; if not, write to the Free
15
 
   Software Foundation, Inc., 59 Temple Place - Suite 330, Boston,
16
 
   MA 02111-1307, USA */
17
 
 
18
 
#include "mysys_priv.h"
 
1
/* -*- mode: c++; c-basic-offset: 2; indent-tabs-mode: nil; -*-
 
2
 *  vim:expandtab:shiftwidth=2:tabstop=2:smarttab:
 
3
 *
 
4
 *  Copyright (C) 2008 Sun Microsystems
 
5
 *
 
6
 *  This program is free software; you can redistribute it and/or modify
 
7
 *  it under the terms of the GNU General Public License as published by
 
8
 *  the Free Software Foundation; version 2 of the License.
 
9
 *
 
10
 *  This program is distributed in the hope that it will be useful,
 
11
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
 
12
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 
13
 *  GNU General Public License for more details.
 
14
 *
 
15
 *  You should have received a copy of the GNU General Public License
 
16
 *  along with this program; if not, write to the Free Software
 
17
 *  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
 
18
 */
 
19
 
 
20
#include <drizzled/global.h>
19
21
 
20
22
#include <mystrings/m_ctype.h>
21
23
#include <drizzled/base.h>
22
 
#include <my_handler.h>
23
 
#include <my_sys.h>
24
 
 
25
 
#include "my_handler_errors.h"
26
 
 
27
 
int ha_compare_text(const CHARSET_INFO * const charset_info, uchar *a, uint a_length,
28
 
                    uchar *b, uint b_length, bool part_key,
 
24
#include <plugin/myisam/my_handler.h>
 
25
#include <mysys/my_sys.h>
 
26
 
 
27
#include <algorithm>
 
28
 
 
29
using namespace std;
 
30
 
 
31
/**
 
32
  Swap the contents of two variables.
 
33
 */
 
34
#define swap_variables(TYPE, a, b) \
 
35
  do {                             \
 
36
    TYPE dummy;                    \
 
37
    dummy= a;                      \
 
38
    a= b;                          \
 
39
    b= dummy;                      \
 
40
  } while (0)
 
41
 
 
42
#define CMP_NUM(a,b) (((a) < (b)) ? -1 : ((a) == (b)) ? 0 : 1)
 
43
 
 
44
 
 
45
int ha_compare_text(const CHARSET_INFO * const charset_info, unsigned char *a, uint32_t a_length,
 
46
                    unsigned char *b, uint32_t b_length, bool part_key,
29
47
                    bool skip_end_space)
30
48
{
31
49
  if (!part_key)
36
54
}
37
55
 
38
56
 
39
 
static int compare_bin(uchar *a, uint a_length, uchar *b, uint b_length,
 
57
static int compare_bin(unsigned char *a, uint32_t a_length, unsigned char *b, uint32_t b_length,
40
58
                       bool part_key, bool skip_end_space)
41
59
{
42
 
  uint length= min(a_length,b_length);
43
 
  uchar *end= a+ length;
 
60
  uint32_t length= min(a_length,b_length);
 
61
  unsigned char *end= a+ length;
44
62
  int flag;
45
63
 
46
64
  while (a < end)
91
109
    next_flag   How keys should be compared
92
110
                If bit SEARCH_FIND is not set the keys includes the row
93
111
                position and this should also be compared
94
 
    diff_pos    OUT Number of first keypart where values differ, counting 
 
112
    diff_pos    OUT Number of first keypart where values differ, counting
95
113
                from one.
96
114
    diff_pos[1] OUT  (b + diff_pos[1]) points to first value in tuple b
97
115
                      that is different from corresponding value in tuple a.
98
 
  
99
 
  EXAMPLES 
 
116
 
 
117
  EXAMPLES
100
118
   Example1: if the function is called for tuples
101
119
     ('aaa','bbb') and ('eee','fff'), then
102
120
     diff_pos[0] = 1 (as 'aaa' != 'eee')
119
137
 
120
138
#define FCMP(A,B) ((int) (A) - (int) (B))
121
139
 
122
 
int ha_key_cmp(register HA_KEYSEG *keyseg, register uchar *a,
123
 
               register uchar *b, uint key_length, uint nextflag,
124
 
               uint *diff_pos)
 
140
int ha_key_cmp(register HA_KEYSEG *keyseg, register unsigned char *a,
 
141
               register unsigned char *b, uint32_t key_length, uint32_t nextflag,
 
142
               uint32_t *diff_pos)
125
143
{
126
144
  int flag;
127
145
  int16_t s_1,s_2;
129
147
  uint32_t u_1,u_2;
130
148
  float f_1,f_2;
131
149
  double d_1,d_2;
132
 
  uint next_key_length;
133
 
  uchar *orig_b= b;
 
150
  uint32_t next_key_length;
 
151
  unsigned char *orig_b= b;
134
152
 
135
153
  *diff_pos=0;
136
154
  for ( ; (int) key_length >0 ; key_length=next_key_length, keyseg++)
137
155
  {
138
 
    uchar *end;
139
 
    uint piks=! (keyseg->flag & HA_NO_SORT);
 
156
    unsigned char *end;
 
157
    uint32_t piks=! (keyseg->flag & HA_NO_SORT);
140
158
    (*diff_pos)++;
141
159
    diff_pos[1]= (uint)(b - orig_b);
142
160
 
167
185
        continue;                               /* To next key part */
168
186
      }
169
187
    }
170
 
    end= a+ min(keyseg->length,key_length);
 
188
    end= a+ min((uint32_t)keyseg->length,key_length);
171
189
    next_key_length=key_length-keyseg->length;
172
190
 
173
191
    switch ((enum ha_base_keytype) keyseg->type) {
191
209
      }
192
210
      else
193
211
      {
194
 
        uint length=(uint) (end-a), a_length=length, b_length=length;
 
212
        uint32_t length=(uint) (end-a), a_length=length, b_length=length;
195
213
        if (piks &&
196
214
            (flag= ha_compare_text(keyseg->charset, a, a_length, b, b_length,
197
215
                                   (bool) ((nextflag & SEARCH_PREFIX) &&
222
240
      }
223
241
      else
224
242
      {
225
 
        uint length=keyseg->length;
 
243
        uint32_t length=keyseg->length;
226
244
        if (piks &&
227
245
            (flag=compare_bin(a,length,b,length,
228
246
                              (bool) ((nextflag & SEARCH_PREFIX) &&
254
272
        b+= b_length;
255
273
        break;
256
274
      }
257
 
      break;
258
275
    case HA_KEYTYPE_VARBINARY1:
259
276
    case HA_KEYTYPE_VARBINARY2:
260
277
      {
272
289
        b+=b_length;
273
290
        break;
274
291
      }
275
 
      break;
276
292
    case HA_KEYTYPE_INT8:
277
293
    {
278
294
      int i_1= (int) *((signed char*) a);
367
383
 
368
384
      if (keyseg->flag & HA_REVERSE_SORT)
369
385
      {
370
 
        swap_variables(uchar*, a, b);
 
386
        swap_variables(unsigned char*, a, b);
371
387
        swap_flag=1;                            /* Remember swap of a & b */
372
388
        end= a+ (int) (end-b);
373
389
      }
392
408
          if (*b != '-')
393
409
            return -1;
394
410
          a++; b++;
395
 
          swap_variables(uchar*, a, b);
 
411
          swap_variables(unsigned char*, a, b);
396
412
          swap_variables(int, alength, blength);
397
413
          swap_flag=1-swap_flag;
398
414
          alength--; blength--;
421
437
      }
422
438
 
423
439
      if (swap_flag)                            /* Restore pointers */
424
 
        swap_variables(uchar*, a, b);
 
440
        swap_variables(unsigned char*, a, b);
425
441
      break;
426
442
    }
427
443
    case HA_KEYTYPE_LONGLONG:
454
470
end:
455
471
  if (!(nextflag & SEARCH_FIND))
456
472
  {
457
 
    uint i;
 
473
    uint32_t i;
458
474
    if (nextflag & (SEARCH_NO_FIND | SEARCH_LAST)) /* Find record after key */
459
475
      return (nextflag & (SEARCH_BIGGER | SEARCH_LAST)) ? -1 : 1;
460
476
    flag=0;
497
513
    NULLs.
498
514
*/
499
515
 
500
 
HA_KEYSEG *ha_find_null(HA_KEYSEG *keyseg, uchar *a)
 
516
HA_KEYSEG *ha_find_null(HA_KEYSEG *keyseg, unsigned char *a)
501
517
{
502
518
  for (; (enum ha_base_keytype) keyseg->type != HA_KEYTYPE_END; keyseg++)
503
519
  {
504
 
    uchar *end;
 
520
    unsigned char *end;
505
521
    if (keyseg->null_bit)
506
522
    {
507
523
      if (!*a++)
554
570
    case HA_KEYTYPE_DOUBLE:
555
571
      a= end;
556
572
      break;
557
 
    case HA_KEYTYPE_END:                        /* purecov: inspected */
 
573
    case HA_KEYTYPE_END:
558
574
      /* keep compiler happy */
559
575
      assert(0);
560
576
      break;
565
581
 
566
582
 
567
583
 
568
 
/*
569
 
  Register handler error messages for usage with my_error()
570
 
 
571
 
  NOTES
572
 
    This is safe to call multiple times as my_error_register()
573
 
    will ignore calls to register already registered error numbers.
574
 
*/
575
 
 
576
 
 
577
 
void my_handler_error_register(void)
578
 
{
579
 
  /*
580
 
    If you got compilation error here about compile_time_assert array, check
581
 
    that every HA_ERR_xxx constant has a corresponding error message in
582
 
    handler_error_messages[] list (check mysys/ma_handler_errors.h and
583
 
    include/my_base.h).
584
 
  */
585
 
  compile_time_assert(HA_ERR_FIRST + array_elements(handler_error_messages) ==
586
 
                      HA_ERR_LAST + 1);
587
 
  my_error_register(handler_error_messages, HA_ERR_FIRST,
588
 
                    HA_ERR_FIRST+ array_elements(handler_error_messages)-1);
589
 
}
590
 
 
591
 
 
592
 
void my_handler_error_unregister(void)
593
 
{
594
 
  my_error_unregister(HA_ERR_FIRST,
595
 
                      HA_ERR_FIRST+ array_elements(handler_error_messages)-1);
596
 
}