| 1 | #ifndef FIELD_INCLUDED |
| 2 | #define FIELD_INCLUDED |
| 3 | /* Copyright (c) 2000, 2015, Oracle and/or its affiliates. |
| 4 | Copyright (c) 2008, 2017, MariaDB Corporation. |
| 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 | Because of the function make_new_field() all field classes that have static |
| 21 | variables must declare the size_of() member function. |
| 22 | */ |
| 23 | |
| 24 | #ifdef USE_PRAGMA_INTERFACE |
| 25 | #pragma interface /* gcc class implementation */ |
| 26 | #endif |
| 27 | |
| 28 | #include "mysqld.h" /* system_charset_info */ |
| 29 | #include "table.h" /* TABLE */ |
| 30 | #include "sql_string.h" /* String */ |
| 31 | #include "my_decimal.h" /* my_decimal */ |
| 32 | #include "sql_error.h" /* Sql_condition */ |
| 33 | #include "compat56.h" |
| 34 | #include "sql_type.h" /* Type_std_attributes */ |
| 35 | #include "field_comp.h" |
| 36 | |
| 37 | class Send_field; |
| 38 | class Copy_field; |
| 39 | class Protocol; |
| 40 | class Create_field; |
| 41 | class Relay_log_info; |
| 42 | class Field; |
| 43 | class Column_statistics; |
| 44 | class Column_statistics_collected; |
| 45 | class Item_func; |
| 46 | class Item_bool_func; |
| 47 | class Item_equal; |
| 48 | class Virtual_tmp_table; |
| 49 | class Qualified_column_ident; |
| 50 | class Table_ident; |
| 51 | |
| 52 | enum enum_check_fields |
| 53 | { |
| 54 | CHECK_FIELD_IGNORE, |
| 55 | CHECK_FIELD_EXPRESSION, |
| 56 | CHECK_FIELD_WARN, |
| 57 | CHECK_FIELD_ERROR_FOR_NULL, |
| 58 | }; |
| 59 | |
| 60 | /* |
| 61 | Common declarations for Field and Item |
| 62 | */ |
| 63 | class Value_source |
| 64 | { |
| 65 | protected: |
| 66 | |
| 67 | // Parameters for warning and note generation |
| 68 | class Warn_filter |
| 69 | { |
| 70 | bool m_want_warning_edom; |
| 71 | bool m_want_note_truncated_spaces; |
| 72 | public: |
| 73 | Warn_filter(bool want_warning_edom, bool want_note_truncated_spaces) : |
| 74 | m_want_warning_edom(want_warning_edom), |
| 75 | m_want_note_truncated_spaces(want_note_truncated_spaces) |
| 76 | { } |
| 77 | Warn_filter(const THD *thd); |
| 78 | bool want_warning_edom() const |
| 79 | { return m_want_warning_edom; } |
| 80 | bool want_note_truncated_spaces() const |
| 81 | { return m_want_note_truncated_spaces; } |
| 82 | }; |
| 83 | class Warn_filter_all: public Warn_filter |
| 84 | { |
| 85 | public: |
| 86 | Warn_filter_all() :Warn_filter(true, true) { } |
| 87 | }; |
| 88 | |
| 89 | class Converter_double_to_longlong |
| 90 | { |
| 91 | protected: |
| 92 | bool m_error; |
| 93 | longlong m_result; |
| 94 | public: |
| 95 | Converter_double_to_longlong(double nr, bool unsigned_flag); |
| 96 | longlong result() const { return m_result; } |
| 97 | bool error() const { return m_error; } |
| 98 | void push_warning(THD *thd, double nr, bool unsigned_flag); |
| 99 | }; |
| 100 | class Converter_double_to_longlong_with_warn: |
| 101 | public Converter_double_to_longlong |
| 102 | { |
| 103 | public: |
| 104 | Converter_double_to_longlong_with_warn(THD *thd, double nr, |
| 105 | bool unsigned_flag) |
| 106 | :Converter_double_to_longlong(nr, unsigned_flag) |
| 107 | { |
| 108 | if (m_error) |
| 109 | push_warning(thd, nr, unsigned_flag); |
| 110 | } |
| 111 | Converter_double_to_longlong_with_warn(double nr, bool unsigned_flag) |
| 112 | :Converter_double_to_longlong(nr, unsigned_flag) |
| 113 | { |
| 114 | if (m_error) |
| 115 | push_warning(current_thd, nr, unsigned_flag); |
| 116 | } |
| 117 | }; |
| 118 | |
| 119 | // String-to-number converters |
| 120 | class Converter_string_to_number |
| 121 | { |
| 122 | protected: |
| 123 | char *m_end_of_num; // Where the low-level conversion routine stopped |
| 124 | int m_error; // The error code returned by the low-level routine |
| 125 | bool m_edom; // If EDOM-alike error happened during conversion |
| 126 | /** |
| 127 | Check string-to-number conversion and produce a warning if |
| 128 | - could not convert any digits (EDOM-alike error) |
| 129 | - found garbage at the end of the string |
| 130 | - found extra spaces at the end (a note) |
| 131 | See also Field_num::check_edom_and_truncation() for a similar function. |
| 132 | |
| 133 | @param thd - the thread that will be used to generate warnings. |
| 134 | Can be NULL (which means current_thd will be used |
| 135 | if a warning is really necessary). |
| 136 | @param type - name of the data type |
| 137 | (e.g. "INTEGER", "DECIMAL", "DOUBLE") |
| 138 | @param cs - character set of the original string |
| 139 | @param str - the original string |
| 140 | @param end - the end of the string |
| 141 | @param allow_notes - tells if trailing space notes should be displayed |
| 142 | or suppressed. |
| 143 | |
| 144 | Unlike Field_num::check_edom_and_truncation(), this function does not |
| 145 | distinguish between EDOM and truncation and reports the same warning for |
| 146 | both cases. Perhaps we should eventually print different warnings, |
| 147 | to make the explicit CAST work closer to the implicit cast in |
| 148 | Field_xxx::store(). |
| 149 | */ |
| 150 | void check_edom_and_truncation(THD *thd, Warn_filter filter, |
| 151 | const char *type, |
| 152 | CHARSET_INFO *cs, |
| 153 | const char *str, |
| 154 | size_t length) const; |
| 155 | public: |
| 156 | int error() const { return m_error; } |
| 157 | }; |
| 158 | |
| 159 | class Converter_strntod: public Converter_string_to_number |
| 160 | { |
| 161 | double m_result; |
| 162 | public: |
| 163 | Converter_strntod(CHARSET_INFO *cs, const char *str, size_t length) |
| 164 | { |
| 165 | m_result= my_strntod(cs, (char *) str, length, &m_end_of_num, &m_error); |
| 166 | // strntod() does not set an error if the input string was empty |
| 167 | m_edom= m_error !=0 || str == m_end_of_num; |
| 168 | } |
| 169 | double result() const { return m_result; } |
| 170 | }; |
| 171 | |
| 172 | class Converter_string_to_longlong: public Converter_string_to_number |
| 173 | { |
| 174 | protected: |
| 175 | longlong m_result; |
| 176 | public: |
| 177 | longlong result() const { return m_result; } |
| 178 | }; |
| 179 | |
| 180 | class Converter_strntoll: public Converter_string_to_longlong |
| 181 | { |
| 182 | public: |
| 183 | Converter_strntoll(CHARSET_INFO *cs, const char *str, size_t length) |
| 184 | { |
| 185 | m_result= my_strntoll(cs, str, length, 10, &m_end_of_num, &m_error); |
| 186 | /* |
| 187 | All non-zero errors means EDOM error. |
| 188 | strntoll() does not set an error if the input string was empty. |
| 189 | Check it here. |
| 190 | Notice the different with the same condition in Converter_strntoll10. |
| 191 | */ |
| 192 | m_edom= m_error != 0 || str == m_end_of_num; |
| 193 | } |
| 194 | }; |
| 195 | |
| 196 | class Converter_strtoll10: public Converter_string_to_longlong |
| 197 | { |
| 198 | public: |
| 199 | Converter_strtoll10(CHARSET_INFO *cs, const char *str, size_t length) |
| 200 | { |
| 201 | m_end_of_num= (char *) str + length; |
| 202 | m_result= (*(cs->cset->strtoll10))(cs, str, &m_end_of_num, &m_error); |
| 203 | /* |
| 204 | Negative error means "good negative number". |
| 205 | Only a positive m_error value means a real error. |
| 206 | strtoll10() sets error to MY_ERRNO_EDOM in case of an empty string, |
| 207 | so we don't have to additionally catch empty strings here. |
| 208 | */ |
| 209 | m_edom= m_error > 0; |
| 210 | } |
| 211 | }; |
| 212 | |
| 213 | class Converter_str2my_decimal: public Converter_string_to_number |
| 214 | { |
| 215 | public: |
| 216 | Converter_str2my_decimal(uint mask, |
| 217 | CHARSET_INFO *cs, const char *str, size_t length, |
| 218 | my_decimal *buf) |
| 219 | { |
| 220 | DBUG_ASSERT(length < UINT_MAX32); |
| 221 | m_error= str2my_decimal(mask, str, length, cs, |
| 222 | buf, (const char **) &m_end_of_num); |
| 223 | // E_DEC_TRUNCATED means a very minor truncation: '1e-100' -> 0 |
| 224 | m_edom= m_error && m_error != E_DEC_TRUNCATED; |
| 225 | } |
| 226 | }; |
| 227 | |
| 228 | |
| 229 | // String-to-number converters with automatic warning generation |
| 230 | class Converter_strntod_with_warn: public Converter_strntod |
| 231 | { |
| 232 | public: |
| 233 | Converter_strntod_with_warn(THD *thd, Warn_filter filter, |
| 234 | CHARSET_INFO *cs, |
| 235 | const char *str, size_t length) |
| 236 | :Converter_strntod(cs, str, length) |
| 237 | { |
| 238 | check_edom_and_truncation(thd, filter, "DOUBLE" , cs, str, length); |
| 239 | } |
| 240 | }; |
| 241 | |
| 242 | class Converter_strntoll_with_warn: public Converter_strntoll |
| 243 | { |
| 244 | public: |
| 245 | Converter_strntoll_with_warn(THD *thd, Warn_filter filter, |
| 246 | CHARSET_INFO *cs, |
| 247 | const char *str, size_t length) |
| 248 | :Converter_strntoll(cs, str, length) |
| 249 | { |
| 250 | check_edom_and_truncation(thd, filter, "INTEGER" , cs, str, length); |
| 251 | } |
| 252 | }; |
| 253 | |
| 254 | class Converter_strtoll10_with_warn: public Converter_strtoll10 |
| 255 | { |
| 256 | public: |
| 257 | Converter_strtoll10_with_warn(THD *thd, Warn_filter filter, |
| 258 | CHARSET_INFO *cs, |
| 259 | const char *str, size_t length) |
| 260 | :Converter_strtoll10(cs, str, length) |
| 261 | { |
| 262 | check_edom_and_truncation(thd, filter, "INTEGER" , cs, str, length); |
| 263 | } |
| 264 | }; |
| 265 | |
| 266 | class Converter_str2my_decimal_with_warn: public Converter_str2my_decimal |
| 267 | { |
| 268 | public: |
| 269 | Converter_str2my_decimal_with_warn(THD *thd, Warn_filter filter, |
| 270 | uint mask, CHARSET_INFO *cs, |
| 271 | const char *str, size_t length, |
| 272 | my_decimal *buf) |
| 273 | :Converter_str2my_decimal(mask, cs, str, length, buf) |
| 274 | { |
| 275 | check_edom_and_truncation(thd, filter, "DECIMAL" , cs, str, length); |
| 276 | } |
| 277 | }; |
| 278 | |
| 279 | |
| 280 | // String-to-number convertion methods for the old code compatibility |
| 281 | longlong longlong_from_string_with_check(CHARSET_INFO *cs, const char *cptr, |
| 282 | const char *end) const |
| 283 | { |
| 284 | /* |
| 285 | TODO: Give error if we wanted a signed integer and we got an unsigned |
| 286 | one |
| 287 | |
| 288 | Notice, longlong_from_string_with_check() honors thd->no_error, because |
| 289 | it's used to handle queries like this: |
| 290 | SELECT COUNT(@@basedir); |
| 291 | and is called when Item_func_get_system_var::update_null_value() |
| 292 | suppresses warnings and then calls val_int(). |
| 293 | The other methods {double|decimal}_from_string_with_check() ignore |
| 294 | thd->no_errors, because they are not used for update_null_value() |
| 295 | and they always allow all kind of warnings. |
| 296 | */ |
| 297 | THD *thd= current_thd; |
| 298 | return Converter_strtoll10_with_warn(thd, Warn_filter(thd), |
| 299 | cs, cptr, end - cptr).result(); |
| 300 | } |
| 301 | |
| 302 | double double_from_string_with_check(CHARSET_INFO *cs, const char *cptr, |
| 303 | const char *end) const |
| 304 | { |
| 305 | return Converter_strntod_with_warn(NULL, Warn_filter_all(), |
| 306 | cs, cptr, end - cptr).result(); |
| 307 | } |
| 308 | my_decimal *decimal_from_string_with_check(my_decimal *decimal_value, |
| 309 | CHARSET_INFO *cs, |
| 310 | const char *cptr, |
| 311 | const char *end) |
| 312 | { |
| 313 | Converter_str2my_decimal_with_warn(NULL, Warn_filter_all(), |
| 314 | E_DEC_FATAL_ERROR & ~E_DEC_BAD_NUM, |
| 315 | cs, cptr, end - cptr, decimal_value); |
| 316 | return decimal_value; |
| 317 | } |
| 318 | |
| 319 | longlong longlong_from_hex_hybrid(const char *str, size_t length) |
| 320 | { |
| 321 | const char *end= str + length; |
| 322 | const char *ptr= end - MY_MIN(length, sizeof(longlong)); |
| 323 | ulonglong value= 0; |
| 324 | for ( ; ptr != end ; ptr++) |
| 325 | value= (value << 8) + (ulonglong) (uchar) *ptr; |
| 326 | return (longlong) value; |
| 327 | } |
| 328 | |
| 329 | longlong longlong_from_string_with_check(const String *str) const |
| 330 | { |
| 331 | return longlong_from_string_with_check(str->charset(), |
| 332 | str->ptr(), str->end()); |
| 333 | } |
| 334 | double double_from_string_with_check(const String *str) const |
| 335 | { |
| 336 | return double_from_string_with_check(str->charset(), |
| 337 | str->ptr(), str->end()); |
| 338 | } |
| 339 | my_decimal *decimal_from_string_with_check(my_decimal *decimal_value, |
| 340 | const String *str) |
| 341 | { |
| 342 | return decimal_from_string_with_check(decimal_value, str->charset(), |
| 343 | str->ptr(), str->end()); |
| 344 | } |
| 345 | // End of String-to-number conversion methods |
| 346 | |
| 347 | public: |
| 348 | /* |
| 349 | The enumeration Subst_constraint is currently used only in implementations |
| 350 | of the virtual function subst_argument_checker. |
| 351 | */ |
| 352 | enum Subst_constraint |
| 353 | { |
| 354 | ANY_SUBST, /* Any substitution for a field is allowed */ |
| 355 | IDENTITY_SUBST /* Substitution for a field is allowed if any two |
| 356 | different values of the field type are not equal */ |
| 357 | }; |
| 358 | /* |
| 359 | Item context attributes. |
| 360 | Comparison functions pass their attributes to propagate_equal_fields(). |
| 361 | For exmple, for string comparison, the collation of the comparison |
| 362 | operation is important inside propagate_equal_fields(). |
| 363 | */ |
| 364 | class Context |
| 365 | { |
| 366 | /* |
| 367 | Which type of propagation is allowed: |
| 368 | - ANY_SUBST (loose equality, according to the collation), or |
| 369 | - IDENTITY_SUBST (strict binary equality). |
| 370 | */ |
| 371 | Subst_constraint m_subst_constraint; |
| 372 | /* |
| 373 | Comparison type. |
| 374 | Important only when ANY_SUBSTS. |
| 375 | */ |
| 376 | const Type_handler *m_compare_handler; |
| 377 | /* |
| 378 | Collation of the comparison operation. |
| 379 | Important only when ANY_SUBST. |
| 380 | */ |
| 381 | CHARSET_INFO *m_compare_collation; |
| 382 | public: |
| 383 | Context(Subst_constraint subst, const Type_handler *h, CHARSET_INFO *cs) |
| 384 | :m_subst_constraint(subst), |
| 385 | m_compare_handler(h), |
| 386 | m_compare_collation(cs) |
| 387 | { DBUG_ASSERT(h == h->type_handler_for_comparison()); } |
| 388 | Subst_constraint subst_constraint() const { return m_subst_constraint; } |
| 389 | const Type_handler *compare_type_handler() const |
| 390 | { |
| 391 | DBUG_ASSERT(m_subst_constraint == ANY_SUBST); |
| 392 | return m_compare_handler; |
| 393 | } |
| 394 | CHARSET_INFO *compare_collation() const |
| 395 | { |
| 396 | DBUG_ASSERT(m_subst_constraint == ANY_SUBST); |
| 397 | return m_compare_collation; |
| 398 | } |
| 399 | }; |
| 400 | class Context_identity: public Context |
| 401 | { // Use this to request only exact value, no invariants. |
| 402 | public: |
| 403 | Context_identity() |
| 404 | :Context(IDENTITY_SUBST, &type_handler_long_blob, &my_charset_bin) { } |
| 405 | }; |
| 406 | class Context_boolean: public Context |
| 407 | { // Use this when an item is [a part of] a boolean expression |
| 408 | public: |
| 409 | Context_boolean() |
| 410 | :Context(ANY_SUBST, &type_handler_longlong, &my_charset_bin) { } |
| 411 | }; |
| 412 | }; |
| 413 | |
| 414 | |
| 415 | #define STORAGE_TYPE_MASK 7 |
| 416 | #define COLUMN_FORMAT_MASK 7 |
| 417 | #define COLUMN_FORMAT_SHIFT 3 |
| 418 | |
| 419 | /* The length of the header part for each virtual column in the .frm file */ |
| 420 | #define (b) (3 + MY_TEST(b)) |
| 421 | #define FRM_VCOL_NEW_BASE_SIZE 16 |
| 422 | #define 6 |
| 423 | |
| 424 | class Count_distinct_field; |
| 425 | |
| 426 | struct ha_field_option_struct; |
| 427 | |
| 428 | struct st_cache_field; |
| 429 | int field_conv(Field *to,Field *from); |
| 430 | int truncate_double(double *nr, uint field_length, uint dec, |
| 431 | bool unsigned_flag, double max_value); |
| 432 | |
| 433 | inline uint get_enum_pack_length(int elements) |
| 434 | { |
| 435 | return elements < 256 ? 1 : 2; |
| 436 | } |
| 437 | |
| 438 | inline uint get_set_pack_length(int elements) |
| 439 | { |
| 440 | uint len= (elements + 7) / 8; |
| 441 | return len > 4 ? 8 : len; |
| 442 | } |
| 443 | |
| 444 | |
| 445 | /** |
| 446 | Tests if field type is temporal and has date part, |
| 447 | i.e. represents DATE, DATETIME or TIMESTAMP types in SQL. |
| 448 | |
| 449 | @param type Field type, as returned by field->type(). |
| 450 | @retval true If field type is temporal type with date part. |
| 451 | @retval false If field type is not temporal type with date part. |
| 452 | */ |
| 453 | inline bool is_temporal_type_with_date(enum_field_types type) |
| 454 | { |
| 455 | switch (type) |
| 456 | { |
| 457 | case MYSQL_TYPE_DATE: |
| 458 | case MYSQL_TYPE_DATETIME: |
| 459 | case MYSQL_TYPE_TIMESTAMP: |
| 460 | return true; |
| 461 | case MYSQL_TYPE_DATETIME2: |
| 462 | case MYSQL_TYPE_TIMESTAMP2: |
| 463 | DBUG_ASSERT(0); // field->real_type() should not get to here. |
| 464 | default: |
| 465 | return false; |
| 466 | } |
| 467 | } |
| 468 | |
| 469 | |
| 470 | /** |
| 471 | Convert temporal real types as retuned by field->real_type() |
| 472 | to field type as returned by field->type(). |
| 473 | |
| 474 | @param real_type Real type. |
| 475 | @retval Field type. |
| 476 | */ |
| 477 | inline enum_field_types real_type_to_type(enum_field_types real_type) |
| 478 | { |
| 479 | switch (real_type) |
| 480 | { |
| 481 | case MYSQL_TYPE_TIME2: |
| 482 | return MYSQL_TYPE_TIME; |
| 483 | case MYSQL_TYPE_DATETIME2: |
| 484 | return MYSQL_TYPE_DATETIME; |
| 485 | case MYSQL_TYPE_TIMESTAMP2: |
| 486 | return MYSQL_TYPE_TIMESTAMP; |
| 487 | case MYSQL_TYPE_NEWDATE: |
| 488 | return MYSQL_TYPE_DATE; |
| 489 | /* Note: NEWDECIMAL is a type, not only a real_type */ |
| 490 | default: return real_type; |
| 491 | } |
| 492 | } |
| 493 | |
| 494 | |
| 495 | enum enum_vcol_info_type |
| 496 | { |
| 497 | VCOL_GENERATED_VIRTUAL, VCOL_GENERATED_STORED, |
| 498 | VCOL_DEFAULT, VCOL_CHECK_FIELD, VCOL_CHECK_TABLE, |
| 499 | /* Additional types should be added here */ |
| 500 | /* Following is the highest value last */ |
| 501 | VCOL_TYPE_NONE = 127 // Since the 0 value is already in use |
| 502 | }; |
| 503 | |
| 504 | static inline const char *vcol_type_name(enum_vcol_info_type type) |
| 505 | { |
| 506 | switch (type) |
| 507 | { |
| 508 | case VCOL_GENERATED_VIRTUAL: |
| 509 | case VCOL_GENERATED_STORED: |
| 510 | return "GENERATED ALWAYS AS" ; |
| 511 | case VCOL_DEFAULT: |
| 512 | return "DEFAULT" ; |
| 513 | case VCOL_CHECK_FIELD: |
| 514 | case VCOL_CHECK_TABLE: |
| 515 | return "CHECK" ; |
| 516 | case VCOL_TYPE_NONE: |
| 517 | return "UNTYPED" ; |
| 518 | } |
| 519 | return 0; |
| 520 | } |
| 521 | |
| 522 | /* |
| 523 | Flags for Virtual_column_info. If none is set, the expression must be |
| 524 | a constant with no side-effects, so it's calculated at CREATE TABLE time, |
| 525 | stored in table->record[2], and not recalculated for every statement. |
| 526 | */ |
| 527 | #define VCOL_FIELD_REF 1 |
| 528 | #define VCOL_NON_DETERMINISTIC 2 |
| 529 | #define VCOL_SESSION_FUNC 4 /* uses session data, e.g. USER or DAYNAME */ |
| 530 | #define VCOL_TIME_FUNC 8 |
| 531 | #define VCOL_AUTO_INC 16 |
| 532 | #define VCOL_IMPOSSIBLE 32 |
| 533 | #define VCOL_NOT_VIRTUAL 64 /* Function can't be virtual */ |
| 534 | |
| 535 | #define VCOL_NOT_STRICTLY_DETERMINISTIC \ |
| 536 | (VCOL_NON_DETERMINISTIC | VCOL_TIME_FUNC | VCOL_SESSION_FUNC) |
| 537 | |
| 538 | /* |
| 539 | Virtual_column_info is the class to contain additional |
| 540 | characteristics that is specific for a virtual/computed |
| 541 | field such as: |
| 542 | - the defining expression that is evaluated to compute the value |
| 543 | of the field |
| 544 | - whether the field is to be stored in the database |
| 545 | - whether the field is used in a partitioning expression |
| 546 | */ |
| 547 | |
| 548 | class Virtual_column_info: public Sql_alloc |
| 549 | { |
| 550 | private: |
| 551 | enum_vcol_info_type vcol_type; /* Virtual column expression type */ |
| 552 | /* |
| 553 | The following data is only updated by the parser and read |
| 554 | when a Create_field object is created/initialized. |
| 555 | */ |
| 556 | enum_field_types field_type; /* Real field type*/ |
| 557 | /* Flag indicating that the field used in a partitioning expression */ |
| 558 | bool in_partitioning_expr; |
| 559 | |
| 560 | public: |
| 561 | /* Flag indicating that the field is physically stored in the database */ |
| 562 | bool stored_in_db; |
| 563 | bool utf8; /* Already in utf8 */ |
| 564 | Item *expr; |
| 565 | LEX_CSTRING name; /* Name of constraint */ |
| 566 | uint flags; |
| 567 | |
| 568 | Virtual_column_info() |
| 569 | : vcol_type((enum_vcol_info_type)VCOL_TYPE_NONE), |
| 570 | field_type((enum enum_field_types)MYSQL_TYPE_VIRTUAL), |
| 571 | in_partitioning_expr(FALSE), stored_in_db(FALSE), |
| 572 | utf8(TRUE), expr(NULL), flags(0) |
| 573 | { |
| 574 | name.str= NULL; |
| 575 | name.length= 0; |
| 576 | }; |
| 577 | ~Virtual_column_info() {} |
| 578 | enum_vcol_info_type get_vcol_type() const |
| 579 | { |
| 580 | return vcol_type; |
| 581 | } |
| 582 | void set_vcol_type(enum_vcol_info_type v_type) |
| 583 | { |
| 584 | vcol_type= v_type; |
| 585 | } |
| 586 | const char *get_vcol_type_name() const |
| 587 | { |
| 588 | DBUG_ASSERT(vcol_type != VCOL_TYPE_NONE); |
| 589 | return vcol_type_name(vcol_type); |
| 590 | } |
| 591 | enum_field_types get_real_type() const |
| 592 | { |
| 593 | return field_type; |
| 594 | } |
| 595 | void set_field_type(enum_field_types fld_type) |
| 596 | { |
| 597 | /* Calling this function can only be done once. */ |
| 598 | field_type= fld_type; |
| 599 | } |
| 600 | bool is_stored() const |
| 601 | { |
| 602 | return stored_in_db; |
| 603 | } |
| 604 | void set_stored_in_db_flag(bool stored) |
| 605 | { |
| 606 | stored_in_db= stored; |
| 607 | } |
| 608 | bool is_in_partitioning_expr() const |
| 609 | { |
| 610 | return in_partitioning_expr; |
| 611 | } |
| 612 | void mark_as_in_partitioning_expr() |
| 613 | { |
| 614 | in_partitioning_expr= TRUE; |
| 615 | } |
| 616 | inline bool is_equal(const Virtual_column_info* vcol) const; |
| 617 | inline void print(String*); |
| 618 | }; |
| 619 | |
| 620 | class Field: public Value_source |
| 621 | { |
| 622 | Field(const Item &); /* Prevent use of these */ |
| 623 | void operator=(Field &); |
| 624 | protected: |
| 625 | int save_in_field_str(Field *to) |
| 626 | { |
| 627 | StringBuffer<MAX_FIELD_WIDTH> result(charset()); |
| 628 | val_str(&result); |
| 629 | return to->store(result.ptr(), result.length(), charset()); |
| 630 | } |
| 631 | static void do_field_int(Copy_field *copy); |
| 632 | static void do_field_real(Copy_field *copy); |
| 633 | static void do_field_string(Copy_field *copy); |
| 634 | static void do_field_temporal(Copy_field *copy); |
| 635 | static void do_field_timestamp(Copy_field *copy); |
| 636 | static void do_field_decimal(Copy_field *copy); |
| 637 | public: |
| 638 | static void *operator new(size_t size, MEM_ROOT *mem_root) throw () |
| 639 | { return alloc_root(mem_root, size); } |
| 640 | static void *operator new(size_t size) throw () |
| 641 | { |
| 642 | DBUG_ASSERT(size < UINT_MAX32); |
| 643 | return thd_alloc(current_thd, (uint) size); |
| 644 | } |
| 645 | static void operator delete(void *ptr_arg, size_t size) { TRASH_FREE(ptr_arg, size); } |
| 646 | static void operator delete(void *ptr, MEM_ROOT *mem_root) |
| 647 | { DBUG_ASSERT(0); } |
| 648 | |
| 649 | /** |
| 650 | Used by System Versioning. |
| 651 | */ |
| 652 | virtual void set_max() |
| 653 | { DBUG_ASSERT(0); } |
| 654 | virtual bool is_max() |
| 655 | { DBUG_ASSERT(0); return false; } |
| 656 | |
| 657 | uchar *ptr; // Position to field in record |
| 658 | |
| 659 | field_visibility_t invisible; |
| 660 | /** |
| 661 | Byte where the @c NULL bit is stored inside a record. If this Field is a |
| 662 | @c NOT @c NULL field, this member is @c NULL. |
| 663 | */ |
| 664 | uchar *null_ptr; |
| 665 | /* |
| 666 | Note that you can use table->in_use as replacement for current_thd member |
| 667 | only inside of val_*() and store() members (e.g. you can't use it in cons) |
| 668 | */ |
| 669 | TABLE *table; // Pointer for table |
| 670 | TABLE *orig_table; // Pointer to original table |
| 671 | const char * const *table_name; // Pointer to alias in TABLE |
| 672 | LEX_CSTRING field_name; |
| 673 | LEX_CSTRING ; |
| 674 | /** reference to the list of options or NULL */ |
| 675 | engine_option_value *option_list; |
| 676 | ha_field_option_struct *option_struct; /* structure with parsed options */ |
| 677 | /* Field is part of the following keys */ |
| 678 | key_map key_start, part_of_key, part_of_key_not_clustered; |
| 679 | |
| 680 | /* |
| 681 | Bitmap of indexes that have records ordered by col1, ... this_field, ... |
| 682 | |
| 683 | For example, INDEX (col(prefix_n)) is not present in col.part_of_sortkey. |
| 684 | */ |
| 685 | key_map part_of_sortkey; |
| 686 | /* |
| 687 | We use three additional unireg types for TIMESTAMP to overcome limitation |
| 688 | of current binary format of .frm file. We'd like to be able to support |
| 689 | NOW() as default and on update value for such fields but unable to hold |
| 690 | this info anywhere except unireg_check field. This issue will be resolved |
| 691 | in more clean way with transition to new text based .frm format. |
| 692 | See also comment for Field_timestamp::Field_timestamp(). |
| 693 | */ |
| 694 | enum utype { |
| 695 | NONE=0, |
| 696 | NEXT_NUMBER=15, // AUTO_INCREMENT |
| 697 | TIMESTAMP_OLD_FIELD=18, // TIMESTAMP created before 4.1.3 |
| 698 | TIMESTAMP_DN_FIELD=21, // TIMESTAMP DEFAULT NOW() |
| 699 | TIMESTAMP_UN_FIELD=22, // TIMESTAMP ON UPDATE NOW() |
| 700 | TIMESTAMP_DNUN_FIELD=23, // TIMESTAMP DEFAULT NOW() ON UPDATE NOW() |
| 701 | TMYSQL_COMPRESSED= 24, // Compatibility with TMySQL |
| 702 | }; |
| 703 | enum geometry_type |
| 704 | { |
| 705 | GEOM_GEOMETRY = 0, GEOM_POINT = 1, GEOM_LINESTRING = 2, GEOM_POLYGON = 3, |
| 706 | GEOM_MULTIPOINT = 4, GEOM_MULTILINESTRING = 5, GEOM_MULTIPOLYGON = 6, |
| 707 | GEOM_GEOMETRYCOLLECTION = 7 |
| 708 | }; |
| 709 | enum imagetype { itRAW, itMBR}; |
| 710 | |
| 711 | utype unireg_check; |
| 712 | uint32 field_length; // Length of field |
| 713 | uint32 flags; |
| 714 | uint16 field_index; // field number in fields array |
| 715 | uchar null_bit; // Bit used to test null bit |
| 716 | /** |
| 717 | If true, this field was created in create_tmp_field_from_item from a NULL |
| 718 | value. This means that the type of the field is just a guess, and the type |
| 719 | may be freely coerced to another type. |
| 720 | |
| 721 | @see create_tmp_field_from_item |
| 722 | @see Item_type_holder::get_real_type |
| 723 | |
| 724 | */ |
| 725 | bool is_created_from_null_item; |
| 726 | |
| 727 | /* TRUE in Field objects created for column min/max values */ |
| 728 | bool is_stat_field; |
| 729 | |
| 730 | /* |
| 731 | Selectivity of the range condition over this field. |
| 732 | When calculating this selectivity a range predicate |
| 733 | is taken into account only if: |
| 734 | - it is extracted from the WHERE clause |
| 735 | - it depends only on the table the field belongs to |
| 736 | */ |
| 737 | double cond_selectivity; |
| 738 | |
| 739 | /* |
| 740 | The next field in the class of equal fields at the top AND level |
| 741 | of the WHERE clause |
| 742 | */ |
| 743 | Field *next_equal_field; |
| 744 | |
| 745 | /* |
| 746 | This structure is used for statistical data on the column |
| 747 | that has been read from the statistical table column_stat |
| 748 | */ |
| 749 | Column_statistics *read_stats; |
| 750 | /* |
| 751 | This structure is used for statistical data on the column that |
| 752 | is collected by the function collect_statistics_for_table |
| 753 | */ |
| 754 | Column_statistics_collected *collected_stats; |
| 755 | |
| 756 | /* |
| 757 | This is additional data provided for any computed(virtual) field, |
| 758 | default function or check constraint. |
| 759 | In particular it includes a pointer to the item by which this field |
| 760 | can be computed from other fields. |
| 761 | */ |
| 762 | Virtual_column_info *vcol_info, *check_constraint, *default_value; |
| 763 | |
| 764 | Field(uchar *ptr_arg,uint32 length_arg,uchar *null_ptr_arg, |
| 765 | uchar null_bit_arg, utype unireg_check_arg, |
| 766 | const LEX_CSTRING *field_name_arg); |
| 767 | virtual ~Field() {} |
| 768 | |
| 769 | DTCollation dtcollation() const |
| 770 | { |
| 771 | return DTCollation(charset(), derivation(), repertoire()); |
| 772 | } |
| 773 | virtual Type_std_attributes type_std_attributes() const |
| 774 | { |
| 775 | return Type_std_attributes(field_length, decimals(), |
| 776 | MY_TEST(flags & UNSIGNED_FLAG), |
| 777 | dtcollation()); |
| 778 | } |
| 779 | |
| 780 | bool is_unsigned() const { return flags & UNSIGNED_FLAG; } |
| 781 | |
| 782 | /** |
| 783 | Convenience definition of a copy function returned by |
| 784 | Field::get_copy_func() |
| 785 | */ |
| 786 | typedef void Copy_func(Copy_field*); |
| 787 | virtual Copy_func *get_copy_func(const Field *from) const= 0; |
| 788 | /* Store functions returns 1 on overflow and -1 on fatal error */ |
| 789 | virtual int store_field(Field *from) { return from->save_in_field(this); } |
| 790 | virtual int save_in_field(Field *to)= 0; |
| 791 | /** |
| 792 | Check if it is possible just copy the value |
| 793 | of the field 'from' to the field 'this', e.g. for |
| 794 | INSERT INTO t1 (field1) SELECT field2 FROM t2; |
| 795 | @param from - The field to copy from |
| 796 | @retval true - it is possible to just copy value of 'from' to 'this' |
| 797 | @retval false - conversion is needed |
| 798 | */ |
| 799 | virtual bool memcpy_field_possible(const Field *from) const= 0; |
| 800 | virtual int store(const char *to, size_t length,CHARSET_INFO *cs)=0; |
| 801 | virtual int store_hex_hybrid(const char *str, size_t length); |
| 802 | virtual int store(double nr)=0; |
| 803 | virtual int store(longlong nr, bool unsigned_val)=0; |
| 804 | virtual int store_decimal(const my_decimal *d)=0; |
| 805 | virtual int store_time_dec(const MYSQL_TIME *ltime, uint dec); |
| 806 | virtual int store_timestamp(my_time_t timestamp, ulong sec_part); |
| 807 | int store_time(const MYSQL_TIME *ltime) |
| 808 | { return store_time_dec(ltime, TIME_SECOND_PART_DIGITS); } |
| 809 | int store(const char *to, size_t length, CHARSET_INFO *cs, |
| 810 | enum_check_fields check_level); |
| 811 | int store(const LEX_STRING *ls, CHARSET_INFO *cs) |
| 812 | { |
| 813 | DBUG_ASSERT(ls->length < UINT_MAX32); |
| 814 | return store(ls->str, (uint) ls->length, cs); |
| 815 | } |
| 816 | int store(const LEX_CSTRING *ls, CHARSET_INFO *cs) |
| 817 | { |
| 818 | DBUG_ASSERT(ls->length < UINT_MAX32); |
| 819 | return store(ls->str, (uint) ls->length, cs); |
| 820 | } |
| 821 | int store(const LEX_CSTRING &ls, CHARSET_INFO *cs) |
| 822 | { |
| 823 | DBUG_ASSERT(ls.length < UINT_MAX32); |
| 824 | return store(ls.str, (uint) ls.length, cs); |
| 825 | } |
| 826 | virtual double val_real(void)=0; |
| 827 | virtual longlong val_int(void)=0; |
| 828 | virtual ulonglong val_uint(void) |
| 829 | { |
| 830 | return (ulonglong) val_int(); |
| 831 | } |
| 832 | virtual bool val_bool(void)= 0; |
| 833 | virtual my_decimal *val_decimal(my_decimal *); |
| 834 | inline String *val_str(String *str) { return val_str(str, str); } |
| 835 | /* |
| 836 | val_str(buf1, buf2) gets two buffers and should use them as follows: |
| 837 | if it needs a temp buffer to convert result to string - use buf1 |
| 838 | example Field_tiny::val_str() |
| 839 | if the value exists as a string already - use buf2 |
| 840 | example Field_string::val_str() |
| 841 | consequently, buf2 may be created as 'String buf;' - no memory |
| 842 | will be allocated for it. buf1 will be allocated to hold a |
| 843 | value if it's too small. Using allocated buffer for buf2 may result in |
| 844 | an unnecessary free (and later, may be an alloc). |
| 845 | This trickery is used to decrease a number of malloc calls. |
| 846 | */ |
| 847 | virtual String *val_str(String*,String *)=0; |
| 848 | String *val_int_as_str(String *val_buffer, bool unsigned_flag); |
| 849 | /* |
| 850 | Return the field value as a LEX_CSTRING, without padding to full length |
| 851 | (MODE_PAD_CHAR_TO_FULL_LENGTH is temporarily suppressed during the call). |
| 852 | |
| 853 | In case of an empty value, to[0] is assigned to empty_clex_string, |
| 854 | memory is not allocated. |
| 855 | In case of a non-empty value, the memory is allocated on mem_root. |
| 856 | In case of a memory allocation failure, to[0] is assigned to {NULL,0}. |
| 857 | |
| 858 | @param [IN] mem_root store non-empty values here |
| 859 | @param [OUT to return the string here |
| 860 | @retval false (success) |
| 861 | @retval true (EOM) |
| 862 | */ |
| 863 | bool val_str_nopad(MEM_ROOT *mem_root, LEX_CSTRING *to); |
| 864 | fast_field_copier get_fast_field_copier(const Field *from); |
| 865 | /* |
| 866 | str_needs_quotes() returns TRUE if the value returned by val_str() needs |
| 867 | to be quoted when used in constructing an SQL query. |
| 868 | */ |
| 869 | virtual bool str_needs_quotes() { return FALSE; } |
| 870 | Item_result result_type () const |
| 871 | { |
| 872 | return type_handler()->result_type(); |
| 873 | } |
| 874 | Item_result cmp_type () const |
| 875 | { |
| 876 | return type_handler()->cmp_type(); |
| 877 | } |
| 878 | static enum_field_types field_type_merge(enum_field_types, enum_field_types); |
| 879 | virtual bool eq(Field *field) |
| 880 | { |
| 881 | return (ptr == field->ptr && null_ptr == field->null_ptr && |
| 882 | null_bit == field->null_bit && field->type() == type()); |
| 883 | } |
| 884 | virtual bool eq_def(const Field *field) const; |
| 885 | |
| 886 | /* |
| 887 | pack_length() returns size (in bytes) used to store field data in memory |
| 888 | (i.e. it returns the maximum size of the field in a row of the table, |
| 889 | which is located in RAM). |
| 890 | */ |
| 891 | virtual uint32 pack_length() const { return (uint32) field_length; } |
| 892 | |
| 893 | /* |
| 894 | pack_length_in_rec() returns size (in bytes) used to store field data on |
| 895 | storage (i.e. it returns the maximal size of the field in a row of the |
| 896 | table, which is located on disk). |
| 897 | */ |
| 898 | virtual uint32 pack_length_in_rec() const { return pack_length(); } |
| 899 | virtual bool compatible_field_size(uint metadata, Relay_log_info *rli, |
| 900 | uint16 mflags, int *order); |
| 901 | virtual uint pack_length_from_metadata(uint field_metadata) |
| 902 | { |
| 903 | DBUG_ENTER("Field::pack_length_from_metadata" ); |
| 904 | DBUG_RETURN(field_metadata); |
| 905 | } |
| 906 | virtual uint row_pack_length() const { return 0; } |
| 907 | |
| 908 | |
| 909 | /** |
| 910 | Retrieve the field metadata for fields. |
| 911 | |
| 912 | This default implementation returns 0 and saves 0 in the first_byte value. |
| 913 | |
| 914 | @param first_byte First byte of field metadata |
| 915 | |
| 916 | @returns 0 no bytes written. |
| 917 | */ |
| 918 | |
| 919 | virtual int save_field_metadata(uchar *first_byte) |
| 920 | { return 0; } |
| 921 | |
| 922 | |
| 923 | /* |
| 924 | data_length() return the "real size" of the data in memory. |
| 925 | */ |
| 926 | virtual uint32 data_length() { return pack_length(); } |
| 927 | virtual uint32 sort_length() const { return pack_length(); } |
| 928 | |
| 929 | /* |
| 930 | Get the number bytes occupied by the value in the field. |
| 931 | CHAR values are stripped of trailing spaces. |
| 932 | Flexible values are stripped of their length. |
| 933 | */ |
| 934 | virtual uint32 value_length() |
| 935 | { |
| 936 | uint len; |
| 937 | if (!zero_pack() && |
| 938 | (type() == MYSQL_TYPE_STRING && |
| 939 | (len= pack_length()) >= 4 && len < 256)) |
| 940 | { |
| 941 | uchar *str, *end; |
| 942 | for (str= ptr, end= str+len; end > str && end[-1] == ' '; end--) {} |
| 943 | len=(uint) (end-str); |
| 944 | return len; |
| 945 | } |
| 946 | return data_length(); |
| 947 | } |
| 948 | |
| 949 | /** |
| 950 | Get the maximum size of the data in packed format. |
| 951 | |
| 952 | @return Maximum data length of the field when packed using the |
| 953 | Field::pack() function. |
| 954 | */ |
| 955 | virtual uint32 max_data_length() const { |
| 956 | return pack_length(); |
| 957 | }; |
| 958 | |
| 959 | virtual int reset(void) { bzero(ptr,pack_length()); return 0; } |
| 960 | virtual void reset_fields() {} |
| 961 | const uchar *ptr_in_record(const uchar *record) const |
| 962 | { |
| 963 | my_ptrdiff_t l_offset= (my_ptrdiff_t) (record - table->record[0]); |
| 964 | return ptr + l_offset; |
| 965 | } |
| 966 | virtual int set_default(); |
| 967 | |
| 968 | bool has_update_default_function() const |
| 969 | { |
| 970 | return flags & ON_UPDATE_NOW_FLAG; |
| 971 | } |
| 972 | bool has_default_now_unireg_check() const |
| 973 | { |
| 974 | return unireg_check == TIMESTAMP_DN_FIELD |
| 975 | || unireg_check == TIMESTAMP_DNUN_FIELD; |
| 976 | } |
| 977 | |
| 978 | /* |
| 979 | Mark the field as having a value supplied by the client, thus it should |
| 980 | not be auto-updated. |
| 981 | */ |
| 982 | void set_has_explicit_value() |
| 983 | { |
| 984 | bitmap_set_bit(&table->has_value_set, field_index); |
| 985 | } |
| 986 | bool has_explicit_value() |
| 987 | { |
| 988 | return bitmap_is_set(&table->has_value_set, field_index); |
| 989 | } |
| 990 | void clear_has_explicit_value() |
| 991 | { |
| 992 | bitmap_clear_bit(&table->has_value_set, field_index); |
| 993 | } |
| 994 | bool set_explicit_default(Item *value); |
| 995 | |
| 996 | virtual my_time_t get_timestamp(const uchar *pos, ulong *sec_part) const |
| 997 | { DBUG_ASSERT(0); return 0; } |
| 998 | my_time_t get_timestamp(ulong *sec_part) const |
| 999 | { |
| 1000 | return get_timestamp(ptr, sec_part); |
| 1001 | } |
| 1002 | |
| 1003 | /** |
| 1004 | Evaluates the @c UPDATE default function, if one exists, and stores the |
| 1005 | result in the record buffer. If no such function exists for the column, |
| 1006 | or the function is not valid for the column's data type, invoking this |
| 1007 | function has no effect. |
| 1008 | */ |
| 1009 | virtual int evaluate_update_default_function() { return 0; } |
| 1010 | |
| 1011 | virtual bool binary() const { return 1; } |
| 1012 | virtual bool zero_pack() const { return 1; } |
| 1013 | virtual enum ha_base_keytype key_type() const { return HA_KEYTYPE_BINARY; } |
| 1014 | virtual uint32 key_length() const { return pack_length(); } |
| 1015 | virtual const Type_handler *type_handler() const= 0; |
| 1016 | virtual enum_field_types type() const |
| 1017 | { |
| 1018 | return type_handler()->field_type(); |
| 1019 | } |
| 1020 | virtual enum_field_types real_type() const |
| 1021 | { |
| 1022 | return type_handler()->real_field_type(); |
| 1023 | } |
| 1024 | virtual enum_field_types binlog_type() const |
| 1025 | { |
| 1026 | /* |
| 1027 | Binlog stores field->type() as type code by default. For example, |
| 1028 | it puts MYSQL_TYPE_STRING in case of CHAR, VARCHAR, SET and ENUM, |
| 1029 | with extra data type details put into metadata. |
| 1030 | |
| 1031 | Binlog behaviour slightly differs between various MySQL and MariaDB |
| 1032 | versions for the temporal data types TIME, DATETIME and TIMESTAMP. |
| 1033 | |
| 1034 | MySQL prior to 5.6 uses MYSQL_TYPE_TIME, MYSQL_TYPE_DATETIME |
| 1035 | and MYSQL_TYPE_TIMESTAMP type codes in binlog and stores no |
| 1036 | additional metadata. |
| 1037 | |
| 1038 | MariaDB-5.3 implements new versions for TIME, DATATIME, TIMESTAMP |
| 1039 | with fractional second precision, but uses the old format for the |
| 1040 | types TIME(0), DATETIME(0), TIMESTAMP(0), and it still stores |
| 1041 | MYSQL_TYPE_TIME, MYSQL_TYPE_DATETIME and MYSQL_TYPE_TIMESTAMP in binlog, |
| 1042 | with no additional metadata. |
| 1043 | So row-based replication between temporal data types of |
| 1044 | different precision is not possible in MariaDB. |
| 1045 | |
| 1046 | MySQL-5.6 also implements a new version of TIME, DATETIME, TIMESTAMP |
| 1047 | which support fractional second precision 0..6, and use the new |
| 1048 | format even for the types TIME(0), DATETIME(0), TIMESTAMP(0). |
| 1049 | For these new data types, MySQL-5.6 stores new type codes |
| 1050 | MYSQL_TYPE_TIME2, MYSQL_TYPE_DATETIME2, MYSQL_TYPE_TIMESTAMP2 in binlog, |
| 1051 | with fractional precision 0..6 put into metadata. |
| 1052 | This makes it in theory possible to do row-based replication between |
| 1053 | columns of different fractional precision (e.g. from TIME(1) on master |
| 1054 | to TIME(6) on slave). However, it's not currently fully implemented yet. |
| 1055 | MySQL-5.6 can only do row-based replication from the old types |
| 1056 | TIME, DATETIME, TIMESTAMP (represented by MYSQL_TYPE_TIME, |
| 1057 | MYSQL_TYPE_DATETIME and MYSQL_TYPE_TIMESTAMP type codes in binlog) |
| 1058 | to the new corresponding types TIME(0), DATETIME(0), TIMESTAMP(0). |
| 1059 | |
| 1060 | Note: MariaDB starting from the version 10.0 understands the new |
| 1061 | MySQL-5.6 type codes MYSQL_TYPE_TIME2, MYSQL_TYPE_DATETIME2, |
| 1062 | MYSQL_TYPE_TIMESTAMP2. When started over MySQL-5.6 tables both on |
| 1063 | master and on slave, MariaDB-10.0 can also do row-based replication |
| 1064 | from the old types TIME, DATETIME, TIMESTAMP to the new MySQL-5.6 |
| 1065 | types TIME(0), DATETIME(0), TIMESTAMP(0). |
| 1066 | |
| 1067 | Note: perhaps binlog should eventually be modified to store |
| 1068 | real_type() instead of type() for all column types. |
| 1069 | */ |
| 1070 | return type(); |
| 1071 | } |
| 1072 | inline int cmp(const uchar *str) { return cmp(ptr,str); } |
| 1073 | virtual int cmp_max(const uchar *a, const uchar *b, uint max_len) |
| 1074 | { return cmp(a, b); } |
| 1075 | virtual int cmp(const uchar *,const uchar *)=0; |
| 1076 | virtual int cmp_binary(const uchar *a,const uchar *b, uint32 max_length=~0U) |
| 1077 | { return memcmp(a,b,pack_length()); } |
| 1078 | virtual int cmp_offset(uint row_offset) |
| 1079 | { return cmp(ptr,ptr+row_offset); } |
| 1080 | virtual int cmp_binary_offset(uint row_offset) |
| 1081 | { return cmp_binary(ptr, ptr+row_offset); }; |
| 1082 | virtual int key_cmp(const uchar *a,const uchar *b) |
| 1083 | { return cmp(a, b); } |
| 1084 | virtual int key_cmp(const uchar *str, uint length) |
| 1085 | { return cmp(ptr,str); } |
| 1086 | /* |
| 1087 | Update the value m of the 'min_val' field with the current value v |
| 1088 | of this field if force_update is set to TRUE or if v < m. |
| 1089 | Return TRUE if the value has been updated. |
| 1090 | */ |
| 1091 | virtual bool update_min(Field *min_val, bool force_update) |
| 1092 | { |
| 1093 | bool update_fl= force_update || cmp(ptr, min_val->ptr) < 0; |
| 1094 | if (update_fl) |
| 1095 | { |
| 1096 | min_val->set_notnull(); |
| 1097 | memcpy(min_val->ptr, ptr, pack_length()); |
| 1098 | } |
| 1099 | return update_fl; |
| 1100 | } |
| 1101 | /* |
| 1102 | Update the value m of the 'max_val' field with the current value v |
| 1103 | of this field if force_update is set to TRUE or if v > m. |
| 1104 | Return TRUE if the value has been updated. |
| 1105 | */ |
| 1106 | virtual bool update_max(Field *max_val, bool force_update) |
| 1107 | { |
| 1108 | bool update_fl= force_update || cmp(ptr, max_val->ptr) > 0; |
| 1109 | if (update_fl) |
| 1110 | { |
| 1111 | max_val->set_notnull(); |
| 1112 | memcpy(max_val->ptr, ptr, pack_length()); |
| 1113 | } |
| 1114 | return update_fl; |
| 1115 | } |
| 1116 | virtual void store_field_value(uchar *val, uint len) |
| 1117 | { |
| 1118 | memcpy(ptr, val, len); |
| 1119 | } |
| 1120 | virtual uint decimals() const { return 0; } |
| 1121 | virtual Information_schema_numeric_attributes |
| 1122 | information_schema_numeric_attributes() const |
| 1123 | { |
| 1124 | return Information_schema_numeric_attributes(); |
| 1125 | } |
| 1126 | virtual Information_schema_character_attributes |
| 1127 | information_schema_character_attributes() const |
| 1128 | { |
| 1129 | return Information_schema_character_attributes(); |
| 1130 | } |
| 1131 | /* |
| 1132 | Caller beware: sql_type can change str.Ptr, so check |
| 1133 | ptr() to see if it changed if you are using your own buffer |
| 1134 | in str and restore it with set() if needed |
| 1135 | */ |
| 1136 | virtual void sql_type(String &str) const =0; |
| 1137 | virtual uint size_of() const =0; // For new field |
| 1138 | inline bool is_null(my_ptrdiff_t row_offset= 0) const |
| 1139 | { |
| 1140 | /* |
| 1141 | The table may have been marked as containing only NULL values |
| 1142 | for all fields if it is a NULL-complemented row of an OUTER JOIN |
| 1143 | or if the query is an implicitly grouped query (has aggregate |
| 1144 | functions but no GROUP BY clause) with no qualifying rows. If |
| 1145 | this is the case (in which TABLE::null_row is true), the field |
| 1146 | is considered to be NULL. |
| 1147 | |
| 1148 | Note that if a table->null_row is set then also all null_bits are |
| 1149 | set for the row. |
| 1150 | |
| 1151 | In the case of the 'result_field' for GROUP BY, table->null_row might |
| 1152 | refer to the *next* row in the table (when the algorithm is: read the |
| 1153 | next row, see if any of group column values have changed, send the |
| 1154 | result - grouped - row to the client if yes). So, table->null_row might |
| 1155 | be wrong, but such a result_field is always nullable (that's defined by |
| 1156 | original_field->maybe_null()) and we trust its null bit. |
| 1157 | */ |
| 1158 | return null_ptr ? null_ptr[row_offset] & null_bit : table->null_row; |
| 1159 | } |
| 1160 | inline bool is_real_null(my_ptrdiff_t row_offset= 0) const |
| 1161 | { return null_ptr && (null_ptr[row_offset] & null_bit); } |
| 1162 | inline bool is_null_in_record(const uchar *record) const |
| 1163 | { |
| 1164 | if (maybe_null_in_table()) |
| 1165 | return record[(uint) (null_ptr - table->record[0])] & null_bit; |
| 1166 | return 0; |
| 1167 | } |
| 1168 | inline void set_null(my_ptrdiff_t row_offset= 0) |
| 1169 | { if (null_ptr) null_ptr[row_offset]|= null_bit; } |
| 1170 | inline void set_notnull(my_ptrdiff_t row_offset= 0) |
| 1171 | { if (null_ptr) null_ptr[row_offset]&= (uchar) ~null_bit; } |
| 1172 | inline bool maybe_null(void) const |
| 1173 | { return null_ptr != 0 || table->maybe_null; } |
| 1174 | // Set to NULL on LOAD DATA or LOAD XML |
| 1175 | virtual bool load_data_set_null(THD *thd); |
| 1176 | // Reset when a LOAD DATA file ended unexpectedly |
| 1177 | virtual bool load_data_set_no_data(THD *thd, bool fixed_format); |
| 1178 | void load_data_set_value(const char *pos, uint length, CHARSET_INFO *cs); |
| 1179 | |
| 1180 | /* @return true if this field is NULL-able (even if temporarily) */ |
| 1181 | inline bool real_maybe_null(void) const { return null_ptr != 0; } |
| 1182 | uint null_offset(const uchar *record) const |
| 1183 | { return (uint) (null_ptr - record); } |
| 1184 | /* |
| 1185 | For a NULL-able field (that can actually store a NULL value in a table) |
| 1186 | null_ptr points to the "null bitmap" in the table->record[0] header. For |
| 1187 | NOT NULL fields it is either 0 or points outside table->record[0] into the |
| 1188 | table->triggers->extra_null_bitmap (so that the field can store a NULL |
| 1189 | value temporarily, only in memory) |
| 1190 | */ |
| 1191 | bool maybe_null_in_table() const |
| 1192 | { return null_ptr >= table->record[0] && null_ptr <= ptr; } |
| 1193 | |
| 1194 | uint null_offset() const |
| 1195 | { return null_offset(table->record[0]); } |
| 1196 | void set_null_ptr(uchar *p_null_ptr, uint p_null_bit) |
| 1197 | { |
| 1198 | null_ptr= p_null_ptr; |
| 1199 | null_bit= p_null_bit; |
| 1200 | } |
| 1201 | |
| 1202 | bool stored_in_db() const { return !vcol_info || vcol_info->stored_in_db; } |
| 1203 | |
| 1204 | inline THD *get_thd() const |
| 1205 | { return likely(table) ? table->in_use : current_thd; } |
| 1206 | |
| 1207 | enum { |
| 1208 | LAST_NULL_BYTE_UNDEF= 0 |
| 1209 | }; |
| 1210 | |
| 1211 | /* |
| 1212 | Find the position of the last null byte for the field. |
| 1213 | |
| 1214 | SYNOPSIS |
| 1215 | last_null_byte() |
| 1216 | |
| 1217 | DESCRIPTION |
| 1218 | Return a pointer to the last byte of the null bytes where the |
| 1219 | field conceptually is placed. |
| 1220 | |
| 1221 | RETURN VALUE |
| 1222 | The position of the last null byte relative to the beginning of |
| 1223 | the record. If the field does not use any bits of the null |
| 1224 | bytes, the value 0 (LAST_NULL_BYTE_UNDEF) is returned. |
| 1225 | */ |
| 1226 | size_t last_null_byte() const { |
| 1227 | size_t bytes= do_last_null_byte(); |
| 1228 | DBUG_PRINT("debug" , ("last_null_byte() ==> %ld" , (long) bytes)); |
| 1229 | DBUG_ASSERT(bytes <= table->s->null_bytes); |
| 1230 | return bytes; |
| 1231 | } |
| 1232 | |
| 1233 | void make_sort_key(uchar *buff, uint length); |
| 1234 | virtual void make_send_field(Send_field *); |
| 1235 | virtual void sort_string(uchar *buff,uint length)=0; |
| 1236 | virtual bool optimize_range(uint idx, uint part) const; |
| 1237 | virtual void free() {} |
| 1238 | virtual Field *make_new_field(MEM_ROOT *root, TABLE *new_table, |
| 1239 | bool keep_type); |
| 1240 | virtual Field *new_key_field(MEM_ROOT *root, TABLE *new_table, |
| 1241 | uchar *new_ptr, uint32 length, |
| 1242 | uchar *new_null_ptr, uint new_null_bit); |
| 1243 | Field *clone(MEM_ROOT *mem_root, TABLE *new_table); |
| 1244 | Field *clone(MEM_ROOT *mem_root, TABLE *new_table, my_ptrdiff_t diff, |
| 1245 | bool stat_flag= FALSE); |
| 1246 | Field *clone(MEM_ROOT *mem_root, my_ptrdiff_t diff); |
| 1247 | inline void move_field(uchar *ptr_arg,uchar *null_ptr_arg,uchar null_bit_arg) |
| 1248 | { |
| 1249 | ptr=ptr_arg; null_ptr=null_ptr_arg; null_bit=null_bit_arg; |
| 1250 | } |
| 1251 | inline void move_field(uchar *ptr_arg) { ptr=ptr_arg; } |
| 1252 | inline uchar *record_ptr() // record[0] or wherever the field was moved to |
| 1253 | { |
| 1254 | my_ptrdiff_t offset= table->s->field[field_index]->ptr - table->s->default_values; |
| 1255 | return ptr - offset; |
| 1256 | } |
| 1257 | virtual void move_field_offset(my_ptrdiff_t ptr_diff) |
| 1258 | { |
| 1259 | ptr=ADD_TO_PTR(ptr,ptr_diff, uchar*); |
| 1260 | if (null_ptr) |
| 1261 | null_ptr=ADD_TO_PTR(null_ptr,ptr_diff,uchar*); |
| 1262 | } |
| 1263 | virtual void get_image(uchar *buff, uint length, CHARSET_INFO *cs) |
| 1264 | { memcpy(buff,ptr,length); } |
| 1265 | virtual void set_image(const uchar *buff,uint length, CHARSET_INFO *cs) |
| 1266 | { memcpy(ptr,buff,length); } |
| 1267 | |
| 1268 | |
| 1269 | /* |
| 1270 | Copy a field part into an output buffer. |
| 1271 | |
| 1272 | SYNOPSIS |
| 1273 | Field::get_key_image() |
| 1274 | buff [out] output buffer |
| 1275 | length output buffer size |
| 1276 | type itMBR for geometry blobs, otherwise itRAW |
| 1277 | |
| 1278 | DESCRIPTION |
| 1279 | This function makes a copy of field part of size equal to or |
| 1280 | less than "length" parameter value. |
| 1281 | For fields of string types (CHAR, VARCHAR, TEXT) the rest of buffer |
| 1282 | is padded by zero byte. |
| 1283 | |
| 1284 | NOTES |
| 1285 | For variable length character fields (i.e. UTF-8) the "length" |
| 1286 | parameter means a number of output buffer bytes as if all field |
| 1287 | characters have maximal possible size (mbmaxlen). In the other words, |
| 1288 | "length" parameter is a number of characters multiplied by |
| 1289 | field_charset->mbmaxlen. |
| 1290 | |
| 1291 | RETURN |
| 1292 | Number of copied bytes (excluding padded zero bytes -- see above). |
| 1293 | */ |
| 1294 | |
| 1295 | virtual uint get_key_image(uchar *buff, uint length, imagetype type_arg) |
| 1296 | { |
| 1297 | get_image(buff, length, &my_charset_bin); |
| 1298 | return length; |
| 1299 | } |
| 1300 | virtual void set_key_image(const uchar *buff,uint length) |
| 1301 | { set_image(buff,length, &my_charset_bin); } |
| 1302 | inline longlong val_int_offset(uint row_offset) |
| 1303 | { |
| 1304 | ptr+=row_offset; |
| 1305 | longlong tmp=val_int(); |
| 1306 | ptr-=row_offset; |
| 1307 | return tmp; |
| 1308 | } |
| 1309 | inline longlong val_int(const uchar *new_ptr) |
| 1310 | { |
| 1311 | uchar *old_ptr= ptr; |
| 1312 | longlong return_value; |
| 1313 | ptr= (uchar*) new_ptr; |
| 1314 | return_value= val_int(); |
| 1315 | ptr= old_ptr; |
| 1316 | return return_value; |
| 1317 | } |
| 1318 | inline String *val_str(String *str, const uchar *new_ptr) |
| 1319 | { |
| 1320 | uchar *old_ptr= ptr; |
| 1321 | ptr= (uchar*) new_ptr; |
| 1322 | val_str(str); |
| 1323 | ptr= old_ptr; |
| 1324 | return str; |
| 1325 | } |
| 1326 | virtual bool send_binary(Protocol *protocol); |
| 1327 | |
| 1328 | virtual uchar *pack(uchar *to, const uchar *from, uint max_length); |
| 1329 | /** |
| 1330 | @overload Field::pack(uchar*, const uchar*, uint, bool) |
| 1331 | */ |
| 1332 | uchar *pack(uchar *to, const uchar *from) |
| 1333 | { |
| 1334 | DBUG_ENTER("Field::pack" ); |
| 1335 | uchar *result= this->pack(to, from, UINT_MAX); |
| 1336 | DBUG_RETURN(result); |
| 1337 | } |
| 1338 | |
| 1339 | virtual const uchar *unpack(uchar* to, const uchar *from, |
| 1340 | const uchar *from_end, uint param_data=0); |
| 1341 | |
| 1342 | virtual uint packed_col_length(const uchar *to, uint length) |
| 1343 | { return length;} |
| 1344 | virtual uint max_packed_col_length(uint max_length) |
| 1345 | { return max_length;} |
| 1346 | |
| 1347 | uint offset(uchar *record) const |
| 1348 | { |
| 1349 | return (uint) (ptr - record); |
| 1350 | } |
| 1351 | void copy_from_tmp(int offset); |
| 1352 | uint fill_cache_field(struct st_cache_field *copy); |
| 1353 | virtual bool get_date(MYSQL_TIME *ltime, ulonglong fuzzydate); |
| 1354 | bool get_time(MYSQL_TIME *ltime) { return get_date(ltime, TIME_TIME_ONLY); } |
| 1355 | virtual TYPELIB *get_typelib() const { return NULL; } |
| 1356 | virtual CHARSET_INFO *charset(void) const { return &my_charset_bin; } |
| 1357 | virtual CHARSET_INFO *charset_for_protocol(void) const |
| 1358 | { return binary() ? &my_charset_bin : charset(); } |
| 1359 | virtual CHARSET_INFO *sort_charset(void) const { return charset(); } |
| 1360 | virtual bool has_charset(void) const { return FALSE; } |
| 1361 | virtual enum Derivation derivation(void) const |
| 1362 | { return DERIVATION_IMPLICIT; } |
| 1363 | virtual uint repertoire(void) const { return MY_REPERTOIRE_UNICODE30; } |
| 1364 | virtual int set_time() { return 1; } |
| 1365 | bool set_warning(Sql_condition::enum_warning_level, unsigned int code, |
| 1366 | int cuted_increment) const; |
| 1367 | protected: |
| 1368 | bool set_warning(unsigned int code, int cuted_increment) const |
| 1369 | { |
| 1370 | return set_warning(Sql_condition::WARN_LEVEL_WARN, code, cuted_increment); |
| 1371 | } |
| 1372 | bool set_note(unsigned int code, int cuted_increment) const |
| 1373 | { |
| 1374 | return set_warning(Sql_condition::WARN_LEVEL_NOTE, code, cuted_increment); |
| 1375 | } |
| 1376 | void set_datetime_warning(Sql_condition::enum_warning_level, uint code, |
| 1377 | const ErrConv *str, timestamp_type ts_type, |
| 1378 | int cuted_increment) const; |
| 1379 | void set_datetime_warning(uint code, |
| 1380 | const ErrConv *str, timestamp_type ts_type, |
| 1381 | int cuted_increment) const |
| 1382 | { |
| 1383 | set_datetime_warning(Sql_condition::WARN_LEVEL_WARN, code, str, ts_type, |
| 1384 | cuted_increment); |
| 1385 | } |
| 1386 | void set_warning_truncated_wrong_value(const char *type, const char *value); |
| 1387 | inline bool check_overflow(int op_result) |
| 1388 | { |
| 1389 | return (op_result == E_DEC_OVERFLOW); |
| 1390 | } |
| 1391 | int warn_if_overflow(int op_result); |
| 1392 | Copy_func *get_identical_copy_func() const; |
| 1393 | public: |
| 1394 | void set_table_name(String *alias) |
| 1395 | { |
| 1396 | table_name= &alias->Ptr; |
| 1397 | } |
| 1398 | void init(TABLE *table_arg) |
| 1399 | { |
| 1400 | orig_table= table= table_arg; |
| 1401 | set_table_name(&table_arg->alias); |
| 1402 | } |
| 1403 | |
| 1404 | /* maximum possible display length */ |
| 1405 | virtual uint32 max_display_length() const= 0; |
| 1406 | /** |
| 1407 | Whether a field being created is compatible with a existing one. |
| 1408 | |
| 1409 | Used by the ALTER TABLE code to evaluate whether the new definition |
| 1410 | of a table is compatible with the old definition so that it can |
| 1411 | determine if data needs to be copied over (table data change). |
| 1412 | */ |
| 1413 | virtual uint is_equal(Create_field *new_field); |
| 1414 | /* convert decimal to longlong with overflow check */ |
| 1415 | longlong convert_decimal2longlong(const my_decimal *val, bool unsigned_flag, |
| 1416 | int *err); |
| 1417 | /* The max. number of characters */ |
| 1418 | virtual uint32 char_length() const |
| 1419 | { |
| 1420 | return field_length / charset()->mbmaxlen; |
| 1421 | } |
| 1422 | |
| 1423 | virtual geometry_type get_geometry_type() |
| 1424 | { |
| 1425 | /* shouldn't get here. */ |
| 1426 | DBUG_ASSERT(0); |
| 1427 | return GEOM_GEOMETRY; |
| 1428 | } |
| 1429 | |
| 1430 | ha_storage_media field_storage_type() const |
| 1431 | { |
| 1432 | return (ha_storage_media) |
| 1433 | ((flags >> FIELD_FLAGS_STORAGE_MEDIA) & 3); |
| 1434 | } |
| 1435 | |
| 1436 | void set_storage_type(ha_storage_media storage_type_arg) |
| 1437 | { |
| 1438 | DBUG_ASSERT(field_storage_type() == HA_SM_DEFAULT); |
| 1439 | flags |= static_cast<uint32>(storage_type_arg) << |
| 1440 | FIELD_FLAGS_STORAGE_MEDIA; |
| 1441 | } |
| 1442 | |
| 1443 | column_format_type column_format() const |
| 1444 | { |
| 1445 | return (column_format_type) |
| 1446 | ((flags >> FIELD_FLAGS_COLUMN_FORMAT) & 3); |
| 1447 | } |
| 1448 | |
| 1449 | void set_column_format(column_format_type column_format_arg) |
| 1450 | { |
| 1451 | DBUG_ASSERT(column_format() == COLUMN_FORMAT_TYPE_DEFAULT); |
| 1452 | flags |= static_cast<uint32>(column_format_arg) << |
| 1453 | FIELD_FLAGS_COLUMN_FORMAT; |
| 1454 | } |
| 1455 | |
| 1456 | bool vers_sys_field() const |
| 1457 | { |
| 1458 | return flags & (VERS_SYS_START_FLAG | VERS_SYS_END_FLAG); |
| 1459 | } |
| 1460 | |
| 1461 | bool vers_update_unversioned() const |
| 1462 | { |
| 1463 | return flags & VERS_UPDATE_UNVERSIONED_FLAG; |
| 1464 | } |
| 1465 | |
| 1466 | /* |
| 1467 | Validate a non-null field value stored in the given record |
| 1468 | according to the current thread settings, e.g. sql_mode. |
| 1469 | @param thd - the thread |
| 1470 | @param record - the record to check in |
| 1471 | */ |
| 1472 | virtual bool validate_value_in_record(THD *thd, const uchar *record) const |
| 1473 | { return false; } |
| 1474 | bool validate_value_in_record_with_warn(THD *thd, const uchar *record); |
| 1475 | key_map get_possible_keys(); |
| 1476 | |
| 1477 | /* Hash value */ |
| 1478 | virtual void hash(ulong *nr, ulong *nr2); |
| 1479 | |
| 1480 | /** |
| 1481 | Checks whether a string field is part of write_set. |
| 1482 | |
| 1483 | @return |
| 1484 | FALSE - If field is not char/varchar/.... |
| 1485 | - If field is char/varchar/.. and is not part of write set. |
| 1486 | TRUE - If field is char/varchar/.. and is part of write set. |
| 1487 | */ |
| 1488 | virtual bool is_varchar_and_in_write_set() const { return FALSE; } |
| 1489 | |
| 1490 | /* Check whether the field can be used as a join attribute in hash join */ |
| 1491 | virtual bool hash_join_is_possible() { return TRUE; } |
| 1492 | virtual bool eq_cmp_as_binary() { return TRUE; } |
| 1493 | |
| 1494 | /* Position of the field value within the interval of [min, max] */ |
| 1495 | virtual double pos_in_interval(Field *min, Field *max) |
| 1496 | { |
| 1497 | return (double) 0.5; |
| 1498 | } |
| 1499 | |
| 1500 | /* |
| 1501 | Check if comparison between the field and an item unambiguously |
| 1502 | identifies a distinct field value. |
| 1503 | |
| 1504 | Example1: SELECT * FROM t1 WHERE int_column=10; |
| 1505 | This example returns distinct integer value of 10. |
| 1506 | |
| 1507 | Example2: SELECT * FROM t1 WHERE varchar_column=DATE'2001-01-01' |
| 1508 | This example returns non-distinct values. |
| 1509 | Comparison as DATE will return '2001-01-01' and '2001-01-01x', |
| 1510 | but these two values are not equal to each other as VARCHARs. |
| 1511 | See also the function with the same name in sql_select.cc. |
| 1512 | */ |
| 1513 | virtual bool test_if_equality_guarantees_uniqueness(const Item *const_item) |
| 1514 | const; |
| 1515 | virtual bool can_be_substituted_to_equal_item(const Context &ctx, |
| 1516 | const Item_equal *item); |
| 1517 | virtual Item *get_equal_const_item(THD *thd, const Context &ctx, |
| 1518 | Item *const_item) |
| 1519 | { |
| 1520 | return const_item; |
| 1521 | } |
| 1522 | virtual bool can_optimize_keypart_ref(const Item_bool_func *cond, |
| 1523 | const Item *item) const; |
| 1524 | virtual bool can_optimize_hash_join(const Item_bool_func *cond, |
| 1525 | const Item *item) const |
| 1526 | { |
| 1527 | return can_optimize_keypart_ref(cond, item); |
| 1528 | } |
| 1529 | virtual bool can_optimize_group_min_max(const Item_bool_func *cond, |
| 1530 | const Item *const_item) const; |
| 1531 | /** |
| 1532 | Test if Field can use range optimizer for a standard comparison operation: |
| 1533 | <=, <, =, <=>, >, >= |
| 1534 | Note, this method does not cover spatial operations. |
| 1535 | */ |
| 1536 | virtual bool can_optimize_range(const Item_bool_func *cond, |
| 1537 | const Item *item, |
| 1538 | bool is_eq_func) const; |
| 1539 | |
| 1540 | bool can_optimize_outer_join_table_elimination(const Item_bool_func *cond, |
| 1541 | const Item *item) const |
| 1542 | { |
| 1543 | // Exactly the same rules with REF access |
| 1544 | return can_optimize_keypart_ref(cond, item); |
| 1545 | } |
| 1546 | |
| 1547 | bool save_in_field_default_value(bool view_eror_processing); |
| 1548 | bool save_in_field_ignore_value(bool view_error_processing); |
| 1549 | |
| 1550 | /* Mark field in read map. Updates also virtual fields */ |
| 1551 | void register_field_in_read_map(); |
| 1552 | |
| 1553 | virtual Compression_method *compression_method() const { return 0; } |
| 1554 | |
| 1555 | virtual Virtual_tmp_table **virtual_tmp_table_addr() |
| 1556 | { |
| 1557 | return NULL; |
| 1558 | } |
| 1559 | virtual bool sp_prepare_and_store_item(THD *thd, Item **value); |
| 1560 | |
| 1561 | friend int cre_myisam(char * name, TABLE *form, uint options, |
| 1562 | ulonglong auto_increment_value); |
| 1563 | friend class Copy_field; |
| 1564 | friend class Item_avg_field; |
| 1565 | friend class Item_std_field; |
| 1566 | friend class Item_sum_num; |
| 1567 | friend class Item_sum_sum; |
| 1568 | friend class Item_sum_count; |
| 1569 | friend class Item_sum_avg; |
| 1570 | friend class Item_sum_std; |
| 1571 | friend class Item_sum_min; |
| 1572 | friend class Item_sum_max; |
| 1573 | friend class Item_func_group_concat; |
| 1574 | |
| 1575 | private: |
| 1576 | /* |
| 1577 | Primitive for implementing last_null_byte(). |
| 1578 | |
| 1579 | SYNOPSIS |
| 1580 | do_last_null_byte() |
| 1581 | |
| 1582 | DESCRIPTION |
| 1583 | Primitive for the implementation of the last_null_byte() |
| 1584 | function. This represents the inheritance interface and can be |
| 1585 | overridden by subclasses. |
| 1586 | */ |
| 1587 | virtual size_t do_last_null_byte() const; |
| 1588 | |
| 1589 | protected: |
| 1590 | uchar *pack_int(uchar *to, const uchar *from, size_t size) |
| 1591 | { |
| 1592 | memcpy(to, from, size); |
| 1593 | return to + size; |
| 1594 | } |
| 1595 | |
| 1596 | const uchar *unpack_int(uchar* to, const uchar *from, |
| 1597 | const uchar *from_end, size_t size) |
| 1598 | { |
| 1599 | if (from + size > from_end) |
| 1600 | return 0; |
| 1601 | memcpy(to, from, size); |
| 1602 | return from + size; |
| 1603 | } |
| 1604 | |
| 1605 | uchar *pack_int16(uchar *to, const uchar *from) |
| 1606 | { return pack_int(to, from, 2); } |
| 1607 | const uchar *unpack_int16(uchar* to, const uchar *from, const uchar *from_end) |
| 1608 | { return unpack_int(to, from, from_end, 2); } |
| 1609 | uchar *pack_int24(uchar *to, const uchar *from) |
| 1610 | { return pack_int(to, from, 3); } |
| 1611 | const uchar *unpack_int24(uchar* to, const uchar *from, const uchar *from_end) |
| 1612 | { return unpack_int(to, from, from_end, 3); } |
| 1613 | uchar *pack_int32(uchar *to, const uchar *from) |
| 1614 | { return pack_int(to, from, 4); } |
| 1615 | const uchar *unpack_int32(uchar* to, const uchar *from, const uchar *from_end) |
| 1616 | { return unpack_int(to, from, from_end, 4); } |
| 1617 | uchar *pack_int64(uchar* to, const uchar *from) |
| 1618 | { return pack_int(to, from, 8); } |
| 1619 | const uchar *unpack_int64(uchar* to, const uchar *from, const uchar *from_end) |
| 1620 | { return unpack_int(to, from, from_end, 8); } |
| 1621 | |
| 1622 | double pos_in_interval_val_real(Field *min, Field *max); |
| 1623 | double pos_in_interval_val_str(Field *min, Field *max, uint data_offset); |
| 1624 | }; |
| 1625 | |
| 1626 | |
| 1627 | class Field_num :public Field { |
| 1628 | protected: |
| 1629 | int check_edom_and_important_data_truncation(const char *type, bool edom, |
| 1630 | CHARSET_INFO *cs, |
| 1631 | const char *str, size_t length, |
| 1632 | const char *end_of_num); |
| 1633 | int check_edom_and_truncation(const char *type, bool edom, |
| 1634 | CHARSET_INFO *cs, |
| 1635 | const char *str, size_t length, |
| 1636 | const char *end_of_num); |
| 1637 | int check_int(CHARSET_INFO *cs, const char *str, size_t length, |
| 1638 | const char *int_end, int error) |
| 1639 | { |
| 1640 | return check_edom_and_truncation("integer" , |
| 1641 | error == MY_ERRNO_EDOM || str == int_end, |
| 1642 | cs, str, length, int_end); |
| 1643 | } |
| 1644 | bool get_int(CHARSET_INFO *cs, const char *from, size_t len, |
| 1645 | longlong *rnd, ulonglong unsigned_max, |
| 1646 | longlong signed_min, longlong signed_max); |
| 1647 | void prepend_zeros(String *value) const; |
| 1648 | Item *get_equal_zerofill_const_item(THD *thd, const Context &ctx, |
| 1649 | Item *const_item); |
| 1650 | public: |
| 1651 | const uint8 dec; |
| 1652 | bool zerofill,unsigned_flag; // Purify cannot handle bit fields |
| 1653 | Field_num(uchar *ptr_arg,uint32 len_arg, uchar *null_ptr_arg, |
| 1654 | uchar null_bit_arg, utype unireg_check_arg, |
| 1655 | const LEX_CSTRING *field_name_arg, |
| 1656 | uint8 dec_arg, bool zero_arg, bool unsigned_arg); |
| 1657 | enum Derivation derivation(void) const { return DERIVATION_NUMERIC; } |
| 1658 | uint repertoire(void) const { return MY_REPERTOIRE_NUMERIC; } |
| 1659 | CHARSET_INFO *charset(void) const { return &my_charset_numeric; } |
| 1660 | Item *get_equal_const_item(THD *thd, const Context &ctx, Item *const_item) |
| 1661 | { |
| 1662 | return (flags & ZEROFILL_FLAG) ? |
| 1663 | get_equal_zerofill_const_item(thd, ctx, const_item) : |
| 1664 | const_item; |
| 1665 | } |
| 1666 | void add_zerofill_and_unsigned(String &res) const; |
| 1667 | friend class Create_field; |
| 1668 | void make_send_field(Send_field *); |
| 1669 | uint decimals() const { return (uint) dec; } |
| 1670 | uint size_of() const { return sizeof(*this); } |
| 1671 | bool eq_def(const Field *field) const; |
| 1672 | Copy_func *get_copy_func(const Field *from) const |
| 1673 | { |
| 1674 | return do_field_int; |
| 1675 | } |
| 1676 | int save_in_field(Field *to) |
| 1677 | { |
| 1678 | return to->store(val_int(), MY_TEST(flags & UNSIGNED_FLAG)); |
| 1679 | } |
| 1680 | bool memcpy_field_possible(const Field *from) const |
| 1681 | { |
| 1682 | return real_type() == from->real_type() && |
| 1683 | pack_length() == from->pack_length() && |
| 1684 | !((flags & UNSIGNED_FLAG) && !(from->flags & UNSIGNED_FLAG)) && |
| 1685 | decimals() == from->decimals(); |
| 1686 | } |
| 1687 | uint is_equal(Create_field *new_field); |
| 1688 | uint row_pack_length() const { return pack_length(); } |
| 1689 | uint32 pack_length_from_metadata(uint field_metadata) { |
| 1690 | uint32 length= pack_length(); |
| 1691 | DBUG_PRINT("result" , ("pack_length_from_metadata(%d): %u" , |
| 1692 | field_metadata, length)); |
| 1693 | return length; |
| 1694 | } |
| 1695 | double pos_in_interval(Field *min, Field *max) |
| 1696 | { |
| 1697 | return pos_in_interval_val_real(min, max); |
| 1698 | } |
| 1699 | }; |
| 1700 | |
| 1701 | |
| 1702 | class Field_str :public Field { |
| 1703 | protected: |
| 1704 | // TODO-10.2: Reuse DTCollation instead of these three members |
| 1705 | CHARSET_INFO *field_charset; |
| 1706 | enum Derivation field_derivation; |
| 1707 | uint field_repertoire; |
| 1708 | public: |
| 1709 | bool can_be_substituted_to_equal_item(const Context &ctx, |
| 1710 | const Item_equal *item_equal); |
| 1711 | Field_str(uchar *ptr_arg,uint32 len_arg, uchar *null_ptr_arg, |
| 1712 | uchar null_bit_arg, utype unireg_check_arg, |
| 1713 | const LEX_CSTRING *field_name_arg, |
| 1714 | const DTCollation &collation); |
| 1715 | uint decimals() const { return NOT_FIXED_DEC; } |
| 1716 | int save_in_field(Field *to) { return save_in_field_str(to); } |
| 1717 | bool memcpy_field_possible(const Field *from) const |
| 1718 | { |
| 1719 | return real_type() == from->real_type() && |
| 1720 | pack_length() == from->pack_length() && |
| 1721 | charset() == from->charset(); |
| 1722 | } |
| 1723 | int store(double nr); |
| 1724 | int store(longlong nr, bool unsigned_val); |
| 1725 | int store_decimal(const my_decimal *); |
| 1726 | int store(const char *to,size_t length,CHARSET_INFO *cs)=0; |
| 1727 | int store_hex_hybrid(const char *str, size_t length) |
| 1728 | { |
| 1729 | return store(str, length, &my_charset_bin); |
| 1730 | } |
| 1731 | uint repertoire(void) const { return field_repertoire; } |
| 1732 | CHARSET_INFO *charset(void) const { return field_charset; } |
| 1733 | enum Derivation derivation(void) const { return field_derivation; } |
| 1734 | bool binary() const { return field_charset == &my_charset_bin; } |
| 1735 | uint32 max_display_length() const { return field_length; } |
| 1736 | uint32 char_length() const { return field_length / field_charset->mbmaxlen; } |
| 1737 | Information_schema_character_attributes |
| 1738 | information_schema_character_attributes() const |
| 1739 | { |
| 1740 | return Information_schema_character_attributes(max_display_length(), |
| 1741 | char_length()); |
| 1742 | } |
| 1743 | friend class Create_field; |
| 1744 | my_decimal *val_decimal(my_decimal *); |
| 1745 | bool val_bool() { return val_real() != 0e0; } |
| 1746 | virtual bool str_needs_quotes() { return TRUE; } |
| 1747 | uint is_equal(Create_field *new_field); |
| 1748 | bool eq_cmp_as_binary() { return MY_TEST(flags & BINARY_FLAG); } |
| 1749 | virtual uint length_size() { return 0; } |
| 1750 | double pos_in_interval(Field *min, Field *max) |
| 1751 | { |
| 1752 | return pos_in_interval_val_str(min, max, length_size()); |
| 1753 | } |
| 1754 | bool test_if_equality_guarantees_uniqueness(const Item *const_item) const; |
| 1755 | }; |
| 1756 | |
| 1757 | /* base class for Field_string, Field_varstring and Field_blob */ |
| 1758 | |
| 1759 | class Field_longstr :public Field_str |
| 1760 | { |
| 1761 | protected: |
| 1762 | int report_if_important_data(const char *ptr, const char *end, |
| 1763 | bool count_spaces); |
| 1764 | bool check_string_copy_error(const String_copier *copier, |
| 1765 | const char *end, CHARSET_INFO *cs); |
| 1766 | int check_conversion_status(const String_copier *copier, |
| 1767 | const char *end, CHARSET_INFO *cs, |
| 1768 | bool count_spaces) |
| 1769 | { |
| 1770 | if (check_string_copy_error(copier, end, cs)) |
| 1771 | return 2; |
| 1772 | return report_if_important_data(copier->source_end_pos(), |
| 1773 | end, count_spaces); |
| 1774 | } |
| 1775 | int well_formed_copy_with_check(char *to, size_t to_length, |
| 1776 | CHARSET_INFO *from_cs, |
| 1777 | const char *from, size_t from_length, |
| 1778 | size_t nchars, bool count_spaces, |
| 1779 | uint *copy_length) |
| 1780 | { |
| 1781 | String_copier copier; |
| 1782 | |
| 1783 | *copy_length= copier.well_formed_copy(field_charset, to, to_length, |
| 1784 | from_cs, from, from_length, |
| 1785 | nchars); |
| 1786 | |
| 1787 | return check_conversion_status(&copier, from + from_length, from_cs, count_spaces); |
| 1788 | } |
| 1789 | bool cmp_to_string_with_same_collation(const Item_bool_func *cond, |
| 1790 | const Item *item) const; |
| 1791 | bool cmp_to_string_with_stricter_collation(const Item_bool_func *cond, |
| 1792 | const Item *item) const; |
| 1793 | int compress(char *to, uint to_length, |
| 1794 | const char *from, uint length, |
| 1795 | uint max_length, |
| 1796 | uint *out_length, |
| 1797 | CHARSET_INFO *cs, size_t nchars); |
| 1798 | String *uncompress(String *val_buffer, String *val_ptr, |
| 1799 | const uchar *from, uint from_length); |
| 1800 | public: |
| 1801 | Field_longstr(uchar *ptr_arg, uint32 len_arg, uchar *null_ptr_arg, |
| 1802 | uchar null_bit_arg, utype unireg_check_arg, |
| 1803 | const LEX_CSTRING *field_name_arg, |
| 1804 | const DTCollation &collation) |
| 1805 | :Field_str(ptr_arg, len_arg, null_ptr_arg, null_bit_arg, unireg_check_arg, |
| 1806 | field_name_arg, collation) |
| 1807 | {} |
| 1808 | |
| 1809 | int store_decimal(const my_decimal *d); |
| 1810 | uint32 max_data_length() const; |
| 1811 | |
| 1812 | bool is_varchar_and_in_write_set() const |
| 1813 | { |
| 1814 | DBUG_ASSERT(table && table->write_set); |
| 1815 | return bitmap_is_set(table->write_set, field_index); |
| 1816 | } |
| 1817 | bool match_collation_to_optimize_range() const { return true; } |
| 1818 | |
| 1819 | bool can_optimize_keypart_ref(const Item_bool_func *cond, |
| 1820 | const Item *item) const; |
| 1821 | bool can_optimize_hash_join(const Item_bool_func *cond, |
| 1822 | const Item *item) const; |
| 1823 | bool can_optimize_group_min_max(const Item_bool_func *cond, |
| 1824 | const Item *const_item) const; |
| 1825 | bool can_optimize_range(const Item_bool_func *cond, |
| 1826 | const Item *item, |
| 1827 | bool is_eq_func) const; |
| 1828 | }; |
| 1829 | |
| 1830 | /* base class for float and double and decimal (old one) */ |
| 1831 | class Field_real :public Field_num { |
| 1832 | protected: |
| 1833 | double get_double(const char *str, size_t length, CHARSET_INFO *cs, int *err); |
| 1834 | public: |
| 1835 | bool not_fixed; |
| 1836 | |
| 1837 | Field_real(uchar *ptr_arg, uint32 len_arg, uchar *null_ptr_arg, |
| 1838 | uchar null_bit_arg, utype unireg_check_arg, |
| 1839 | const LEX_CSTRING *field_name_arg, |
| 1840 | uint8 dec_arg, bool zero_arg, bool unsigned_arg) |
| 1841 | :Field_num(ptr_arg, len_arg, null_ptr_arg, null_bit_arg, unireg_check_arg, |
| 1842 | field_name_arg, dec_arg, zero_arg, unsigned_arg), |
| 1843 | not_fixed(dec_arg >= FLOATING_POINT_DECIMALS) |
| 1844 | {} |
| 1845 | Copy_func *get_copy_func(const Field *from) const |
| 1846 | { |
| 1847 | return do_field_real; |
| 1848 | } |
| 1849 | Information_schema_numeric_attributes |
| 1850 | information_schema_numeric_attributes() const |
| 1851 | { |
| 1852 | return dec == NOT_FIXED_DEC ? |
| 1853 | Information_schema_numeric_attributes(field_length) : |
| 1854 | Information_schema_numeric_attributes(field_length, dec); |
| 1855 | } |
| 1856 | int save_in_field(Field *to) { return to->store(val_real()); } |
| 1857 | bool memcpy_field_possible(const Field *from) const |
| 1858 | { |
| 1859 | /* |
| 1860 | Cannot do memcpy from a longer field to a shorter field, |
| 1861 | e.g. a DOUBLE(53,10) into a DOUBLE(10,10). |
| 1862 | But it should be OK the other way around. |
| 1863 | */ |
| 1864 | return Field_num::memcpy_field_possible(from) && |
| 1865 | field_length >= from->field_length; |
| 1866 | } |
| 1867 | int store_decimal(const my_decimal *); |
| 1868 | int store_time_dec(const MYSQL_TIME *ltime, uint dec); |
| 1869 | bool get_date(MYSQL_TIME *ltime, ulonglong fuzzydate); |
| 1870 | my_decimal *val_decimal(my_decimal *); |
| 1871 | bool val_bool() { return val_real() != 0e0; } |
| 1872 | uint32 max_display_length() const { return field_length; } |
| 1873 | uint size_of() const { return sizeof(*this); } |
| 1874 | Item *get_equal_const_item(THD *thd, const Context &ctx, Item *const_item); |
| 1875 | }; |
| 1876 | |
| 1877 | |
| 1878 | class Field_decimal :public Field_real { |
| 1879 | public: |
| 1880 | Field_decimal(uchar *ptr_arg, uint32 len_arg, uchar *null_ptr_arg, |
| 1881 | uchar null_bit_arg, |
| 1882 | enum utype unireg_check_arg, const LEX_CSTRING *field_name_arg, |
| 1883 | uint8 dec_arg,bool zero_arg,bool unsigned_arg) |
| 1884 | :Field_real(ptr_arg, len_arg, null_ptr_arg, null_bit_arg, |
| 1885 | unireg_check_arg, field_name_arg, |
| 1886 | dec_arg, zero_arg, unsigned_arg) |
| 1887 | {} |
| 1888 | const Type_handler *type_handler() const { return &type_handler_olddecimal; } |
| 1889 | enum ha_base_keytype key_type() const |
| 1890 | { return zerofill ? HA_KEYTYPE_BINARY : HA_KEYTYPE_NUM; } |
| 1891 | Information_schema_numeric_attributes |
| 1892 | information_schema_numeric_attributes() const |
| 1893 | { |
| 1894 | uint tmp= dec ? 2 : 1; // The sign and the decimal point |
| 1895 | return Information_schema_numeric_attributes(field_length - tmp, dec); |
| 1896 | } |
| 1897 | Copy_func *get_copy_func(const Field *from) const |
| 1898 | { |
| 1899 | return eq_def(from) ? get_identical_copy_func() : do_field_string; |
| 1900 | } |
| 1901 | int reset(void); |
| 1902 | int store(const char *to,size_t length,CHARSET_INFO *charset); |
| 1903 | int store(double nr); |
| 1904 | int store(longlong nr, bool unsigned_val); |
| 1905 | double val_real(void); |
| 1906 | longlong val_int(void); |
| 1907 | String *val_str(String*,String *); |
| 1908 | int cmp(const uchar *,const uchar *); |
| 1909 | void sort_string(uchar *buff,uint length); |
| 1910 | void overflow(bool negative); |
| 1911 | bool zero_pack() const { return 0; } |
| 1912 | void sql_type(String &str) const; |
| 1913 | virtual uchar *pack(uchar* to, const uchar *from, uint max_length) |
| 1914 | { |
| 1915 | return Field::pack(to, from, max_length); |
| 1916 | } |
| 1917 | }; |
| 1918 | |
| 1919 | |
| 1920 | /* New decimal/numeric field which use fixed point arithmetic */ |
| 1921 | class Field_new_decimal :public Field_num { |
| 1922 | private: |
| 1923 | int save_field_metadata(uchar *first_byte); |
| 1924 | public: |
| 1925 | /* The maximum number of decimal digits can be stored */ |
| 1926 | uint precision; |
| 1927 | uint bin_size; |
| 1928 | /* |
| 1929 | Constructors take max_length of the field as a parameter - not the |
| 1930 | precision as the number of decimal digits allowed. |
| 1931 | So for example we need to count length from precision handling |
| 1932 | CREATE TABLE ( DECIMAL(x,y)) |
| 1933 | */ |
| 1934 | Field_new_decimal(uchar *ptr_arg, uint32 len_arg, uchar *null_ptr_arg, |
| 1935 | uchar null_bit_arg, |
| 1936 | enum utype unireg_check_arg, |
| 1937 | const LEX_CSTRING *field_name_arg, |
| 1938 | uint8 dec_arg, bool zero_arg, bool unsigned_arg); |
| 1939 | const Type_handler *type_handler() const { return &type_handler_newdecimal; } |
| 1940 | enum ha_base_keytype key_type() const { return HA_KEYTYPE_BINARY; } |
| 1941 | Copy_func *get_copy_func(const Field *from) const |
| 1942 | { |
| 1943 | // if (from->real_type() == MYSQL_TYPE_BIT) // QQ: why? |
| 1944 | // return do_field_int; |
| 1945 | return do_field_decimal; |
| 1946 | } |
| 1947 | int save_in_field(Field *to) |
| 1948 | { |
| 1949 | my_decimal buff; |
| 1950 | return to->store_decimal(val_decimal(&buff)); |
| 1951 | } |
| 1952 | bool memcpy_field_possible(const Field *from) const |
| 1953 | { |
| 1954 | return Field_num::memcpy_field_possible(from) && |
| 1955 | field_length == from->field_length; |
| 1956 | } |
| 1957 | int reset(void); |
| 1958 | bool store_value(const my_decimal *decimal_value); |
| 1959 | bool store_value(const my_decimal *decimal_value, int *native_error); |
| 1960 | void set_value_on_overflow(my_decimal *decimal_value, bool sign); |
| 1961 | int store(const char *to, size_t length, CHARSET_INFO *charset); |
| 1962 | int store(double nr); |
| 1963 | int store(longlong nr, bool unsigned_val); |
| 1964 | int store_time_dec(const MYSQL_TIME *ltime, uint dec); |
| 1965 | int store_decimal(const my_decimal *); |
| 1966 | double val_real(void); |
| 1967 | longlong val_int(void); |
| 1968 | my_decimal *val_decimal(my_decimal *); |
| 1969 | String *val_str(String*, String *); |
| 1970 | bool get_date(MYSQL_TIME *ltime, ulonglong fuzzydate); |
| 1971 | bool val_bool() |
| 1972 | { |
| 1973 | my_decimal decimal_value; |
| 1974 | my_decimal *val= val_decimal(&decimal_value); |
| 1975 | return val ? !my_decimal_is_zero(val) : 0; |
| 1976 | } |
| 1977 | int cmp(const uchar *, const uchar *); |
| 1978 | void sort_string(uchar *buff, uint length); |
| 1979 | bool zero_pack() const { return 0; } |
| 1980 | void sql_type(String &str) const; |
| 1981 | uint32 max_display_length() const { return field_length; } |
| 1982 | Information_schema_numeric_attributes |
| 1983 | information_schema_numeric_attributes() const |
| 1984 | { |
| 1985 | return Information_schema_numeric_attributes(precision, dec); |
| 1986 | } |
| 1987 | uint size_of() const { return sizeof(*this); } |
| 1988 | uint32 pack_length() const { return (uint32) bin_size; } |
| 1989 | uint pack_length_from_metadata(uint field_metadata); |
| 1990 | uint row_pack_length() const { return pack_length(); } |
| 1991 | bool compatible_field_size(uint field_metadata, Relay_log_info *rli, |
| 1992 | uint16 mflags, int *order_var); |
| 1993 | uint is_equal(Create_field *new_field); |
| 1994 | virtual const uchar *unpack(uchar* to, const uchar *from, const uchar *from_end, uint param_data); |
| 1995 | Item *get_equal_const_item(THD *thd, const Context &ctx, Item *const_item); |
| 1996 | }; |
| 1997 | |
| 1998 | |
| 1999 | class Field_int :public Field_num |
| 2000 | { |
| 2001 | protected: |
| 2002 | String *val_str_from_long(String *val_buffer, uint max_char_length, |
| 2003 | int radix, long nr); |
| 2004 | public: |
| 2005 | Field_int(uchar *ptr_arg, uint32 len_arg, uchar *null_ptr_arg, |
| 2006 | uchar null_bit_arg, enum utype unireg_check_arg, |
| 2007 | const LEX_CSTRING *field_name_arg, bool zero_arg, bool unsigned_arg) |
| 2008 | :Field_num(ptr_arg, len_arg, null_ptr_arg, null_bit_arg, |
| 2009 | unireg_check_arg, field_name_arg, 0, zero_arg, unsigned_arg) |
| 2010 | {} |
| 2011 | int store_decimal(const my_decimal *); |
| 2012 | my_decimal *val_decimal(my_decimal *); |
| 2013 | bool val_bool() { return val_int() != 0; } |
| 2014 | int store_time_dec(const MYSQL_TIME *ltime, uint dec); |
| 2015 | bool get_date(MYSQL_TIME *ltime, ulonglong fuzzydate); |
| 2016 | virtual const Type_limits_int *type_limits_int() const= 0; |
| 2017 | uint32 max_display_length() const |
| 2018 | { |
| 2019 | return type_limits_int()->char_length(); |
| 2020 | } |
| 2021 | Type_std_attributes type_std_attributes() const |
| 2022 | { |
| 2023 | /* |
| 2024 | For integer data types, the user-specified length does not constrain the |
| 2025 | supported range, so e.g. a column of the INT(1) data type supports the |
| 2026 | full integer range anyway. |
| 2027 | Choose the maximum from the user-specified length and the maximum |
| 2028 | possible length determined by the data type capacity: |
| 2029 | INT(1) -> 11 |
| 2030 | INT(10) -> 11 |
| 2031 | INT(40) -> 40 |
| 2032 | */ |
| 2033 | uint32 length1= max_display_length(); |
| 2034 | uint32 length2= field_length; |
| 2035 | return Type_std_attributes(MY_MAX(length1, length2), decimals(), |
| 2036 | MY_TEST(flags & UNSIGNED_FLAG), |
| 2037 | dtcollation()); |
| 2038 | } |
| 2039 | Information_schema_numeric_attributes |
| 2040 | information_schema_numeric_attributes() const |
| 2041 | { |
| 2042 | uint32 prec= type_limits_int()->precision(); |
| 2043 | return Information_schema_numeric_attributes(prec, 0); |
| 2044 | } |
| 2045 | }; |
| 2046 | |
| 2047 | |
| 2048 | class Field_tiny :public Field_int |
| 2049 | { |
| 2050 | public: |
| 2051 | Field_tiny(uchar *ptr_arg, uint32 len_arg, uchar *null_ptr_arg, |
| 2052 | uchar null_bit_arg, |
| 2053 | enum utype unireg_check_arg, const LEX_CSTRING *field_name_arg, |
| 2054 | bool zero_arg, bool unsigned_arg) |
| 2055 | :Field_int(ptr_arg, len_arg, null_ptr_arg, null_bit_arg, |
| 2056 | unireg_check_arg, field_name_arg, zero_arg, unsigned_arg) |
| 2057 | {} |
| 2058 | const Type_handler *type_handler() const { return &type_handler_tiny; } |
| 2059 | enum ha_base_keytype key_type() const |
| 2060 | { return unsigned_flag ? HA_KEYTYPE_BINARY : HA_KEYTYPE_INT8; } |
| 2061 | int store(const char *to,size_t length,CHARSET_INFO *charset); |
| 2062 | int store(double nr); |
| 2063 | int store(longlong nr, bool unsigned_val); |
| 2064 | int reset(void) { ptr[0]=0; return 0; } |
| 2065 | double val_real(void); |
| 2066 | longlong val_int(void); |
| 2067 | String *val_str(String*,String *); |
| 2068 | bool send_binary(Protocol *protocol); |
| 2069 | int cmp(const uchar *,const uchar *); |
| 2070 | void sort_string(uchar *buff,uint length); |
| 2071 | uint32 pack_length() const { return 1; } |
| 2072 | void sql_type(String &str) const; |
| 2073 | const Type_limits_int *type_limits_int() const |
| 2074 | { |
| 2075 | return type_handler_tiny.type_limits_int_by_unsigned_flag(is_unsigned()); |
| 2076 | } |
| 2077 | |
| 2078 | virtual uchar *pack(uchar* to, const uchar *from, uint max_length) |
| 2079 | { |
| 2080 | *to= *from; |
| 2081 | return to + 1; |
| 2082 | } |
| 2083 | |
| 2084 | virtual const uchar *unpack(uchar* to, const uchar *from, |
| 2085 | const uchar *from_end, uint param_data) |
| 2086 | { |
| 2087 | if (from == from_end) |
| 2088 | return 0; |
| 2089 | *to= *from; |
| 2090 | return from + 1; |
| 2091 | } |
| 2092 | }; |
| 2093 | |
| 2094 | |
| 2095 | class Field_short :public Field_int |
| 2096 | { |
| 2097 | public: |
| 2098 | Field_short(uchar *ptr_arg, uint32 len_arg, uchar *null_ptr_arg, |
| 2099 | uchar null_bit_arg, |
| 2100 | enum utype unireg_check_arg, const LEX_CSTRING *field_name_arg, |
| 2101 | bool zero_arg, bool unsigned_arg) |
| 2102 | :Field_int(ptr_arg, len_arg, null_ptr_arg, null_bit_arg, |
| 2103 | unireg_check_arg, field_name_arg, zero_arg, unsigned_arg) |
| 2104 | {} |
| 2105 | Field_short(uint32 len_arg,bool maybe_null_arg, |
| 2106 | const LEX_CSTRING *field_name_arg, |
| 2107 | bool unsigned_arg) |
| 2108 | :Field_int((uchar*) 0, len_arg, maybe_null_arg ? (uchar*) "" : 0,0, |
| 2109 | NONE, field_name_arg, 0, unsigned_arg) |
| 2110 | {} |
| 2111 | const Type_handler *type_handler() const { return &type_handler_short; } |
| 2112 | enum ha_base_keytype key_type() const |
| 2113 | { return unsigned_flag ? HA_KEYTYPE_USHORT_INT : HA_KEYTYPE_SHORT_INT;} |
| 2114 | int store(const char *to,size_t length,CHARSET_INFO *charset); |
| 2115 | int store(double nr); |
| 2116 | int store(longlong nr, bool unsigned_val); |
| 2117 | int reset(void) { ptr[0]=ptr[1]=0; return 0; } |
| 2118 | double val_real(void); |
| 2119 | longlong val_int(void); |
| 2120 | String *val_str(String*,String *); |
| 2121 | bool send_binary(Protocol *protocol); |
| 2122 | int cmp(const uchar *,const uchar *); |
| 2123 | void sort_string(uchar *buff,uint length); |
| 2124 | uint32 pack_length() const { return 2; } |
| 2125 | void sql_type(String &str) const; |
| 2126 | const Type_limits_int *type_limits_int() const |
| 2127 | { |
| 2128 | return type_handler_short.type_limits_int_by_unsigned_flag(is_unsigned()); |
| 2129 | } |
| 2130 | virtual uchar *pack(uchar* to, const uchar *from, uint max_length) |
| 2131 | { return pack_int16(to, from); } |
| 2132 | |
| 2133 | virtual const uchar *unpack(uchar* to, const uchar *from, |
| 2134 | const uchar *from_end, uint param_data) |
| 2135 | { return unpack_int16(to, from, from_end); } |
| 2136 | }; |
| 2137 | |
| 2138 | class Field_medium :public Field_int |
| 2139 | { |
| 2140 | public: |
| 2141 | Field_medium(uchar *ptr_arg, uint32 len_arg, uchar *null_ptr_arg, |
| 2142 | uchar null_bit_arg, |
| 2143 | enum utype unireg_check_arg, const LEX_CSTRING *field_name_arg, |
| 2144 | bool zero_arg, bool unsigned_arg) |
| 2145 | :Field_int(ptr_arg, len_arg, null_ptr_arg, null_bit_arg, |
| 2146 | unireg_check_arg, field_name_arg, zero_arg, unsigned_arg) |
| 2147 | {} |
| 2148 | const Type_handler *type_handler() const { return &type_handler_int24; } |
| 2149 | enum ha_base_keytype key_type() const |
| 2150 | { return unsigned_flag ? HA_KEYTYPE_UINT24 : HA_KEYTYPE_INT24; } |
| 2151 | int store(const char *to,size_t length,CHARSET_INFO *charset); |
| 2152 | int store(double nr); |
| 2153 | int store(longlong nr, bool unsigned_val); |
| 2154 | int reset(void) { ptr[0]=ptr[1]=ptr[2]=0; return 0; } |
| 2155 | double val_real(void); |
| 2156 | longlong val_int(void); |
| 2157 | String *val_str(String*,String *); |
| 2158 | bool send_binary(Protocol *protocol); |
| 2159 | int cmp(const uchar *,const uchar *); |
| 2160 | void sort_string(uchar *buff,uint length); |
| 2161 | uint32 pack_length() const { return 3; } |
| 2162 | void sql_type(String &str) const; |
| 2163 | const Type_limits_int *type_limits_int() const |
| 2164 | { |
| 2165 | return type_handler_int24.type_limits_int_by_unsigned_flag(is_unsigned()); |
| 2166 | } |
| 2167 | virtual uchar *pack(uchar* to, const uchar *from, uint max_length) |
| 2168 | { |
| 2169 | return Field::pack(to, from, max_length); |
| 2170 | } |
| 2171 | }; |
| 2172 | |
| 2173 | |
| 2174 | class Field_long :public Field_int |
| 2175 | { |
| 2176 | public: |
| 2177 | Field_long(uchar *ptr_arg, uint32 len_arg, uchar *null_ptr_arg, |
| 2178 | uchar null_bit_arg, |
| 2179 | enum utype unireg_check_arg, const LEX_CSTRING *field_name_arg, |
| 2180 | bool zero_arg, bool unsigned_arg) |
| 2181 | :Field_int(ptr_arg, len_arg, null_ptr_arg, null_bit_arg, |
| 2182 | unireg_check_arg, field_name_arg, zero_arg, unsigned_arg) |
| 2183 | {} |
| 2184 | Field_long(uint32 len_arg,bool maybe_null_arg, |
| 2185 | const LEX_CSTRING *field_name_arg, |
| 2186 | bool unsigned_arg) |
| 2187 | :Field_int((uchar*) 0, len_arg, maybe_null_arg ? (uchar*) "" : 0,0, |
| 2188 | NONE, field_name_arg, 0, unsigned_arg) |
| 2189 | {} |
| 2190 | const Type_handler *type_handler() const { return &type_handler_long; } |
| 2191 | enum ha_base_keytype key_type() const |
| 2192 | { return unsigned_flag ? HA_KEYTYPE_ULONG_INT : HA_KEYTYPE_LONG_INT; } |
| 2193 | int store(const char *to,size_t length,CHARSET_INFO *charset); |
| 2194 | int store(double nr); |
| 2195 | int store(longlong nr, bool unsigned_val); |
| 2196 | int reset(void) { ptr[0]=ptr[1]=ptr[2]=ptr[3]=0; return 0; } |
| 2197 | double val_real(void); |
| 2198 | longlong val_int(void); |
| 2199 | bool send_binary(Protocol *protocol); |
| 2200 | String *val_str(String*,String *); |
| 2201 | int cmp(const uchar *,const uchar *); |
| 2202 | void sort_string(uchar *buff,uint length); |
| 2203 | uint32 pack_length() const { return 4; } |
| 2204 | void sql_type(String &str) const; |
| 2205 | const Type_limits_int *type_limits_int() const |
| 2206 | { |
| 2207 | return type_handler_long.type_limits_int_by_unsigned_flag(is_unsigned()); |
| 2208 | } |
| 2209 | virtual uchar *pack(uchar* to, const uchar *from, |
| 2210 | uint max_length __attribute__((unused))) |
| 2211 | { |
| 2212 | return pack_int32(to, from); |
| 2213 | } |
| 2214 | virtual const uchar *unpack(uchar* to, const uchar *from, |
| 2215 | const uchar *from_end, |
| 2216 | uint param_data __attribute__((unused))) |
| 2217 | { |
| 2218 | return unpack_int32(to, from, from_end); |
| 2219 | } |
| 2220 | }; |
| 2221 | |
| 2222 | |
| 2223 | class Field_longlong :public Field_int |
| 2224 | { |
| 2225 | public: |
| 2226 | Field_longlong(uchar *ptr_arg, uint32 len_arg, uchar *null_ptr_arg, |
| 2227 | uchar null_bit_arg, |
| 2228 | enum utype unireg_check_arg, const LEX_CSTRING *field_name_arg, |
| 2229 | bool zero_arg, bool unsigned_arg) |
| 2230 | :Field_int(ptr_arg, len_arg, null_ptr_arg, null_bit_arg, |
| 2231 | unireg_check_arg, field_name_arg, zero_arg, unsigned_arg) |
| 2232 | {} |
| 2233 | Field_longlong(uint32 len_arg,bool maybe_null_arg, |
| 2234 | const LEX_CSTRING *field_name_arg, |
| 2235 | bool unsigned_arg) |
| 2236 | :Field_int((uchar*) 0, len_arg, maybe_null_arg ? (uchar*) "" : 0,0, |
| 2237 | NONE, field_name_arg, 0, unsigned_arg) |
| 2238 | {} |
| 2239 | const Type_handler *type_handler() const { return &type_handler_longlong; } |
| 2240 | enum ha_base_keytype key_type() const |
| 2241 | { return unsigned_flag ? HA_KEYTYPE_ULONGLONG : HA_KEYTYPE_LONGLONG; } |
| 2242 | int store(const char *to,size_t length,CHARSET_INFO *charset); |
| 2243 | int store(double nr); |
| 2244 | int store(longlong nr, bool unsigned_val); |
| 2245 | int reset(void) |
| 2246 | { |
| 2247 | ptr[0]=ptr[1]=ptr[2]=ptr[3]=ptr[4]=ptr[5]=ptr[6]=ptr[7]=0; |
| 2248 | return 0; |
| 2249 | } |
| 2250 | double val_real(void); |
| 2251 | longlong val_int(void); |
| 2252 | String *val_str(String*,String *); |
| 2253 | bool send_binary(Protocol *protocol); |
| 2254 | int cmp(const uchar *,const uchar *); |
| 2255 | void sort_string(uchar *buff,uint length); |
| 2256 | uint32 pack_length() const { return 8; } |
| 2257 | void sql_type(String &str) const; |
| 2258 | const Type_limits_int *type_limits_int() const |
| 2259 | { |
| 2260 | return type_handler_longlong.type_limits_int_by_unsigned_flag(is_unsigned()); |
| 2261 | } |
| 2262 | virtual uchar *pack(uchar* to, const uchar *from, |
| 2263 | uint max_length __attribute__((unused))) |
| 2264 | { |
| 2265 | return pack_int64(to, from); |
| 2266 | } |
| 2267 | const uchar *unpack(uchar* to, const uchar *from, const uchar *from_end, |
| 2268 | uint param_data __attribute__((unused))) |
| 2269 | { |
| 2270 | return unpack_int64(to, from, from_end); |
| 2271 | } |
| 2272 | |
| 2273 | void set_max(); |
| 2274 | bool is_max(); |
| 2275 | }; |
| 2276 | |
| 2277 | |
| 2278 | class Field_vers_trx_id :public Field_longlong { |
| 2279 | MYSQL_TIME cache; |
| 2280 | ulonglong cached; |
| 2281 | public: |
| 2282 | Field_vers_trx_id(uchar *ptr_arg, uint32 len_arg, uchar *null_ptr_arg, |
| 2283 | uchar null_bit_arg, enum utype unireg_check_arg, |
| 2284 | const LEX_CSTRING *field_name_arg, bool zero_arg, |
| 2285 | bool unsigned_arg) |
| 2286 | : Field_longlong(ptr_arg, len_arg, null_ptr_arg, null_bit_arg, |
| 2287 | unireg_check_arg, field_name_arg, zero_arg, |
| 2288 | unsigned_arg), |
| 2289 | cached(0) |
| 2290 | {} |
| 2291 | const Type_handler *type_handler() const { return &type_handler_vers_trx_id; } |
| 2292 | uint size_of() const { return sizeof(*this); } |
| 2293 | bool get_date(MYSQL_TIME *ltime, ulonglong fuzzydate, ulonglong trx_id); |
| 2294 | bool get_date(MYSQL_TIME *ltime, ulonglong fuzzydate) |
| 2295 | { |
| 2296 | return get_date(ltime, fuzzydate, (ulonglong) val_int()); |
| 2297 | } |
| 2298 | bool test_if_equality_guarantees_uniqueness(const Item *item) const; |
| 2299 | bool can_optimize_keypart_ref(const Item_bool_func *cond, |
| 2300 | const Item *item) const |
| 2301 | { |
| 2302 | return true; |
| 2303 | } |
| 2304 | |
| 2305 | bool can_optimize_group_min_max(const Item_bool_func *cond, |
| 2306 | const Item *const_item) const |
| 2307 | { |
| 2308 | return true; |
| 2309 | } |
| 2310 | bool can_optimize_range(const Item_bool_func *cond, |
| 2311 | const Item *item, |
| 2312 | bool is_eq_func) const |
| 2313 | { |
| 2314 | return true; |
| 2315 | } |
| 2316 | /* cmp_type() cannot be TIME_RESULT, because we want to compare this field against |
| 2317 | integers. But in all other cases we treat it as TIME_RESULT! */ |
| 2318 | }; |
| 2319 | |
| 2320 | |
| 2321 | class Field_float :public Field_real { |
| 2322 | public: |
| 2323 | Field_float(uchar *ptr_arg, uint32 len_arg, uchar *null_ptr_arg, |
| 2324 | uchar null_bit_arg, |
| 2325 | enum utype unireg_check_arg, const LEX_CSTRING *field_name_arg, |
| 2326 | uint8 dec_arg,bool zero_arg,bool unsigned_arg) |
| 2327 | :Field_real(ptr_arg, len_arg, null_ptr_arg, null_bit_arg, |
| 2328 | unireg_check_arg, field_name_arg, |
| 2329 | dec_arg, zero_arg, unsigned_arg) |
| 2330 | { |
| 2331 | if (dec_arg >= FLOATING_POINT_DECIMALS) |
| 2332 | dec_arg= NOT_FIXED_DEC; |
| 2333 | } |
| 2334 | Field_float(uint32 len_arg, bool maybe_null_arg, |
| 2335 | const LEX_CSTRING *field_name_arg, uint8 dec_arg) |
| 2336 | :Field_real((uchar*) 0, len_arg, maybe_null_arg ? (uchar*) "" : 0, (uint) 0, |
| 2337 | NONE, field_name_arg, dec_arg, 0, 0) |
| 2338 | { |
| 2339 | if (dec_arg >= FLOATING_POINT_DECIMALS) |
| 2340 | dec_arg= NOT_FIXED_DEC; |
| 2341 | } |
| 2342 | const Type_handler *type_handler() const { return &type_handler_float; } |
| 2343 | enum ha_base_keytype key_type() const { return HA_KEYTYPE_FLOAT; } |
| 2344 | int store(const char *to,size_t length,CHARSET_INFO *charset); |
| 2345 | int store(double nr); |
| 2346 | int store(longlong nr, bool unsigned_val); |
| 2347 | int reset(void) { bzero(ptr,sizeof(float)); return 0; } |
| 2348 | double val_real(void); |
| 2349 | longlong val_int(void); |
| 2350 | String *val_str(String*,String *); |
| 2351 | bool send_binary(Protocol *protocol); |
| 2352 | int cmp(const uchar *,const uchar *); |
| 2353 | void sort_string(uchar *buff,uint length); |
| 2354 | uint32 pack_length() const { return sizeof(float); } |
| 2355 | uint row_pack_length() const { return pack_length(); } |
| 2356 | void sql_type(String &str) const; |
| 2357 | private: |
| 2358 | int save_field_metadata(uchar *first_byte); |
| 2359 | }; |
| 2360 | |
| 2361 | |
| 2362 | class Field_double :public Field_real { |
| 2363 | longlong val_int_from_real(bool want_unsigned_result); |
| 2364 | public: |
| 2365 | Field_double(uchar *ptr_arg, uint32 len_arg, uchar *null_ptr_arg, |
| 2366 | uchar null_bit_arg, |
| 2367 | enum utype unireg_check_arg, const LEX_CSTRING *field_name_arg, |
| 2368 | uint8 dec_arg,bool zero_arg,bool unsigned_arg) |
| 2369 | :Field_real(ptr_arg, len_arg, null_ptr_arg, null_bit_arg, |
| 2370 | unireg_check_arg, field_name_arg, |
| 2371 | dec_arg, zero_arg, unsigned_arg) |
| 2372 | { |
| 2373 | if (dec_arg >= FLOATING_POINT_DECIMALS) |
| 2374 | dec_arg= NOT_FIXED_DEC; |
| 2375 | } |
| 2376 | Field_double(uint32 len_arg, bool maybe_null_arg, |
| 2377 | const LEX_CSTRING *field_name_arg, uint8 dec_arg) |
| 2378 | :Field_real((uchar*) 0, len_arg, maybe_null_arg ? (uchar*) "" : 0, (uint) 0, |
| 2379 | NONE, field_name_arg, dec_arg, 0, 0) |
| 2380 | { |
| 2381 | if (dec_arg >= FLOATING_POINT_DECIMALS) |
| 2382 | dec_arg= NOT_FIXED_DEC; |
| 2383 | } |
| 2384 | Field_double(uint32 len_arg, bool maybe_null_arg, |
| 2385 | const LEX_CSTRING *field_name_arg, |
| 2386 | uint8 dec_arg, bool not_fixed_arg) |
| 2387 | :Field_real((uchar*) 0, len_arg, maybe_null_arg ? (uchar*) "" : 0, (uint) 0, |
| 2388 | NONE, field_name_arg, dec_arg, 0, 0) |
| 2389 | { |
| 2390 | not_fixed= not_fixed_arg; |
| 2391 | if (dec_arg >= FLOATING_POINT_DECIMALS) |
| 2392 | dec_arg= NOT_FIXED_DEC; |
| 2393 | } |
| 2394 | const Type_handler *type_handler() const { return &type_handler_double; } |
| 2395 | enum ha_base_keytype key_type() const { return HA_KEYTYPE_DOUBLE; } |
| 2396 | int store(const char *to,size_t length,CHARSET_INFO *charset); |
| 2397 | int store(double nr); |
| 2398 | int store(longlong nr, bool unsigned_val); |
| 2399 | int reset(void) { bzero(ptr,sizeof(double)); return 0; } |
| 2400 | double val_real(void); |
| 2401 | longlong val_int(void) { return val_int_from_real(false); } |
| 2402 | ulonglong val_uint(void) { return (ulonglong) val_int_from_real(true); } |
| 2403 | String *val_str(String*,String *); |
| 2404 | bool send_binary(Protocol *protocol); |
| 2405 | int cmp(const uchar *,const uchar *); |
| 2406 | void sort_string(uchar *buff,uint length); |
| 2407 | uint32 pack_length() const { return sizeof(double); } |
| 2408 | uint row_pack_length() const { return pack_length(); } |
| 2409 | void sql_type(String &str) const; |
| 2410 | private: |
| 2411 | int save_field_metadata(uchar *first_byte); |
| 2412 | }; |
| 2413 | |
| 2414 | |
| 2415 | /* Everything saved in this will disappear. It will always return NULL */ |
| 2416 | |
| 2417 | class Field_null :public Field_str { |
| 2418 | static uchar null[1]; |
| 2419 | public: |
| 2420 | Field_null(uchar *ptr_arg, uint32 len_arg, |
| 2421 | enum utype unireg_check_arg, const LEX_CSTRING *field_name_arg, |
| 2422 | const DTCollation &collation) |
| 2423 | :Field_str(ptr_arg, len_arg, null, 1, |
| 2424 | unireg_check_arg, field_name_arg, collation) |
| 2425 | {} |
| 2426 | const Type_handler *type_handler() const { return &type_handler_null; } |
| 2427 | Information_schema_character_attributes |
| 2428 | information_schema_character_attributes() const |
| 2429 | { |
| 2430 | return Information_schema_character_attributes(); |
| 2431 | } |
| 2432 | Copy_func *get_copy_func(const Field *from) const |
| 2433 | { |
| 2434 | return do_field_string; |
| 2435 | } |
| 2436 | int store(const char *to, size_t length, CHARSET_INFO *cs) |
| 2437 | { null[0]=1; return 0; } |
| 2438 | int store(double nr) { null[0]=1; return 0; } |
| 2439 | int store(longlong nr, bool unsigned_val) { null[0]=1; return 0; } |
| 2440 | int store_decimal(const my_decimal *d) { null[0]=1; return 0; } |
| 2441 | int reset(void) { return 0; } |
| 2442 | double val_real(void) { return 0.0;} |
| 2443 | longlong val_int(void) { return 0;} |
| 2444 | bool val_bool(void) { return false; } |
| 2445 | my_decimal *val_decimal(my_decimal *) { return 0; } |
| 2446 | String *val_str(String *value,String *value2) |
| 2447 | { value2->length(0); return value2;} |
| 2448 | int cmp(const uchar *a, const uchar *b) { return 0;} |
| 2449 | void sort_string(uchar *buff, uint length) {} |
| 2450 | uint32 pack_length() const { return 0; } |
| 2451 | void sql_type(String &str) const; |
| 2452 | uint size_of() const { return sizeof(*this); } |
| 2453 | uint32 max_display_length() const { return 4; } |
| 2454 | void move_field_offset(my_ptrdiff_t ptr_diff) {} |
| 2455 | bool can_optimize_keypart_ref(const Item_bool_func *cond, |
| 2456 | const Item *item) const |
| 2457 | { |
| 2458 | return false; |
| 2459 | } |
| 2460 | bool can_optimize_group_min_max(const Item_bool_func *cond, |
| 2461 | const Item *const_item) const |
| 2462 | { |
| 2463 | return false; |
| 2464 | } |
| 2465 | }; |
| 2466 | |
| 2467 | |
| 2468 | class Field_temporal: public Field { |
| 2469 | protected: |
| 2470 | Item *get_equal_const_item_datetime(THD *thd, const Context &ctx, |
| 2471 | Item *const_item); |
| 2472 | public: |
| 2473 | Field_temporal(uchar *ptr_arg,uint32 len_arg, uchar *null_ptr_arg, |
| 2474 | uchar null_bit_arg, utype unireg_check_arg, |
| 2475 | const LEX_CSTRING *field_name_arg) |
| 2476 | :Field(ptr_arg, len_arg, null_ptr_arg, null_bit_arg, unireg_check_arg, |
| 2477 | field_name_arg) |
| 2478 | { flags|= BINARY_FLAG; } |
| 2479 | int store_hex_hybrid(const char *str, size_t length) |
| 2480 | { |
| 2481 | return store(str, length, &my_charset_bin); |
| 2482 | } |
| 2483 | Copy_func *get_copy_func(const Field *from) const; |
| 2484 | int save_in_field(Field *to) |
| 2485 | { |
| 2486 | MYSQL_TIME ltime; |
| 2487 | if (get_date(<ime, 0)) |
| 2488 | return to->reset(); |
| 2489 | return to->store_time_dec(<ime, decimals()); |
| 2490 | } |
| 2491 | bool memcpy_field_possible(const Field *from) const; |
| 2492 | uint32 max_display_length() const { return field_length; } |
| 2493 | bool str_needs_quotes() { return TRUE; } |
| 2494 | enum Derivation derivation(void) const { return DERIVATION_NUMERIC; } |
| 2495 | uint repertoire(void) const { return MY_REPERTOIRE_NUMERIC; } |
| 2496 | CHARSET_INFO *charset(void) const { return &my_charset_numeric; } |
| 2497 | CHARSET_INFO *sort_charset(void) const { return &my_charset_bin; } |
| 2498 | bool binary() const { return true; } |
| 2499 | bool val_bool() { return val_real() != 0e0; } |
| 2500 | uint is_equal(Create_field *new_field); |
| 2501 | bool eq_def(const Field *field) const |
| 2502 | { |
| 2503 | return (Field::eq_def(field) && decimals() == field->decimals()); |
| 2504 | } |
| 2505 | my_decimal *val_decimal(my_decimal*); |
| 2506 | void set_warnings(Sql_condition::enum_warning_level trunc_level, |
| 2507 | const ErrConv *str, int was_cut, timestamp_type ts_type); |
| 2508 | double pos_in_interval(Field *min, Field *max) |
| 2509 | { |
| 2510 | return pos_in_interval_val_real(min, max); |
| 2511 | } |
| 2512 | bool can_optimize_keypart_ref(const Item_bool_func *cond, |
| 2513 | const Item *item) const; |
| 2514 | bool can_optimize_group_min_max(const Item_bool_func *cond, |
| 2515 | const Item *const_item) const; |
| 2516 | bool can_optimize_range(const Item_bool_func *cond, |
| 2517 | const Item *item, |
| 2518 | bool is_eq_func) const |
| 2519 | { |
| 2520 | return true; |
| 2521 | } |
| 2522 | }; |
| 2523 | |
| 2524 | |
| 2525 | /** |
| 2526 | Abstract class for: |
| 2527 | - DATE |
| 2528 | - DATETIME |
| 2529 | - DATETIME(1..6) |
| 2530 | - DATETIME(0..6) - MySQL56 version |
| 2531 | */ |
| 2532 | class Field_temporal_with_date: public Field_temporal { |
| 2533 | protected: |
| 2534 | int store_TIME_with_warning(MYSQL_TIME *ltime, const ErrConv *str, |
| 2535 | int was_cut, int have_smth_to_conv); |
| 2536 | virtual void store_TIME(MYSQL_TIME *ltime) = 0; |
| 2537 | virtual bool get_TIME(MYSQL_TIME *ltime, const uchar *pos, |
| 2538 | ulonglong fuzzydate) const = 0; |
| 2539 | bool validate_MMDD(bool not_zero_date, uint month, uint day, |
| 2540 | ulonglong fuzzydate) const |
| 2541 | { |
| 2542 | if (!not_zero_date) |
| 2543 | return fuzzydate & TIME_NO_ZERO_DATE; |
| 2544 | if (!month || !day) |
| 2545 | return fuzzydate & TIME_NO_ZERO_IN_DATE; |
| 2546 | return false; |
| 2547 | } |
| 2548 | public: |
| 2549 | Field_temporal_with_date(uchar *ptr_arg, uint32 len_arg, |
| 2550 | uchar *null_ptr_arg, uchar null_bit_arg, |
| 2551 | utype unireg_check_arg, |
| 2552 | const LEX_CSTRING *field_name_arg) |
| 2553 | :Field_temporal(ptr_arg, len_arg, null_ptr_arg, null_bit_arg, |
| 2554 | unireg_check_arg, field_name_arg) |
| 2555 | {} |
| 2556 | int store(const char *to, size_t length, CHARSET_INFO *charset); |
| 2557 | int store(double nr); |
| 2558 | int store(longlong nr, bool unsigned_val); |
| 2559 | int store_time_dec(const MYSQL_TIME *ltime, uint dec); |
| 2560 | int store_decimal(const my_decimal *); |
| 2561 | bool validate_value_in_record(THD *thd, const uchar *record) const; |
| 2562 | }; |
| 2563 | |
| 2564 | |
| 2565 | class Field_timestamp :public Field_temporal { |
| 2566 | protected: |
| 2567 | sql_mode_t sql_mode_for_timestamp(THD *thd) const; |
| 2568 | int store_TIME_with_warning(THD *, MYSQL_TIME *, const ErrConv *, |
| 2569 | int warnings, bool have_smth_to_conv); |
| 2570 | public: |
| 2571 | Field_timestamp(uchar *ptr_arg, uint32 len_arg, |
| 2572 | uchar *null_ptr_arg, uchar null_bit_arg, |
| 2573 | enum utype unireg_check_arg, |
| 2574 | const LEX_CSTRING *field_name_arg, |
| 2575 | TABLE_SHARE *share); |
| 2576 | const Type_handler *type_handler() const { return &type_handler_timestamp; } |
| 2577 | enum ha_base_keytype key_type() const { return HA_KEYTYPE_ULONG_INT; } |
| 2578 | Copy_func *get_copy_func(const Field *from) const; |
| 2579 | int store(const char *to,size_t length,CHARSET_INFO *charset); |
| 2580 | int store(double nr); |
| 2581 | int store(longlong nr, bool unsigned_val); |
| 2582 | int store_time_dec(const MYSQL_TIME *ltime, uint dec); |
| 2583 | int store_decimal(const my_decimal *); |
| 2584 | int store_timestamp(my_time_t timestamp, ulong sec_part); |
| 2585 | int save_in_field(Field *to); |
| 2586 | double val_real(void); |
| 2587 | longlong val_int(void); |
| 2588 | String *val_str(String*,String *); |
| 2589 | bool send_binary(Protocol *protocol); |
| 2590 | int cmp(const uchar *,const uchar *); |
| 2591 | void sort_string(uchar *buff,uint length); |
| 2592 | uint32 pack_length() const { return 4; } |
| 2593 | void sql_type(String &str) const; |
| 2594 | bool zero_pack() const { return 0; } |
| 2595 | int set_time(); |
| 2596 | int evaluate_update_default_function() |
| 2597 | { |
| 2598 | int res= 0; |
| 2599 | if (has_update_default_function()) |
| 2600 | res= set_time(); |
| 2601 | return res; |
| 2602 | } |
| 2603 | /* Get TIMESTAMP field value as seconds since begging of Unix Epoch */ |
| 2604 | my_time_t get_timestamp(const uchar *pos, ulong *sec_part) const; |
| 2605 | my_time_t get_timestamp(ulong *sec_part) const |
| 2606 | { |
| 2607 | return get_timestamp(ptr, sec_part); |
| 2608 | } |
| 2609 | virtual void store_TIME(my_time_t timestamp, ulong sec_part) |
| 2610 | { |
| 2611 | int4store(ptr,timestamp); |
| 2612 | } |
| 2613 | bool get_date(MYSQL_TIME *ltime, ulonglong fuzzydate); |
| 2614 | uchar *pack(uchar *to, const uchar *from, |
| 2615 | uint max_length __attribute__((unused))) |
| 2616 | { |
| 2617 | return pack_int32(to, from); |
| 2618 | } |
| 2619 | const uchar *unpack(uchar* to, const uchar *from, const uchar *from_end, |
| 2620 | uint param_data __attribute__((unused))) |
| 2621 | { |
| 2622 | return unpack_int32(to, from, from_end); |
| 2623 | } |
| 2624 | bool validate_value_in_record(THD *thd, const uchar *record) const; |
| 2625 | Item *get_equal_const_item(THD *thd, const Context &ctx, Item *const_item) |
| 2626 | { |
| 2627 | return get_equal_const_item_datetime(thd, ctx, const_item); |
| 2628 | } |
| 2629 | bool load_data_set_null(THD *thd); |
| 2630 | bool load_data_set_no_data(THD *thd, bool fixed_format); |
| 2631 | uint size_of() const { return sizeof(*this); } |
| 2632 | }; |
| 2633 | |
| 2634 | |
| 2635 | /** |
| 2636 | Abstract class for: |
| 2637 | - TIMESTAMP(1..6) |
| 2638 | - TIMESTAMP(0..6) - MySQL56 version |
| 2639 | */ |
| 2640 | class Field_timestamp_with_dec :public Field_timestamp { |
| 2641 | protected: |
| 2642 | uint dec; |
| 2643 | public: |
| 2644 | Field_timestamp_with_dec(uchar *ptr_arg, |
| 2645 | uchar *null_ptr_arg, uchar null_bit_arg, |
| 2646 | enum utype unireg_check_arg, |
| 2647 | const LEX_CSTRING *field_name_arg, |
| 2648 | TABLE_SHARE *share, uint dec_arg) : |
| 2649 | Field_timestamp(ptr_arg, |
| 2650 | MAX_DATETIME_WIDTH + dec_arg + MY_TEST(dec_arg), null_ptr_arg, |
| 2651 | null_bit_arg, unireg_check_arg, field_name_arg, share), |
| 2652 | dec(dec_arg) |
| 2653 | { |
| 2654 | DBUG_ASSERT(dec <= TIME_SECOND_PART_DIGITS); |
| 2655 | } |
| 2656 | uint decimals() const { return dec; } |
| 2657 | enum ha_base_keytype key_type() const { return HA_KEYTYPE_BINARY; } |
| 2658 | uchar *pack(uchar *to, const uchar *from, uint max_length) |
| 2659 | { return Field::pack(to, from, max_length); } |
| 2660 | const uchar *unpack(uchar* to, const uchar *from, const uchar *from_end, |
| 2661 | uint param_data) |
| 2662 | { return Field::unpack(to, from, from_end, param_data); } |
| 2663 | void make_send_field(Send_field *field); |
| 2664 | void sort_string(uchar *to, uint length) |
| 2665 | { |
| 2666 | DBUG_ASSERT(length == pack_length()); |
| 2667 | memcpy(to, ptr, length); |
| 2668 | } |
| 2669 | bool send_binary(Protocol *protocol); |
| 2670 | double val_real(void); |
| 2671 | my_decimal* val_decimal(my_decimal*); |
| 2672 | int set_time(); |
| 2673 | }; |
| 2674 | |
| 2675 | |
| 2676 | class Field_timestamp_hires :public Field_timestamp_with_dec { |
| 2677 | uint sec_part_bytes(uint dec) const |
| 2678 | { |
| 2679 | return Type_handler_timestamp::sec_part_bytes(dec); |
| 2680 | } |
| 2681 | public: |
| 2682 | Field_timestamp_hires(uchar *ptr_arg, |
| 2683 | uchar *null_ptr_arg, uchar null_bit_arg, |
| 2684 | enum utype unireg_check_arg, |
| 2685 | const LEX_CSTRING *field_name_arg, |
| 2686 | TABLE_SHARE *share, uint dec_arg) : |
| 2687 | Field_timestamp_with_dec(ptr_arg, null_ptr_arg, null_bit_arg, |
| 2688 | unireg_check_arg, field_name_arg, share, dec_arg) |
| 2689 | { |
| 2690 | DBUG_ASSERT(dec); |
| 2691 | } |
| 2692 | my_time_t get_timestamp(const uchar *pos, ulong *sec_part) const; |
| 2693 | void store_TIME(my_time_t timestamp, ulong sec_part); |
| 2694 | int cmp(const uchar *,const uchar *); |
| 2695 | uint32 pack_length() const { return 4 + sec_part_bytes(dec); } |
| 2696 | uint size_of() const { return sizeof(*this); } |
| 2697 | }; |
| 2698 | |
| 2699 | |
| 2700 | /** |
| 2701 | TIMESTAMP(0..6) - MySQL56 version |
| 2702 | */ |
| 2703 | class Field_timestampf :public Field_timestamp_with_dec { |
| 2704 | int save_field_metadata(uchar *metadata_ptr) |
| 2705 | { |
| 2706 | *metadata_ptr= (uchar) decimals(); |
| 2707 | return 1; |
| 2708 | } |
| 2709 | public: |
| 2710 | Field_timestampf(uchar *ptr_arg, |
| 2711 | uchar *null_ptr_arg, uchar null_bit_arg, |
| 2712 | enum utype unireg_check_arg, |
| 2713 | const LEX_CSTRING *field_name_arg, |
| 2714 | TABLE_SHARE *share, uint dec_arg) : |
| 2715 | Field_timestamp_with_dec(ptr_arg, null_ptr_arg, null_bit_arg, |
| 2716 | unireg_check_arg, field_name_arg, share, dec_arg) |
| 2717 | {} |
| 2718 | const Type_handler *type_handler() const { return &type_handler_timestamp2; } |
| 2719 | enum_field_types binlog_type() const { return MYSQL_TYPE_TIMESTAMP2; } |
| 2720 | uint32 pack_length() const |
| 2721 | { |
| 2722 | return my_timestamp_binary_length(dec); |
| 2723 | } |
| 2724 | uint row_pack_length() const { return pack_length(); } |
| 2725 | uint pack_length_from_metadata(uint field_metadata) |
| 2726 | { |
| 2727 | DBUG_ENTER("Field_timestampf::pack_length_from_metadata" ); |
| 2728 | uint tmp= my_timestamp_binary_length(field_metadata); |
| 2729 | DBUG_RETURN(tmp); |
| 2730 | } |
| 2731 | int cmp(const uchar *a_ptr,const uchar *b_ptr) |
| 2732 | { |
| 2733 | return memcmp(a_ptr, b_ptr, pack_length()); |
| 2734 | } |
| 2735 | void set_max(); |
| 2736 | bool is_max(); |
| 2737 | void store_TIME(my_time_t timestamp, ulong sec_part); |
| 2738 | my_time_t get_timestamp(const uchar *pos, ulong *sec_part) const; |
| 2739 | my_time_t get_timestamp(ulong *sec_part) const |
| 2740 | { |
| 2741 | return get_timestamp(ptr, sec_part); |
| 2742 | } |
| 2743 | uint size_of() const { return sizeof(*this); } |
| 2744 | }; |
| 2745 | |
| 2746 | |
| 2747 | class Field_year :public Field_tiny { |
| 2748 | public: |
| 2749 | Field_year(uchar *ptr_arg, uint32 len_arg, uchar *null_ptr_arg, |
| 2750 | uchar null_bit_arg, |
| 2751 | enum utype unireg_check_arg, const LEX_CSTRING *field_name_arg) |
| 2752 | :Field_tiny(ptr_arg, len_arg, null_ptr_arg, null_bit_arg, |
| 2753 | unireg_check_arg, field_name_arg, 1, 1) |
| 2754 | {} |
| 2755 | const Type_handler *type_handler() const { return &type_handler_year; } |
| 2756 | Copy_func *get_copy_func(const Field *from) const |
| 2757 | { |
| 2758 | if (eq_def(from)) |
| 2759 | return get_identical_copy_func(); |
| 2760 | switch (from->cmp_type()) { |
| 2761 | case STRING_RESULT: |
| 2762 | { |
| 2763 | const Type_handler *handler= from->type_handler(); |
| 2764 | if (handler == &type_handler_enum || handler == &type_handler_set) |
| 2765 | return do_field_int; |
| 2766 | return do_field_string; |
| 2767 | } |
| 2768 | case TIME_RESULT: |
| 2769 | return do_field_temporal; |
| 2770 | case DECIMAL_RESULT: |
| 2771 | return do_field_decimal; |
| 2772 | case REAL_RESULT: |
| 2773 | return do_field_real; |
| 2774 | case INT_RESULT: |
| 2775 | break; |
| 2776 | case ROW_RESULT: |
| 2777 | default: |
| 2778 | DBUG_ASSERT(0); |
| 2779 | break; |
| 2780 | } |
| 2781 | return do_field_int; |
| 2782 | } |
| 2783 | int store(const char *to,size_t length,CHARSET_INFO *charset); |
| 2784 | int store(double nr); |
| 2785 | int store(longlong nr, bool unsigned_val); |
| 2786 | int store_time_dec(const MYSQL_TIME *ltime, uint dec); |
| 2787 | double val_real(void); |
| 2788 | longlong val_int(void); |
| 2789 | String *val_str(String*,String *); |
| 2790 | bool get_date(MYSQL_TIME *ltime, ulonglong fuzzydate); |
| 2791 | bool send_binary(Protocol *protocol); |
| 2792 | Information_schema_numeric_attributes |
| 2793 | information_schema_numeric_attributes() const |
| 2794 | { |
| 2795 | return Information_schema_numeric_attributes(); |
| 2796 | } |
| 2797 | uint32 max_display_length() const { return field_length; } |
| 2798 | void sql_type(String &str) const; |
| 2799 | }; |
| 2800 | |
| 2801 | |
| 2802 | class Field_date :public Field_temporal_with_date { |
| 2803 | void store_TIME(MYSQL_TIME *ltime); |
| 2804 | bool get_TIME(MYSQL_TIME *ltime, const uchar *pos, ulonglong fuzzydate) const; |
| 2805 | public: |
| 2806 | Field_date(uchar *ptr_arg, uchar *null_ptr_arg, uchar null_bit_arg, |
| 2807 | enum utype unireg_check_arg, const LEX_CSTRING *field_name_arg) |
| 2808 | :Field_temporal_with_date(ptr_arg, MAX_DATE_WIDTH, null_ptr_arg, null_bit_arg, |
| 2809 | unireg_check_arg, field_name_arg) {} |
| 2810 | const Type_handler *type_handler() const { return &type_handler_date; } |
| 2811 | enum ha_base_keytype key_type() const { return HA_KEYTYPE_ULONG_INT; } |
| 2812 | int reset(void) { ptr[0]=ptr[1]=ptr[2]=ptr[3]=0; return 0; } |
| 2813 | bool get_date(MYSQL_TIME *ltime, ulonglong fuzzydate) |
| 2814 | { return Field_date::get_TIME(ltime, ptr, fuzzydate); } |
| 2815 | double val_real(void); |
| 2816 | longlong val_int(void); |
| 2817 | String *val_str(String*,String *); |
| 2818 | bool send_binary(Protocol *protocol); |
| 2819 | int cmp(const uchar *,const uchar *); |
| 2820 | void sort_string(uchar *buff,uint length); |
| 2821 | uint32 pack_length() const { return 4; } |
| 2822 | void sql_type(String &str) const; |
| 2823 | uchar *pack(uchar* to, const uchar *from, |
| 2824 | uint max_length __attribute__((unused))) |
| 2825 | { |
| 2826 | return pack_int32(to, from); |
| 2827 | } |
| 2828 | const uchar *unpack(uchar* to, const uchar *from, const uchar *from_end, |
| 2829 | uint param_data __attribute__((unused))) |
| 2830 | { |
| 2831 | return unpack_int32(to, from, from_end); |
| 2832 | } |
| 2833 | uint size_of() const { return sizeof(*this); } |
| 2834 | }; |
| 2835 | |
| 2836 | |
| 2837 | class Field_newdate :public Field_temporal_with_date { |
| 2838 | void store_TIME(MYSQL_TIME *ltime); |
| 2839 | bool get_TIME(MYSQL_TIME *ltime, const uchar *pos, ulonglong fuzzydate) const; |
| 2840 | public: |
| 2841 | Field_newdate(uchar *ptr_arg, uchar *null_ptr_arg, uchar null_bit_arg, |
| 2842 | enum utype unireg_check_arg, const LEX_CSTRING *field_name_arg) |
| 2843 | :Field_temporal_with_date(ptr_arg, MAX_DATE_WIDTH, null_ptr_arg, null_bit_arg, |
| 2844 | unireg_check_arg, field_name_arg) |
| 2845 | {} |
| 2846 | const Type_handler *type_handler() const { return &type_handler_newdate; } |
| 2847 | enum ha_base_keytype key_type() const { return HA_KEYTYPE_UINT24; } |
| 2848 | int reset(void) { ptr[0]=ptr[1]=ptr[2]=0; return 0; } |
| 2849 | double val_real(void); |
| 2850 | longlong val_int(void); |
| 2851 | String *val_str(String*,String *); |
| 2852 | bool send_binary(Protocol *protocol); |
| 2853 | int cmp(const uchar *,const uchar *); |
| 2854 | void sort_string(uchar *buff,uint length); |
| 2855 | uint32 pack_length() const { return 3; } |
| 2856 | void sql_type(String &str) const; |
| 2857 | bool get_date(MYSQL_TIME *ltime, ulonglong fuzzydate) |
| 2858 | { return Field_newdate::get_TIME(ltime, ptr, fuzzydate); } |
| 2859 | uint size_of() const { return sizeof(*this); } |
| 2860 | Item *get_equal_const_item(THD *thd, const Context &ctx, Item *const_item); |
| 2861 | }; |
| 2862 | |
| 2863 | |
| 2864 | class Field_time :public Field_temporal { |
| 2865 | /* |
| 2866 | when this Field_time instance is used for storing values for index lookups |
| 2867 | (see class store_key, Field::new_key_field(), etc), the following |
| 2868 | might be set to TO_DAYS(CURDATE()). See also Field_time::store_time_dec() |
| 2869 | */ |
| 2870 | long curdays; |
| 2871 | protected: |
| 2872 | virtual void store_TIME(const MYSQL_TIME *ltime); |
| 2873 | int store_TIME_with_warning(MYSQL_TIME *ltime, const ErrConv *str, |
| 2874 | int was_cut, int have_smth_to_conv); |
| 2875 | void set_warnings(Sql_condition::enum_warning_level level, |
| 2876 | const ErrConv *str, int was_cut) |
| 2877 | { |
| 2878 | Field_temporal::set_warnings(level, str, was_cut, MYSQL_TIMESTAMP_TIME); |
| 2879 | } |
| 2880 | bool check_zero_in_date_with_warn(ulonglong fuzzydate); |
| 2881 | static void do_field_time(Copy_field *copy); |
| 2882 | public: |
| 2883 | Field_time(uchar *ptr_arg, uint length_arg, uchar *null_ptr_arg, |
| 2884 | uchar null_bit_arg, enum utype unireg_check_arg, |
| 2885 | const LEX_CSTRING *field_name_arg) |
| 2886 | :Field_temporal(ptr_arg, length_arg, null_ptr_arg, null_bit_arg, |
| 2887 | unireg_check_arg, field_name_arg), curdays(0) |
| 2888 | {} |
| 2889 | bool can_be_substituted_to_equal_item(const Context &ctx, |
| 2890 | const Item_equal *item_equal); |
| 2891 | const Type_handler *type_handler() const { return &type_handler_time; } |
| 2892 | enum ha_base_keytype key_type() const { return HA_KEYTYPE_INT24; } |
| 2893 | Copy_func *get_copy_func(const Field *from) const |
| 2894 | { |
| 2895 | return from->cmp_type() == REAL_RESULT ? do_field_string : // MDEV-9344 |
| 2896 | from->type() == MYSQL_TYPE_YEAR ? do_field_int : |
| 2897 | from->type() == MYSQL_TYPE_BIT ? do_field_int : |
| 2898 | eq_def(from) ? get_identical_copy_func() : |
| 2899 | do_field_time; |
| 2900 | } |
| 2901 | bool memcpy_field_possible(const Field *from) const |
| 2902 | { |
| 2903 | return real_type() == from->real_type() && |
| 2904 | decimals() == from->decimals(); |
| 2905 | } |
| 2906 | int store_time_dec(const MYSQL_TIME *ltime, uint dec); |
| 2907 | int store(const char *to,size_t length,CHARSET_INFO *charset); |
| 2908 | int store(double nr); |
| 2909 | int store(longlong nr, bool unsigned_val); |
| 2910 | int store_decimal(const my_decimal *); |
| 2911 | double val_real(void); |
| 2912 | longlong val_int(void); |
| 2913 | String *val_str(String*,String *); |
| 2914 | bool get_date(MYSQL_TIME *ltime, ulonglong fuzzydate); |
| 2915 | bool send_binary(Protocol *protocol); |
| 2916 | int cmp(const uchar *,const uchar *); |
| 2917 | void sort_string(uchar *buff,uint length); |
| 2918 | uint32 pack_length() const { return 3; } |
| 2919 | void sql_type(String &str) const; |
| 2920 | uint size_of() const { return sizeof(*this); } |
| 2921 | void set_curdays(THD *thd); |
| 2922 | Field *new_key_field(MEM_ROOT *root, TABLE *new_table, |
| 2923 | uchar *new_ptr, uint32 length, |
| 2924 | uchar *new_null_ptr, uint new_null_bit); |
| 2925 | Item *get_equal_const_item(THD *thd, const Context &ctx, Item *const_item); |
| 2926 | }; |
| 2927 | |
| 2928 | |
| 2929 | /** |
| 2930 | Abstract class for: |
| 2931 | - TIME(1..6) |
| 2932 | - TIME(0..6) - MySQL56 version |
| 2933 | */ |
| 2934 | class Field_time_with_dec :public Field_time { |
| 2935 | protected: |
| 2936 | uint dec; |
| 2937 | public: |
| 2938 | Field_time_with_dec(uchar *ptr_arg, uchar *null_ptr_arg, uchar null_bit_arg, |
| 2939 | enum utype unireg_check_arg, |
| 2940 | const LEX_CSTRING *field_name_arg, |
| 2941 | uint dec_arg) |
| 2942 | :Field_time(ptr_arg, MIN_TIME_WIDTH + dec_arg + MY_TEST(dec_arg), |
| 2943 | null_ptr_arg, null_bit_arg, unireg_check_arg, field_name_arg), |
| 2944 | dec(dec_arg) |
| 2945 | { |
| 2946 | DBUG_ASSERT(dec <= TIME_SECOND_PART_DIGITS); |
| 2947 | } |
| 2948 | uint decimals() const { return dec; } |
| 2949 | enum ha_base_keytype key_type() const { return HA_KEYTYPE_BINARY; } |
| 2950 | longlong val_int(void); |
| 2951 | double val_real(void); |
| 2952 | void make_send_field(Send_field *); |
| 2953 | }; |
| 2954 | |
| 2955 | |
| 2956 | /** |
| 2957 | TIME(1..6) |
| 2958 | */ |
| 2959 | class Field_time_hires :public Field_time_with_dec { |
| 2960 | longlong zero_point; |
| 2961 | void store_TIME(const MYSQL_TIME *); |
| 2962 | public: |
| 2963 | Field_time_hires(uchar *ptr_arg, uchar *null_ptr_arg, uchar null_bit_arg, |
| 2964 | enum utype unireg_check_arg, const LEX_CSTRING *field_name_arg, |
| 2965 | uint dec_arg) |
| 2966 | :Field_time_with_dec(ptr_arg, null_ptr_arg, |
| 2967 | null_bit_arg, unireg_check_arg, field_name_arg, |
| 2968 | dec_arg) |
| 2969 | { |
| 2970 | DBUG_ASSERT(dec); |
| 2971 | zero_point= sec_part_shift( |
| 2972 | ((TIME_MAX_VALUE_SECONDS+1LL)*TIME_SECOND_PART_FACTOR), dec); |
| 2973 | } |
| 2974 | int reset(void); |
| 2975 | bool get_date(MYSQL_TIME *ltime, ulonglong fuzzydate); |
| 2976 | int cmp(const uchar *,const uchar *); |
| 2977 | void sort_string(uchar *buff,uint length); |
| 2978 | uint32 pack_length() const { return Type_handler_time::hires_bytes(dec); } |
| 2979 | uint size_of() const { return sizeof(*this); } |
| 2980 | }; |
| 2981 | |
| 2982 | |
| 2983 | /** |
| 2984 | TIME(0..6) - MySQL56 version |
| 2985 | */ |
| 2986 | class Field_timef :public Field_time_with_dec { |
| 2987 | void store_TIME(const MYSQL_TIME *ltime); |
| 2988 | int save_field_metadata(uchar *metadata_ptr) |
| 2989 | { |
| 2990 | *metadata_ptr= (uchar) decimals(); |
| 2991 | return 1; |
| 2992 | } |
| 2993 | public: |
| 2994 | Field_timef(uchar *ptr_arg, uchar *null_ptr_arg, uchar null_bit_arg, |
| 2995 | enum utype unireg_check_arg, const LEX_CSTRING *field_name_arg, |
| 2996 | uint dec_arg) |
| 2997 | :Field_time_with_dec(ptr_arg, null_ptr_arg, |
| 2998 | null_bit_arg, unireg_check_arg, field_name_arg, |
| 2999 | dec_arg) |
| 3000 | { |
| 3001 | DBUG_ASSERT(dec <= TIME_SECOND_PART_DIGITS); |
| 3002 | } |
| 3003 | const Type_handler *type_handler() const { return &type_handler_time2; } |
| 3004 | enum_field_types binlog_type() const { return MYSQL_TYPE_TIME2; } |
| 3005 | uint32 pack_length() const |
| 3006 | { |
| 3007 | return my_time_binary_length(dec); |
| 3008 | } |
| 3009 | uint row_pack_length() const { return pack_length(); } |
| 3010 | uint pack_length_from_metadata(uint field_metadata) |
| 3011 | { |
| 3012 | DBUG_ENTER("Field_timef::pack_length_from_metadata" ); |
| 3013 | uint tmp= my_time_binary_length(field_metadata); |
| 3014 | DBUG_RETURN(tmp); |
| 3015 | } |
| 3016 | void sort_string(uchar *to, uint length) |
| 3017 | { |
| 3018 | DBUG_ASSERT(length == Field_timef::pack_length()); |
| 3019 | memcpy(to, ptr, length); |
| 3020 | } |
| 3021 | int cmp(const uchar *a_ptr, const uchar *b_ptr) |
| 3022 | { |
| 3023 | return memcmp(a_ptr, b_ptr, pack_length()); |
| 3024 | } |
| 3025 | int reset(); |
| 3026 | bool get_date(MYSQL_TIME *ltime, ulonglong fuzzydate); |
| 3027 | uint size_of() const { return sizeof(*this); } |
| 3028 | }; |
| 3029 | |
| 3030 | |
| 3031 | class Field_datetime :public Field_temporal_with_date { |
| 3032 | void store_TIME(MYSQL_TIME *ltime); |
| 3033 | bool get_TIME(MYSQL_TIME *ltime, const uchar *pos, ulonglong fuzzydate) const; |
| 3034 | public: |
| 3035 | Field_datetime(uchar *ptr_arg, uint length_arg, uchar *null_ptr_arg, |
| 3036 | uchar null_bit_arg, enum utype unireg_check_arg, |
| 3037 | const LEX_CSTRING *field_name_arg) |
| 3038 | :Field_temporal_with_date(ptr_arg, length_arg, null_ptr_arg, null_bit_arg, |
| 3039 | unireg_check_arg, field_name_arg) |
| 3040 | { |
| 3041 | if (unireg_check == TIMESTAMP_UN_FIELD || |
| 3042 | unireg_check == TIMESTAMP_DNUN_FIELD) |
| 3043 | flags|= ON_UPDATE_NOW_FLAG; |
| 3044 | } |
| 3045 | const Type_handler *type_handler() const { return &type_handler_datetime; } |
| 3046 | enum ha_base_keytype key_type() const { return HA_KEYTYPE_ULONGLONG; } |
| 3047 | double val_real(void); |
| 3048 | longlong val_int(void); |
| 3049 | String *val_str(String*,String *); |
| 3050 | bool send_binary(Protocol *protocol); |
| 3051 | int cmp(const uchar *,const uchar *); |
| 3052 | void sort_string(uchar *buff,uint length); |
| 3053 | uint32 pack_length() const { return 8; } |
| 3054 | void sql_type(String &str) const; |
| 3055 | bool get_date(MYSQL_TIME *ltime, ulonglong fuzzydate) |
| 3056 | { return Field_datetime::get_TIME(ltime, ptr, fuzzydate); } |
| 3057 | int set_time(); |
| 3058 | int evaluate_update_default_function() |
| 3059 | { |
| 3060 | int res= 0; |
| 3061 | if (has_update_default_function()) |
| 3062 | res= set_time(); |
| 3063 | return res; |
| 3064 | } |
| 3065 | uchar *pack(uchar* to, const uchar *from, |
| 3066 | uint max_length __attribute__((unused))) |
| 3067 | { |
| 3068 | return pack_int64(to, from); |
| 3069 | } |
| 3070 | const uchar *unpack(uchar* to, const uchar *from, const uchar *from_end, |
| 3071 | uint param_data __attribute__((unused))) |
| 3072 | { |
| 3073 | return unpack_int64(to, from, from_end); |
| 3074 | } |
| 3075 | Item *get_equal_const_item(THD *thd, const Context &ctx, Item *const_item) |
| 3076 | { |
| 3077 | return get_equal_const_item_datetime(thd, ctx, const_item); |
| 3078 | } |
| 3079 | uint size_of() const { return sizeof(*this); } |
| 3080 | }; |
| 3081 | |
| 3082 | |
| 3083 | /** |
| 3084 | Abstract class for: |
| 3085 | - DATETIME(1..6) |
| 3086 | - DATETIME(0..6) - MySQL56 version |
| 3087 | */ |
| 3088 | class Field_datetime_with_dec :public Field_datetime { |
| 3089 | protected: |
| 3090 | uint dec; |
| 3091 | public: |
| 3092 | Field_datetime_with_dec(uchar *ptr_arg, uchar *null_ptr_arg, |
| 3093 | uchar null_bit_arg, enum utype unireg_check_arg, |
| 3094 | const LEX_CSTRING *field_name_arg, uint dec_arg) |
| 3095 | :Field_datetime(ptr_arg, MAX_DATETIME_WIDTH + dec_arg + MY_TEST(dec_arg), |
| 3096 | null_ptr_arg, null_bit_arg, unireg_check_arg, |
| 3097 | field_name_arg), dec(dec_arg) |
| 3098 | { |
| 3099 | DBUG_ASSERT(dec <= TIME_SECOND_PART_DIGITS); |
| 3100 | } |
| 3101 | uint decimals() const { return dec; } |
| 3102 | enum ha_base_keytype key_type() const { return HA_KEYTYPE_BINARY; } |
| 3103 | void make_send_field(Send_field *field); |
| 3104 | bool send_binary(Protocol *protocol); |
| 3105 | uchar *pack(uchar *to, const uchar *from, uint max_length) |
| 3106 | { return Field::pack(to, from, max_length); } |
| 3107 | const uchar *unpack(uchar* to, const uchar *from, const uchar *from_end, |
| 3108 | uint param_data) |
| 3109 | { return Field::unpack(to, from, from_end, param_data); } |
| 3110 | void sort_string(uchar *to, uint length) |
| 3111 | { |
| 3112 | DBUG_ASSERT(length == pack_length()); |
| 3113 | memcpy(to, ptr, length); |
| 3114 | } |
| 3115 | double val_real(void); |
| 3116 | longlong val_int(void); |
| 3117 | String *val_str(String*,String *); |
| 3118 | }; |
| 3119 | |
| 3120 | |
| 3121 | /** |
| 3122 | DATETIME(1..6) |
| 3123 | */ |
| 3124 | class Field_datetime_hires :public Field_datetime_with_dec { |
| 3125 | void store_TIME(MYSQL_TIME *ltime); |
| 3126 | bool get_TIME(MYSQL_TIME *ltime, const uchar *pos, ulonglong fuzzydate) const; |
| 3127 | public: |
| 3128 | Field_datetime_hires(uchar *ptr_arg, uchar *null_ptr_arg, |
| 3129 | uchar null_bit_arg, enum utype unireg_check_arg, |
| 3130 | const LEX_CSTRING *field_name_arg, uint dec_arg) |
| 3131 | :Field_datetime_with_dec(ptr_arg, null_ptr_arg, null_bit_arg, |
| 3132 | unireg_check_arg, field_name_arg, dec_arg) |
| 3133 | { |
| 3134 | DBUG_ASSERT(dec); |
| 3135 | } |
| 3136 | int cmp(const uchar *,const uchar *); |
| 3137 | uint32 pack_length() const { return Type_handler_datetime::hires_bytes(dec); } |
| 3138 | bool get_date(MYSQL_TIME *ltime, ulonglong fuzzydate) |
| 3139 | { return Field_datetime_hires::get_TIME(ltime, ptr, fuzzydate); } |
| 3140 | uint size_of() const { return sizeof(*this); } |
| 3141 | }; |
| 3142 | |
| 3143 | |
| 3144 | /** |
| 3145 | DATETIME(0..6) - MySQL56 version |
| 3146 | */ |
| 3147 | class Field_datetimef :public Field_datetime_with_dec { |
| 3148 | void store_TIME(MYSQL_TIME *ltime); |
| 3149 | bool get_TIME(MYSQL_TIME *ltime, const uchar *pos, ulonglong fuzzydate) const; |
| 3150 | int save_field_metadata(uchar *metadata_ptr) |
| 3151 | { |
| 3152 | *metadata_ptr= (uchar) decimals(); |
| 3153 | return 1; |
| 3154 | } |
| 3155 | public: |
| 3156 | Field_datetimef(uchar *ptr_arg, uchar *null_ptr_arg, |
| 3157 | uchar null_bit_arg, enum utype unireg_check_arg, |
| 3158 | const LEX_CSTRING *field_name_arg, uint dec_arg) |
| 3159 | :Field_datetime_with_dec(ptr_arg, null_ptr_arg, null_bit_arg, |
| 3160 | unireg_check_arg, field_name_arg, dec_arg) |
| 3161 | {} |
| 3162 | const Type_handler *type_handler() const { return &type_handler_datetime2; } |
| 3163 | enum_field_types binlog_type() const { return MYSQL_TYPE_DATETIME2; } |
| 3164 | uint32 pack_length() const |
| 3165 | { |
| 3166 | return my_datetime_binary_length(dec); |
| 3167 | } |
| 3168 | uint row_pack_length() const { return pack_length(); } |
| 3169 | uint pack_length_from_metadata(uint field_metadata) |
| 3170 | { |
| 3171 | DBUG_ENTER("Field_datetimef::pack_length_from_metadata" ); |
| 3172 | uint tmp= my_datetime_binary_length(field_metadata); |
| 3173 | DBUG_RETURN(tmp); |
| 3174 | } |
| 3175 | int cmp(const uchar *a_ptr, const uchar *b_ptr) |
| 3176 | { |
| 3177 | return memcmp(a_ptr, b_ptr, pack_length()); |
| 3178 | } |
| 3179 | int reset(); |
| 3180 | bool get_date(MYSQL_TIME *ltime, ulonglong fuzzydate) |
| 3181 | { return Field_datetimef::get_TIME(ltime, ptr, fuzzydate); } |
| 3182 | uint size_of() const { return sizeof(*this); } |
| 3183 | }; |
| 3184 | |
| 3185 | |
| 3186 | static inline Field_timestamp * |
| 3187 | new_Field_timestamp(MEM_ROOT *root,uchar *ptr, uchar *null_ptr, uchar null_bit, |
| 3188 | enum Field::utype unireg_check, |
| 3189 | const LEX_CSTRING *field_name, |
| 3190 | TABLE_SHARE *share, uint dec) |
| 3191 | { |
| 3192 | if (dec==0) |
| 3193 | return new (root) |
| 3194 | Field_timestamp(ptr, MAX_DATETIME_WIDTH, null_ptr, |
| 3195 | null_bit, unireg_check, field_name, share); |
| 3196 | if (dec >= FLOATING_POINT_DECIMALS) |
| 3197 | dec= MAX_DATETIME_PRECISION; |
| 3198 | return new (root) |
| 3199 | Field_timestamp_hires(ptr, null_ptr, null_bit, unireg_check, |
| 3200 | field_name, share, dec); |
| 3201 | } |
| 3202 | |
| 3203 | static inline Field_time * |
| 3204 | new_Field_time(MEM_ROOT *root, uchar *ptr, uchar *null_ptr, uchar null_bit, |
| 3205 | enum Field::utype unireg_check, const LEX_CSTRING *field_name, |
| 3206 | uint dec) |
| 3207 | { |
| 3208 | if (dec == 0) |
| 3209 | return new (root) |
| 3210 | Field_time(ptr, MIN_TIME_WIDTH, null_ptr, null_bit, unireg_check, |
| 3211 | field_name); |
| 3212 | if (dec >= FLOATING_POINT_DECIMALS) |
| 3213 | dec= MAX_DATETIME_PRECISION; |
| 3214 | return new (root) |
| 3215 | Field_time_hires(ptr, null_ptr, null_bit, unireg_check, field_name, dec); |
| 3216 | } |
| 3217 | |
| 3218 | static inline Field_datetime * |
| 3219 | new_Field_datetime(MEM_ROOT *root, uchar *ptr, uchar *null_ptr, uchar null_bit, |
| 3220 | enum Field::utype unireg_check, |
| 3221 | const LEX_CSTRING *field_name, uint dec) |
| 3222 | { |
| 3223 | if (dec == 0) |
| 3224 | return new (root) |
| 3225 | Field_datetime(ptr, MAX_DATETIME_WIDTH, null_ptr, null_bit, |
| 3226 | unireg_check, field_name); |
| 3227 | if (dec >= FLOATING_POINT_DECIMALS) |
| 3228 | dec= MAX_DATETIME_PRECISION; |
| 3229 | return new (root) |
| 3230 | Field_datetime_hires(ptr, null_ptr, null_bit, |
| 3231 | unireg_check, field_name, dec); |
| 3232 | } |
| 3233 | |
| 3234 | class Field_string :public Field_longstr { |
| 3235 | class Warn_filter_string: public Warn_filter |
| 3236 | { |
| 3237 | public: |
| 3238 | Warn_filter_string(const THD *thd, const Field_string *field); |
| 3239 | }; |
| 3240 | bool is_var_string() const |
| 3241 | { |
| 3242 | return can_alter_field_type && |
| 3243 | orig_table && |
| 3244 | (orig_table->s->db_create_options & HA_OPTION_PACK_RECORD) && |
| 3245 | field_length >= 4 && |
| 3246 | orig_table->s->frm_version < FRM_VER_TRUE_VARCHAR; |
| 3247 | } |
| 3248 | public: |
| 3249 | bool can_alter_field_type; |
| 3250 | Field_string(uchar *ptr_arg, uint32 len_arg,uchar *null_ptr_arg, |
| 3251 | uchar null_bit_arg, |
| 3252 | enum utype unireg_check_arg, const LEX_CSTRING *field_name_arg, |
| 3253 | const DTCollation &collation) |
| 3254 | :Field_longstr(ptr_arg, len_arg, null_ptr_arg, null_bit_arg, |
| 3255 | unireg_check_arg, field_name_arg, collation), |
| 3256 | can_alter_field_type(1) {}; |
| 3257 | Field_string(uint32 len_arg,bool maybe_null_arg, |
| 3258 | const LEX_CSTRING *field_name_arg, |
| 3259 | const DTCollation &collation) |
| 3260 | :Field_longstr((uchar*) 0, len_arg, maybe_null_arg ? (uchar*) "" : 0, 0, |
| 3261 | NONE, field_name_arg, collation), |
| 3262 | can_alter_field_type(1) {}; |
| 3263 | |
| 3264 | const Type_handler *type_handler() const |
| 3265 | { |
| 3266 | if (is_var_string()) |
| 3267 | return &type_handler_var_string; |
| 3268 | return &type_handler_string; |
| 3269 | } |
| 3270 | enum ha_base_keytype key_type() const |
| 3271 | { return binary() ? HA_KEYTYPE_BINARY : HA_KEYTYPE_TEXT; } |
| 3272 | bool zero_pack() const { return 0; } |
| 3273 | Copy_func *get_copy_func(const Field *from) const; |
| 3274 | int reset(void) |
| 3275 | { |
| 3276 | charset()->cset->fill(charset(),(char*) ptr, field_length, |
| 3277 | (has_charset() ? ' ' : 0)); |
| 3278 | return 0; |
| 3279 | } |
| 3280 | int store(const char *to,size_t length,CHARSET_INFO *charset); |
| 3281 | using Field_str::store; |
| 3282 | double val_real(void); |
| 3283 | longlong val_int(void); |
| 3284 | String *val_str(String*,String *); |
| 3285 | my_decimal *val_decimal(my_decimal *); |
| 3286 | int cmp(const uchar *,const uchar *); |
| 3287 | void sort_string(uchar *buff,uint length); |
| 3288 | void sql_type(String &str) const; |
| 3289 | virtual uchar *pack(uchar *to, const uchar *from, |
| 3290 | uint max_length); |
| 3291 | virtual const uchar *unpack(uchar* to, const uchar *from, |
| 3292 | const uchar *from_end,uint param_data); |
| 3293 | uint pack_length_from_metadata(uint field_metadata) |
| 3294 | { |
| 3295 | DBUG_PRINT("debug" , ("field_metadata: 0x%04x" , field_metadata)); |
| 3296 | if (field_metadata == 0) |
| 3297 | return row_pack_length(); |
| 3298 | return (((field_metadata >> 4) & 0x300) ^ 0x300) + (field_metadata & 0x00ff); |
| 3299 | } |
| 3300 | bool compatible_field_size(uint field_metadata, Relay_log_info *rli, |
| 3301 | uint16 mflags, int *order_var); |
| 3302 | uint row_pack_length() const { return field_length; } |
| 3303 | int pack_cmp(const uchar *a,const uchar *b,uint key_length, |
| 3304 | bool insert_or_update); |
| 3305 | int pack_cmp(const uchar *b,uint key_length,bool insert_or_update); |
| 3306 | uint packed_col_length(const uchar *to, uint length); |
| 3307 | uint max_packed_col_length(uint max_length); |
| 3308 | uint size_of() const { return sizeof(*this); } |
| 3309 | bool has_charset(void) const |
| 3310 | { return charset() == &my_charset_bin ? FALSE : TRUE; } |
| 3311 | Field *make_new_field(MEM_ROOT *root, TABLE *new_table, bool keep_type); |
| 3312 | virtual uint get_key_image(uchar *buff,uint length, imagetype type); |
| 3313 | private: |
| 3314 | int save_field_metadata(uchar *first_byte); |
| 3315 | }; |
| 3316 | |
| 3317 | |
| 3318 | class Field_varstring :public Field_longstr { |
| 3319 | public: |
| 3320 | uchar *get_data() const |
| 3321 | { |
| 3322 | return ptr + length_bytes; |
| 3323 | } |
| 3324 | uint get_length() const |
| 3325 | { |
| 3326 | return length_bytes == 1 ? (uint) *ptr : uint2korr(ptr); |
| 3327 | } |
| 3328 | protected: |
| 3329 | void store_length(uint32 number) |
| 3330 | { |
| 3331 | if (length_bytes == 1) |
| 3332 | *ptr= (uchar) number; |
| 3333 | else |
| 3334 | int2store(ptr, number); |
| 3335 | } |
| 3336 | public: |
| 3337 | /* |
| 3338 | The maximum space available in a Field_varstring, in bytes. See |
| 3339 | length_bytes. |
| 3340 | */ |
| 3341 | static const uint MAX_SIZE; |
| 3342 | /* Store number of bytes used to store length (1 or 2) */ |
| 3343 | uint32 length_bytes; |
| 3344 | Field_varstring(uchar *ptr_arg, |
| 3345 | uint32 len_arg, uint length_bytes_arg, |
| 3346 | uchar *null_ptr_arg, uchar null_bit_arg, |
| 3347 | enum utype unireg_check_arg, const LEX_CSTRING *field_name_arg, |
| 3348 | TABLE_SHARE *share, const DTCollation &collation) |
| 3349 | :Field_longstr(ptr_arg, len_arg, null_ptr_arg, null_bit_arg, |
| 3350 | unireg_check_arg, field_name_arg, collation), |
| 3351 | length_bytes(length_bytes_arg) |
| 3352 | { |
| 3353 | share->varchar_fields++; |
| 3354 | } |
| 3355 | Field_varstring(uint32 len_arg,bool maybe_null_arg, |
| 3356 | const LEX_CSTRING *field_name_arg, |
| 3357 | TABLE_SHARE *share, const DTCollation &collation) |
| 3358 | :Field_longstr((uchar*) 0,len_arg, maybe_null_arg ? (uchar*) "" : 0, 0, |
| 3359 | NONE, field_name_arg, collation), |
| 3360 | length_bytes(len_arg < 256 ? 1 :2) |
| 3361 | { |
| 3362 | share->varchar_fields++; |
| 3363 | } |
| 3364 | |
| 3365 | const Type_handler *type_handler() const { return &type_handler_varchar; } |
| 3366 | enum ha_base_keytype key_type() const; |
| 3367 | uint row_pack_length() const { return field_length; } |
| 3368 | bool zero_pack() const { return 0; } |
| 3369 | int reset(void) { bzero(ptr,field_length+length_bytes); return 0; } |
| 3370 | uint32 pack_length() const { return (uint32) field_length+length_bytes; } |
| 3371 | uint32 key_length() const { return (uint32) field_length; } |
| 3372 | uint32 sort_length() const |
| 3373 | { |
| 3374 | return (uint32) field_length + (field_charset == &my_charset_bin ? |
| 3375 | length_bytes : 0); |
| 3376 | } |
| 3377 | Copy_func *get_copy_func(const Field *from) const; |
| 3378 | bool memcpy_field_possible(const Field *from) const |
| 3379 | { |
| 3380 | return Field_str::memcpy_field_possible(from) && |
| 3381 | !compression_method() == !from->compression_method() && |
| 3382 | length_bytes == ((Field_varstring*) from)->length_bytes; |
| 3383 | } |
| 3384 | int store(const char *to,size_t length,CHARSET_INFO *charset); |
| 3385 | using Field_str::store; |
| 3386 | double val_real(void); |
| 3387 | longlong val_int(void); |
| 3388 | String *val_str(String*,String *); |
| 3389 | my_decimal *val_decimal(my_decimal *); |
| 3390 | int cmp_max(const uchar *, const uchar *, uint max_length); |
| 3391 | int cmp(const uchar *a,const uchar *b) |
| 3392 | { |
| 3393 | return cmp_max(a, b, ~0U); |
| 3394 | } |
| 3395 | void sort_string(uchar *buff,uint length); |
| 3396 | uint get_key_image(uchar *buff,uint length, imagetype type); |
| 3397 | void set_key_image(const uchar *buff,uint length); |
| 3398 | void sql_type(String &str) const; |
| 3399 | virtual uchar *pack(uchar *to, const uchar *from, uint max_length); |
| 3400 | virtual const uchar *unpack(uchar* to, const uchar *from, |
| 3401 | const uchar *from_end, uint param_data); |
| 3402 | int cmp_binary(const uchar *a,const uchar *b, uint32 max_length=~0U); |
| 3403 | int key_cmp(const uchar *,const uchar*); |
| 3404 | int key_cmp(const uchar *str, uint length); |
| 3405 | uint packed_col_length(const uchar *to, uint length); |
| 3406 | uint max_packed_col_length(uint max_length); |
| 3407 | uint32 data_length(); |
| 3408 | uint size_of() const { return sizeof(*this); } |
| 3409 | bool has_charset(void) const |
| 3410 | { return charset() == &my_charset_bin ? FALSE : TRUE; } |
| 3411 | Field *make_new_field(MEM_ROOT *root, TABLE *new_table, bool keep_type); |
| 3412 | Field *new_key_field(MEM_ROOT *root, TABLE *new_table, |
| 3413 | uchar *new_ptr, uint32 length, |
| 3414 | uchar *new_null_ptr, uint new_null_bit); |
| 3415 | uint is_equal(Create_field *new_field); |
| 3416 | void hash(ulong *nr, ulong *nr2); |
| 3417 | uint length_size() { return length_bytes; } |
| 3418 | private: |
| 3419 | int save_field_metadata(uchar *first_byte); |
| 3420 | }; |
| 3421 | |
| 3422 | |
| 3423 | class Field_varstring_compressed: public Field_varstring { |
| 3424 | public: |
| 3425 | Field_varstring_compressed(uchar *ptr_arg, |
| 3426 | uint32 len_arg, uint length_bytes_arg, |
| 3427 | uchar *null_ptr_arg, uchar null_bit_arg, |
| 3428 | enum utype unireg_check_arg, |
| 3429 | const LEX_CSTRING *field_name_arg, |
| 3430 | TABLE_SHARE *share, const DTCollation &collation, |
| 3431 | Compression_method *compression_method_arg): |
| 3432 | Field_varstring(ptr_arg, len_arg, length_bytes_arg, null_ptr_arg, |
| 3433 | null_bit_arg, unireg_check_arg, field_name_arg, |
| 3434 | share, collation), |
| 3435 | compression_method_ptr(compression_method_arg) { DBUG_ASSERT(len_arg > 0); } |
| 3436 | Compression_method *compression_method() const |
| 3437 | { return compression_method_ptr; } |
| 3438 | private: |
| 3439 | Compression_method *compression_method_ptr; |
| 3440 | int store(const char *to, size_t length, CHARSET_INFO *charset); |
| 3441 | using Field_str::store; |
| 3442 | String *val_str(String *, String *); |
| 3443 | double val_real(void); |
| 3444 | longlong val_int(void); |
| 3445 | uint size_of() const { return sizeof(*this); } |
| 3446 | enum_field_types binlog_type() const { return MYSQL_TYPE_VARCHAR_COMPRESSED; } |
| 3447 | void sql_type(String &str) const |
| 3448 | { |
| 3449 | Field_varstring::sql_type(str); |
| 3450 | str.append(STRING_WITH_LEN(" /*!100301 COMPRESSED*/" )); |
| 3451 | } |
| 3452 | uint32 max_display_length() const { return field_length - 1; } |
| 3453 | uint32 char_length() const |
| 3454 | { |
| 3455 | return (field_length - 1) / field_charset->mbmaxlen; |
| 3456 | } |
| 3457 | int cmp_max(const uchar *a_ptr, const uchar *b_ptr, uint max_len); |
| 3458 | |
| 3459 | /* |
| 3460 | Compressed fields can't have keys as two rows may have different |
| 3461 | compression methods or compression levels. |
| 3462 | */ |
| 3463 | |
| 3464 | int key_cmp(const uchar *str, uint length) |
| 3465 | { DBUG_ASSERT(0); return 0; } |
| 3466 | using Field_varstring::key_cmp; |
| 3467 | }; |
| 3468 | |
| 3469 | |
| 3470 | static inline uint8 number_storage_requirement(uint32 n) |
| 3471 | { |
| 3472 | return n < 256 ? 1 : n < 65536 ? 2 : n < 16777216 ? 3 : 4; |
| 3473 | } |
| 3474 | |
| 3475 | |
| 3476 | static inline void store_bigendian(ulonglong num, uchar *to, uint bytes) |
| 3477 | { |
| 3478 | switch(bytes) { |
| 3479 | case 1: mi_int1store(to, num); break; |
| 3480 | case 2: mi_int2store(to, num); break; |
| 3481 | case 3: mi_int3store(to, num); break; |
| 3482 | case 4: mi_int4store(to, num); break; |
| 3483 | case 5: mi_int5store(to, num); break; |
| 3484 | case 6: mi_int6store(to, num); break; |
| 3485 | case 7: mi_int7store(to, num); break; |
| 3486 | case 8: mi_int8store(to, num); break; |
| 3487 | default: DBUG_ASSERT(0); |
| 3488 | } |
| 3489 | } |
| 3490 | |
| 3491 | |
| 3492 | static inline longlong read_bigendian(const uchar *from, uint bytes) |
| 3493 | { |
| 3494 | switch(bytes) { |
| 3495 | case 1: return mi_uint1korr(from); |
| 3496 | case 2: return mi_uint2korr(from); |
| 3497 | case 3: return mi_uint3korr(from); |
| 3498 | case 4: return mi_uint4korr(from); |
| 3499 | case 5: return mi_uint5korr(from); |
| 3500 | case 6: return mi_uint6korr(from); |
| 3501 | case 7: return mi_uint7korr(from); |
| 3502 | case 8: return mi_sint8korr(from); |
| 3503 | default: DBUG_ASSERT(0); return 0; |
| 3504 | } |
| 3505 | } |
| 3506 | |
| 3507 | |
| 3508 | extern LEX_CSTRING temp_lex_str; |
| 3509 | |
| 3510 | class Field_blob :public Field_longstr { |
| 3511 | protected: |
| 3512 | /** |
| 3513 | The number of bytes used to represent the length of the blob. |
| 3514 | */ |
| 3515 | uint packlength; |
| 3516 | |
| 3517 | /** |
| 3518 | The 'value'-object is a cache fronting the storage engine. |
| 3519 | */ |
| 3520 | String value; |
| 3521 | /** |
| 3522 | Cache for blob values when reading a row with a virtual blob |
| 3523 | field. This is needed to not destroy the old cached value when |
| 3524 | updating the blob with a new value when creating the new row. |
| 3525 | */ |
| 3526 | String read_value; |
| 3527 | |
| 3528 | static void do_copy_blob(Copy_field *copy); |
| 3529 | static void do_conv_blob(Copy_field *copy); |
| 3530 | public: |
| 3531 | Field_blob(uchar *ptr_arg, uchar *null_ptr_arg, uchar null_bit_arg, |
| 3532 | enum utype unireg_check_arg, const LEX_CSTRING *field_name_arg, |
| 3533 | TABLE_SHARE *share, uint blob_pack_length, |
| 3534 | const DTCollation &collation); |
| 3535 | Field_blob(uint32 len_arg,bool maybe_null_arg, const LEX_CSTRING *field_name_arg, |
| 3536 | const DTCollation &collation) |
| 3537 | :Field_longstr((uchar*) 0, len_arg, maybe_null_arg ? (uchar*) "" : 0, 0, |
| 3538 | NONE, field_name_arg, collation), |
| 3539 | packlength(4) |
| 3540 | { |
| 3541 | flags|= BLOB_FLAG; |
| 3542 | } |
| 3543 | Field_blob(uint32 len_arg,bool maybe_null_arg, |
| 3544 | const LEX_CSTRING *field_name_arg, |
| 3545 | const DTCollation &collation, bool set_packlength) |
| 3546 | :Field_longstr((uchar*) 0,len_arg, maybe_null_arg ? (uchar*) "" : 0, 0, |
| 3547 | NONE, field_name_arg, collation) |
| 3548 | { |
| 3549 | flags|= BLOB_FLAG; |
| 3550 | packlength= set_packlength ? number_storage_requirement(len_arg) : 4; |
| 3551 | } |
| 3552 | Field_blob(uint32 packlength_arg) |
| 3553 | :Field_longstr((uchar*) 0, 0, (uchar*) "" , 0, NONE, &temp_lex_str, |
| 3554 | system_charset_info), |
| 3555 | packlength(packlength_arg) {} |
| 3556 | const Type_handler *type_handler() const; |
| 3557 | /* Note that the default copy constructor is used, in clone() */ |
| 3558 | enum_field_types type() const |
| 3559 | { |
| 3560 | /* |
| 3561 | We cannot return type_handler()->field_type() here. |
| 3562 | Some pieces of the code (e.g. in engines) rely on the fact |
| 3563 | that Field::type(), Field::real_type() and Item_field::field_type() |
| 3564 | return MYSQL_TYPE_BLOB for all blob variants. |
| 3565 | We should eventually fix all such code pieces to expect |
| 3566 | all BLOB type codes. |
| 3567 | */ |
| 3568 | return MYSQL_TYPE_BLOB; |
| 3569 | } |
| 3570 | enum_field_types real_type() const |
| 3571 | { |
| 3572 | return MYSQL_TYPE_BLOB; |
| 3573 | } |
| 3574 | enum ha_base_keytype key_type() const |
| 3575 | { return binary() ? HA_KEYTYPE_VARBINARY2 : HA_KEYTYPE_VARTEXT2; } |
| 3576 | Type_std_attributes type_std_attributes() const |
| 3577 | { |
| 3578 | return Type_std_attributes(Field_blob::max_display_length(), decimals(), |
| 3579 | MY_TEST(flags & UNSIGNED_FLAG), |
| 3580 | dtcollation()); |
| 3581 | } |
| 3582 | Information_schema_character_attributes |
| 3583 | information_schema_character_attributes() const |
| 3584 | { |
| 3585 | uint32 octets= Field_blob::octet_length(); |
| 3586 | uint32 chars= octets / field_charset->mbminlen; |
| 3587 | return Information_schema_character_attributes(octets, chars); |
| 3588 | } |
| 3589 | Copy_func *get_copy_func(const Field *from) const |
| 3590 | { |
| 3591 | /* |
| 3592 | TODO: MDEV-9331 |
| 3593 | if (from->type() == MYSQL_TYPE_BIT) |
| 3594 | return do_field_int; |
| 3595 | */ |
| 3596 | if (!(from->flags & BLOB_FLAG) || from->charset() != charset() || |
| 3597 | !from->compression_method() != !compression_method()) |
| 3598 | return do_conv_blob; |
| 3599 | if (from->pack_length() != Field_blob::pack_length()) |
| 3600 | return do_copy_blob; |
| 3601 | return get_identical_copy_func(); |
| 3602 | } |
| 3603 | int store_field(Field *from) |
| 3604 | { // Be sure the value is stored |
| 3605 | from->val_str(&value); |
| 3606 | if (table->copy_blobs || |
| 3607 | (!value.is_alloced() && from->is_varchar_and_in_write_set())) |
| 3608 | value.copy(); |
| 3609 | return store(value.ptr(), value.length(), from->charset()); |
| 3610 | } |
| 3611 | bool memcpy_field_possible(const Field *from) const |
| 3612 | { |
| 3613 | return Field_str::memcpy_field_possible(from) && |
| 3614 | !compression_method() == !from->compression_method() && |
| 3615 | !table->copy_blobs; |
| 3616 | } |
| 3617 | int store(const char *to, size_t length, CHARSET_INFO *charset); |
| 3618 | using Field_str::store; |
| 3619 | double val_real(void); |
| 3620 | longlong val_int(void); |
| 3621 | String *val_str(String*,String *); |
| 3622 | my_decimal *val_decimal(my_decimal *); |
| 3623 | int cmp_max(const uchar *, const uchar *, uint max_length); |
| 3624 | int cmp(const uchar *a,const uchar *b) |
| 3625 | { return cmp_max(a, b, ~0U); } |
| 3626 | int cmp(const uchar *a, uint32 a_length, const uchar *b, uint32 b_length); |
| 3627 | int cmp_binary(const uchar *a,const uchar *b, uint32 max_length=~0U); |
| 3628 | int key_cmp(const uchar *,const uchar*); |
| 3629 | int key_cmp(const uchar *str, uint length); |
| 3630 | /* Never update the value of min_val for a blob field */ |
| 3631 | bool update_min(Field *min_val, bool force_update) { return FALSE; } |
| 3632 | /* Never update the value of max_val for a blob field */ |
| 3633 | bool update_max(Field *max_val, bool force_update) { return FALSE; } |
| 3634 | uint32 key_length() const { return 0; } |
| 3635 | void sort_string(uchar *buff,uint length); |
| 3636 | uint32 pack_length() const |
| 3637 | { return (uint32) (packlength + portable_sizeof_char_ptr); } |
| 3638 | |
| 3639 | /** |
| 3640 | Return the packed length without the pointer size added. |
| 3641 | |
| 3642 | This is used to determine the size of the actual data in the row |
| 3643 | buffer. |
| 3644 | |
| 3645 | @returns The length of the raw data itself without the pointer. |
| 3646 | */ |
| 3647 | uint32 pack_length_no_ptr() const |
| 3648 | { return (uint32) (packlength); } |
| 3649 | uint row_pack_length() const { return pack_length_no_ptr(); } |
| 3650 | uint32 sort_length() const; |
| 3651 | uint32 value_length() { return get_length(); } |
| 3652 | virtual uint32 max_data_length() const |
| 3653 | { |
| 3654 | return (uint32) (((ulonglong) 1 << (packlength*8)) -1); |
| 3655 | } |
| 3656 | int reset(void) { bzero(ptr, packlength+sizeof(uchar*)); return 0; } |
| 3657 | void reset_fields() { bzero((uchar*) &value,sizeof(value)); bzero((uchar*) &read_value,sizeof(read_value)); } |
| 3658 | uint32 get_field_buffer_size(void) { return value.alloced_length(); } |
| 3659 | void store_length(uchar *i_ptr, uint i_packlength, uint32 i_number); |
| 3660 | inline void store_length(size_t number) |
| 3661 | { |
| 3662 | DBUG_ASSERT(number < UINT_MAX32); |
| 3663 | store_length(ptr, packlength, (uint32)number); |
| 3664 | } |
| 3665 | inline uint32 get_length(uint row_offset= 0) const |
| 3666 | { return get_length(ptr+row_offset, this->packlength); } |
| 3667 | uint32 get_length(const uchar *ptr, uint packlength) const; |
| 3668 | uint32 get_length(const uchar *ptr_arg) const |
| 3669 | { return get_length(ptr_arg, this->packlength); } |
| 3670 | inline uchar *get_ptr() const { return get_ptr(0); } |
| 3671 | inline uchar *get_ptr(my_ptrdiff_t row_offset) const |
| 3672 | { |
| 3673 | uchar *s; |
| 3674 | memcpy(&s, ptr + packlength + row_offset, sizeof(uchar*)); |
| 3675 | return s; |
| 3676 | } |
| 3677 | inline void set_ptr(uchar *length, uchar *data) |
| 3678 | { |
| 3679 | memcpy(ptr,length,packlength); |
| 3680 | memcpy(ptr+packlength, &data,sizeof(char*)); |
| 3681 | } |
| 3682 | void set_ptr_offset(my_ptrdiff_t ptr_diff, uint32 length, const uchar *data) |
| 3683 | { |
| 3684 | uchar *ptr_ofs= ADD_TO_PTR(ptr,ptr_diff,uchar*); |
| 3685 | store_length(ptr_ofs, packlength, length); |
| 3686 | memcpy(ptr_ofs+packlength, &data, sizeof(char*)); |
| 3687 | } |
| 3688 | inline void set_ptr(uint32 length, uchar *data) |
| 3689 | { |
| 3690 | set_ptr_offset(0, length, data); |
| 3691 | } |
| 3692 | int copy_value(Field_blob *from); |
| 3693 | uint get_key_image(uchar *buff,uint length, imagetype type); |
| 3694 | void set_key_image(const uchar *buff,uint length); |
| 3695 | Field *new_key_field(MEM_ROOT *root, TABLE *new_table, |
| 3696 | uchar *new_ptr, uint32 length, |
| 3697 | uchar *new_null_ptr, uint new_null_bit); |
| 3698 | void sql_type(String &str) const; |
| 3699 | inline bool copy() |
| 3700 | { |
| 3701 | uchar *tmp= get_ptr(); |
| 3702 | if (value.copy((char*) tmp, get_length(), charset())) |
| 3703 | { |
| 3704 | Field_blob::reset(); |
| 3705 | return 1; |
| 3706 | } |
| 3707 | tmp=(uchar*) value.ptr(); |
| 3708 | memcpy(ptr+packlength, &tmp, sizeof(char*)); |
| 3709 | return 0; |
| 3710 | } |
| 3711 | /* store value for the duration of the current read record */ |
| 3712 | inline void swap_value_and_read_value() |
| 3713 | { |
| 3714 | read_value.swap(value); |
| 3715 | } |
| 3716 | inline void set_value(uchar *data) |
| 3717 | { |
| 3718 | /* Set value pointer. Lengths are not important */ |
| 3719 | value.reset((char*) data, 1, 1, &my_charset_bin); |
| 3720 | } |
| 3721 | virtual uchar *pack(uchar *to, const uchar *from, uint max_length); |
| 3722 | virtual const uchar *unpack(uchar *to, const uchar *from, |
| 3723 | const uchar *from_end, uint param_data); |
| 3724 | uint packed_col_length(const uchar *col_ptr, uint length); |
| 3725 | uint max_packed_col_length(uint max_length); |
| 3726 | void free() |
| 3727 | { |
| 3728 | value.free(); |
| 3729 | read_value.free(); |
| 3730 | } |
| 3731 | inline void clear_temporary() |
| 3732 | { |
| 3733 | uchar *tmp= get_ptr(); |
| 3734 | if (likely(value.ptr() == (char*) tmp)) |
| 3735 | bzero((uchar*) &value, sizeof(value)); |
| 3736 | else |
| 3737 | { |
| 3738 | /* |
| 3739 | Currently read_value should never point to tmp, the following code |
| 3740 | is mainly here to make things future proof. |
| 3741 | */ |
| 3742 | if (unlikely(read_value.ptr() == (char*) tmp)) |
| 3743 | bzero((uchar*) &read_value, sizeof(read_value)); |
| 3744 | } |
| 3745 | } |
| 3746 | uint size_of() const { return sizeof(*this); } |
| 3747 | bool has_charset(void) const |
| 3748 | { return charset() == &my_charset_bin ? FALSE : TRUE; } |
| 3749 | uint32 max_display_length() const; |
| 3750 | uint32 char_length() const; |
| 3751 | uint32 octet_length() const; |
| 3752 | uint is_equal(Create_field *new_field); |
| 3753 | private: |
| 3754 | int save_field_metadata(uchar *first_byte); |
| 3755 | }; |
| 3756 | |
| 3757 | |
| 3758 | class Field_blob_compressed: public Field_blob { |
| 3759 | public: |
| 3760 | Field_blob_compressed(uchar *ptr_arg, uchar *null_ptr_arg, |
| 3761 | uchar null_bit_arg, enum utype unireg_check_arg, |
| 3762 | const LEX_CSTRING *field_name_arg, TABLE_SHARE *share, |
| 3763 | uint blob_pack_length, const DTCollation &collation, |
| 3764 | Compression_method *compression_method_arg): |
| 3765 | Field_blob(ptr_arg, null_ptr_arg, null_bit_arg, unireg_check_arg, |
| 3766 | field_name_arg, share, blob_pack_length, collation), |
| 3767 | compression_method_ptr(compression_method_arg) {} |
| 3768 | Compression_method *compression_method() const |
| 3769 | { return compression_method_ptr; } |
| 3770 | private: |
| 3771 | Compression_method *compression_method_ptr; |
| 3772 | int store(const char *to, size_t length, CHARSET_INFO *charset); |
| 3773 | using Field_str::store; |
| 3774 | String *val_str(String *, String *); |
| 3775 | double val_real(void); |
| 3776 | longlong val_int(void); |
| 3777 | uint size_of() const { return sizeof(*this); } |
| 3778 | enum_field_types binlog_type() const { return MYSQL_TYPE_BLOB_COMPRESSED; } |
| 3779 | void sql_type(String &str) const |
| 3780 | { |
| 3781 | Field_blob::sql_type(str); |
| 3782 | str.append(STRING_WITH_LEN(" /*!100301 COMPRESSED*/" )); |
| 3783 | } |
| 3784 | |
| 3785 | /* |
| 3786 | Compressed fields can't have keys as two rows may have different |
| 3787 | compression methods or compression levels. |
| 3788 | */ |
| 3789 | |
| 3790 | uint get_key_image(uchar *buff, uint length, imagetype type_arg) |
| 3791 | { DBUG_ASSERT(0); return 0; } |
| 3792 | void set_key_image(const uchar *buff, uint length) |
| 3793 | { DBUG_ASSERT(0); } |
| 3794 | int key_cmp(const uchar *a, const uchar *b) |
| 3795 | { DBUG_ASSERT(0); return 0; } |
| 3796 | int key_cmp(const uchar *str, uint length) |
| 3797 | { DBUG_ASSERT(0); return 0; } |
| 3798 | Field *new_key_field(MEM_ROOT *root, TABLE *new_table, |
| 3799 | uchar *new_ptr, uint32 length, |
| 3800 | uchar *new_null_ptr, uint new_null_bit) |
| 3801 | { DBUG_ASSERT(0); return 0; } |
| 3802 | }; |
| 3803 | |
| 3804 | |
| 3805 | #ifdef HAVE_SPATIAL |
| 3806 | class Field_geom :public Field_blob { |
| 3807 | public: |
| 3808 | enum geometry_type geom_type; |
| 3809 | uint srid; |
| 3810 | uint precision; |
| 3811 | enum storage_type { GEOM_STORAGE_WKB= 0, GEOM_STORAGE_BINARY= 1}; |
| 3812 | enum storage_type storage; |
| 3813 | |
| 3814 | Field_geom(uchar *ptr_arg, uchar *null_ptr_arg, uchar null_bit_arg, |
| 3815 | enum utype unireg_check_arg, const LEX_CSTRING *field_name_arg, |
| 3816 | TABLE_SHARE *share, uint blob_pack_length, |
| 3817 | enum geometry_type geom_type_arg, uint field_srid) |
| 3818 | :Field_blob(ptr_arg, null_ptr_arg, null_bit_arg, unireg_check_arg, |
| 3819 | field_name_arg, share, blob_pack_length, &my_charset_bin) |
| 3820 | { geom_type= geom_type_arg; srid= field_srid; } |
| 3821 | enum ha_base_keytype key_type() const { return HA_KEYTYPE_VARBINARY2; } |
| 3822 | const Type_handler *type_handler() const |
| 3823 | { |
| 3824 | return &type_handler_geometry; |
| 3825 | } |
| 3826 | enum_field_types type() const |
| 3827 | { |
| 3828 | return MYSQL_TYPE_GEOMETRY; |
| 3829 | } |
| 3830 | enum_field_types real_type() const |
| 3831 | { |
| 3832 | return MYSQL_TYPE_GEOMETRY; |
| 3833 | } |
| 3834 | Information_schema_character_attributes |
| 3835 | information_schema_character_attributes() const |
| 3836 | { |
| 3837 | return Information_schema_character_attributes(); |
| 3838 | } |
| 3839 | bool can_optimize_range(const Item_bool_func *cond, |
| 3840 | const Item *item, |
| 3841 | bool is_eq_func) const; |
| 3842 | void sql_type(String &str) const; |
| 3843 | uint is_equal(Create_field *new_field); |
| 3844 | int store(const char *to, size_t length, CHARSET_INFO *charset); |
| 3845 | int store(double nr); |
| 3846 | int store(longlong nr, bool unsigned_val); |
| 3847 | int store_decimal(const my_decimal *); |
| 3848 | uint size_of() const { return sizeof(*this); } |
| 3849 | /** |
| 3850 | Key length is provided only to support hash joins. (compared byte for byte) |
| 3851 | Ex: SELECT .. FROM t1,t2 WHERE t1.field_geom1=t2.field_geom2. |
| 3852 | |
| 3853 | The comparison is not very relevant, as identical geometry might be |
| 3854 | represented differently, but we need to support it either way. |
| 3855 | */ |
| 3856 | uint32 key_length() const { return packlength; } |
| 3857 | |
| 3858 | /** |
| 3859 | Non-nullable GEOMETRY types cannot have defaults, |
| 3860 | but the underlying blob must still be reset. |
| 3861 | */ |
| 3862 | int reset(void) { return Field_blob::reset() || !maybe_null(); } |
| 3863 | bool load_data_set_null(THD *thd); |
| 3864 | bool load_data_set_no_data(THD *thd, bool fixed_format); |
| 3865 | |
| 3866 | geometry_type get_geometry_type() { return geom_type; }; |
| 3867 | static geometry_type geometry_type_merge(geometry_type, geometry_type); |
| 3868 | uint get_srid() { return srid; } |
| 3869 | }; |
| 3870 | |
| 3871 | uint gis_field_options_image(uchar *buff, List<Create_field> &create_fields); |
| 3872 | uint gis_field_options_read(const uchar *buf, size_t buf_len, |
| 3873 | Field_geom::storage_type *st_type,uint *precision, uint *scale, uint *srid); |
| 3874 | |
| 3875 | #endif /*HAVE_SPATIAL*/ |
| 3876 | |
| 3877 | |
| 3878 | class Field_enum :public Field_str { |
| 3879 | static void do_field_enum(Copy_field *copy_field); |
| 3880 | protected: |
| 3881 | uint packlength; |
| 3882 | public: |
| 3883 | TYPELIB *typelib; |
| 3884 | Field_enum(uchar *ptr_arg, uint32 len_arg, uchar *null_ptr_arg, |
| 3885 | uchar null_bit_arg, |
| 3886 | enum utype unireg_check_arg, const LEX_CSTRING *field_name_arg, |
| 3887 | uint packlength_arg, |
| 3888 | TYPELIB *typelib_arg, |
| 3889 | const DTCollation &collation) |
| 3890 | :Field_str(ptr_arg, len_arg, null_ptr_arg, null_bit_arg, |
| 3891 | unireg_check_arg, field_name_arg, collation), |
| 3892 | packlength(packlength_arg),typelib(typelib_arg) |
| 3893 | { |
| 3894 | flags|=ENUM_FLAG; |
| 3895 | } |
| 3896 | Field *make_new_field(MEM_ROOT *root, TABLE *new_table, bool keep_type); |
| 3897 | const Type_handler *type_handler() const { return &type_handler_enum; } |
| 3898 | enum ha_base_keytype key_type() const; |
| 3899 | Copy_func *get_copy_func(const Field *from) const |
| 3900 | { |
| 3901 | if (eq_def(from)) |
| 3902 | return get_identical_copy_func(); |
| 3903 | if (real_type() == MYSQL_TYPE_ENUM && |
| 3904 | from->real_type() == MYSQL_TYPE_ENUM) |
| 3905 | return do_field_enum; |
| 3906 | if (from->result_type() == STRING_RESULT) |
| 3907 | return do_field_string; |
| 3908 | return do_field_int; |
| 3909 | } |
| 3910 | int store_field(Field *from) |
| 3911 | { |
| 3912 | if (from->real_type() == MYSQL_TYPE_ENUM && from->val_int() == 0) |
| 3913 | { |
| 3914 | store_type(0); |
| 3915 | return 0; |
| 3916 | } |
| 3917 | return from->save_in_field(this); |
| 3918 | } |
| 3919 | int save_in_field(Field *to) |
| 3920 | { |
| 3921 | if (to->result_type() != STRING_RESULT) |
| 3922 | return to->store(val_int(), 0); |
| 3923 | return save_in_field_str(to); |
| 3924 | } |
| 3925 | bool memcpy_field_possible(const Field *from) const { return false; } |
| 3926 | int store(const char *to,size_t length,CHARSET_INFO *charset); |
| 3927 | int store(double nr); |
| 3928 | int store(longlong nr, bool unsigned_val); |
| 3929 | double val_real(void); |
| 3930 | longlong val_int(void); |
| 3931 | String *val_str(String*,String *); |
| 3932 | int cmp(const uchar *,const uchar *); |
| 3933 | void sort_string(uchar *buff,uint length); |
| 3934 | uint32 pack_length() const { return (uint32) packlength; } |
| 3935 | void store_type(ulonglong value); |
| 3936 | void sql_type(String &str) const; |
| 3937 | uint size_of() const { return sizeof(*this); } |
| 3938 | uint pack_length_from_metadata(uint field_metadata) |
| 3939 | { return (field_metadata & 0x00ff); } |
| 3940 | uint row_pack_length() const { return pack_length(); } |
| 3941 | virtual bool zero_pack() const { return 0; } |
| 3942 | bool optimize_range(uint idx, uint part) const { return 0; } |
| 3943 | bool eq_def(const Field *field) const; |
| 3944 | bool has_charset(void) const { return TRUE; } |
| 3945 | /* enum and set are sorted as integers */ |
| 3946 | CHARSET_INFO *sort_charset(void) const { return &my_charset_bin; } |
| 3947 | uint decimals() const { return 0; } |
| 3948 | TYPELIB *get_typelib() const { return typelib; } |
| 3949 | |
| 3950 | virtual uchar *pack(uchar *to, const uchar *from, uint max_length); |
| 3951 | virtual const uchar *unpack(uchar *to, const uchar *from, |
| 3952 | const uchar *from_end, uint param_data); |
| 3953 | |
| 3954 | bool can_optimize_keypart_ref(const Item_bool_func *cond, |
| 3955 | const Item *item) const; |
| 3956 | bool can_optimize_group_min_max(const Item_bool_func *cond, |
| 3957 | const Item *const_item) const |
| 3958 | { |
| 3959 | /* |
| 3960 | Can't use GROUP_MIN_MAX optimization for ENUM and SET, |
| 3961 | because the values are stored as numbers in index, |
| 3962 | while MIN() and MAX() work as strings. |
| 3963 | It would return the records with min and max enum numeric indexes. |
| 3964 | "Bug#45300 MAX() and ENUM type" should be fixed first. |
| 3965 | */ |
| 3966 | return false; |
| 3967 | } |
| 3968 | bool can_optimize_range(const Item_bool_func *cond, |
| 3969 | const Item *item, |
| 3970 | bool is_eq_func) const; |
| 3971 | private: |
| 3972 | int save_field_metadata(uchar *first_byte); |
| 3973 | uint is_equal(Create_field *new_field); |
| 3974 | }; |
| 3975 | |
| 3976 | |
| 3977 | class Field_set :public Field_enum { |
| 3978 | public: |
| 3979 | Field_set(uchar *ptr_arg, uint32 len_arg, uchar *null_ptr_arg, |
| 3980 | uchar null_bit_arg, |
| 3981 | enum utype unireg_check_arg, const LEX_CSTRING *field_name_arg, |
| 3982 | uint32 packlength_arg, |
| 3983 | TYPELIB *typelib_arg, const DTCollation &collation) |
| 3984 | :Field_enum(ptr_arg, len_arg, null_ptr_arg, null_bit_arg, |
| 3985 | unireg_check_arg, field_name_arg, |
| 3986 | packlength_arg, |
| 3987 | typelib_arg, collation), |
| 3988 | empty_set_string("" , 0, collation.collation) |
| 3989 | { |
| 3990 | flags=(flags & ~ENUM_FLAG) | SET_FLAG; |
| 3991 | } |
| 3992 | int store_field(Field *from) { return from->save_in_field(this); } |
| 3993 | int store(const char *to,size_t length,CHARSET_INFO *charset); |
| 3994 | int store(double nr) { return Field_set::store((longlong) nr, FALSE); } |
| 3995 | int store(longlong nr, bool unsigned_val); |
| 3996 | |
| 3997 | virtual bool zero_pack() const { return 1; } |
| 3998 | String *val_str(String*,String *); |
| 3999 | void sql_type(String &str) const; |
| 4000 | uint size_of() const { return sizeof(*this); } |
| 4001 | const Type_handler *type_handler() const { return &type_handler_set; } |
| 4002 | bool has_charset(void) const { return TRUE; } |
| 4003 | private: |
| 4004 | const String empty_set_string; |
| 4005 | }; |
| 4006 | |
| 4007 | |
| 4008 | /* |
| 4009 | Note: |
| 4010 | To use Field_bit::cmp_binary() you need to copy the bits stored in |
| 4011 | the beginning of the record (the NULL bytes) to each memory you |
| 4012 | want to compare (where the arguments point). |
| 4013 | |
| 4014 | This is the reason: |
| 4015 | - Field_bit::cmp_binary() is only implemented in the base class |
| 4016 | (Field::cmp_binary()). |
| 4017 | - Field::cmp_binary() currenly use pack_length() to calculate how |
| 4018 | long the data is. |
| 4019 | - pack_length() includes size of the bits stored in the NULL bytes |
| 4020 | of the record. |
| 4021 | */ |
| 4022 | class Field_bit :public Field { |
| 4023 | public: |
| 4024 | uchar *bit_ptr; // position in record where 'uneven' bits store |
| 4025 | uchar bit_ofs; // offset to 'uneven' high bits |
| 4026 | uint bit_len; // number of 'uneven' high bits |
| 4027 | uint bytes_in_rec; |
| 4028 | Field_bit(uchar *ptr_arg, uint32 len_arg, uchar *null_ptr_arg, |
| 4029 | uchar null_bit_arg, uchar *bit_ptr_arg, uchar bit_ofs_arg, |
| 4030 | enum utype unireg_check_arg, const LEX_CSTRING *field_name_arg); |
| 4031 | const Type_handler *type_handler() const { return &type_handler_bit; } |
| 4032 | enum ha_base_keytype key_type() const { return HA_KEYTYPE_BIT; } |
| 4033 | uint32 key_length() const { return (uint32) (field_length + 7) / 8; } |
| 4034 | uint32 max_data_length() const { return (field_length + 7) / 8; } |
| 4035 | uint32 max_display_length() const { return field_length; } |
| 4036 | Information_schema_numeric_attributes |
| 4037 | information_schema_numeric_attributes() const |
| 4038 | { |
| 4039 | return Information_schema_numeric_attributes(field_length); |
| 4040 | } |
| 4041 | uint size_of() const { return sizeof(*this); } |
| 4042 | int reset(void) { |
| 4043 | bzero(ptr, bytes_in_rec); |
| 4044 | if (bit_ptr && (bit_len > 0)) // reset odd bits among null bits |
| 4045 | clr_rec_bits(bit_ptr, bit_ofs, bit_len); |
| 4046 | return 0; |
| 4047 | } |
| 4048 | Copy_func *get_copy_func(const Field *from) const |
| 4049 | { |
| 4050 | return do_field_int; |
| 4051 | } |
| 4052 | int save_in_field(Field *to) { return to->store(val_int(), true); } |
| 4053 | bool memcpy_field_possible(const Field *from) const { return false; } |
| 4054 | int store(const char *to, size_t length, CHARSET_INFO *charset); |
| 4055 | int store(double nr); |
| 4056 | int store(longlong nr, bool unsigned_val); |
| 4057 | int store_decimal(const my_decimal *); |
| 4058 | double val_real(void); |
| 4059 | longlong val_int(void); |
| 4060 | String *val_str(String*, String *); |
| 4061 | virtual bool str_needs_quotes() { return TRUE; } |
| 4062 | my_decimal *val_decimal(my_decimal *); |
| 4063 | bool val_bool() { return val_int() != 0; } |
| 4064 | int cmp(const uchar *a, const uchar *b) |
| 4065 | { |
| 4066 | DBUG_ASSERT(ptr == a || ptr == b); |
| 4067 | if (ptr == a) |
| 4068 | return Field_bit::key_cmp(b, bytes_in_rec + MY_TEST(bit_len)); |
| 4069 | else |
| 4070 | return Field_bit::key_cmp(a, bytes_in_rec + MY_TEST(bit_len)) * -1; |
| 4071 | } |
| 4072 | int cmp_binary_offset(uint row_offset) |
| 4073 | { return cmp_offset(row_offset); } |
| 4074 | int cmp_max(const uchar *a, const uchar *b, uint max_length); |
| 4075 | int key_cmp(const uchar *a, const uchar *b) |
| 4076 | { return cmp_binary((uchar *) a, (uchar *) b); } |
| 4077 | int key_cmp(const uchar *str, uint length); |
| 4078 | int cmp_offset(uint row_offset); |
| 4079 | bool update_min(Field *min_val, bool force_update) |
| 4080 | { |
| 4081 | longlong val= val_int(); |
| 4082 | bool update_fl= force_update || val < min_val->val_int(); |
| 4083 | if (update_fl) |
| 4084 | { |
| 4085 | min_val->set_notnull(); |
| 4086 | min_val->store(val, FALSE); |
| 4087 | } |
| 4088 | return update_fl; |
| 4089 | } |
| 4090 | bool update_max(Field *max_val, bool force_update) |
| 4091 | { |
| 4092 | longlong val= val_int(); |
| 4093 | bool update_fl= force_update || val > max_val->val_int(); |
| 4094 | if (update_fl) |
| 4095 | { |
| 4096 | max_val->set_notnull(); |
| 4097 | max_val->store(val, FALSE); |
| 4098 | } |
| 4099 | return update_fl; |
| 4100 | } |
| 4101 | void store_field_value(uchar *val, uint len) |
| 4102 | { |
| 4103 | store(*((longlong *)val), TRUE); |
| 4104 | } |
| 4105 | double pos_in_interval(Field *min, Field *max) |
| 4106 | { |
| 4107 | return pos_in_interval_val_real(min, max); |
| 4108 | } |
| 4109 | void get_image(uchar *buff, uint length, CHARSET_INFO *cs) |
| 4110 | { get_key_image(buff, length, itRAW); } |
| 4111 | void set_image(const uchar *buff,uint length, CHARSET_INFO *cs) |
| 4112 | { Field_bit::store((char *) buff, length, cs); } |
| 4113 | uint get_key_image(uchar *buff, uint length, imagetype type); |
| 4114 | void set_key_image(const uchar *buff, uint length) |
| 4115 | { Field_bit::store((char*) buff, length, &my_charset_bin); } |
| 4116 | void sort_string(uchar *buff, uint length) |
| 4117 | { get_key_image(buff, length, itRAW); } |
| 4118 | uint32 pack_length() const { return (uint32) (field_length + 7) / 8; } |
| 4119 | uint32 pack_length_in_rec() const { return bytes_in_rec; } |
| 4120 | uint pack_length_from_metadata(uint field_metadata); |
| 4121 | uint row_pack_length() const |
| 4122 | { return (bytes_in_rec + ((bit_len > 0) ? 1 : 0)); } |
| 4123 | bool compatible_field_size(uint metadata, Relay_log_info *rli, |
| 4124 | uint16 mflags, int *order_var); |
| 4125 | void sql_type(String &str) const; |
| 4126 | virtual uchar *pack(uchar *to, const uchar *from, uint max_length); |
| 4127 | virtual const uchar *unpack(uchar *to, const uchar *from, |
| 4128 | const uchar *from_end, uint param_data); |
| 4129 | virtual int set_default(); |
| 4130 | |
| 4131 | Field *new_key_field(MEM_ROOT *root, TABLE *new_table, |
| 4132 | uchar *new_ptr, uint32 length, |
| 4133 | uchar *new_null_ptr, uint new_null_bit); |
| 4134 | void set_bit_ptr(uchar *bit_ptr_arg, uchar bit_ofs_arg) |
| 4135 | { |
| 4136 | bit_ptr= bit_ptr_arg; |
| 4137 | bit_ofs= bit_ofs_arg; |
| 4138 | } |
| 4139 | bool eq(Field *field) |
| 4140 | { |
| 4141 | return (Field::eq(field) && |
| 4142 | bit_ptr == ((Field_bit *)field)->bit_ptr && |
| 4143 | bit_ofs == ((Field_bit *)field)->bit_ofs); |
| 4144 | } |
| 4145 | uint is_equal(Create_field *new_field); |
| 4146 | void move_field_offset(my_ptrdiff_t ptr_diff) |
| 4147 | { |
| 4148 | Field::move_field_offset(ptr_diff); |
| 4149 | bit_ptr= ADD_TO_PTR(bit_ptr, ptr_diff, uchar*); |
| 4150 | } |
| 4151 | void hash(ulong *nr, ulong *nr2); |
| 4152 | |
| 4153 | private: |
| 4154 | virtual size_t do_last_null_byte() const; |
| 4155 | int save_field_metadata(uchar *first_byte); |
| 4156 | }; |
| 4157 | |
| 4158 | |
| 4159 | /** |
| 4160 | BIT field represented as chars for non-MyISAM tables. |
| 4161 | |
| 4162 | @todo The inheritance relationship is backwards since Field_bit is |
| 4163 | an extended version of Field_bit_as_char and not the other way |
| 4164 | around. Hence, we should refactor it to fix the hierarchy order. |
| 4165 | */ |
| 4166 | class Field_bit_as_char: public Field_bit { |
| 4167 | public: |
| 4168 | Field_bit_as_char(uchar *ptr_arg, uint32 len_arg, uchar *null_ptr_arg, |
| 4169 | uchar null_bit_arg, |
| 4170 | enum utype unireg_check_arg, const LEX_CSTRING *field_name_arg); |
| 4171 | enum ha_base_keytype key_type() const { return HA_KEYTYPE_BINARY; } |
| 4172 | uint size_of() const { return sizeof(*this); } |
| 4173 | int store(const char *to, size_t length, CHARSET_INFO *charset); |
| 4174 | int store(double nr) { return Field_bit::store(nr); } |
| 4175 | int store(longlong nr, bool unsigned_val) |
| 4176 | { return Field_bit::store(nr, unsigned_val); } |
| 4177 | void sql_type(String &str) const; |
| 4178 | }; |
| 4179 | |
| 4180 | |
| 4181 | class Field_row: public Field_null |
| 4182 | { |
| 4183 | class Virtual_tmp_table *m_table; |
| 4184 | public: |
| 4185 | Field_row(uchar *ptr_arg, const LEX_CSTRING *field_name_arg) |
| 4186 | :Field_null(ptr_arg, 0, Field::NONE, field_name_arg, &my_charset_bin), |
| 4187 | m_table(NULL) |
| 4188 | {} |
| 4189 | ~Field_row(); |
| 4190 | Virtual_tmp_table **virtual_tmp_table_addr() { return &m_table; } |
| 4191 | bool sp_prepare_and_store_item(THD *thd, Item **value); |
| 4192 | }; |
| 4193 | |
| 4194 | |
| 4195 | extern const LEX_CSTRING null_clex_str; |
| 4196 | |
| 4197 | Field *make_field(TABLE_SHARE *share, MEM_ROOT *mem_root, |
| 4198 | uchar *ptr, uint32 field_length, |
| 4199 | uchar *null_pos, uchar null_bit, |
| 4200 | uint pack_flag, const Type_handler *handler, |
| 4201 | CHARSET_INFO *cs, |
| 4202 | Field::geometry_type geom_type, uint srid, |
| 4203 | Field::utype unireg_check, |
| 4204 | TYPELIB *interval, const LEX_CSTRING *field_name, |
| 4205 | uint32 flags); |
| 4206 | |
| 4207 | /* |
| 4208 | Create field class for CREATE TABLE |
| 4209 | */ |
| 4210 | class Column_definition: public Sql_alloc, |
| 4211 | public Type_handler_hybrid_field_type |
| 4212 | { |
| 4213 | /** |
| 4214 | Create "interval" from "interval_list". |
| 4215 | @param mem_root - memory root to create the TYPELIB |
| 4216 | instance and its values on |
| 4217 | @param reuse_interval_list_values - determines if TYPELIB can reuse strings |
| 4218 | from interval_list, or should always |
| 4219 | allocate a copy on mem_root, even if |
| 4220 | character set conversion is not needed |
| 4221 | @retval false on success |
| 4222 | @retval true on error (bad values, or EOM) |
| 4223 | */ |
| 4224 | bool create_interval_from_interval_list(MEM_ROOT *mem_root, |
| 4225 | bool reuse_interval_list_values); |
| 4226 | |
| 4227 | /* |
| 4228 | Calculate TYPELIB (set or enum) max and total lengths |
| 4229 | |
| 4230 | @param cs charset+collation pair of the interval |
| 4231 | @param max_length length of the longest item |
| 4232 | @param tot_length sum of the item lengths |
| 4233 | |
| 4234 | After this method call: |
| 4235 | - ENUM uses max_length |
| 4236 | - SET uses tot_length. |
| 4237 | */ |
| 4238 | void calculate_interval_lengths(uint32 *max_length, uint32 *tot_length) |
| 4239 | { |
| 4240 | const char **pos; |
| 4241 | uint *len; |
| 4242 | *max_length= *tot_length= 0; |
| 4243 | for (pos= interval->type_names, len= interval->type_lengths; |
| 4244 | *pos ; pos++, len++) |
| 4245 | { |
| 4246 | size_t length= charset->cset->numchars(charset, *pos, *pos + *len); |
| 4247 | DBUG_ASSERT(length < UINT_MAX32); |
| 4248 | *tot_length+= (uint) length; |
| 4249 | set_if_bigger(*max_length, (uint32)length); |
| 4250 | } |
| 4251 | } |
| 4252 | bool prepare_stage1_check_typelib_default(); |
| 4253 | bool prepare_stage1_convert_default(THD *, MEM_ROOT *, CHARSET_INFO *to); |
| 4254 | const Type_handler *field_type() const; // Prevent using this |
| 4255 | Compression_method *compression_method_ptr; |
| 4256 | public: |
| 4257 | LEX_CSTRING field_name; |
| 4258 | LEX_CSTRING comment; // Comment for field |
| 4259 | enum enum_column_versioning |
| 4260 | { |
| 4261 | VERSIONING_NOT_SET, |
| 4262 | WITH_VERSIONING, |
| 4263 | WITHOUT_VERSIONING |
| 4264 | }; |
| 4265 | Item *on_update; // ON UPDATE NOW() |
| 4266 | /* |
| 4267 | At various stages in execution this can be length of field in bytes or |
| 4268 | max number of characters. |
| 4269 | */ |
| 4270 | ulonglong length; |
| 4271 | field_visibility_t invisible; |
| 4272 | /* |
| 4273 | The value of `length' as set by parser: is the number of characters |
| 4274 | for most of the types, or of bytes for BLOBs or numeric types. |
| 4275 | */ |
| 4276 | uint32 char_length; |
| 4277 | uint decimals, flags, pack_length, key_length; |
| 4278 | Field::utype unireg_check; |
| 4279 | TYPELIB *interval; // Which interval to use |
| 4280 | List<String> interval_list; |
| 4281 | CHARSET_INFO *charset; |
| 4282 | uint32 srid; |
| 4283 | Field::geometry_type geom_type; |
| 4284 | engine_option_value *option_list; |
| 4285 | |
| 4286 | uint pack_flag; |
| 4287 | |
| 4288 | /* |
| 4289 | This is additinal data provided for any computed(virtual) field. |
| 4290 | In particular it includes a pointer to the item by which this field |
| 4291 | can be computed from other fields. |
| 4292 | */ |
| 4293 | Virtual_column_info |
| 4294 | *vcol_info, // Virtual field |
| 4295 | *default_value, // Default value |
| 4296 | *check_constraint; // Check constraint |
| 4297 | |
| 4298 | enum_column_versioning versioning; |
| 4299 | |
| 4300 | Column_definition() |
| 4301 | :Type_handler_hybrid_field_type(&type_handler_null), |
| 4302 | compression_method_ptr(0), |
| 4303 | comment(null_clex_str), |
| 4304 | on_update(NULL), length(0), invisible(VISIBLE), decimals(0), |
| 4305 | flags(0), pack_length(0), key_length(0), unireg_check(Field::NONE), |
| 4306 | interval(0), charset(&my_charset_bin), |
| 4307 | srid(0), geom_type(Field::GEOM_GEOMETRY), |
| 4308 | option_list(NULL), pack_flag(0), |
| 4309 | vcol_info(0), default_value(0), check_constraint(0), |
| 4310 | versioning(VERSIONING_NOT_SET) |
| 4311 | { |
| 4312 | interval_list.empty(); |
| 4313 | } |
| 4314 | |
| 4315 | Column_definition(THD *thd, Field *field, Field *orig_field); |
| 4316 | void set_attributes(const Lex_field_type_st &type, CHARSET_INFO *cs); |
| 4317 | void create_length_to_internal_length_null() |
| 4318 | { |
| 4319 | DBUG_ASSERT(length == 0); |
| 4320 | key_length= pack_length= 0; |
| 4321 | } |
| 4322 | void create_length_to_internal_length_simple() |
| 4323 | { |
| 4324 | key_length= pack_length= type_handler()->calc_pack_length((uint32) length); |
| 4325 | } |
| 4326 | void create_length_to_internal_length_string() |
| 4327 | { |
| 4328 | length*= charset->mbmaxlen; |
| 4329 | if (real_field_type() == MYSQL_TYPE_VARCHAR && compression_method()) |
| 4330 | length++; |
| 4331 | DBUG_ASSERT(length <= UINT_MAX32); |
| 4332 | key_length= (uint) length; |
| 4333 | pack_length= type_handler()->calc_pack_length((uint32) length); |
| 4334 | } |
| 4335 | void create_length_to_internal_length_typelib() |
| 4336 | { |
| 4337 | /* Pack_length already calculated in sql_parse.cc */ |
| 4338 | length*= charset->mbmaxlen; |
| 4339 | key_length= pack_length; |
| 4340 | } |
| 4341 | bool vers_sys_field() const |
| 4342 | { |
| 4343 | return flags & (VERS_SYS_START_FLAG | VERS_SYS_END_FLAG); |
| 4344 | } |
| 4345 | void create_length_to_internal_length_bit(); |
| 4346 | void create_length_to_internal_length_newdecimal(); |
| 4347 | |
| 4348 | /** |
| 4349 | Prepare a SET/ENUM field. |
| 4350 | Create "interval" from "interval_list" if needed, and adjust "length". |
| 4351 | @param mem_root - Memory root to allocate TYPELIB and |
| 4352 | its values on |
| 4353 | @param reuse_interval_list_values - determines if TYPELIB can reuse value |
| 4354 | buffers from interval_list, or should |
| 4355 | always allocate a copy on mem_root, |
| 4356 | even if character set conversion |
| 4357 | is not needed |
| 4358 | */ |
| 4359 | bool prepare_interval_field(MEM_ROOT *mem_root, |
| 4360 | bool reuse_interval_list_values); |
| 4361 | |
| 4362 | void prepare_interval_field_calc_length() |
| 4363 | { |
| 4364 | uint32 field_length, dummy; |
| 4365 | if (real_field_type() == MYSQL_TYPE_SET) |
| 4366 | { |
| 4367 | calculate_interval_lengths(&dummy, &field_length); |
| 4368 | length= field_length + (interval->count - 1); |
| 4369 | } |
| 4370 | else /* MYSQL_TYPE_ENUM */ |
| 4371 | { |
| 4372 | calculate_interval_lengths(&field_length, &dummy); |
| 4373 | length= field_length; |
| 4374 | } |
| 4375 | set_if_smaller(length, MAX_FIELD_WIDTH - 1); |
| 4376 | } |
| 4377 | |
| 4378 | bool prepare_blob_field(THD *thd); |
| 4379 | |
| 4380 | bool sp_prepare_create_field(THD *thd, MEM_ROOT *mem_root); |
| 4381 | |
| 4382 | bool prepare_stage1(THD *thd, MEM_ROOT *mem_root, |
| 4383 | handler *file, ulonglong table_flags); |
| 4384 | bool prepare_stage1_typelib(THD *thd, MEM_ROOT *mem_root, |
| 4385 | handler *file, ulonglong table_flags); |
| 4386 | bool prepare_stage1_string(THD *thd, MEM_ROOT *mem_root, |
| 4387 | handler *file, ulonglong table_flags); |
| 4388 | bool prepare_stage1_bit(THD *thd, MEM_ROOT *mem_root, |
| 4389 | handler *file, ulonglong table_flags); |
| 4390 | |
| 4391 | void redefine_stage1_common(const Column_definition *dup_field, |
| 4392 | const handler *file, |
| 4393 | const Schema_specification_st *schema); |
| 4394 | bool redefine_stage1(const Column_definition *dup_field, const handler *file, |
| 4395 | const Schema_specification_st *schema) |
| 4396 | { |
| 4397 | const Type_handler *handler= dup_field->type_handler(); |
| 4398 | return handler->Column_definition_redefine_stage1(this, dup_field, |
| 4399 | file, schema); |
| 4400 | } |
| 4401 | bool prepare_stage2(handler *handler, ulonglong table_flags); |
| 4402 | bool prepare_stage2_blob(handler *handler, |
| 4403 | ulonglong table_flags, uint field_flags); |
| 4404 | bool prepare_stage2_varchar(ulonglong table_flags); |
| 4405 | bool prepare_stage2_typelib(const char *type_name, uint field_flags, |
| 4406 | uint *dup_val_count); |
| 4407 | uint pack_flag_numeric(uint dec) const; |
| 4408 | uint sign_length() const { return flags & UNSIGNED_FLAG ? 0 : 1; } |
| 4409 | bool check_length(uint mysql_errno, uint max_allowed_length) const; |
| 4410 | bool fix_attributes_real(uint default_length); |
| 4411 | bool fix_attributes_int(uint default_length); |
| 4412 | bool fix_attributes_decimal(); |
| 4413 | bool fix_attributes_temporal_with_time(uint int_part_length); |
| 4414 | bool fix_attributes_bit(); |
| 4415 | |
| 4416 | bool check(THD *thd); |
| 4417 | |
| 4418 | bool stored_in_db() const { return !vcol_info || vcol_info->stored_in_db; } |
| 4419 | |
| 4420 | ha_storage_media field_storage_type() const |
| 4421 | { |
| 4422 | return (ha_storage_media) |
| 4423 | ((flags >> FIELD_FLAGS_STORAGE_MEDIA) & 3); |
| 4424 | } |
| 4425 | |
| 4426 | column_format_type column_format() const |
| 4427 | { |
| 4428 | return (column_format_type) |
| 4429 | ((flags >> FIELD_FLAGS_COLUMN_FORMAT) & 3); |
| 4430 | } |
| 4431 | |
| 4432 | bool has_default_function() const |
| 4433 | { |
| 4434 | return unireg_check != Field::NONE; |
| 4435 | } |
| 4436 | |
| 4437 | Field *make_field(TABLE_SHARE *share, MEM_ROOT *mem_root, |
| 4438 | uchar *ptr, uchar *null_pos, uchar null_bit, |
| 4439 | const LEX_CSTRING *field_name_arg) const |
| 4440 | { |
| 4441 | return ::make_field(share, mem_root, ptr, |
| 4442 | (uint32)length, null_pos, null_bit, |
| 4443 | pack_flag, type_handler(), charset, |
| 4444 | geom_type, srid, unireg_check, interval, |
| 4445 | field_name_arg, flags); |
| 4446 | } |
| 4447 | Field *make_field(TABLE_SHARE *share, MEM_ROOT *mem_root, |
| 4448 | const LEX_CSTRING *field_name_arg) const |
| 4449 | { |
| 4450 | return make_field(share, mem_root, (uchar *) 0, (uchar *) "" , 0, |
| 4451 | field_name_arg); |
| 4452 | } |
| 4453 | /* Return true if default is an expression that must be saved explicitely */ |
| 4454 | bool has_default_expression(); |
| 4455 | |
| 4456 | bool has_default_now_unireg_check() const |
| 4457 | { |
| 4458 | return unireg_check == Field::TIMESTAMP_DN_FIELD |
| 4459 | || unireg_check == Field::TIMESTAMP_DNUN_FIELD; |
| 4460 | } |
| 4461 | |
| 4462 | void set_type(const Column_definition &other) |
| 4463 | { |
| 4464 | set_handler(other.type_handler()); |
| 4465 | length= other.length; |
| 4466 | char_length= other.char_length; |
| 4467 | decimals= other.decimals; |
| 4468 | flags= other.flags; |
| 4469 | pack_length= other.pack_length; |
| 4470 | key_length= other.key_length; |
| 4471 | unireg_check= other.unireg_check; |
| 4472 | interval= other.interval; |
| 4473 | charset= other.charset; |
| 4474 | srid= other.srid; |
| 4475 | geom_type= other.geom_type; |
| 4476 | pack_flag= other.pack_flag; |
| 4477 | } |
| 4478 | |
| 4479 | // Replace the entire value by another definition |
| 4480 | void set_column_definition(const Column_definition *def) |
| 4481 | { |
| 4482 | *this= *def; |
| 4483 | } |
| 4484 | bool set_compressed(const char *method); |
| 4485 | void set_compression_method(Compression_method *compression_method_arg) |
| 4486 | { compression_method_ptr= compression_method_arg; } |
| 4487 | Compression_method *compression_method() const |
| 4488 | { return compression_method_ptr; } |
| 4489 | }; |
| 4490 | |
| 4491 | |
| 4492 | /** |
| 4493 | List of ROW element definitions, e.g.: |
| 4494 | DECLARE a ROW(a INT,b VARCHAR(10)) |
| 4495 | */ |
| 4496 | class Row_definition_list: public List<class Spvar_definition> |
| 4497 | { |
| 4498 | public: |
| 4499 | inline bool eq_name(const Spvar_definition *def, const LEX_CSTRING *name) const; |
| 4500 | /** |
| 4501 | Find a ROW field by name. |
| 4502 | @param [IN] name - the name |
| 4503 | @param [OUT] offset - if the ROW field found, its offset it returned here |
| 4504 | @retval NULL - the ROW field was not found |
| 4505 | @retval !NULL - the pointer to the found ROW field |
| 4506 | */ |
| 4507 | Spvar_definition *find_row_field_by_name(const LEX_CSTRING *name, uint *offset) const |
| 4508 | { |
| 4509 | // Cast-off the "const" qualifier |
| 4510 | List_iterator<Spvar_definition> it(*((List<Spvar_definition>*)this)); |
| 4511 | Spvar_definition *def; |
| 4512 | for (*offset= 0; (def= it++); (*offset)++) |
| 4513 | { |
| 4514 | if (eq_name(def, name)) |
| 4515 | return def; |
| 4516 | } |
| 4517 | return 0; |
| 4518 | } |
| 4519 | bool adjust_formal_params_to_actual_params(THD *thd, List<Item> *args); |
| 4520 | bool adjust_formal_params_to_actual_params(THD *thd, |
| 4521 | Item **args, uint arg_count); |
| 4522 | bool resolve_type_refs(THD *); |
| 4523 | }; |
| 4524 | |
| 4525 | /** |
| 4526 | This class is used during a stored routine or a trigger execution, |
| 4527 | at sp_rcontext::create() time. |
| 4528 | Currently it can represent: |
| 4529 | - variables with explicit data types: DECLARE a INT; |
| 4530 | - variables with data type references: DECLARE a t1.a%TYPE; |
| 4531 | - ROW type variables |
| 4532 | |
| 4533 | Notes: |
| 4534 | - Scalar variables have m_field_definitions==NULL. |
| 4535 | - ROW variables are defined as having MYSQL_TYPE_NULL, |
| 4536 | with a non-empty m_field_definitions. |
| 4537 | |
| 4538 | Data type references to other object types will be added soon, e.g.: |
| 4539 | - DECLARE a table_name%ROWTYPE; |
| 4540 | - DECLARE a cursor_name%ROWTYPE; |
| 4541 | - DECLARE a record_name%TYPE; |
| 4542 | - DECLARE a variable_name%TYPE; |
| 4543 | */ |
| 4544 | class Spvar_definition: public Column_definition |
| 4545 | { |
| 4546 | Qualified_column_ident *m_column_type_ref; // for %TYPE |
| 4547 | Table_ident *m_table_rowtype_ref; // for table%ROWTYPE |
| 4548 | bool m_cursor_rowtype_ref; // for cursor%ROWTYPE |
| 4549 | uint m_cursor_rowtype_offset; // for cursor%ROWTYPE |
| 4550 | Row_definition_list *m_row_field_definitions; // for ROW |
| 4551 | public: |
| 4552 | Spvar_definition() |
| 4553 | :m_column_type_ref(NULL), |
| 4554 | m_table_rowtype_ref(NULL), |
| 4555 | m_cursor_rowtype_ref(false), |
| 4556 | m_cursor_rowtype_offset(0), |
| 4557 | m_row_field_definitions(NULL) |
| 4558 | { } |
| 4559 | Spvar_definition(THD *thd, Field *field) |
| 4560 | :Column_definition(thd, field, NULL), |
| 4561 | m_column_type_ref(NULL), |
| 4562 | m_table_rowtype_ref(NULL), |
| 4563 | m_cursor_rowtype_ref(false), |
| 4564 | m_cursor_rowtype_offset(0), |
| 4565 | m_row_field_definitions(NULL) |
| 4566 | { } |
| 4567 | const Type_handler *type_handler() const |
| 4568 | { |
| 4569 | return Type_handler_hybrid_field_type::type_handler(); |
| 4570 | } |
| 4571 | bool is_column_type_ref() const { return m_column_type_ref != 0; } |
| 4572 | bool is_table_rowtype_ref() const { return m_table_rowtype_ref != 0; } |
| 4573 | bool is_cursor_rowtype_ref() const { return m_cursor_rowtype_ref; } |
| 4574 | bool is_explicit_data_type() const |
| 4575 | { |
| 4576 | return !is_column_type_ref() && |
| 4577 | !is_table_rowtype_ref() && |
| 4578 | !is_cursor_rowtype_ref(); |
| 4579 | } |
| 4580 | Qualified_column_ident *column_type_ref() const |
| 4581 | { |
| 4582 | return m_column_type_ref; |
| 4583 | } |
| 4584 | void set_column_type_ref(Qualified_column_ident *ref) |
| 4585 | { |
| 4586 | m_column_type_ref= ref; |
| 4587 | } |
| 4588 | |
| 4589 | Table_ident *table_rowtype_ref() const |
| 4590 | { |
| 4591 | return m_table_rowtype_ref; |
| 4592 | } |
| 4593 | void set_table_rowtype_ref(Table_ident *ref) |
| 4594 | { |
| 4595 | DBUG_ASSERT(ref); |
| 4596 | set_handler(&type_handler_row); |
| 4597 | m_table_rowtype_ref= ref; |
| 4598 | } |
| 4599 | |
| 4600 | uint cursor_rowtype_offset() const |
| 4601 | { |
| 4602 | return m_cursor_rowtype_offset; |
| 4603 | } |
| 4604 | void set_cursor_rowtype_ref(uint offset) |
| 4605 | { |
| 4606 | set_handler(&type_handler_row); |
| 4607 | m_cursor_rowtype_ref= true; |
| 4608 | m_cursor_rowtype_offset= offset; |
| 4609 | } |
| 4610 | |
| 4611 | /* |
| 4612 | Find a ROW field by name. |
| 4613 | See Row_field_list::find_row_field_by_name() for details. |
| 4614 | */ |
| 4615 | Spvar_definition *find_row_field_by_name(const LEX_CSTRING *name, uint *offset) const |
| 4616 | { |
| 4617 | DBUG_ASSERT(m_row_field_definitions); |
| 4618 | return m_row_field_definitions->find_row_field_by_name(name, offset); |
| 4619 | } |
| 4620 | uint is_row() const |
| 4621 | { |
| 4622 | return m_row_field_definitions != NULL; |
| 4623 | } |
| 4624 | // Check if "this" defines a ROW variable with n elements |
| 4625 | uint is_row(uint n) const |
| 4626 | { |
| 4627 | return m_row_field_definitions != NULL && |
| 4628 | m_row_field_definitions->elements == n; |
| 4629 | } |
| 4630 | Row_definition_list *row_field_definitions() const |
| 4631 | { |
| 4632 | return m_row_field_definitions; |
| 4633 | } |
| 4634 | void set_row_field_definitions(Row_definition_list *list) |
| 4635 | { |
| 4636 | DBUG_ASSERT(list); |
| 4637 | set_handler(&type_handler_row); |
| 4638 | m_row_field_definitions= list; |
| 4639 | } |
| 4640 | |
| 4641 | }; |
| 4642 | |
| 4643 | |
| 4644 | inline bool Row_definition_list::eq_name(const Spvar_definition *def, |
| 4645 | const LEX_CSTRING *name) const |
| 4646 | { |
| 4647 | return def->field_name.length == name->length && my_strcasecmp(system_charset_info, def->field_name.str, name->str) == 0; |
| 4648 | } |
| 4649 | |
| 4650 | |
| 4651 | class Create_field :public Column_definition |
| 4652 | { |
| 4653 | public: |
| 4654 | LEX_CSTRING change; // If done with alter table |
| 4655 | LEX_CSTRING after; // Put column after this one |
| 4656 | Field *field; // For alter table |
| 4657 | TYPELIB *save_interval; // Temporary copy for the above |
| 4658 | // Used only for UCS2 intervals |
| 4659 | |
| 4660 | /** structure with parsed options (for comparing fields in ALTER TABLE) */ |
| 4661 | ha_field_option_struct *option_struct; |
| 4662 | uint offset; |
| 4663 | uint8 interval_id; // For rea_create_table |
| 4664 | bool create_if_not_exists; // Used in ALTER TABLE IF NOT EXISTS |
| 4665 | |
| 4666 | Create_field(): |
| 4667 | Column_definition(), |
| 4668 | field(0), option_struct(NULL), |
| 4669 | create_if_not_exists(false) |
| 4670 | { |
| 4671 | change= after= null_clex_str; |
| 4672 | } |
| 4673 | Create_field(THD *thd, Field *old_field, Field *orig_field): |
| 4674 | Column_definition(thd, old_field, orig_field), |
| 4675 | change(old_field->field_name), |
| 4676 | field(old_field), option_struct(old_field->option_struct), |
| 4677 | create_if_not_exists(false) |
| 4678 | { |
| 4679 | after= null_clex_str; |
| 4680 | } |
| 4681 | /* Used to make a clone of this object for ALTER/CREATE TABLE */ |
| 4682 | Create_field *clone(MEM_ROOT *mem_root) const; |
| 4683 | }; |
| 4684 | |
| 4685 | |
| 4686 | /* |
| 4687 | A class for sending info to the client |
| 4688 | */ |
| 4689 | |
| 4690 | class Send_field :public Sql_alloc { |
| 4691 | public: |
| 4692 | const char *db_name; |
| 4693 | const char *table_name,*org_table_name; |
| 4694 | LEX_CSTRING col_name, org_col_name; |
| 4695 | ulong length; |
| 4696 | uint flags, decimals; |
| 4697 | enum_field_types type; |
| 4698 | Send_field() {} |
| 4699 | }; |
| 4700 | |
| 4701 | |
| 4702 | /* |
| 4703 | A class for quick copying data to fields |
| 4704 | */ |
| 4705 | |
| 4706 | class Copy_field :public Sql_alloc { |
| 4707 | public: |
| 4708 | uchar *from_ptr,*to_ptr; |
| 4709 | uchar *from_null_ptr,*to_null_ptr; |
| 4710 | bool *null_row; |
| 4711 | uint from_bit,to_bit; |
| 4712 | /** |
| 4713 | Number of bytes in the fields pointed to by 'from_ptr' and |
| 4714 | 'to_ptr'. Usually this is the number of bytes that are copied from |
| 4715 | 'from_ptr' to 'to_ptr'. |
| 4716 | |
| 4717 | For variable-length fields (VARCHAR), the first byte(s) describe |
| 4718 | the actual length of the text. For VARCHARs with length |
| 4719 | < 256 there is 1 length byte |
| 4720 | >= 256 there is 2 length bytes |
| 4721 | Thus, if from_field is VARCHAR(10), from_length (and in most cases |
| 4722 | to_length) is 11. For VARCHAR(1024), the length is 1026. @see |
| 4723 | Field_varstring::length_bytes |
| 4724 | |
| 4725 | Note that for VARCHARs, do_copy() will be do_varstring*() which |
| 4726 | only copies the length-bytes (1 or 2) + the actual length of the |
| 4727 | text instead of from/to_length bytes. |
| 4728 | */ |
| 4729 | uint from_length,to_length; |
| 4730 | Field *from_field,*to_field; |
| 4731 | String tmp; // For items |
| 4732 | |
| 4733 | Copy_field() {} |
| 4734 | ~Copy_field() {} |
| 4735 | void set(Field *to,Field *from,bool save); // Field to field |
| 4736 | void set(uchar *to,Field *from); // Field to string |
| 4737 | void (*do_copy)(Copy_field *); |
| 4738 | void (*do_copy2)(Copy_field *); // Used to handle null values |
| 4739 | }; |
| 4740 | |
| 4741 | |
| 4742 | uint pack_length_to_packflag(uint type); |
| 4743 | enum_field_types get_blob_type_from_length(ulong length); |
| 4744 | int set_field_to_null(Field *field); |
| 4745 | int set_field_to_null_with_conversions(Field *field, bool no_conversions); |
| 4746 | int convert_null_to_field_value_or_error(Field *field); |
| 4747 | bool check_expression(Virtual_column_info *vcol, LEX_CSTRING *name, |
| 4748 | enum_vcol_info_type type); |
| 4749 | |
| 4750 | /* |
| 4751 | The following are for the interface with the .frm file |
| 4752 | */ |
| 4753 | |
| 4754 | #define FIELDFLAG_DECIMAL 1U |
| 4755 | #define FIELDFLAG_BINARY 1U // Shares same flag |
| 4756 | #define FIELDFLAG_NUMBER 2U |
| 4757 | #define FIELDFLAG_ZEROFILL 4U |
| 4758 | #define FIELDFLAG_PACK 120U // Bits used for packing |
| 4759 | #define FIELDFLAG_INTERVAL 256U // mangled with decimals! |
| 4760 | #define FIELDFLAG_BITFIELD 512U // mangled with decimals! |
| 4761 | #define FIELDFLAG_BLOB 1024U // mangled with decimals! |
| 4762 | #define FIELDFLAG_GEOM 2048U // mangled with decimals! |
| 4763 | |
| 4764 | #define FIELDFLAG_TREAT_BIT_AS_CHAR 4096U /* use Field_bit_as_char */ |
| 4765 | #define FIELDFLAG_LONG_DECIMAL 8192U |
| 4766 | #define FIELDFLAG_NO_DEFAULT 16384U /* sql */ |
| 4767 | #define FIELDFLAG_MAYBE_NULL 32768U // sql |
| 4768 | #define FIELDFLAG_HEX_ESCAPE 0x10000U |
| 4769 | #define FIELDFLAG_PACK_SHIFT 3 |
| 4770 | #define FIELDFLAG_DEC_SHIFT 8 |
| 4771 | #define FIELDFLAG_MAX_DEC 63U |
| 4772 | |
| 4773 | #define MTYP_TYPENR(type) (type & 127U) /* Remove bits from type */ |
| 4774 | |
| 4775 | #define f_is_dec(x) ((x) & FIELDFLAG_DECIMAL) |
| 4776 | #define f_is_num(x) ((x) & FIELDFLAG_NUMBER) |
| 4777 | #define f_is_zerofill(x) ((x) & FIELDFLAG_ZEROFILL) |
| 4778 | #define f_is_packed(x) ((x) & FIELDFLAG_PACK) |
| 4779 | #define f_packtype(x) (((x) >> FIELDFLAG_PACK_SHIFT) & 15) |
| 4780 | #define f_decimals(x) ((uint8) (((x) >> FIELDFLAG_DEC_SHIFT) & FIELDFLAG_MAX_DEC)) |
| 4781 | #define f_is_alpha(x) (!f_is_num(x)) |
| 4782 | #define f_is_binary(x) ((x) & FIELDFLAG_BINARY) // 4.0- compatibility |
| 4783 | #define f_is_enum(x) (((x) & (FIELDFLAG_INTERVAL | FIELDFLAG_NUMBER)) == FIELDFLAG_INTERVAL) |
| 4784 | #define f_is_bitfield(x) (((x) & (FIELDFLAG_BITFIELD | FIELDFLAG_NUMBER)) == FIELDFLAG_BITFIELD) |
| 4785 | #define f_is_blob(x) (((x) & (FIELDFLAG_BLOB | FIELDFLAG_NUMBER)) == FIELDFLAG_BLOB) |
| 4786 | #define f_is_geom(x) (((x) & (FIELDFLAG_GEOM | FIELDFLAG_NUMBER)) == FIELDFLAG_GEOM) |
| 4787 | #define f_settype(x) (((uint) (x)) << FIELDFLAG_PACK_SHIFT) |
| 4788 | #define f_maybe_null(x) ((x) & FIELDFLAG_MAYBE_NULL) |
| 4789 | #define f_no_default(x) ((x) & FIELDFLAG_NO_DEFAULT) |
| 4790 | #define f_bit_as_char(x) ((x) & FIELDFLAG_TREAT_BIT_AS_CHAR) |
| 4791 | #define f_is_hex_escape(x) ((x) & FIELDFLAG_HEX_ESCAPE) |
| 4792 | #define f_visibility(x) (static_cast<field_visibility_t> ((x) & INVISIBLE_MAX_BITS)) |
| 4793 | |
| 4794 | inline |
| 4795 | ulonglong TABLE::vers_end_id() const |
| 4796 | { |
| 4797 | DBUG_ASSERT(versioned(VERS_TRX_ID)); |
| 4798 | return static_cast<ulonglong>(vers_end_field()->val_int()); |
| 4799 | } |
| 4800 | |
| 4801 | inline |
| 4802 | ulonglong TABLE::vers_start_id() const |
| 4803 | { |
| 4804 | DBUG_ASSERT(versioned(VERS_TRX_ID)); |
| 4805 | return static_cast<ulonglong>(vers_start_field()->val_int()); |
| 4806 | } |
| 4807 | |
| 4808 | |
| 4809 | #endif /* FIELD_INCLUDED */ |
| 4810 | |