~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to storage/innobase/row/row0ext.c

  • Committer: Monty Taylor
  • Date: 2008-09-15 17:24:04 UTC
  • Revision ID: monty@inaugust.com-20080915172404-ygh6hiyu0q7qpa9x
Removed strndup calls.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
/******************************************************
2
 
Caching of externally stored column prefixes
3
 
 
4
 
(c) 2006 Innobase Oy
5
 
 
6
 
Created September 2006 Marko Makela
7
 
*******************************************************/
8
 
 
9
 
#include "row0ext.h"
10
 
 
11
 
#ifdef UNIV_NONINL
12
 
#include "row0ext.ic"
13
 
#endif
14
 
 
15
 
#include "btr0cur.h"
16
 
 
17
 
/************************************************************************
18
 
Fills the column prefix cache of an externally stored column. */
19
 
static
20
 
void
21
 
row_ext_cache_fill(
22
 
/*===============*/
23
 
        row_ext_t*      ext,    /* in/out: column prefix cache */
24
 
        ulint           i,      /* in: index of ext->ext[] */
25
 
        ulint           zip_size,/* compressed page size in bytes, or 0 */
26
 
        const dfield_t* dfield) /* in: data field */
27
 
{
28
 
        const byte*     field   = dfield_get_data(dfield);
29
 
        ulint           f_len   = dfield_get_len(dfield);
30
 
        byte*           buf     = ext->buf + i * REC_MAX_INDEX_COL_LEN;
31
 
 
32
 
        ut_ad(i < ext->n_ext);
33
 
        ut_ad(dfield_is_ext(dfield));
34
 
        ut_a(f_len >= BTR_EXTERN_FIELD_REF_SIZE);
35
 
 
36
 
        if (UNIV_UNLIKELY(!memcmp(field_ref_zero,
37
 
                                  field + f_len - BTR_EXTERN_FIELD_REF_SIZE,
38
 
                                  BTR_EXTERN_FIELD_REF_SIZE))) {
39
 
                /* The BLOB pointer is not set: we cannot fetch it */
40
 
                ext->len[i] = 0;
41
 
        } else {
42
 
                /* Fetch at most REC_MAX_INDEX_COL_LEN of the column.
43
 
                The column must be non-empty. */
44
 
                ext->len[i] = btr_copy_externally_stored_field_prefix(
45
 
                        buf, REC_MAX_INDEX_COL_LEN, zip_size, field, f_len);
46
 
                ut_a(ext->len[i]);
47
 
        }
48
 
}
49
 
 
50
 
/************************************************************************
51
 
Creates a cache of column prefixes of externally stored columns. */
52
 
UNIV_INTERN
53
 
row_ext_t*
54
 
row_ext_create(
55
 
/*===========*/
56
 
                                /* out,own: column prefix cache */
57
 
        ulint           n_ext,  /* in: number of externally stored columns */
58
 
        const ulint*    ext,    /* in: col_no's of externally stored columns
59
 
                                in the InnoDB table object, as reported by
60
 
                                dict_col_get_no(); NOT relative to the records
61
 
                                in the clustered index */
62
 
        const dtuple_t* tuple,  /* in: data tuple containing the field
63
 
                                references of the externally stored
64
 
                                columns; must be indexed by col_no;
65
 
                                the clustered index record must be
66
 
                                covered by a lock or a page latch
67
 
                                to prevent deletion (rollback or purge). */
68
 
        ulint           zip_size,/* compressed page size in bytes, or 0 */
69
 
        mem_heap_t*     heap)   /* in: heap where created */
70
 
{
71
 
        ulint           i;
72
 
        row_ext_t*      ret = mem_heap_alloc(heap, (sizeof *ret)
73
 
                                             + (n_ext - 1) * sizeof ret->len);
74
 
 
75
 
        ut_ad(ut_is_2pow(zip_size));
76
 
        ut_ad(zip_size <= UNIV_PAGE_SIZE);
77
 
 
78
 
        ret->n_ext = n_ext;
79
 
        ret->ext = ext;
80
 
        ret->buf = mem_heap_alloc(heap, n_ext * REC_MAX_INDEX_COL_LEN);
81
 
#ifdef UNIV_DEBUG
82
 
        memset(ret->buf, 0xaa, n_ext * REC_MAX_INDEX_COL_LEN);
83
 
        UNIV_MEM_ALLOC(ret->buf, n_ext * REC_MAX_INDEX_COL_LEN);
84
 
#endif
85
 
 
86
 
        /* Fetch the BLOB prefixes */
87
 
        for (i = 0; i < n_ext; i++) {
88
 
                const dfield_t* dfield;
89
 
 
90
 
                dfield = dtuple_get_nth_field(tuple, ext[i]);
91
 
                row_ext_cache_fill(ret, i, zip_size, dfield);
92
 
        }
93
 
 
94
 
        return(ret);
95
 
}