00001 /***************************************************************************** 00002 00003 Copyright (C) 1996, 2009, Innobase Oy. All Rights Reserved. 00004 00005 This program is free software; you can redistribute it and/or modify it under 00006 the terms of the GNU General Public License as published by the Free Software 00007 Foundation; version 2 of the License. 00008 00009 This program is distributed in the hope that it will be useful, but WITHOUT 00010 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS 00011 FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. 00012 00013 You should have received a copy of the GNU General Public License along with 00014 this program; if not, write to the Free Software Foundation, Inc., 51 Franklin 00015 St, Fifth Floor, Boston, MA 02110-1301 USA 00016 00017 *****************************************************************************/ 00018 00019 /**************************************************/ 00026 #pragma once 00027 #ifndef data0type_h 00028 #define data0type_h 00029 00030 #include "univ.i" 00031 00032 extern ulint data_mysql_default_charset_coll; 00033 #define DATA_MYSQL_LATIN1_SWEDISH_CHARSET_COLL 8 00034 #define DATA_MYSQL_BINARY_CHARSET_COLL 63 00035 00036 /* SQL data type struct */ 00037 typedef struct dtype_struct dtype_t; 00038 00039 /*-------------------------------------------*/ 00040 /* The 'MAIN TYPE' of a column */ 00041 #define DATA_VARCHAR 1 /* character varying of the 00042 latin1_swedish_ci charset-collation; note 00043 that the MySQL format for this, DATA_BINARY, 00044 DATA_VARMYSQL, is also affected by whether the 00045 'precise type' contains 00046 DATA_MYSQL_TRUE_VARCHAR */ 00047 #define DATA_CHAR 2 /* fixed length character of the 00048 latin1_swedish_ci charset-collation */ 00049 #define DATA_FIXBINARY 3 /* binary string of fixed length */ 00050 #define DATA_BINARY 4 /* binary string */ 00051 #define DATA_BLOB 5 /* binary large object, or a TEXT type; 00052 if prtype & DATA_BINARY_TYPE == 0, then this is 00053 actually a TEXT column (or a BLOB created 00054 with < 4.0.14; since column prefix indexes 00055 came only in 4.0.14, the missing flag in BLOBs 00056 created before that does not cause any harm) */ 00057 #define DATA_INT 6 /* integer: can be any size 1 - 8 bytes */ 00058 #define DATA_SYS_CHILD 7 /* address of the child page in node pointer */ 00059 #define DATA_SYS 8 /* system column */ 00060 00061 /* Data types >= DATA_FLOAT must be compared using the whole field, not as 00062 binary strings */ 00063 00064 #define DATA_FLOAT 9 00065 #define DATA_DOUBLE 10 00066 #define DATA_DECIMAL 11 /* decimal number stored as an ASCII string */ 00067 #define DATA_VARMYSQL 12 /* any charset varying length char */ 00068 #define DATA_MYSQL 13 /* any charset fixed length char */ 00069 /* NOTE that 4.1.1 used DATA_MYSQL and 00070 DATA_VARMYSQL for all character sets, and the 00071 charset-collation for tables created with it 00072 can also be latin1_swedish_ci */ 00073 #define DATA_MTYPE_MAX 63 /* dtype_store_for_order_and_null_size() 00074 requires the values are <= 63 */ 00075 /*-------------------------------------------*/ 00076 /* The 'PRECISE TYPE' of a column */ 00077 /* 00078 Tables created by a MySQL user have the following convention: 00079 00080 - In the least significant byte in the precise type we store the MySQL type 00081 code (not applicable for system columns). 00082 00083 - In the second least significant byte we OR flags DATA_NOT_NULL, 00084 DATA_UNSIGNED, DATA_BINARY_TYPE. 00085 00086 - In the third least significant byte of the precise type of string types we 00087 store the MySQL charset-collation code. In DATA_BLOB columns created with 00088 < 4.0.14 we do not actually know if it is a BLOB or a TEXT column. Since there 00089 are no indexes on prefixes of BLOB or TEXT columns in < 4.0.14, this is no 00090 problem, though. 00091 00092 Note that versions < 4.1.2 or < 5.0.1 did not store the charset code to the 00093 precise type, since the charset was always the default charset of the MySQL 00094 installation. If the stored charset code is 0 in the system table SYS_COLUMNS 00095 of InnoDB, that means that the default charset of this MySQL installation 00096 should be used. 00097 00098 When loading a table definition from the system tables to the InnoDB data 00099 dictionary cache in main memory, InnoDB versions >= 4.1.2 and >= 5.0.1 check 00100 if the stored charset-collation is 0, and if that is the case and the type is 00101 a non-binary string, replace that 0 by the default charset-collation code of 00102 this MySQL installation. In short, in old tables, the charset-collation code 00103 in the system tables on disk can be 0, but in in-memory data structures 00104 (dtype_t), the charset-collation code is always != 0 for non-binary string 00105 types. 00106 00107 In new tables, in binary string types, the charset-collation code is the 00108 MySQL code for the 'binary charset', that is, != 0. 00109 00110 For binary string types and for DATA_CHAR, DATA_VARCHAR, and for those 00111 DATA_BLOB which are binary or have the charset-collation latin1_swedish_ci, 00112 InnoDB performs all comparisons internally, without resorting to the MySQL 00113 comparison functions. This is to save CPU time. 00114 00115 InnoDB's own internal system tables have different precise types for their 00116 columns, and for them the precise type is usually not used at all. 00117 */ 00118 00119 #define DATA_ENGLISH 4 /* English language character string: this 00120 is a relic from pre-MySQL time and only used 00121 for InnoDBs own system tables */ 00122 #define DATA_ERROR 111 /* another relic from pre-MySQL time */ 00123 00124 #define DATA_MYSQL_TYPE_MASK 255 /* AND with this mask to extract the MySQL 00125 type from the precise type */ 00126 #if defined(BUILD_DRIZZLE) 00127 # define DATA_MYSQL_TRUE_VARCHAR 7 /* Drizzle type code for true VARCHAR */ 00128 #else 00129 # define DATA_MYSQL_TRUE_VARCHAR 15 /* MySQL type code for the >= 5.0.3 00130 format true VARCHAR */ 00131 #endif 00132 00133 /* Precise data types for system columns and the length of those columns; 00134 NOTE: the values must run from 0 up in the order given! All codes must 00135 be less than 256 */ 00136 #define DATA_ROW_ID 0 /* row id: a 48-bit integer */ 00137 #define DATA_ROW_ID_LEN 6 /* stored length for row id */ 00138 00139 #define DATA_TRX_ID 1 /* transaction id: 6 bytes */ 00140 #define DATA_TRX_ID_LEN 6 00141 00142 #define DATA_ROLL_PTR 2 /* rollback data pointer: 7 bytes */ 00143 #define DATA_ROLL_PTR_LEN 7 00144 00145 #define DATA_N_SYS_COLS 3 /* number of system columns defined above */ 00146 00147 #define DATA_SYS_PRTYPE_MASK 0xF /* mask to extract the above from prtype */ 00148 00149 /* Flags ORed to the precise data type */ 00150 #define DATA_NOT_NULL 256 /* this is ORed to the precise type when 00151 the column is declared as NOT NULL */ 00152 #define DATA_UNSIGNED 512 /* this id ORed to the precise type when 00153 we have an unsigned integer type */ 00154 #define DATA_BINARY_TYPE 1024 /* if the data type is a binary character 00155 string, this is ORed to the precise type: 00156 this only holds for tables created with 00157 >= MySQL-4.0.14 */ 00158 /* #define DATA_NONLATIN1 2048 This is a relic from < 4.1.2 and < 5.0.1. 00159 In earlier versions this was set for some 00160 BLOB columns. 00161 */ 00162 #define DATA_LONG_TRUE_VARCHAR 4096 /* this is ORed to the precise data 00163 type when the column is true VARCHAR where 00164 MySQL uses 2 bytes to store the data len; 00165 for shorter VARCHARs MySQL uses only 1 byte */ 00166 /*-------------------------------------------*/ 00167 00168 /* This many bytes we need to store the type information affecting the 00169 alphabetical order for a single field and decide the storage size of an 00170 SQL null*/ 00171 #define DATA_ORDER_NULL_TYPE_BUF_SIZE 4 00172 /* In the >= 4.1.x storage format we add 2 bytes more so that we can also 00173 store the charset-collation number; one byte is left unused, though */ 00174 #define DATA_NEW_ORDER_NULL_TYPE_BUF_SIZE 6 00175 00176 /* Maximum multi-byte character length in bytes, plus 1 */ 00177 #define DATA_MBMAX 5 00178 00179 /* Pack mbminlen, mbmaxlen to mbminmaxlen. */ 00180 #define DATA_MBMINMAXLEN(mbminlen, mbmaxlen) \ 00181 ((mbmaxlen) * DATA_MBMAX + (mbminlen)) 00182 /* Get mbminlen from mbminmaxlen. Cast the result of UNIV_EXPECT to ulint 00183 because in GCC it returns a long. */ 00184 #define DATA_MBMINLEN(mbminmaxlen) ((ulint) \ 00185 UNIV_EXPECT(((mbminmaxlen) % DATA_MBMAX), \ 00186 1)) 00187 /* Get mbmaxlen from mbminmaxlen. */ 00188 #define DATA_MBMAXLEN(mbminmaxlen) ((ulint) ((mbminmaxlen) / DATA_MBMAX)) 00189 00190 #ifndef UNIV_HOTBACKUP 00191 /*********************************************************************/ 00194 UNIV_INLINE 00195 ulint 00196 dtype_get_mysql_type( 00197 /*=================*/ 00198 const dtype_t* type); 00199 /*********************************************************************/ 00204 UNIV_INTERN 00205 ulint 00206 dtype_get_at_most_n_mbchars( 00207 /*========================*/ 00208 ulint prtype, 00209 ulint mbminmaxlen, 00211 ulint prefix_len, 00214 ulint data_len, 00215 const char* str); 00217 #endif /* !UNIV_HOTBACKUP */ 00218 /*********************************************************************/ 00222 UNIV_INTERN 00223 ibool 00224 dtype_is_string_type( 00225 /*=================*/ 00226 ulint mtype); 00227 /*********************************************************************/ 00232 UNIV_INTERN 00233 ibool 00234 dtype_is_binary_string_type( 00235 /*========================*/ 00236 ulint mtype, 00237 ulint prtype); 00238 /*********************************************************************/ 00244 UNIV_INTERN 00245 ibool 00246 dtype_is_non_binary_string_type( 00247 /*============================*/ 00248 ulint mtype, 00249 ulint prtype); 00250 /*********************************************************************/ 00252 UNIV_INLINE 00253 void 00254 dtype_set( 00255 /*======*/ 00256 dtype_t* type, 00257 ulint mtype, 00258 ulint prtype, 00259 ulint len); 00260 /*********************************************************************/ 00262 UNIV_INLINE 00263 void 00264 dtype_copy( 00265 /*=======*/ 00266 dtype_t* type1, 00267 const dtype_t* type2); 00268 /*********************************************************************/ 00271 UNIV_INLINE 00272 ulint 00273 dtype_get_mtype( 00274 /*============*/ 00275 const dtype_t* type); 00276 /*********************************************************************/ 00279 UNIV_INLINE 00280 ulint 00281 dtype_get_prtype( 00282 /*=============*/ 00283 const dtype_t* type); 00284 #ifndef UNIV_HOTBACKUP 00285 /*********************************************************************/ 00287 UNIV_INLINE 00288 void 00289 dtype_get_mblen( 00290 /*============*/ 00291 ulint mtype, 00292 ulint prtype, 00293 ulint* mbminlen, 00295 ulint* mbmaxlen); 00297 /*********************************************************************/ 00300 UNIV_INLINE 00301 ulint 00302 dtype_get_charset_coll( 00303 /*===================*/ 00304 ulint prtype); 00305 /*********************************************************************/ 00309 UNIV_INTERN 00310 ulint 00311 dtype_form_prtype( 00312 /*==============*/ 00313 ulint old_prtype, 00315 ulint charset_coll); 00316 /*********************************************************************/ 00321 UNIV_INLINE 00322 ibool 00323 dtype_is_utf8( 00324 /*==========*/ 00325 ulint prtype); 00326 #endif /* !UNIV_HOTBACKUP */ 00327 /*********************************************************************/ 00330 UNIV_INLINE 00331 ulint 00332 dtype_get_len( 00333 /*==========*/ 00334 const dtype_t* type); 00335 #ifndef UNIV_HOTBACKUP 00336 /*********************************************************************/ 00340 UNIV_INLINE 00341 ulint 00342 dtype_get_mbminlen( 00343 /*===============*/ 00344 const dtype_t* type); 00345 /*********************************************************************/ 00349 UNIV_INLINE 00350 ulint 00351 dtype_get_mbmaxlen( 00352 /*===============*/ 00353 const dtype_t* type); 00354 /*********************************************************************/ 00356 UNIV_INLINE 00357 void 00358 dtype_set_mbminmaxlen( 00359 /*==================*/ 00360 dtype_t* type, 00361 ulint mbminlen, 00364 ulint mbmaxlen); 00367 /*********************************************************************/ 00370 UNIV_INLINE 00371 ulint 00372 dtype_get_pad_char( 00373 /*===============*/ 00374 ulint mtype, 00375 ulint prtype); 00376 #endif /* !UNIV_HOTBACKUP */ 00377 /***********************************************************************/ 00380 UNIV_INLINE 00381 ulint 00382 dtype_get_fixed_size_low( 00383 /*=====================*/ 00384 ulint mtype, 00385 ulint prtype, 00386 ulint len, 00387 ulint mbminmaxlen, 00389 ulint comp); 00390 #ifndef UNIV_HOTBACKUP 00391 /***********************************************************************/ 00394 UNIV_INLINE 00395 ulint 00396 dtype_get_min_size_low( 00397 /*===================*/ 00398 ulint mtype, 00399 ulint prtype, 00400 ulint len, 00401 ulint mbminmaxlen); 00403 /***********************************************************************/ 00407 UNIV_INLINE 00408 ulint 00409 dtype_get_max_size_low( 00410 /*===================*/ 00411 ulint mtype, 00412 ulint len); 00413 #endif /* !UNIV_HOTBACKUP */ 00414 /***********************************************************************/ 00418 UNIV_INLINE 00419 ulint 00420 dtype_get_sql_null_size( 00421 /*====================*/ 00422 const dtype_t* type, 00423 ulint comp); 00424 #ifndef UNIV_HOTBACKUP 00425 /**********************************************************************/ 00428 UNIV_INLINE 00429 void 00430 dtype_read_for_order_and_null_size( 00431 /*===============================*/ 00432 dtype_t* type, 00433 const byte* buf); 00434 /**********************************************************************/ 00438 UNIV_INLINE 00439 void 00440 dtype_new_store_for_order_and_null_size( 00441 /*====================================*/ 00442 byte* buf, 00445 const dtype_t* type, 00446 ulint prefix_len); 00448 /**********************************************************************/ 00452 UNIV_INLINE 00453 void 00454 dtype_new_read_for_order_and_null_size( 00455 /*===================================*/ 00456 dtype_t* type, 00457 const byte* buf); 00458 #endif /* !UNIV_HOTBACKUP */ 00459 00460 /*********************************************************************/ 00463 UNIV_INTERN 00464 ibool 00465 dtype_validate( 00466 /*===========*/ 00467 const dtype_t* type); 00468 /*********************************************************************/ 00470 UNIV_INTERN 00471 void 00472 dtype_print( 00473 /*========*/ 00474 const dtype_t* type); 00476 /* Structure for an SQL data type. 00477 If you add fields to this structure, be sure to initialize them everywhere. 00478 This structure is initialized in the following functions: 00479 dtype_set() 00480 dtype_read_for_order_and_null_size() 00481 dtype_new_read_for_order_and_null_size() 00482 sym_tab_add_null_lit() */ 00483 00484 struct dtype_struct{ 00485 unsigned mtype:8; 00486 unsigned prtype:24; 00494 /* the remaining fields do not affect alphabetical ordering: */ 00495 00496 unsigned len:16; 00504 #ifndef UNIV_HOTBACKUP 00505 unsigned mbminmaxlen:5; 00510 #endif /* !UNIV_HOTBACKUP */ 00511 }; 00512 00513 #ifndef UNIV_NONINL 00514 #include "data0type.ic" 00515 #endif 00516 00517 #endif