MySQL 5.6.14 Source Code Document
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
NdbRecord.hpp
1 /*
2  Copyright (C) 2007, 2008 MySQL AB
3  All rights reserved. Use is subject to license terms.
4 
5  This program is free software; you can redistribute it and/or modify
6  it under the terms of the GNU General Public License as published by
7  the Free Software Foundation; version 2 of the License.
8 
9  This program is distributed in the hope that it will be useful,
10  but WITHOUT ANY WARRANTY; without even the implied warranty of
11  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12  GNU General Public License for more details.
13 
14  You should have received a copy of the GNU General Public License
15  along with this program; if not, write to the Free Software
16  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
17 */
18 
19 #ifndef NdbRecord_H
20 #define NdbRecord_H
21 
22 class NdbRecord {
23 public:
24  /* Flag bits for the entire NdbRecord. */
25  enum RecFlags
26  {
27  /*
28  This flag tells whether this NdbRecord is a PK record for the table,
29  ie. that it describes _exactly_ the primary key attributes, no more and
30  no less.
31  */
32  RecIsKeyRecord= 0x1,
33 
34  /*
35  This flag tells whether this NdbRecord includes _at least_ all PK columns
36  (and possibly other columns). This is a requirement for many key-based
37  operations.
38  */
39  RecHasAllKeys= 0x2,
40 
41  /* This NdbRecord is for an ordered index, not a table. */
42  RecIsIndex= 0x4,
43 
44  /* This NdbRecord has at least one blob. */
45  RecHasBlob= 0x8,
46 
47  /*
48  The table has at least one blob (though the NdbRecord may not include
49  it). This is needed so that deleteTuple() can know to delete all blob
50  parts.
51  */
52  RecTableHasBlob= 0x10,
53 
54  /* This NdbRecord is a default NdbRecord */
55  RecIsDefaultRec= 0x20
56 
57  /* The table has user defined partitioning */
58  ,RecHasUserDefinedPartitioning = 0x40
59  };
60 
61  /* Flag bits for individual columns in the NdbRecord. */
62  enum ColFlags
63  {
64  /*
65  This flag tells whether the column is part of the primary key, used
66  for insert.
67  */
68  IsKey= 0x1,
69  /* This flag is true if column is disk based. */
70  IsDisk= 0x2,
71  /* True if column can be NULL and has a NULL bit. */
72  IsNullable= 0x04,
73  /*
74  Flags for determining the actual length of data (which for varsize
75  columns is different from the maximum size.
76  The flags are mutually exclusive.
77  */
78  IsVar1ByteLen= 0x08,
79  IsVar2ByteLen= 0x10,
80  /* Flag for column that is a part of the distribution key. */
81  IsDistributionKey= 0x20,
82  /* Flag for blob columns. */
83  IsBlob= 0x40,
84  /*
85  Flag for special handling of short varchar for index keys, which is
86  used by mysqld to avoid converting index key rows.
87  */
88  IsMysqldShrinkVarchar= 0x80,
89  /* Bitfield stored in the internal mysqld format. */
90  IsMysqldBitfield= 0x100
91  };
92 
93  struct Attr
94  {
95  Uint32 attrId;
96  Uint32 column_no;
97  /*
98  The index_attrId member is the attribute id in the index table object,
99  which is used to specify ordered index bounds in KEYINFO signal.
100  Note that this is different from the normal attribute id in the main
101  table, unless the ordered index is on columns (0..N).
102  */
103  Uint32 index_attrId;
104  /* Offset of data from the start of a row. */
105  Uint32 offset;
106  /*
107  Maximum size of the attribute. This is duplicated here to avoid having
108  to dig into Table object for every attribute fetch/store.
109  */
110  Uint32 maxSize;
111  /*
112  Alignment information for the attribute, duplicated from column info
113  */
114  Uint32 orgAttrSize;
115  /* Number of bits in a bitfield. */
116  Uint32 bitCount;
117 
118  /* Flags, or-ed from enum ColFlags. */
119  Uint32 flags;
120 
121  /* Character set information, for ordered index merge sort. */
122  CHARSET_INFO *charset_info;
123  /* Function used to compare attributes during merge sort. */
124  NdbSqlUtil::Cmp *compare_function;
125 
126 
127  /* NULL bit location (only for nullable columns, ie. flags&IsNullable). */
128  Uint32 nullbit_byte_offset;
129  Uint32 nullbit_bit_in_byte;
130 
131  bool get_var_length(const char *row, Uint32& len) const
132  {
133  if (flags & IsVar1ByteLen)
134  len= 1 + *((Uint8*)(row+offset));
135  else if (flags & IsVar2ByteLen)
136  len= 2 + uint2korr(row+offset);
137  else
138  len= maxSize;
139  return len <= maxSize;
140  }
141  bool is_null(const char *row) const
142  {
143  return (flags & IsNullable) &&
144  (row[nullbit_byte_offset] & (1 << nullbit_bit_in_byte));
145  }
146 
147  /* 255 bytes of data and 1 byte of length */
148  STATIC_CONST( SHRINK_VARCHAR_BUFFSIZE= 256 );
149  /*
150  Mysqld uses a slightly different format for storing varchar in
151  index keys; the length is always two bytes little endian, even
152  for max size < 256.
153  This converts to the usual format expected by NDB kernel.
154  */
155  bool shrink_varchar(const char *row, Uint32& out_len, char *buf) const
156  {
157  const char *p= row + offset;
158  Uint32 len= uint2korr(p);
159  if (len >= SHRINK_VARCHAR_BUFFSIZE || len >= maxSize)
160  {
161  out_len = 0;
162  return false;
163  }
164  buf[0]= (unsigned char)len;
165  memcpy(buf+1, p+2, len);
166  out_len= len + 1;
167  return true;
168  }
169  /*
170  Accessing mysqld format bitfields.
171  For internal use in myqsld.
172  In mysqld, fractional bytes of each bit field are stored inside the
173  null bytes area.
174  */
175  void get_mysqld_bitfield(const char *src_row, char *dst_buffer) const;
176  void put_mysqld_bitfield(char *dst_row, const char *src_buffer) const;
177  };
178 
179  /*
180  ToDo: For now we need to hang on to the Table *, since lots of the
181  existing code (class NdbOperation*, class NdbScanFilter) depends
182  on having access to it.
183  Long-term, we want to eliminate it (instead relying only on copying
184  tableId, fragmentCount etc. into the NdbRecord.
185  */
186  const NdbTableImpl *table;
187 
188  Uint32 tableId;
189  Uint32 tableVersion;
190  /* Copy of table->m_keyLenInWords. */
191  Uint32 m_keyLenInWords;
192  /* Total maximum size of TRANSID_AI data (for computing batch size). */
193  Uint32 m_max_transid_ai_bytes;
201  /* Flags, or-ed from enum RecFlags. */
202  Uint32 flags;
203  /* Size of row (really end of right-most defined attribute in row). */
204  Uint32 m_row_size;
205 
206  /*
207  Array of index (into columns[]) of primary key columns, in order.
208  Physical storage for these is after columns[] array.
209  This array is only fully initialised if flags&RecHasAllKeys.
210  */
211  const Uint32 *key_indexes;
212  /* Length of key_indexes array. */
213  Uint32 key_index_length;
214  /*
215  Array of index (into columns[]) of distribution keys, in attrId order.
216  This is used to build the distribution key, which is the concatenation
217  of key values in attrId order.
218 
219  If the index does not include all of the base table's distribution keys,
220  this array is empty (zero length).
221  */
222  const Uint32 *distkey_indexes;
223  /* Length of distkey_indexes array. */
224  Uint32 distkey_index_length;
225 
232  const int *m_attrId_indexes;
233  /* Size of array pointed to by m_attrId_indexes. */
234  Uint32 m_attrId_indexes_length;
235 
236  /*
237  m_min_distkey_prefix_length is the minimum lenght of an index prefix
238  needed to include all distribution keys. In other words, it is one more
239  that the index of the last distribution key in the index order.
240 
241  This member only makes sense for an index NdbRecord.
242  */
243  Uint32 m_min_distkey_prefix_length;
244  /* The real size of the array at the end of this struct. */
245  Uint32 noOfColumns;
246  struct Attr columns[1];
247 
248  /* Copy a user-supplied mask to internal mask. */
249  void copyMask(Uint32 *dst, const unsigned char *src) const;
250 
251  /* Clear internal mask. */
252  void clearMask(Uint32 *dst) const
253  {
254  BitmaskImpl::clear((NDB_MAX_ATTRIBUTES_IN_TABLE+31)>>5, dst);
255  }
256 };
257 
258 #endif