~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to storage/innobase/data/data0data.c

  • Committer: Mark Atwood
  • Date: 2009-03-04 01:02:00 UTC
  • mto: (968.2.20 mordred)
  • mto: This revision was merged to the branch mainline in revision 971.
  • Revision ID: me@mark.atwood.name-20090304010200-t1n4xxdoil2yae9a
add gearman logging plugin

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
/*****************************************************************************
2
 
 
3
 
Copyright (C) 1994, 2009, Innobase Oy. All Rights Reserved.
4
 
 
5
 
This program is free software; you can redistribute it and/or modify it under
6
 
the terms of the GNU General Public License as published by the Free Software
7
 
Foundation; version 2 of the License.
8
 
 
9
 
This program is distributed in the hope that it will be useful, but WITHOUT
10
 
ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
11
 
FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
12
 
 
13
 
You should have received a copy of the GNU General Public License along with
14
 
this program; if not, write to the Free Software Foundation, Inc., 51 Franklin
15
 
St, Fifth Floor, Boston, MA 02110-1301 USA
16
 
 
17
 
*****************************************************************************/
18
 
 
19
 
/********************************************************************//**
20
 
@file data/data0data.c
 
1
/************************************************************************
21
2
SQL data field and tuple
22
3
 
 
4
(c) 1994-1996 Innobase Oy
 
5
 
23
6
Created 5/30/1994 Heikki Tuuri
24
7
*************************************************************************/
25
8
 
29
12
#include "data0data.ic"
30
13
#endif
31
14
 
32
 
#ifndef UNIV_HOTBACKUP
33
15
#include "rem0rec.h"
34
16
#include "rem0cmp.h"
35
17
#include "page0page.h"
38
20
#include "btr0cur.h"
39
21
 
40
22
#include <ctype.h>
41
 
#endif /* !UNIV_HOTBACKUP */
42
23
 
43
24
#ifdef UNIV_DEBUG
44
 
/** Dummy variable to catch access to uninitialized fields.  In the
45
 
debug version, dtuple_create() will make all fields of dtuple_t point
46
 
to data_error. */
 
25
/* data pointers of tuple fields are initialized to point here
 
26
for error checking */
47
27
UNIV_INTERN byte        data_error;
48
28
 
49
 
# ifndef UNIV_DEBUG_VALGRIND
50
 
/** this is used to fool the compiler in dtuple_validate */
 
29
/* this is used to fool the compiler in dtuple_validate */
51
30
UNIV_INTERN ulint       data_dummy;
52
 
# endif /* !UNIV_DEBUG_VALGRIND */
53
31
#endif /* UNIV_DEBUG */
54
32
 
55
 
#ifndef UNIV_HOTBACKUP
56
 
/*********************************************************************//**
57
 
Tests if dfield data length and content is equal to the given.
58
 
@return TRUE if equal */
 
33
/*************************************************************************
 
34
Tests if dfield data length and content is equal to the given. */
59
35
UNIV_INTERN
60
36
ibool
61
37
dfield_data_is_binary_equal(
62
38
/*========================*/
63
 
        const dfield_t* field,  /*!< in: field */
64
 
        ulint           len,    /*!< in: data length or UNIV_SQL_NULL */
65
 
        const byte*     data)   /*!< in: data */
 
39
                                /* out: TRUE if equal */
 
40
        const dfield_t* field,  /* in: field */
 
41
        ulint           len,    /* in: data length or UNIV_SQL_NULL */
 
42
        const byte*     data)   /* in: data */
66
43
{
67
44
        if (len != dfield_get_len(field)) {
68
45
 
82
59
        return(TRUE);
83
60
}
84
61
 
85
 
/************************************************************//**
86
 
Compare two data tuples, respecting the collation of character fields.
87
 
@return 1, 0 , -1 if tuple1 is greater, equal, less, respectively,
88
 
than tuple2 */
 
62
/****************************************************************
 
63
Compare two data tuples, respecting the collation of character fields. */
89
64
UNIV_INTERN
90
65
int
91
66
dtuple_coll_cmp(
92
67
/*============*/
93
 
        const dtuple_t* tuple1, /*!< in: tuple 1 */
94
 
        const dtuple_t* tuple2) /*!< in: tuple 2 */
 
68
                                /* out: 1, 0 , -1 if tuple1 is greater, equal,
 
69
                                less, respectively, than tuple2 */
 
70
        const dtuple_t* tuple1, /* in: tuple 1 */
 
71
        const dtuple_t* tuple2) /* in: tuple 2 */
95
72
{
96
73
        ulint   n_fields;
97
74
        ulint   i;
124
101
        return(0);
125
102
}
126
103
 
127
 
/*********************************************************************//**
 
104
/*************************************************************************
128
105
Sets number of fields used in a tuple. Normally this is set in
129
106
dtuple_create, but if you want later to set it smaller, you can use this. */
130
107
UNIV_INTERN
131
108
void
132
109
dtuple_set_n_fields(
133
110
/*================*/
134
 
        dtuple_t*       tuple,          /*!< in: tuple */
135
 
        ulint           n_fields)       /*!< in: number of fields */
 
111
        dtuple_t*       tuple,          /* in: tuple */
 
112
        ulint           n_fields)       /* in: number of fields */
136
113
{
137
114
        ut_ad(tuple);
138
115
 
140
117
        tuple->n_fields_cmp = n_fields;
141
118
}
142
119
 
143
 
/**********************************************************//**
144
 
Checks that a data field is typed.
145
 
@return TRUE if ok */
 
120
/**************************************************************
 
121
Checks that a data field is typed. */
146
122
static
147
123
ibool
148
124
dfield_check_typed_no_assert(
149
125
/*=========================*/
150
 
        const dfield_t* field)  /*!< in: data field */
 
126
                                /* out: TRUE if ok */
 
127
        const dfield_t* field)  /* in: data field */
151
128
{
152
129
        if (dfield_get_type(field)->mtype > DATA_MYSQL
153
130
            || dfield_get_type(field)->mtype < DATA_VARCHAR) {
162
139
        return(TRUE);
163
140
}
164
141
 
165
 
/**********************************************************//**
166
 
Checks that a data tuple is typed.
167
 
@return TRUE if ok */
 
142
/**************************************************************
 
143
Checks that a data tuple is typed. */
168
144
UNIV_INTERN
169
145
ibool
170
146
dtuple_check_typed_no_assert(
171
147
/*=========================*/
172
 
        const dtuple_t* tuple)  /*!< in: tuple */
 
148
                                /* out: TRUE if ok */
 
149
        const dtuple_t* tuple)  /* in: tuple */
173
150
{
174
151
        const dfield_t* field;
175
152
        ulint           i;
197
174
 
198
175
        return(TRUE);
199
176
}
200
 
#endif /* !UNIV_HOTBACKUP */
201
177
 
202
 
#ifdef UNIV_DEBUG
203
 
/**********************************************************//**
204
 
Checks that a data field is typed. Asserts an error if not.
205
 
@return TRUE if ok */
 
178
/**************************************************************
 
179
Checks that a data field is typed. Asserts an error if not. */
206
180
UNIV_INTERN
207
181
ibool
208
182
dfield_check_typed(
209
183
/*===============*/
210
 
        const dfield_t* field)  /*!< in: data field */
 
184
                                /* out: TRUE if ok */
 
185
        const dfield_t* field)  /* in: data field */
211
186
{
212
187
        if (dfield_get_type(field)->mtype > DATA_MYSQL
213
188
            || dfield_get_type(field)->mtype < DATA_VARCHAR) {
223
198
        return(TRUE);
224
199
}
225
200
 
226
 
/**********************************************************//**
227
 
Checks that a data tuple is typed. Asserts an error if not.
228
 
@return TRUE if ok */
 
201
/**************************************************************
 
202
Checks that a data tuple is typed. Asserts an error if not. */
229
203
UNIV_INTERN
230
204
ibool
231
205
dtuple_check_typed(
232
206
/*===============*/
233
 
        const dtuple_t* tuple)  /*!< in: tuple */
 
207
                                /* out: TRUE if ok */
 
208
        const dtuple_t* tuple)  /* in: tuple */
234
209
{
235
210
        const dfield_t* field;
236
211
        ulint           i;
245
220
        return(TRUE);
246
221
}
247
222
 
248
 
/**********************************************************//**
 
223
#ifdef UNIV_DEBUG
 
224
/**************************************************************
249
225
Validates the consistency of a tuple which must be complete, i.e,
250
 
all fields must have been set.
251
 
@return TRUE if ok */
 
226
all fields must have been set. */
252
227
UNIV_INTERN
253
228
ibool
254
229
dtuple_validate(
255
230
/*============*/
256
 
        const dtuple_t* tuple)  /*!< in: tuple */
 
231
                                /* out: TRUE if ok */
 
232
        const dtuple_t* tuple)  /* in: tuple */
257
233
{
258
234
        const dfield_t* field;
 
235
        const byte*     data;
259
236
        ulint           n_fields;
260
237
        ulint           len;
261
238
        ulint           i;
 
239
        ulint           j;
262
240
 
263
241
        ut_ad(tuple->magic_n == DATA_TUPLE_MAGIC_N);
264
242
 
274
252
 
275
253
                if (!dfield_is_null(field)) {
276
254
 
277
 
                        const byte*     data = dfield_get_data(field);
278
 
#ifndef UNIV_DEBUG_VALGRIND
279
 
                        ulint           j;
 
255
                        data = dfield_get_data(field);
 
256
                        UNIV_MEM_ASSERT_RW(data, len);
280
257
 
281
258
                        for (j = 0; j < len; j++) {
282
259
 
285
262
                                                      code */
286
263
                                data++;
287
264
                        }
288
 
#endif /* !UNIV_DEBUG_VALGRIND */
289
 
 
290
 
                        UNIV_MEM_ASSERT_RW(data, len);
291
265
                }
292
266
        }
293
267
 
297
271
}
298
272
#endif /* UNIV_DEBUG */
299
273
 
300
 
#ifndef UNIV_HOTBACKUP
301
 
/*************************************************************//**
 
274
/*****************************************************************
302
275
Pretty prints a dfield value according to its data type. */
303
276
UNIV_INTERN
304
277
void
305
278
dfield_print(
306
279
/*=========*/
307
 
        const dfield_t* dfield) /*!< in: dfield */
 
280
        const dfield_t* dfield) /* in: dfield */
308
281
{
 
282
        const byte*     data;
 
283
        ulint           len;
309
284
        ulint           i;
310
285
 
311
 
        ulint len = dfield_get_len(dfield);
312
 
        const byte *data = static_cast<const byte *>(dfield_get_data(dfield));
 
286
        len = dfield_get_len(dfield);
 
287
        data = dfield_get_data(dfield);
313
288
 
314
289
        if (dfield_is_null(dfield)) {
315
290
                fputs("NULL", stderr);
338
313
        }
339
314
}
340
315
 
341
 
/*************************************************************//**
 
316
/*****************************************************************
342
317
Pretty prints a dfield value according to its data type. Also the hex string
343
318
is printed if a string contains non-printable characters. */
344
319
UNIV_INTERN
345
320
void
346
321
dfield_print_also_hex(
347
322
/*==================*/
348
 
        const dfield_t* dfield) /*!< in: dfield */
 
323
        const dfield_t* dfield) /* in: dfield */
349
324
{
350
325
        const byte*     data;
351
326
        ulint           len;
354
329
        ibool           print_also_hex;
355
330
 
356
331
        len = dfield_get_len(dfield);
357
 
        data = static_cast<const byte *>(dfield_get_data(dfield));
 
332
        data = dfield_get_data(dfield);
358
333
 
359
334
        if (dfield_is_null(dfield)) {
360
335
                fputs("NULL", stderr);
364
339
 
365
340
        prtype = dtype_get_prtype(dfield_get_type(dfield));
366
341
 
367
 
        ib_id_t id= 0;
368
 
        ulint val= 0;
369
 
        static const ulint UNSIGNED_MASK= 0x80000000;
370
 
 
371
342
        switch (dtype_get_mtype(dfield_get_type(dfield))) {
 
343
                dulint  id;
372
344
        case DATA_INT:
373
345
                switch (len) {
 
346
                        ulint   val;
374
347
                case 1:
375
348
                        val = mach_read_from_1(data);
376
349
 
408
381
                        val = mach_read_from_4(data);
409
382
 
410
383
                        if (!(prtype & DATA_UNSIGNED)) {
411
 
                                val &= ~UNSIGNED_MASK;
 
384
                                val &= ~0x80000000;
412
385
                                fprintf(stderr, "%ld", (long) val);
413
386
                        } else {
414
387
                                fprintf(stderr, "%lu", (ulong) val);
417
390
 
418
391
                case 6:
419
392
                        id = mach_read_from_6(data);
420
 
                        fprintf(stderr, "%llu", (ullint) id);
 
393
                        fprintf(stderr, "{%lu %lu}",
 
394
                                ut_dulint_get_high(id),
 
395
                                ut_dulint_get_low(id));
421
396
                        break;
422
397
 
423
398
                case 7:
424
399
                        id = mach_read_from_7(data);
425
 
                        fprintf(stderr, "%llu", (ullint) id);
 
400
                        fprintf(stderr, "{%lu %lu}",
 
401
                                ut_dulint_get_high(id),
 
402
                                ut_dulint_get_low(id));
426
403
                        break;
427
404
                case 8:
428
405
                        id = mach_read_from_8(data);
429
 
                        fprintf(stderr, "%llu", (ullint) id);
 
406
                        fprintf(stderr, "{%lu %lu}",
 
407
                                ut_dulint_get_high(id),
 
408
                                ut_dulint_get_low(id));
430
409
                        break;
431
410
                default:
432
411
                        goto print_hex;
438
417
                case DATA_TRX_ID:
439
418
                        id = mach_read_from_6(data);
440
419
 
441
 
                        fprintf(stderr, "trx_id " TRX_ID_FMT, id);
 
420
                        fprintf(stderr, "trx_id " TRX_ID_FMT,
 
421
                                TRX_ID_PREP_PRINTF(id));
442
422
                        break;
443
423
 
444
424
                case DATA_ROLL_PTR:
445
425
                        id = mach_read_from_7(data);
446
426
 
447
 
                        fprintf(stderr, "roll_ptr " TRX_ID_FMT, id);
 
427
                        fprintf(stderr, "roll_ptr {%lu %lu}",
 
428
                                ut_dulint_get_high(id), ut_dulint_get_low(id));
448
429
                        break;
449
430
 
450
431
                case DATA_ROW_ID:
451
432
                        id = mach_read_from_6(data);
452
433
 
453
 
                        fprintf(stderr, "row_id " TRX_ID_FMT, id);
 
434
                        fprintf(stderr, "row_id {%lu %lu}",
 
435
                                ut_dulint_get_high(id), ut_dulint_get_low(id));
454
436
                        break;
455
437
 
456
438
                default:
457
 
                        id = mach_ull_read_compressed(data);
 
439
                        id = mach_dulint_read_compressed(data);
458
440
 
459
 
                        fprintf(stderr, "mix_id " TRX_ID_FMT, id);
 
441
                        fprintf(stderr, "mix_id {%lu %lu}",
 
442
                                ut_dulint_get_high(id), ut_dulint_get_low(id));
460
443
                }
461
444
                break;
462
445
 
484
467
                        break;
485
468
                }
486
469
 
487
 
                data = static_cast<const byte *>(dfield_get_data(dfield));
 
470
                data = dfield_get_data(dfield);
488
471
                /* fall through */
489
472
 
490
473
        case DATA_BINARY:
502
485
        }
503
486
}
504
487
 
505
 
/*************************************************************//**
 
488
/*****************************************************************
506
489
Print a dfield value using ut_print_buf. */
507
490
static
508
491
void
509
492
dfield_print_raw(
510
493
/*=============*/
511
 
        FILE*           f,              /*!< in: output stream */
512
 
        const dfield_t* dfield)         /*!< in: dfield */
 
494
        FILE*           f,              /* in: output stream */
 
495
        const dfield_t* dfield)         /* in: dfield */
513
496
{
514
497
        ulint   len     = dfield_get_len(dfield);
515
498
        if (!dfield_is_null(dfield)) {
525
508
        }
526
509
}
527
510
 
528
 
/**********************************************************//**
 
511
/**************************************************************
529
512
The following function prints the contents of a tuple. */
530
513
UNIV_INTERN
531
514
void
532
515
dtuple_print(
533
516
/*=========*/
534
 
        FILE*           f,      /*!< in: output stream */
535
 
        const dtuple_t* tuple)  /*!< in: tuple */
 
517
        FILE*           f,      /* in: output stream */
 
518
        const dtuple_t* tuple)  /* in: tuple */
536
519
{
537
520
        ulint           n_fields;
538
521
        ulint           i;
547
530
                dfield_print_raw(f, dtuple_get_nth_field(tuple, i));
548
531
 
549
532
                putc(';', f);
550
 
                putc('\n', f);
551
533
        }
552
534
 
 
535
        putc('\n', f);
553
536
        ut_ad(dtuple_validate(tuple));
554
537
}
555
538
 
556
 
/**************************************************************//**
 
539
/******************************************************************
557
540
Moves parts of long fields in entry to the big record vector so that
558
541
the size of tuple drops below the maximum record size allowed in the
559
542
database. Moves data only from those fields which are not necessary
560
 
to determine uniquely the insertion place of the tuple in the index.
561
 
@return own: created big record vector, NULL if we are not able to
562
 
shorten the entry enough, i.e., if there are too many fixed-length or
563
 
short fields in entry or the index is clustered */
 
543
to determine uniquely the insertion place of the tuple in the index. */
564
544
UNIV_INTERN
565
545
big_rec_t*
566
546
dtuple_convert_big_rec(
567
547
/*===================*/
568
 
        dict_index_t*   index,  /*!< in: index */
569
 
        dtuple_t*       entry,  /*!< in/out: index entry */
570
 
        ulint*          n_ext)  /*!< in/out: number of
 
548
                                /* out, own: created big record vector,
 
549
                                NULL if we are not able to shorten
 
550
                                the entry enough, i.e., if there are
 
551
                                too many fixed-length or short fields
 
552
                                in entry or the index is clustered */
 
553
        dict_index_t*   index,  /* in: index */
 
554
        dtuple_t*       entry,  /* in/out: index entry */
 
555
        ulint*          n_ext)  /* in/out: number of
571
556
                                externally stored columns */
572
557
{
573
558
        mem_heap_t*     heap;
607
592
        heap = mem_heap_create(size + dtuple_get_n_fields(entry)
608
593
                               * sizeof(big_rec_field_t) + 1000);
609
594
 
610
 
        vector = static_cast<big_rec_t *>(mem_heap_alloc(heap, sizeof(big_rec_t)));
 
595
        vector = mem_heap_alloc(heap, sizeof(big_rec_t));
611
596
 
612
597
        vector->heap = heap;
613
 
        vector->fields = static_cast<big_rec_field_t *>(mem_heap_alloc(heap, dtuple_get_n_fields(entry)
614
 
                                        * sizeof(big_rec_field_t)));
 
598
        vector->fields = mem_heap_alloc(heap, dtuple_get_n_fields(entry)
 
599
                                        * sizeof(big_rec_field_t));
615
600
 
616
601
        /* Decide which fields to shorten: the algorithm is to look for
617
602
        a variable-length field that yields the biggest savings when
656
641
                                goto skip_field;
657
642
                        }
658
643
 
659
 
                        /* In DYNAMIC and COMPRESSED format, store
660
 
                        locally any non-BLOB columns whose maximum
661
 
                        length does not exceed 256 bytes.  This is
662
 
                        because there is no room for the "external
663
 
                        storage" flag when the maximum length is 255
664
 
                        bytes or less. This restriction trivially
665
 
                        holds in REDUNDANT and COMPACT format, because
666
 
                        there we always store locally columns whose
667
 
                        length is up to local_len == 788 bytes.
668
 
                        @see rec_init_offsets_comp_ordinary */
669
 
                        if (ifield->col->mtype != DATA_BLOB
670
 
                            && ifield->col->len < 256) {
671
 
                                goto skip_field;
672
 
                        }
673
 
 
674
 
                        /* In DYNAMIC and COMPRESSED format, store
675
 
                        locally any non-BLOB columns whose maximum
676
 
                        length does not exceed 256 bytes.  This is
677
 
                        because there is no room for the "external
678
 
                        storage" flag when the maximum length is 255
679
 
                        bytes or less. This restriction trivially
680
 
                        holds in REDUNDANT and COMPACT format, because
681
 
                        there we always store locally columns whose
682
 
                        length is up to local_len == 788 bytes.
683
 
                        @see rec_init_offsets_comp_ordinary */
684
 
                        if (ifield->col->mtype != DATA_BLOB
685
 
                            && ifield->col->len < 256) {
686
 
                                goto skip_field;
687
 
                        }
688
 
 
689
 
                        /* In DYNAMIC and COMPRESSED format, store
690
 
                        locally any non-BLOB columns whose maximum
691
 
                        length does not exceed 256 bytes.  This is
692
 
                        because there is no room for the "external
693
 
                        storage" flag when the maximum length is 255
694
 
                        bytes or less. This restriction trivially
695
 
                        holds in REDUNDANT and COMPACT format, because
696
 
                        there we always store locally columns whose
697
 
                        length is up to local_len == 788 bytes.
698
 
                        @see rec_init_offsets_comp_ordinary */
699
 
                        if (ifield->col->mtype != DATA_BLOB
700
 
                            && ifield->col->len < 256) {
701
 
                                goto skip_field;
702
 
                        }
703
 
 
704
644
                        longest_i = i;
705
645
                        longest = savings;
706
646
 
732
672
                b->data = (char*) dfield_get_data(dfield) + local_prefix_len;
733
673
 
734
674
                /* Allocate the locally stored part of the column. */
735
 
                data = static_cast<unsigned char *>(mem_heap_alloc(heap, local_len));
 
675
                data = mem_heap_alloc(heap, local_len);
736
676
 
737
677
                /* Copy the local prefix. */
738
678
                memcpy(data, dfield_get_data(dfield), local_prefix_len);
759
699
        return(vector);
760
700
}
761
701
 
762
 
/**************************************************************//**
 
702
/******************************************************************
763
703
Puts back to entry the data stored in vector. Note that to ensure the
764
704
fields in entry can accommodate the data, vector must have been created
765
705
from entry with dtuple_convert_big_rec. */
767
707
void
768
708
dtuple_convert_back_big_rec(
769
709
/*========================*/
770
 
        dict_index_t*   /*index __attribute__((unused))*/,      /*!< in: index */
771
 
        dtuple_t*       entry,  /*!< in: entry whose data was put to vector */
772
 
        big_rec_t*      vector) /*!< in, own: big rec vector; it is
 
710
        dict_index_t*   index __attribute__((unused)),  /* in: index */
 
711
        dtuple_t*       entry,  /* in: entry whose data was put to vector */
 
712
        big_rec_t*      vector) /* in, own: big rec vector; it is
773
713
                                freed in this function */
774
714
{
775
715
        big_rec_field_t*                b       = vector->fields;
796
736
 
797
737
        mem_heap_free(vector->heap);
798
738
}
799
 
#endif /* !UNIV_HOTBACKUP */