19 #include "my_global.h"
20 #include "sql_plist.h"
21 #include "sql_alloc.h"
29 #include "mysql_com.h"
31 #include "filesort_utils.h"
32 #include "parse_file.h"
41 class st_select_lex_unit;
45 class Security_context;
57 typedef ulonglong nested_join_map;
60 #define tmp_file_prefix "#sql"
61 #define tmp_file_prefix_length 4
62 #define TMP_TABLE_KEY_EXTRA 8
79 enum enum_table_ref_type
93 enum enum_ident_name_check
120 virtual void change_env(THD *thd)
const = 0;
156 virtual void change_env(THD *thd)
const;
217 enum_order direction;
229 table_map used, depend_map;
318 NO_TMP_TABLE, NON_TRANSACTIONAL_TMP_TABLE, TRANSACTIONAL_TMP_TABLE,
319 INTERNAL_TMP_TABLE, SYSTEM_TMP_TABLE
321 enum release_type { RELEASE_NORMAL, RELEASE_WAIT_FOR_DROP };
337 uchar *record_pointers;
338 ha_rows found_records;
351 uchar **get_sort_keys()
354 uchar **alloc_sort_buffer(uint num_records, uint record_length)
357 std::pair<uint, uint> sort_buffer_properties()
const
360 void free_sort_buffer()
363 void init_record_pointers()
366 size_t sort_buffer_size()
const
376 enum enum_table_category
381 TABLE_UNKNOWN_CATEGORY=0,
394 TABLE_CATEGORY_TEMPORARY=1,
404 TABLE_CATEGORY_USER=2,
416 TABLE_CATEGORY_SYSTEM=3,
438 TABLE_CATEGORY_INFORMATION=4,
460 TABLE_CATEGORY_LOG=5,
482 TABLE_CATEGORY_PERFORMANCE=6,
501 TABLE_CATEGORY_RPL_INFO=7
503 typedef enum enum_table_category TABLE_CATEGORY;
505 TABLE_CATEGORY get_table_category(
const LEX_STRING *db,
509 extern ulong refresh_version;
529 virtual void report_error(uint
code,
const char *
fmt, ...)= 0;
550 uint m_deadlock_weight;
553 uint deadlock_weight_arg)
554 : m_ctx(ctx_arg), m_share(share_arg),
555 m_deadlock_weight(deadlock_weight_arg)
562 virtual uint get_deadlock_weight()
const;
575 &Wait_for_flush::prev_in_share> >
611 Field **found_next_number_field;
615 uchar *default_values;
643 ha_rows min_rows, max_rows;
644 ulong avg_row_length;
653 return db_plugin ? plugin_data(db_plugin,
handlerton*) : NULL;
655 enum row_type row_type;
656 enum tmp_table_type tmp_table;
660 uint stats_sample_pages;
662 enum_stats_auto_recalc stats_auto_recalc;
663 uint null_bytes, last_null_bit_pos;
665 uint rec_buff_length;
671 uint max_unique_length;
672 uint total_key_length;
677 uint db_create_options;
678 uint db_options_in_use;
679 uint db_record_offset;
680 uint rowid_field_offset;
683 uint next_number_index;
684 uint next_number_key_offset;
685 uint next_number_keypart;
686 uint error, open_errno, errarg;
687 uint column_bitmap_size;
689 bool null_field_first;
692 bool db_low_byte_first;
703 int cached_row_logging_check;
710 enum ha_storage_media default_storage_media;
715 #ifdef WITH_PARTITION_STORAGE_ENGINE
717 bool auto_partitioned;
718 char *partition_info_str;
719 uint partition_info_str_len;
720 uint partition_info_buffer_size;
770 void set_table_cache_key(
char *key_buff, uint key_length)
772 table_cache_key.str= key_buff;
773 table_cache_key.length= key_length;
778 db.str= table_cache_key.str;
779 db.length= strlen(db.str);
780 table_name.str= db.str + db.length + 1;
781 table_name.length= strlen(table_name.str);
800 void set_table_cache_key(
char *key_buff,
const char *key, uint key_length)
802 memcpy(key_buff, key, key_length);
803 set_table_cache_key(key_buff, key_length);
806 inline bool honor_global_locks()
812 inline ulonglong get_table_def_version()
821 return version != refresh_version;
832 return TABLE_REF_VIEW;
835 return TABLE_REF_BASE_TABLE;
836 case SYSTEM_TMP_TABLE:
837 return TABLE_REF_I_S_TABLE;
839 return TABLE_REF_TMP_TABLE;
899 return (tmp_table == SYSTEM_TMP_TABLE) ? 0 : table_map_id.id();
906 uint deadlock_weight);
926 bool truncated_value;
930 init_alloc_root(&storage, MAX_FIELD_VARCHARLENGTH, 0);
934 free_root(&storage, MYF(0));
938 free_root(&storage, MYF(MY_MARK_BLOCKS_FREE));
939 truncated_value=
false;
951 char *
store(
const char *from, uint length)
953 return (
char*) memdup_root(&storage, from, length);
955 void set_truncated_value(
bool is_truncated_value)
957 truncated_value= is_truncated_value;
959 bool is_truncated_value() {
return truncated_value; }
995 TABLE *cache_next, **cache_prev;
1009 uchar *write_row_record;
1011 uchar *insert_values;
1017 key_map quick_keys, merge_keys;
1043 key_map keys_in_use_for_query;
1045 key_map keys_in_use_for_group_by;
1047 key_map keys_in_use_for_order_by;
1050 Field *next_number_field;
1051 Field *found_next_number_field;
1061 my_bitmap_map *bitmap_init_value;
1062 MY_BITMAP def_read_set, def_write_set, tmp_set;
1082 query_id_t query_id;
1088 ha_rows quick_rows[MAX_KEY];
1091 key_part_map const_key_parts[MAX_KEY];
1093 uint quick_key_parts[MAX_KEY];
1094 uint quick_n_ranges[MAX_KEY];
1104 ha_rows quick_condition_rows;
1108 uint lock_data_start;
1110 uint tablenr,used_fields;
1111 uint temp_pool_slot;
1135 my_bool force_index;
1148 my_bool distinct,const_table,no_rows;
1156 my_bool locked_by_logger;
1161 my_bool locked_by_name;
1162 my_bool fulltext_searched;
1165 my_bool open_by_handler;
1171 my_bool auto_increment_field_not_null;
1172 my_bool insert_or_update;
1173 my_bool alias_name_used;
1174 my_bool get_fields_in_item_tree;
1175 my_bool m_needs_reopen;
1196 #ifdef WITH_PARTITION_STORAGE_ENGINE
1199 bool all_partitions_pruned_away;
1204 bool fill_item_list(
List<Item> *item_list)
const;
1205 void reset_item_list(
List<Item> *item_list)
const;
1206 void clear_column_bitmaps(
void);
1208 void mark_columns_used_by_index_no_reset(uint
index,
MY_BITMAP *map);
1209 void mark_columns_used_by_index(uint
index);
1210 void mark_auto_increment_column(
void);
1212 void mark_columns_needed_for_delete(
void);
1213 void mark_columns_needed_for_insert(
void);
1215 inline void column_bitmaps_set(
MY_BITMAP *read_set_arg,
1218 read_set= read_set_arg;
1219 write_set= write_set_arg;
1220 if (
file && created)
1221 file->column_bitmaps_signal();
1223 inline void column_bitmaps_set_no_signal(
MY_BITMAP *read_set_arg,
1226 read_set= read_set_arg;
1227 write_set= write_set_arg;
1229 inline void use_all_columns()
1231 column_bitmaps_set(&s->all_set, &s->all_set);
1233 inline void default_column_bitmaps()
1235 read_set= &def_read_set;
1236 write_set= &def_write_set;
1240 {
return !db_stat || m_needs_reopen; }
1242 bool add_tmp_key(Field_map *key_parts,
char *key_name);
1243 void use_index(
int key_to_save);
1245 void set_keyread(
bool flag)
1252 file->extra(HA_EXTRA_KEYREAD);
1258 file->extra(HA_EXTRA_NO_KEYREAD);
1278 file->extra(HA_EXTRA_KEYREAD);
1292 enum enum_schema_table_state
1295 PROCESSED_BY_CREATE_SORT_INDEX,
1296 PROCESSED_BY_JOIN_EXEC
1313 #define MY_I_S_MAYBE_NULL 1
1314 #define MY_I_S_UNSIGNED 2
1317 #define SKIP_OPEN_TABLE 0 // do not open table
1318 #define OPEN_FRM_ONLY 1 // open FRM file only
1319 #define OPEN_FULL_TABLE 2 // open FRM,MYD, MYI files
1348 const char* old_name;
1361 const char* table_name;
1371 int idx_field1, idx_field2;
1373 uint i_s_requested_object;
1377 #define JOIN_TYPE_LEFT 1
1378 #define JOIN_TYPE_RIGHT 2
1380 enum enum_derived_type {
1381 VIEW_ALGORITHM_UNDEFINED = 0,
1382 VIEW_ALGORITHM_TMPTABLE,
1383 VIEW_ALGORITHM_MERGE,
1384 DERIVED_ALGORITHM_TMPTABLE
1387 #define VIEW_SUID_INVOKER 0
1388 #define VIEW_SUID_DEFINER 1
1389 #define VIEW_SUID_DEFAULT 2
1392 #define VIEW_CHECK_NONE 0
1393 #define VIEW_CHECK_LOCAL 1
1394 #define VIEW_CHECK_CASCADED 2
1397 #define VIEW_CHECK_OK 0
1398 #define VIEW_CHECK_ERROR 1
1399 #define VIEW_CHECK_SKIP 2
1402 #define MAX_TDC_BLOB_SIZE 65536
1405 class TMP_TABLE_PARAM;
1438 Item *create_item(THD *thd);
1440 const char *table_name();
1441 const char *db_name();
1452 OT_TEMPORARY_OR_BASE= 0, OT_TEMPORARY_ONLY, OT_BASE_ONLY
1466 table_map referenced_by;
1467 Field_map used_fields;
1519 size_t db_length_arg,
1520 const char *table_name_arg,
1521 size_t table_name_length_arg,
1522 const char *alias_arg,
1523 enum thr_lock_type lock_type_arg)
1525 memset(
this, 0,
sizeof(*
this));
1526 db= (
char*) db_name_arg;
1527 db_length= db_length_arg;
1528 table_name= (
char*) table_name_arg;
1529 table_name_length= table_name_length_arg;
1530 alias= (
char*) alias_arg;
1531 lock_type= lock_type_arg;
1532 mdl_request.
init(MDL_key::TABLE, db, table_name,
1533 (lock_type >= TL_WRITE_ALLOW_WRITE) ?
1534 MDL_SHARED_WRITE : MDL_SHARED_READ,
1544 class st_select_lex *select);
1555 char *db, *alias, *table_name, *schema_table_name;
1568 Item **join_cond_ref() {
return &m_join_cond; }
1569 Item *join_cond()
const {
return m_join_cond; }
1571 {
return m_join_cond= val; }
1580 Item *prep_join_cond;
1589 table_map sj_inner_tables;
1604 bool is_natural_join;
1613 bool is_join_columns_complete;
1631 select_union *derived_result;
1666 bool derived_keys_ready;
1668 st_select_lex *schema_select_lex;
1673 bool schema_table_reformed;
1674 TMP_TABLE_PARAM *schema_table_param;
1676 st_select_lex *select_lex;
1706 Security_context *security_ctx;
1711 Security_context *view_sctx;
1728 ulonglong file_version;
1729 ulonglong updatable_view;
1739 ulonglong view_suid;
1740 ulonglong with_check;
1745 uint8 effective_with_check;
1757 ulonglong engine_data;
1759 qc_engine_callback callback_func;
1760 thr_lock_type lock_type;
1764 size_t table_name_length;
1770 table_map dep_tables;
1771 table_map on_expr_dep_tables;
1775 bool cacheable_table;
1777 bool table_in_first_from_clause;
1784 bool contain_auto_increment;
1785 bool multitable_view;
1786 bool compact_view_format;
1788 bool where_processed;
1790 bool check_option_processed;
1792 enum frm_type_enum required_type;
1793 char timestamp_buffer[20];
1798 bool prelocking_placeholder;
1817 bool internal_tmp_table;
1860 bool optimized_away;
1861 uint i_s_requested_object;
1862 bool has_db_lookup_value;
1863 bool has_table_lookup_value;
1864 uint table_open_method;
1865 enum enum_schema_table_state schema_table_state;
1869 #ifdef WITH_PARTITION_STORAGE_ENGINE
1874 void calc_md5(
char *buffer);
1876 int view_check_option(THD *thd,
bool ignore_failure)
const;
1877 bool setup_underlying(THD *thd);
1883 void print(THD *thd,
String *str, enum_query_type query_type);
1886 bool set_insert_values(
MEM_ROOT *mem_root);
1889 TABLE_LIST *first_leaf_for_name_resolution();
1891 bool is_leaf_for_name_resolution();
1893 {
return belong_to_view ? belong_to_view :
this; }
1901 inline bool prepare_check_option(THD *thd)
1904 if (effective_with_check)
1905 res= prep_check_option(thd, effective_with_check);
1908 inline bool prepare_where(THD *thd,
Item **conds,
1909 bool no_where_clause)
1912 return prep_where(thd, conds, no_where_clause);
1925 inline bool is_view_or_derived()
const
1937 void register_want_access(ulong want_access);
1938 bool prepare_security(THD *thd);
1939 #ifndef NO_EMBEDDED_ACCESS_CHECKS
1940 Security_context *find_view_security_context(THD *thd);
1941 bool prepare_view_securety_context(THD *thd);
1947 void reinit_before_use(THD *thd);
1983 ulonglong table_ref_version_arg)
1985 m_table_ref_type= table_ref_type_arg;
1986 m_table_ref_version= table_ref_version_arg;
2012 bool update_derived_keys(
Field*,
Item**, uint);
2014 bool handle_derived(LEX *lex,
bool (*processor)(THD*, LEX*,
TABLE_LIST*));
2015 st_select_lex_unit *
get_unit()
const;
2038 if (embedding->sj_on_expr)
2039 return embedding->embedding;
2044 bool prep_check_option(THD *thd, uint8 check_opt_type);
2045 bool prep_where(THD *thd,
Item **conds,
bool no_where_clause);
2047 enum enum_table_ref_type m_table_ref_type;
2049 ulonglong m_table_ref_version;
2067 virtual void next()= 0;
2068 virtual bool end_of_fields()= 0;
2069 virtual const char *name()= 0;
2070 virtual Item *create_item(THD *)= 0;
2071 virtual Field *field()= 0;
2086 void set_table(
TABLE *
table) { ptr= table->field; }
2087 void next() { ptr++; }
2088 bool end_of_fields() {
return *ptr == 0; }
2090 Item *create_item(THD *thd);
2091 Field *field() {
return *ptr; }
2104 void next() { ptr++; }
2105 bool end_of_fields() {
return ptr == array_end; }
2107 Item *create_item(THD *thd);
2108 Item **item_ptr() {
return &ptr->item; }
2109 Field *field() {
return 0; }
2110 inline Item *item() {
return ptr->item; }
2129 bool end_of_fields() {
return !cur_column_ref; }
2130 const char *name() {
return cur_column_ref->name(); }
2131 Item *create_item(THD *thd) {
return cur_column_ref->create_item(thd); }
2132 Field *field() {
return cur_column_ref->field(); }
2155 TABLE_LIST *table_ref, *first_leaf, *last_leaf;
2160 void set_field_iterator();
2165 bool end_of_fields()
2166 {
return (table_ref == last_leaf && field_it->end_of_fields()); }
2167 const char *name() {
return field_it->name(); }
2168 const char *get_table_name();
2169 const char *get_db_name();
2171 Item *create_item(THD *thd) {
return field_it->create_item(thd); }
2172 Field *field() {
return field_it->field(); }
2214 table_map used_tables;
2215 table_map not_null_tables;
2274 uint32 in_use,locked;
2278 static inline my_bitmap_map *tmp_use_all_columns(
TABLE *
table,
2281 my_bitmap_map *old= bitmap->bitmap;
2282 bitmap->bitmap= table->s->all_set.bitmap;
2287 static inline void tmp_restore_column_map(
MY_BITMAP *bitmap,
2290 bitmap->bitmap= old;
2295 static inline my_bitmap_map *dbug_tmp_use_all_columns(
TABLE *
table,
2299 return tmp_use_all_columns(table, bitmap);
2305 static inline void dbug_tmp_restore_column_map(
MY_BITMAP *bitmap,
2309 tmp_restore_column_map(bitmap, old);
2318 static inline void dbug_tmp_use_all_columns(
TABLE *
table,
2319 my_bitmap_map **save,
2324 save[0]= read_set->bitmap;
2325 save[1]= write_set->bitmap;
2326 (void) tmp_use_all_columns(table, read_set);
2327 (void) tmp_use_all_columns(table, write_set);
2332 static inline void dbug_tmp_restore_column_maps(
MY_BITMAP *read_set,
2334 my_bitmap_map **old)
2337 tmp_restore_column_map(read_set, old[0]);
2338 tmp_restore_column_map(write_set, old[1]);
2343 size_t max_row_length(
TABLE *table,
const uchar *data);
2346 void init_mdl_requests(
TABLE_LIST *table_list);
2348 int open_table_from_share(THD *thd,
TABLE_SHARE *share,
const char *alias,
2349 uint db_stat, uint prgflag, uint ha_open_flags,
2350 TABLE *outparam,
bool is_create_table);
2353 void init_tmp_table_share(THD *thd,
TABLE_SHARE *share,
const char *key,
2357 int open_table_def(THD *thd,
TABLE_SHARE *share, uint db_flags);
2358 void open_table_error(
TABLE_SHARE *share,
int error,
int db_errno,
int errarg);
2360 enum_ident_name_check check_and_convert_db_name(
LEX_STRING *db,
2361 bool preserve_lettercase);
2362 bool check_column_name(
const char *
name);
2363 enum_ident_name_check check_table_name(
const char *
name,
size_t length,
2364 bool check_for_path_chars);
2365 int rename_file_ext(
const char * from,
const char *
to,
const char * ext);
2369 int closefrm(
TABLE *table,
bool free_share);
2370 int read_string(File
file, uchar* *
to,
size_t length);
2371 void free_blobs(
TABLE *table);
2372 void free_field_buffers_larger_than(
TABLE *table, uint32
size);
2373 int set_zone(
int nr,
int min_zone,
int max_zone);
2374 ulong get_form_pos(File
file, uchar *head,
TYPELIB *save_names);
2376 const char *newname);
2377 ulong next_io_size(ulong pos);
2378 void append_unescaped(
String *res,
const char *pos, uint length);
2379 File create_frm(THD *thd,
const char *
name,
const char *db,
2380 const char *table, uint reclength, uchar *
fileinfo,
2382 char *fn_rext(
char *
name);
2385 extern LEX_STRING PERFORMANCE_SCHEMA_DB_NAME;
2399 inline bool is_infoschema_db(
const char *
name,
size_t len)
2401 return (INFORMATION_SCHEMA_NAME.length == len &&
2402 !my_strcasecmp(system_charset_info,
2403 INFORMATION_SCHEMA_NAME.str, name));
2406 inline bool is_infoschema_db(
const char *name)
2408 return !my_strcasecmp(system_charset_info,
2409 INFORMATION_SCHEMA_NAME.str, name);
2417 inline bool is_user_table(
TABLE * table)
2419 const char *name= table->s->table_name.str;
2423 inline void mark_as_null_row(
TABLE *table)
2426 table->status|=STATUS_NULL_ROW;
2427 memset(table->null_flags, 255, table->s->null_bytes);
2430 bool is_simple_order(
ORDER *order);