1 | #ifndef TABLE_INCLUDED |
2 | #define TABLE_INCLUDED |
3 | /* Copyright (c) 2000, 2017, Oracle and/or its affiliates. |
4 | Copyright (c) 2009, 2018, MariaDB |
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 | #include "sql_plist.h" |
20 | #include "sql_list.h" /* Sql_alloc */ |
21 | #include "mdl.h" |
22 | #include "datadict.h" |
23 | #include "sql_string.h" /* String */ |
24 | #include "lex_string.h" |
25 | |
26 | #ifndef MYSQL_CLIENT |
27 | |
28 | #include "hash.h" /* HASH */ |
29 | #include "handler.h" /* row_type, ha_choice, handler */ |
30 | #include "mysql_com.h" /* enum_field_types */ |
31 | #include "thr_lock.h" /* thr_lock_type */ |
32 | #include "filesort_utils.h" |
33 | #include "parse_file.h" |
34 | |
35 | /* Structs that defines the TABLE */ |
36 | |
37 | class Item; /* Needed by ORDER */ |
38 | typedef Item (*Item_ptr); |
39 | class Item_subselect; |
40 | class Item_field; |
41 | class GRANT_TABLE; |
42 | class st_select_lex_unit; |
43 | class st_select_lex; |
44 | class partition_info; |
45 | class COND_EQUAL; |
46 | class Security_context; |
47 | struct TABLE_LIST; |
48 | class ACL_internal_schema_access; |
49 | class ACL_internal_table_access; |
50 | class Field; |
51 | class Table_statistics; |
52 | class With_element; |
53 | struct TDC_element; |
54 | class Virtual_column_info; |
55 | class Table_triggers_list; |
56 | class TMP_TABLE_PARAM; |
57 | class SEQUENCE; |
58 | |
59 | /* |
60 | Used to identify NESTED_JOIN structures within a join (applicable only to |
61 | structures that have not been simplified away and embed more the one |
62 | element) |
63 | */ |
64 | typedef ulonglong nested_join_map; |
65 | |
66 | |
67 | #define tmp_file_prefix "#sql" /**< Prefix for tmp tables */ |
68 | #define tmp_file_prefix_length 4 |
69 | #define 8 |
70 | |
71 | /** |
72 | Enumerate possible types of a table from re-execution |
73 | standpoint. |
74 | TABLE_LIST class has a member of this type. |
75 | At prepared statement prepare, this member is assigned a value |
76 | as of the current state of the database. Before (re-)execution |
77 | of a prepared statement, we check that the value recorded at |
78 | prepare matches the type of the object we obtained from the |
79 | table definition cache. |
80 | |
81 | @sa check_and_update_table_version() |
82 | @sa Execute_observer |
83 | @sa Prepared_statement::reprepare() |
84 | */ |
85 | |
86 | enum enum_table_ref_type |
87 | { |
88 | /** Initial value set by the parser */ |
89 | TABLE_REF_NULL= 0, |
90 | TABLE_REF_VIEW, |
91 | TABLE_REF_BASE_TABLE, |
92 | TABLE_REF_I_S_TABLE, |
93 | TABLE_REF_TMP_TABLE |
94 | }; |
95 | |
96 | |
97 | /*************************************************************************/ |
98 | |
99 | /** |
100 | Object_creation_ctx -- interface for creation context of database objects |
101 | (views, stored routines, events, triggers). Creation context -- is a set |
102 | of attributes, that should be fixed at the creation time and then be used |
103 | each time the object is parsed or executed. |
104 | */ |
105 | |
106 | class Object_creation_ctx |
107 | { |
108 | public: |
109 | Object_creation_ctx *set_n_backup(THD *thd); |
110 | |
111 | void restore_env(THD *thd, Object_creation_ctx *backup_ctx); |
112 | |
113 | protected: |
114 | Object_creation_ctx() {} |
115 | virtual Object_creation_ctx *create_backup_ctx(THD *thd) const = 0; |
116 | |
117 | virtual void change_env(THD *thd) const = 0; |
118 | |
119 | public: |
120 | virtual ~Object_creation_ctx() |
121 | { } |
122 | }; |
123 | |
124 | /*************************************************************************/ |
125 | |
126 | /** |
127 | Default_object_creation_ctx -- default implementation of |
128 | Object_creation_ctx. |
129 | */ |
130 | |
131 | class Default_object_creation_ctx : public Object_creation_ctx |
132 | { |
133 | public: |
134 | CHARSET_INFO *get_client_cs() |
135 | { |
136 | return m_client_cs; |
137 | } |
138 | |
139 | CHARSET_INFO *get_connection_cl() |
140 | { |
141 | return m_connection_cl; |
142 | } |
143 | |
144 | protected: |
145 | Default_object_creation_ctx(THD *thd); |
146 | |
147 | Default_object_creation_ctx(CHARSET_INFO *client_cs, |
148 | CHARSET_INFO *connection_cl); |
149 | |
150 | protected: |
151 | virtual Object_creation_ctx *create_backup_ctx(THD *thd) const; |
152 | |
153 | virtual void change_env(THD *thd) const; |
154 | |
155 | protected: |
156 | /** |
157 | client_cs stores the value of character_set_client session variable. |
158 | The only character set attribute is used. |
159 | |
160 | Client character set is included into query context, because we save |
161 | query in the original character set, which is client character set. So, |
162 | in order to parse the query properly we have to switch client character |
163 | set on parsing. |
164 | */ |
165 | CHARSET_INFO *m_client_cs; |
166 | |
167 | /** |
168 | connection_cl stores the value of collation_connection session |
169 | variable. Both character set and collation attributes are used. |
170 | |
171 | Connection collation is included into query context, becase it defines |
172 | the character set and collation of text literals in internal |
173 | representation of query (item-objects). |
174 | */ |
175 | CHARSET_INFO *m_connection_cl; |
176 | }; |
177 | |
178 | class Query_arena; |
179 | |
180 | /*************************************************************************/ |
181 | |
182 | /** |
183 | View_creation_ctx -- creation context of view objects. |
184 | */ |
185 | |
186 | class View_creation_ctx : public Default_object_creation_ctx, |
187 | public Sql_alloc |
188 | { |
189 | public: |
190 | static View_creation_ctx *create(THD *thd); |
191 | |
192 | static View_creation_ctx *create(THD *thd, |
193 | TABLE_LIST *view); |
194 | |
195 | private: |
196 | View_creation_ctx(THD *thd) |
197 | : Default_object_creation_ctx(thd) |
198 | { } |
199 | }; |
200 | |
201 | /*************************************************************************/ |
202 | |
203 | /* Order clause list element */ |
204 | |
205 | typedef int (*fast_field_copier)(Field *to, Field *from); |
206 | |
207 | |
208 | typedef struct st_order { |
209 | struct st_order *next; |
210 | Item **item; /* Point at item in select fields */ |
211 | Item *item_ptr; /* Storage for initial item */ |
212 | /* |
213 | Reference to the function we are trying to optimize copy to |
214 | a temporary table |
215 | */ |
216 | fast_field_copier fast_field_copier_func; |
217 | /* Field for which above optimizer function setup */ |
218 | Field *fast_field_copier_setup; |
219 | int counter; /* position in SELECT list, correct |
220 | only if counter_used is true*/ |
221 | enum enum_order { |
222 | ORDER_NOT_RELEVANT, |
223 | ORDER_ASC, |
224 | ORDER_DESC |
225 | }; |
226 | |
227 | enum_order direction; /* Requested direction of ordering */ |
228 | bool in_field_list; /* true if in select field list */ |
229 | bool counter_used; /* parameter was counter of columns */ |
230 | Field *field; /* If tmp-table group */ |
231 | char *buff; /* If tmp-table group */ |
232 | table_map used; /* NOTE: the below is only set to 0 but is still used by eq_ref_table */ |
233 | table_map depend_map; |
234 | } ORDER; |
235 | |
236 | /** |
237 | State information for internal tables grants. |
238 | This structure is part of the TABLE_LIST, and is updated |
239 | during the ACL check process. |
240 | @sa GRANT_INFO |
241 | */ |
242 | struct st_grant_internal_info |
243 | { |
244 | /** True if the internal lookup by schema name was done. */ |
245 | bool m_schema_lookup_done; |
246 | /** Cached internal schema access. */ |
247 | const ACL_internal_schema_access *m_schema_access; |
248 | /** True if the internal lookup by table name was done. */ |
249 | bool m_table_lookup_done; |
250 | /** Cached internal table access. */ |
251 | const ACL_internal_table_access *m_table_access; |
252 | }; |
253 | typedef struct st_grant_internal_info GRANT_INTERNAL_INFO; |
254 | |
255 | /** |
256 | @brief The current state of the privilege checking process for the current |
257 | user, SQL statement and SQL object. |
258 | |
259 | @details The privilege checking process is divided into phases depending on |
260 | the level of the privilege to be checked and the type of object to be |
261 | accessed. Due to the mentioned scattering of privilege checking |
262 | functionality, it is necessary to keep track of the state of the |
263 | process. This information is stored in privilege, want_privilege, and |
264 | orig_want_privilege. |
265 | |
266 | A GRANT_INFO also serves as a cache of the privilege hash tables. Relevant |
267 | members are grant_table and version. |
268 | */ |
269 | typedef struct st_grant_info |
270 | { |
271 | /** |
272 | @brief A copy of the privilege information regarding the current host, |
273 | database, object and user. |
274 | |
275 | @details The version of this copy is found in GRANT_INFO::version. |
276 | */ |
277 | GRANT_TABLE *grant_table_user; |
278 | GRANT_TABLE *grant_table_role; |
279 | /** |
280 | @brief Used for cache invalidation when caching privilege information. |
281 | |
282 | @details The privilege information is stored on disk, with dedicated |
283 | caches residing in memory: table-level and column-level privileges, |
284 | respectively, have their own dedicated caches. |
285 | |
286 | The GRANT_INFO works as a level 1 cache with this member updated to the |
287 | current value of the global variable @c grant_version (@c static variable |
288 | in sql_acl.cc). It is updated Whenever the GRANT_INFO is refreshed from |
289 | the level 2 cache. The level 2 cache is the @c column_priv_hash structure |
290 | (@c static variable in sql_acl.cc) |
291 | |
292 | @see grant_version |
293 | */ |
294 | uint version; |
295 | /** |
296 | @brief The set of privileges that the current user has fulfilled for a |
297 | certain host, database, and object. |
298 | |
299 | @details This field is continually updated throughout the access checking |
300 | process. In each step the "wanted privilege" is checked against the |
301 | fulfilled privileges. When/if the intersection of these sets is empty, |
302 | access is granted. |
303 | |
304 | The set is implemented as a bitmap, with the bits defined in sql_acl.h. |
305 | */ |
306 | ulong privilege; |
307 | /** |
308 | @brief the set of privileges that the current user needs to fulfil in |
309 | order to carry out the requested operation. |
310 | */ |
311 | ulong want_privilege; |
312 | /** |
313 | Stores the requested access acl of top level tables list. Is used to |
314 | check access rights to the underlying tables of a view. |
315 | */ |
316 | ulong orig_want_privilege; |
317 | /** The grant state for internal tables. */ |
318 | GRANT_INTERNAL_INFO m_internal; |
319 | } GRANT_INFO; |
320 | |
321 | enum tmp_table_type |
322 | { |
323 | NO_TMP_TABLE, NON_TRANSACTIONAL_TMP_TABLE, TRANSACTIONAL_TMP_TABLE, |
324 | INTERNAL_TMP_TABLE, SYSTEM_TMP_TABLE |
325 | }; |
326 | enum release_type { RELEASE_NORMAL, RELEASE_WAIT_FOR_DROP }; |
327 | |
328 | enum enum_vcol_update_mode |
329 | { |
330 | VCOL_UPDATE_FOR_READ= 0, |
331 | VCOL_UPDATE_FOR_WRITE, |
332 | VCOL_UPDATE_FOR_DELETE, |
333 | VCOL_UPDATE_INDEXED, |
334 | VCOL_UPDATE_INDEXED_FOR_UPDATE, |
335 | VCOL_UPDATE_FOR_REPLACE |
336 | }; |
337 | |
338 | /* Field visibility enums */ |
339 | |
340 | enum field_visibility_t { |
341 | VISIBLE= 0, |
342 | INVISIBLE_USER, |
343 | /* automatically added by the server. Can be queried explicitly |
344 | in SELECT, otherwise invisible from anything" */ |
345 | INVISIBLE_SYSTEM, |
346 | INVISIBLE_FULL |
347 | }; |
348 | |
349 | #define INVISIBLE_MAX_BITS 3 |
350 | |
351 | |
352 | /** |
353 | Category of table found in the table share. |
354 | */ |
355 | enum enum_table_category |
356 | { |
357 | /** |
358 | Unknown value. |
359 | */ |
360 | TABLE_UNKNOWN_CATEGORY=0, |
361 | |
362 | /** |
363 | Temporary table. |
364 | The table is visible only in the session. |
365 | Therefore, |
366 | - FLUSH TABLES WITH READ LOCK |
367 | - SET GLOBAL READ_ONLY = ON |
368 | do not apply to this table. |
369 | Note that LOCK TABLE t FOR READ/WRITE |
370 | can be used on temporary tables. |
371 | Temporary tables are not part of the table cache. |
372 | */ |
373 | TABLE_CATEGORY_TEMPORARY=1, |
374 | |
375 | /** |
376 | User table. |
377 | These tables do honor: |
378 | - LOCK TABLE t FOR READ/WRITE |
379 | - FLUSH TABLES WITH READ LOCK |
380 | - SET GLOBAL READ_ONLY = ON |
381 | User tables are cached in the table cache. |
382 | */ |
383 | TABLE_CATEGORY_USER=2, |
384 | |
385 | /** |
386 | System table, maintained by the server. |
387 | These tables do honor: |
388 | - LOCK TABLE t FOR READ/WRITE |
389 | - FLUSH TABLES WITH READ LOCK |
390 | - SET GLOBAL READ_ONLY = ON |
391 | Typically, writes to system tables are performed by |
392 | the server implementation, not explicitly be a user. |
393 | System tables are cached in the table cache. |
394 | */ |
395 | TABLE_CATEGORY_SYSTEM=3, |
396 | |
397 | /** |
398 | Information schema tables. |
399 | These tables are an interface provided by the system |
400 | to inspect the system metadata. |
401 | These tables do *not* honor: |
402 | - LOCK TABLE t FOR READ/WRITE |
403 | - FLUSH TABLES WITH READ LOCK |
404 | - SET GLOBAL READ_ONLY = ON |
405 | as there is no point in locking explicitly |
406 | an INFORMATION_SCHEMA table. |
407 | Nothing is directly written to information schema tables. |
408 | Note that this value is not used currently, |
409 | since information schema tables are not shared, |
410 | but implemented as session specific temporary tables. |
411 | */ |
412 | /* |
413 | TODO: Fixing the performance issues of I_S will lead |
414 | to I_S tables in the table cache, which should use |
415 | this table type. |
416 | */ |
417 | TABLE_CATEGORY_INFORMATION=4, |
418 | |
419 | /** |
420 | Log tables. |
421 | These tables are an interface provided by the system |
422 | to inspect the system logs. |
423 | These tables do *not* honor: |
424 | - LOCK TABLE t FOR READ/WRITE |
425 | - FLUSH TABLES WITH READ LOCK |
426 | - SET GLOBAL READ_ONLY = ON |
427 | as there is no point in locking explicitly |
428 | a LOG table. |
429 | An example of LOG tables are: |
430 | - mysql.slow_log |
431 | - mysql.general_log, |
432 | which *are* updated even when there is either |
433 | a GLOBAL READ LOCK or a GLOBAL READ_ONLY in effect. |
434 | User queries do not write directly to these tables |
435 | (there are exceptions for log tables). |
436 | The server implementation perform writes. |
437 | Log tables are cached in the table cache. |
438 | */ |
439 | TABLE_CATEGORY_LOG=5, |
440 | |
441 | /** |
442 | Performance schema tables. |
443 | These tables are an interface provided by the system |
444 | to inspect the system performance data. |
445 | These tables do *not* honor: |
446 | - LOCK TABLE t FOR READ/WRITE |
447 | - FLUSH TABLES WITH READ LOCK |
448 | - SET GLOBAL READ_ONLY = ON |
449 | as there is no point in locking explicitly |
450 | a PERFORMANCE_SCHEMA table. |
451 | An example of PERFORMANCE_SCHEMA tables are: |
452 | - performance_schema.* |
453 | which *are* updated (but not using the handler interface) |
454 | even when there is either |
455 | a GLOBAL READ LOCK or a GLOBAL READ_ONLY in effect. |
456 | User queries do not write directly to these tables |
457 | (there are exceptions for SETUP_* tables). |
458 | The server implementation perform writes. |
459 | Performance tables are cached in the table cache. |
460 | */ |
461 | TABLE_CATEGORY_PERFORMANCE=6 |
462 | }; |
463 | typedef enum enum_table_category TABLE_CATEGORY; |
464 | |
465 | TABLE_CATEGORY get_table_category(const LEX_CSTRING *db, |
466 | const LEX_CSTRING *name); |
467 | |
468 | |
469 | typedef struct st_table_field_type |
470 | { |
471 | LEX_CSTRING name; |
472 | LEX_CSTRING type; |
473 | LEX_CSTRING cset; |
474 | } TABLE_FIELD_TYPE; |
475 | |
476 | |
477 | typedef struct st_table_field_def |
478 | { |
479 | uint count; |
480 | const TABLE_FIELD_TYPE *field; |
481 | uint primary_key_parts; |
482 | const uint *primary_key_columns; |
483 | } TABLE_FIELD_DEF; |
484 | |
485 | |
486 | class Table_check_intact |
487 | { |
488 | protected: |
489 | bool has_keys; |
490 | virtual void report_error(uint code, const char *fmt, ...)= 0; |
491 | |
492 | public: |
493 | Table_check_intact(bool keys= false) : has_keys(keys) {} |
494 | virtual ~Table_check_intact() {} |
495 | |
496 | /** Checks whether a table is intact. */ |
497 | bool check(TABLE *table, const TABLE_FIELD_DEF *table_def); |
498 | }; |
499 | |
500 | |
501 | /* |
502 | If the table isn't valid, report the error to the server log only. |
503 | */ |
504 | class Table_check_intact_log_error : public Table_check_intact |
505 | { |
506 | protected: |
507 | void report_error(uint, const char *fmt, ...); |
508 | public: |
509 | Table_check_intact_log_error() : Table_check_intact(true) {} |
510 | }; |
511 | |
512 | |
513 | /** |
514 | Class representing the fact that some thread waits for table |
515 | share to be flushed. Is used to represent information about |
516 | such waits in MDL deadlock detector. |
517 | */ |
518 | |
519 | class Wait_for_flush : public MDL_wait_for_subgraph |
520 | { |
521 | MDL_context *m_ctx; |
522 | TABLE_SHARE *m_share; |
523 | uint m_deadlock_weight; |
524 | public: |
525 | Wait_for_flush(MDL_context *ctx_arg, TABLE_SHARE *share_arg, |
526 | uint deadlock_weight_arg) |
527 | : m_ctx(ctx_arg), m_share(share_arg), |
528 | m_deadlock_weight(deadlock_weight_arg) |
529 | {} |
530 | |
531 | MDL_context *get_ctx() const { return m_ctx; } |
532 | |
533 | virtual bool accept_visitor(MDL_wait_for_graph_visitor *dvisitor); |
534 | |
535 | virtual uint get_deadlock_weight() const; |
536 | |
537 | /** |
538 | Pointers for participating in the list of waiters for table share. |
539 | */ |
540 | Wait_for_flush *next_in_share; |
541 | Wait_for_flush **prev_in_share; |
542 | }; |
543 | |
544 | |
545 | typedef I_P_List <Wait_for_flush, |
546 | I_P_List_adapter<Wait_for_flush, |
547 | &Wait_for_flush::next_in_share, |
548 | &Wait_for_flush::prev_in_share> > |
549 | Wait_for_flush_list; |
550 | |
551 | |
552 | enum open_frm_error { |
553 | OPEN_FRM_OK = 0, |
554 | OPEN_FRM_OPEN_ERROR, |
555 | OPEN_FRM_READ_ERROR, |
556 | OPEN_FRM_CORRUPTED, |
557 | OPEN_FRM_DISCOVER, |
558 | OPEN_FRM_ERROR_ALREADY_ISSUED, |
559 | OPEN_FRM_NOT_A_VIEW, |
560 | OPEN_FRM_NOT_A_TABLE, |
561 | OPEN_FRM_NEEDS_REBUILD |
562 | }; |
563 | |
564 | /** |
565 | Control block to access table statistics loaded |
566 | from persistent statistical tables |
567 | */ |
568 | |
569 | struct TABLE_STATISTICS_CB |
570 | { |
571 | MEM_ROOT mem_root; /* MEM_ROOT to allocate statistical data for the table */ |
572 | Table_statistics *table_stats; /* Structure to access the statistical data */ |
573 | bool stats_can_be_read; /* Memory for statistical data is allocated */ |
574 | bool stats_is_read; /* Statistical data for table has been read |
575 | from statistical tables */ |
576 | bool histograms_can_be_read; |
577 | bool histograms_are_read; |
578 | }; |
579 | |
580 | /** |
581 | This structure is shared between different table objects. There is one |
582 | instance of table share per one table in the database. |
583 | */ |
584 | |
585 | struct TABLE_SHARE |
586 | { |
587 | TABLE_SHARE() {} /* Remove gcc warning */ |
588 | |
589 | /** Category of this table. */ |
590 | TABLE_CATEGORY table_category; |
591 | |
592 | /* hash of field names (contains pointers to elements of field array) */ |
593 | HASH name_hash; /* hash of field names */ |
594 | MEM_ROOT mem_root; |
595 | TYPELIB keynames; /* Pointers to keynames */ |
596 | TYPELIB fieldnames; /* Pointer to fieldnames */ |
597 | TYPELIB *intervals; /* pointer to interval info */ |
598 | mysql_mutex_t LOCK_ha_data; /* To protect access to ha_data */ |
599 | mysql_mutex_t LOCK_share; /* To protect TABLE_SHARE */ |
600 | |
601 | TDC_element *tdc; |
602 | |
603 | LEX_CUSTRING tabledef_version; |
604 | |
605 | engine_option_value *option_list; /* text options for table */ |
606 | ha_table_option_struct *option_struct; /* structure with parsed options */ |
607 | |
608 | /* The following is copied to each TABLE on OPEN */ |
609 | Field **field; |
610 | Field **found_next_number_field; |
611 | KEY *key_info; /* data of keys in database */ |
612 | Virtual_column_info **check_constraints; |
613 | uint *blob_field; /* Index to blobs in Field arrray*/ |
614 | LEX_CUSTRING vcol_defs; /* definitions of generated columns */ |
615 | |
616 | TABLE_STATISTICS_CB stats_cb; |
617 | |
618 | uchar *default_values; /* row with default values */ |
619 | LEX_CSTRING ; /* Comment about table */ |
620 | CHARSET_INFO *table_charset; /* Default charset of string fields */ |
621 | |
622 | MY_BITMAP *check_set; /* Fields used by check constrant */ |
623 | MY_BITMAP all_set; |
624 | /* |
625 | Key which is used for looking-up table in table cache and in the list |
626 | of thread's temporary tables. Has the form of: |
627 | "database_name\0table_name\0" + optional part for temporary tables. |
628 | |
629 | Note that all three 'table_cache_key', 'db' and 'table_name' members |
630 | must be set (and be non-zero) for tables in table cache. They also |
631 | should correspond to each other. |
632 | To ensure this one can use set_table_cache() methods. |
633 | */ |
634 | LEX_CSTRING table_cache_key; |
635 | LEX_CSTRING db; /* Pointer to db */ |
636 | LEX_CSTRING table_name; /* Table name (for open) */ |
637 | LEX_CSTRING path; /* Path to .frm file (from datadir) */ |
638 | LEX_CSTRING normalized_path; /* unpack_filename(path) */ |
639 | LEX_CSTRING connect_string; |
640 | |
641 | const char* orig_table_name; /* Original table name for this tmp table */ |
642 | const char* error_table_name() const /* Get table name for error messages */ |
643 | { |
644 | return tmp_table ? ( |
645 | orig_table_name ? |
646 | orig_table_name : |
647 | "(temporary)" ) : |
648 | table_name.str; |
649 | } |
650 | |
651 | /* |
652 | Set of keys in use, implemented as a Bitmap. |
653 | Excludes keys disabled by ALTER TABLE ... DISABLE KEYS. |
654 | */ |
655 | key_map keys_in_use; |
656 | key_map keys_for_keyread; |
657 | ha_rows min_rows, max_rows; /* create information */ |
658 | ulong avg_row_length; /* create information */ |
659 | ulong mysql_version; /* 0 if .frm is created before 5.0 */ |
660 | ulong reclength; /* Recordlength */ |
661 | /* Stored record length. No generated-only virtual fields are included */ |
662 | ulong stored_rec_length; |
663 | |
664 | plugin_ref db_plugin; /* storage engine plugin */ |
665 | inline handlerton *db_type() const /* table_type for handler */ |
666 | { |
667 | return is_view ? view_pseudo_hton : |
668 | db_plugin ? plugin_hton(db_plugin) : NULL; |
669 | } |
670 | enum row_type row_type; /* How rows are stored */ |
671 | enum Table_type table_type; |
672 | enum tmp_table_type tmp_table; |
673 | |
674 | /** Transactional or not. */ |
675 | enum ha_choice transactional; |
676 | /** Per-page checksums or not. */ |
677 | enum ha_choice page_checksum; |
678 | |
679 | uint key_block_size; /* create key_block_size, if used */ |
680 | uint stats_sample_pages; /* number of pages to sample during |
681 | stats estimation, if used, otherwise 0. */ |
682 | enum_stats_auto_recalc stats_auto_recalc; /* Automatic recalc of stats. */ |
683 | uint null_bytes, last_null_bit_pos; |
684 | /* |
685 | Same as null_bytes, except that if there is only a 'delete-marker' in |
686 | the record then this value is 0. |
687 | */ |
688 | uint null_bytes_for_compare; |
689 | uint fields; /* number of fields */ |
690 | uint stored_fields; /* number of stored fields, purely virtual not included */ |
691 | uint virtual_fields; /* number of purely virtual fields */ |
692 | uint null_fields; /* number of null fields */ |
693 | uint blob_fields; /* number of blob fields */ |
694 | uint varchar_fields; /* number of varchar fields */ |
695 | uint default_fields; /* number of default fields */ |
696 | uint visible_fields; /* number of visible fields */ |
697 | |
698 | uint default_expressions; |
699 | uint table_check_constraints, field_check_constraints; |
700 | |
701 | uint rec_buff_length; /* Size of table->record[] buffer */ |
702 | uint keys, key_parts; |
703 | uint ext_key_parts; /* Total number of key parts in extended keys */ |
704 | uint max_key_length, max_unique_length, total_key_length; |
705 | uint uniques; /* Number of UNIQUE index */ |
706 | uint db_create_options; /* Create options from database */ |
707 | uint db_options_in_use; /* Options in use */ |
708 | uint db_record_offset; /* if HA_REC_IN_SEQ */ |
709 | uint rowid_field_offset; /* Field_nr +1 to rowid field */ |
710 | /* Primary key index number, used in TABLE::key_info[] */ |
711 | uint primary_key; |
712 | uint next_number_index; /* autoincrement key number */ |
713 | uint next_number_key_offset; /* autoinc keypart offset in a key */ |
714 | uint next_number_keypart; /* autoinc keypart number in a key */ |
715 | enum open_frm_error error; /* error from open_table_def() */ |
716 | uint open_errno; /* error from open_table_def() */ |
717 | uint column_bitmap_size; |
718 | uchar frm_version; |
719 | |
720 | bool use_ext_keys; /* Extended keys can be used */ |
721 | bool null_field_first; |
722 | bool system; /* Set if system table (one record) */ |
723 | bool not_usable_by_query_cache; |
724 | bool no_replicate; |
725 | bool crashed; |
726 | bool is_view; |
727 | bool can_cmp_whole_record; |
728 | bool table_creation_was_logged; |
729 | bool non_determinstic_insert; |
730 | bool vcols_need_refixing; |
731 | bool check_set_initialized; |
732 | bool has_update_default_function; |
733 | bool can_do_row_logging; /* 1 if table supports RBR */ |
734 | |
735 | ulong table_map_id; /* for row-based replication */ |
736 | |
737 | /* |
738 | Things that are incompatible between the stored version and the |
739 | current version. This is a set of HA_CREATE... bits that can be used |
740 | to modify create_info->used_fields for ALTER TABLE. |
741 | */ |
742 | ulong incompatible_version; |
743 | |
744 | /** |
745 | For shares representing views File_parser object with view |
746 | definition read from .FRM file. |
747 | */ |
748 | const File_parser *view_def; |
749 | |
750 | /* For sequence tables, the current sequence state */ |
751 | SEQUENCE *sequence; |
752 | |
753 | /* Name of the tablespace used for this table */ |
754 | char *tablespace; |
755 | |
756 | #ifdef WITH_PARTITION_STORAGE_ENGINE |
757 | /* filled in when reading from frm */ |
758 | bool auto_partitioned; |
759 | char *partition_info_str; |
760 | uint partition_info_str_len; |
761 | uint partition_info_buffer_size; |
762 | plugin_ref default_part_plugin; |
763 | #endif |
764 | |
765 | /** |
766 | System versioning support. |
767 | */ |
768 | |
769 | vers_sys_type_t versioned; |
770 | uint16 row_start_field; |
771 | uint16 row_end_field; |
772 | |
773 | Field *vers_start_field() |
774 | { |
775 | return field[row_start_field]; |
776 | } |
777 | |
778 | Field *vers_end_field() |
779 | { |
780 | return field[row_end_field]; |
781 | } |
782 | |
783 | /** |
784 | Cache the checked structure of this table. |
785 | |
786 | The pointer data is used to describe the structure that |
787 | a instance of the table must have. Each element of the |
788 | array specifies a field that must exist on the table. |
789 | |
790 | The pointer is cached in order to perform the check only |
791 | once -- when the table is loaded from the disk. |
792 | */ |
793 | const TABLE_FIELD_DEF *table_field_def_cache; |
794 | |
795 | /** Main handler's share */ |
796 | Handler_share *ha_share; |
797 | |
798 | /** Instrumentation for this table share. */ |
799 | PSI_table_share *m_psi; |
800 | |
801 | /* |
802 | Set share's table cache key and update its db and table name appropriately. |
803 | |
804 | SYNOPSIS |
805 | set_table_cache_key() |
806 | key_buff Buffer with already built table cache key to be |
807 | referenced from share. |
808 | key_length Key length. |
809 | |
810 | NOTES |
811 | Since 'key_buff' buffer will be referenced from share it should has same |
812 | life-time as share itself. |
813 | This method automatically ensures that TABLE_SHARE::table_name/db have |
814 | appropriate values by using table cache key as their source. |
815 | */ |
816 | |
817 | void set_table_cache_key(char *key_buff, uint key_length) |
818 | { |
819 | table_cache_key.str= key_buff; |
820 | table_cache_key.length= key_length; |
821 | /* |
822 | Let us use the fact that the key is "db/0/table_name/0" + optional |
823 | part for temporary tables. |
824 | */ |
825 | db.str= table_cache_key.str; |
826 | db.length= strlen(db.str); |
827 | table_name.str= db.str + db.length + 1; |
828 | table_name.length= strlen(table_name.str); |
829 | } |
830 | |
831 | |
832 | /* |
833 | Set share's table cache key and update its db and table name appropriately. |
834 | |
835 | SYNOPSIS |
836 | set_table_cache_key() |
837 | key_buff Buffer to be used as storage for table cache key |
838 | (should be at least key_length bytes). |
839 | key Value for table cache key. |
840 | key_length Key length. |
841 | |
842 | NOTE |
843 | Since 'key_buff' buffer will be used as storage for table cache key |
844 | it should has same life-time as share itself. |
845 | */ |
846 | |
847 | void set_table_cache_key(char *key_buff, const char *key, uint key_length) |
848 | { |
849 | memcpy(key_buff, key, key_length); |
850 | set_table_cache_key(key_buff, key_length); |
851 | } |
852 | |
853 | inline bool honor_global_locks() |
854 | { |
855 | return ((table_category == TABLE_CATEGORY_USER) |
856 | || (table_category == TABLE_CATEGORY_SYSTEM)); |
857 | } |
858 | |
859 | inline bool require_write_privileges() |
860 | { |
861 | return (table_category == TABLE_CATEGORY_LOG); |
862 | } |
863 | |
864 | inline ulong get_table_def_version() |
865 | { |
866 | return table_map_id; |
867 | } |
868 | |
869 | /** |
870 | Convert unrelated members of TABLE_SHARE to one enum |
871 | representing its type. |
872 | |
873 | @todo perhaps we need to have a member instead of a function. |
874 | */ |
875 | enum enum_table_ref_type get_table_ref_type() const |
876 | { |
877 | if (is_view) |
878 | return TABLE_REF_VIEW; |
879 | switch (tmp_table) { |
880 | case NO_TMP_TABLE: |
881 | return TABLE_REF_BASE_TABLE; |
882 | case SYSTEM_TMP_TABLE: |
883 | return TABLE_REF_I_S_TABLE; |
884 | default: |
885 | return TABLE_REF_TMP_TABLE; |
886 | } |
887 | } |
888 | /** |
889 | Return a table metadata version. |
890 | * for base tables and views, we return table_map_id. |
891 | It is assigned from a global counter incremented for each |
892 | new table loaded into the table definition cache (TDC). |
893 | * for temporary tables it's table_map_id again. But for |
894 | temporary tables table_map_id is assigned from |
895 | thd->query_id. The latter is assigned from a thread local |
896 | counter incremented for every new SQL statement. Since |
897 | temporary tables are thread-local, each temporary table |
898 | gets a unique id. |
899 | * for everything else (e.g. information schema tables), |
900 | the version id is zero. |
901 | |
902 | This choice of version id is a large compromise |
903 | to have a working prepared statement validation in 5.1. In |
904 | future version ids will be persistent, as described in WL#4180. |
905 | |
906 | Let's try to explain why and how this limited solution allows |
907 | to validate prepared statements. |
908 | |
909 | Firstly, sets (in mathematical sense) of version numbers |
910 | never intersect for different table types. Therefore, |
911 | version id of a temporary table is never compared with |
912 | a version id of a view, and vice versa. |
913 | |
914 | Secondly, for base tables and views, we know that each DDL flushes |
915 | the respective share from the TDC. This ensures that whenever |
916 | a table is altered or dropped and recreated, it gets a new |
917 | version id. |
918 | Unfortunately, since elements of the TDC are also flushed on |
919 | LRU basis, this choice of version ids leads to false positives. |
920 | E.g. when the TDC size is too small, we may have a SELECT |
921 | * FROM INFORMATION_SCHEMA.TABLES flush all its elements, which |
922 | in turn will lead to a validation error and a subsequent |
923 | reprepare of all prepared statements. This is |
924 | considered acceptable, since as long as prepared statements are |
925 | automatically reprepared, spurious invalidation is only |
926 | a performance hit. Besides, no better simple solution exists. |
927 | |
928 | For temporary tables, using thd->query_id ensures that if |
929 | a temporary table was altered or recreated, a new version id is |
930 | assigned. This suits validation needs very well and will perhaps |
931 | never change. |
932 | |
933 | Metadata of information schema tables never changes. |
934 | Thus we can safely assume 0 for a good enough version id. |
935 | |
936 | Finally, by taking into account table type, we always |
937 | track that a change has taken place when a view is replaced |
938 | with a base table, a base table is replaced with a temporary |
939 | table and so on. |
940 | |
941 | @sa TABLE_LIST::is_table_ref_id_equal() |
942 | */ |
943 | ulong get_table_ref_version() const |
944 | { |
945 | return (tmp_table == SYSTEM_TMP_TABLE) ? 0 : table_map_id; |
946 | } |
947 | |
948 | bool visit_subgraph(Wait_for_flush *waiting_ticket, |
949 | MDL_wait_for_graph_visitor *gvisitor); |
950 | |
951 | bool wait_for_old_version(THD *thd, struct timespec *abstime, |
952 | uint deadlock_weight); |
953 | /** Release resources and free memory occupied by the table share. */ |
954 | void destroy(); |
955 | |
956 | void set_use_ext_keys_flag(bool fl) |
957 | { |
958 | use_ext_keys= fl; |
959 | } |
960 | |
961 | uint actual_n_key_parts(THD *thd); |
962 | |
963 | LEX_CUSTRING *frm_image; ///< only during CREATE TABLE (@sa ha_create_table) |
964 | |
965 | /* |
966 | populates TABLE_SHARE from the table description in the binary frm image. |
967 | if 'write' is true, this frm image is also written into a corresponding |
968 | frm file, that serves as a persistent metadata cache to avoid |
969 | discovering the table over and over again |
970 | */ |
971 | int init_from_binary_frm_image(THD *thd, bool write, |
972 | const uchar *frm_image, size_t frm_length); |
973 | |
974 | /* |
975 | populates TABLE_SHARE from the table description, specified as the |
976 | complete CREATE TABLE sql statement. |
977 | if 'write' is true, this frm image is also written into a corresponding |
978 | frm file, that serves as a persistent metadata cache to avoid |
979 | discovering the table over and over again |
980 | */ |
981 | int init_from_sql_statement_string(THD *thd, bool write, |
982 | const char *sql, size_t sql_length); |
983 | /* |
984 | writes the frm image to an frm file, corresponding to this table |
985 | */ |
986 | bool write_frm_image(const uchar *frm_image, size_t frm_length); |
987 | |
988 | bool write_frm_image(void) |
989 | { return frm_image ? write_frm_image(frm_image->str, frm_image->length) : 0; } |
990 | |
991 | /* |
992 | returns an frm image for this table. |
993 | the memory is allocated and must be freed later |
994 | */ |
995 | bool read_frm_image(const uchar **frm_image, size_t *frm_length); |
996 | |
997 | /* frees the memory allocated in read_frm_image */ |
998 | void free_frm_image(const uchar *frm); |
999 | }; |
1000 | |
1001 | |
1002 | /** |
1003 | Class is used as a BLOB field value storage for |
1004 | intermediate GROUP_CONCAT results. Used only for |
1005 | GROUP_CONCAT with DISTINCT or ORDER BY options. |
1006 | */ |
1007 | |
1008 | class Blob_mem_storage: public Sql_alloc |
1009 | { |
1010 | private: |
1011 | MEM_ROOT storage; |
1012 | /** |
1013 | Sign that some values were cut |
1014 | during saving into the storage. |
1015 | */ |
1016 | bool truncated_value; |
1017 | public: |
1018 | Blob_mem_storage() :truncated_value(false) |
1019 | { |
1020 | init_alloc_root(&storage, "Blob_mem_storage" , MAX_FIELD_VARCHARLENGTH, 0, |
1021 | MYF(0)); |
1022 | } |
1023 | ~ Blob_mem_storage() |
1024 | { |
1025 | free_root(&storage, MYF(0)); |
1026 | } |
1027 | void reset() |
1028 | { |
1029 | free_root(&storage, MYF(MY_MARK_BLOCKS_FREE)); |
1030 | truncated_value= false; |
1031 | } |
1032 | /** |
1033 | Fuction creates duplicate of 'from' |
1034 | string in 'storage' MEM_ROOT. |
1035 | |
1036 | @param from string to copy |
1037 | @param length string length |
1038 | |
1039 | @retval Pointer to the copied string. |
1040 | @retval 0 if an error occurred. |
1041 | */ |
1042 | char *store(const char *from, size_t length) |
1043 | { |
1044 | return (char*) memdup_root(&storage, from, length); |
1045 | } |
1046 | void set_truncated_value(bool is_truncated_value) |
1047 | { |
1048 | truncated_value= is_truncated_value; |
1049 | } |
1050 | bool is_truncated_value() { return truncated_value; } |
1051 | }; |
1052 | |
1053 | |
1054 | /* Information for one open table */ |
1055 | enum index_hint_type |
1056 | { |
1057 | INDEX_HINT_IGNORE, |
1058 | INDEX_HINT_USE, |
1059 | INDEX_HINT_FORCE |
1060 | }; |
1061 | |
1062 | struct st_cond_statistic; |
1063 | |
1064 | #define CHECK_ROW_FOR_NULLS_TO_REJECT (1 << 0) |
1065 | #define REJECT_ROW_DUE_TO_NULL_FIELDS (1 << 1) |
1066 | |
1067 | /* Bitmap of table's fields */ |
1068 | typedef Bitmap<MAX_FIELDS> Field_map; |
1069 | |
1070 | class SplM_opt_info; |
1071 | |
1072 | struct TABLE |
1073 | { |
1074 | TABLE() {} /* Remove gcc warning */ |
1075 | |
1076 | TABLE_SHARE *s; |
1077 | handler *file; |
1078 | TABLE *next, *prev; |
1079 | |
1080 | private: |
1081 | /** |
1082 | Links for the list of all TABLE objects for this share. |
1083 | Declared as private to avoid direct manipulation with those objects. |
1084 | One should use methods of I_P_List template instead. |
1085 | */ |
1086 | TABLE *share_all_next, **share_all_prev; |
1087 | TABLE *global_free_next, **global_free_prev; |
1088 | friend struct All_share_tables; |
1089 | friend struct Table_cache_instance; |
1090 | |
1091 | public: |
1092 | |
1093 | uint32 instance; /** Table cache instance this TABLE is belonging to */ |
1094 | THD *in_use; /* Which thread uses this */ |
1095 | |
1096 | uchar *record[3]; /* Pointer to records */ |
1097 | uchar *write_row_record; /* Used as optimisation in |
1098 | THD::write_row */ |
1099 | uchar *insert_values; /* used by INSERT ... UPDATE */ |
1100 | /* |
1101 | Map of keys that can be used to retrieve all data from this table |
1102 | needed by the query without reading the row. |
1103 | */ |
1104 | key_map covering_keys; |
1105 | key_map quick_keys, intersect_keys; |
1106 | /* |
1107 | A set of keys that can be used in the query that references this |
1108 | table. |
1109 | |
1110 | All indexes disabled on the table's TABLE_SHARE (see TABLE::s) will be |
1111 | subtracted from this set upon instantiation. Thus for any TABLE t it holds |
1112 | that t.keys_in_use_for_query is a subset of t.s.keys_in_use. Generally we |
1113 | must not introduce any new keys here (see setup_tables). |
1114 | |
1115 | The set is implemented as a bitmap. |
1116 | */ |
1117 | key_map keys_in_use_for_query; |
1118 | /* Map of keys that can be used to calculate GROUP BY without sorting */ |
1119 | key_map keys_in_use_for_group_by; |
1120 | /* Map of keys that can be used to calculate ORDER BY without sorting */ |
1121 | key_map keys_in_use_for_order_by; |
1122 | KEY *key_info; /* data of keys in database */ |
1123 | |
1124 | Field **field; /* Pointer to fields */ |
1125 | Field **vfield; /* Pointer to virtual fields*/ |
1126 | Field **default_field; /* Fields with non-constant DEFAULT */ |
1127 | Field *next_number_field; /* Set if next_number is activated */ |
1128 | Field *found_next_number_field; /* Set on open */ |
1129 | Virtual_column_info **check_constraints; |
1130 | |
1131 | /* Table's triggers, 0 if there are no of them */ |
1132 | Table_triggers_list *triggers; |
1133 | TABLE_LIST *pos_in_table_list;/* Element referring to this table */ |
1134 | /* Position in thd->locked_table_list under LOCK TABLES */ |
1135 | TABLE_LIST *pos_in_locked_tables; |
1136 | /* Tables used in DEFAULT and CHECK CONSTRAINT (normally sequence tables) */ |
1137 | TABLE_LIST *internal_tables; |
1138 | |
1139 | /* |
1140 | Not-null for temporary tables only. Non-null values means this table is |
1141 | used to compute GROUP BY, it has a unique of GROUP BY columns. |
1142 | (set by create_tmp_table) |
1143 | */ |
1144 | ORDER *group; |
1145 | String alias; /* alias or table name */ |
1146 | uchar *null_flags; |
1147 | MY_BITMAP def_read_set, def_write_set, tmp_set; |
1148 | MY_BITMAP def_rpl_write_set; |
1149 | MY_BITMAP eq_join_set; /* used to mark equi-joined fields */ |
1150 | MY_BITMAP cond_set; /* used to mark fields from sargable conditions*/ |
1151 | /* Active column sets */ |
1152 | MY_BITMAP *read_set, *write_set, *rpl_write_set; |
1153 | /* Set if using virtual fields */ |
1154 | MY_BITMAP *vcol_set, *def_vcol_set; |
1155 | /* On INSERT: fields that the user specified a value for */ |
1156 | MY_BITMAP has_value_set; |
1157 | |
1158 | /* |
1159 | The ID of the query that opened and is using this table. Has different |
1160 | meanings depending on the table type. |
1161 | |
1162 | Temporary tables: |
1163 | |
1164 | table->query_id is set to thd->query_id for the duration of a statement |
1165 | and is reset to 0 once it is closed by the same statement. A non-zero |
1166 | table->query_id means that a statement is using the table even if it's |
1167 | not the current statement (table is in use by some outer statement). |
1168 | |
1169 | Non-temporary tables: |
1170 | |
1171 | Under pre-locked or LOCK TABLES mode: query_id is set to thd->query_id |
1172 | for the duration of a statement and is reset to 0 once it is closed by |
1173 | the same statement. A non-zero query_id is used to control which tables |
1174 | in the list of pre-opened and locked tables are actually being used. |
1175 | */ |
1176 | query_id_t query_id; |
1177 | |
1178 | /* |
1179 | This structure is used for statistical data on the table that |
1180 | is collected by the function collect_statistics_for_table |
1181 | */ |
1182 | Table_statistics *collected_stats; |
1183 | |
1184 | /* The estimate of the number of records in the table used by optimizer */ |
1185 | ha_rows used_stat_records; |
1186 | |
1187 | /* |
1188 | For each key that has quick_keys.is_set(key) == TRUE: estimate of #records |
1189 | and max #key parts that range access would use. |
1190 | */ |
1191 | ha_rows quick_rows[MAX_KEY]; |
1192 | double quick_costs[MAX_KEY]; |
1193 | |
1194 | /* |
1195 | Bitmaps of key parts that =const for the duration of join execution. If |
1196 | we're in a subquery, then the constant may be different across subquery |
1197 | re-executions. |
1198 | */ |
1199 | key_part_map const_key_parts[MAX_KEY]; |
1200 | |
1201 | uint quick_key_parts[MAX_KEY]; |
1202 | uint quick_n_ranges[MAX_KEY]; |
1203 | |
1204 | /* |
1205 | Estimate of number of records that satisfy SARGable part of the table |
1206 | condition, or table->file->records if no SARGable condition could be |
1207 | constructed. |
1208 | This value is used by join optimizer as an estimate of number of records |
1209 | that will pass the table condition (condition that depends on fields of |
1210 | this table and constants) |
1211 | */ |
1212 | ha_rows quick_condition_rows; |
1213 | |
1214 | double cond_selectivity; |
1215 | List<st_cond_statistic> *cond_selectivity_sampling_explain; |
1216 | |
1217 | table_map map; /* ID bit of table (1,2,4,8,16...) */ |
1218 | |
1219 | uint lock_position; /* Position in MYSQL_LOCK.table */ |
1220 | uint lock_data_start; /* Start pos. in MYSQL_LOCK.locks */ |
1221 | uint lock_count; /* Number of locks */ |
1222 | uint tablenr,used_fields; |
1223 | uint temp_pool_slot; /* Used by intern temp tables */ |
1224 | uint status; /* What's in record[0] */ |
1225 | uint db_stat; /* mode of file as in handler.h */ |
1226 | /* number of select if it is derived table */ |
1227 | uint derived_select_number; |
1228 | /* |
1229 | 0 or JOIN_TYPE_{LEFT|RIGHT}. Currently this is only compared to 0. |
1230 | If maybe_null !=0, this table is inner w.r.t. some outer join operation, |
1231 | and null_row may be true. |
1232 | */ |
1233 | uint maybe_null; |
1234 | int current_lock; /* Type of lock on table */ |
1235 | bool copy_blobs; /* copy_blobs when storing */ |
1236 | /* |
1237 | Set if next_number_field is in the UPDATE fields of INSERT ... ON DUPLICATE |
1238 | KEY UPDATE. |
1239 | */ |
1240 | bool next_number_field_updated; |
1241 | |
1242 | /* |
1243 | If true, the current table row is considered to have all columns set to |
1244 | NULL, including columns declared as "not null" (see maybe_null). |
1245 | */ |
1246 | bool null_row; |
1247 | /* |
1248 | No rows that contain null values can be placed into this table. |
1249 | Currently this flag can be set to true only for a temporary table |
1250 | that used to store the result of materialization of a subquery. |
1251 | */ |
1252 | bool no_rows_with_nulls; |
1253 | /* |
1254 | This field can contain two bit flags: |
1255 | CHECK_ROW_FOR_NULLS_TO_REJECT |
1256 | REJECT_ROW_DUE_TO_NULL_FIELDS |
1257 | The first flag is set for the dynamic contexts where it is prohibited |
1258 | to write any null into the table. |
1259 | The second flag is set only if the first flag is set on. |
1260 | The informs the outer scope that there was an attept to write null |
1261 | into a field of the table in the context where it is prohibited. |
1262 | This flag should be set off as soon as the first flag is set on. |
1263 | Currently these flags are used only the tables tno_rows_with_nulls set |
1264 | to true. |
1265 | */ |
1266 | uint8 null_catch_flags; |
1267 | |
1268 | /* |
1269 | TODO: Each of the following flags take up 8 bits. They can just as easily |
1270 | be put into one single unsigned long and instead of taking up 18 |
1271 | bytes, it would take up 4. |
1272 | */ |
1273 | bool force_index; |
1274 | |
1275 | /** |
1276 | Flag set when the statement contains FORCE INDEX FOR ORDER BY |
1277 | See TABLE_LIST::process_index_hints(). |
1278 | */ |
1279 | bool force_index_order; |
1280 | |
1281 | /** |
1282 | Flag set when the statement contains FORCE INDEX FOR GROUP BY |
1283 | See TABLE_LIST::process_index_hints(). |
1284 | */ |
1285 | bool force_index_group; |
1286 | /* |
1287 | TRUE<=> this table was created with create_tmp_table(... distinct=TRUE..) |
1288 | call |
1289 | */ |
1290 | bool distinct; |
1291 | bool const_table,no_rows, used_for_duplicate_elimination; |
1292 | /** |
1293 | Forces DYNAMIC Aria row format for internal temporary tables. |
1294 | */ |
1295 | bool keep_row_order; |
1296 | |
1297 | bool no_keyread; |
1298 | /** |
1299 | If set, indicate that the table is not replicated by the server. |
1300 | */ |
1301 | bool locked_by_logger; |
1302 | bool locked_by_name; |
1303 | bool fulltext_searched; |
1304 | bool no_cache; |
1305 | /* To signal that the table is associated with a HANDLER statement */ |
1306 | bool open_by_handler; |
1307 | /* |
1308 | To indicate that a non-null value of the auto_increment field |
1309 | was provided by the user or retrieved from the current record. |
1310 | Used only in the MODE_NO_AUTO_VALUE_ON_ZERO mode. |
1311 | */ |
1312 | bool auto_increment_field_not_null; |
1313 | bool insert_or_update; /* Can be used by the handler */ |
1314 | bool alias_name_used; /* true if table_name is alias */ |
1315 | bool get_fields_in_item_tree; /* Signal to fix_field */ |
1316 | bool m_needs_reopen; |
1317 | private: |
1318 | bool created; /* For tmp tables. TRUE <=> tmp table was actually created.*/ |
1319 | public: |
1320 | #ifdef HAVE_REPLICATION |
1321 | /* used in RBR Triggers */ |
1322 | bool master_had_triggers; |
1323 | #endif |
1324 | |
1325 | REGINFO reginfo; /* field connections */ |
1326 | MEM_ROOT mem_root; |
1327 | /** |
1328 | Initialized in Item_func_group_concat::setup for appropriate |
1329 | temporary table if GROUP_CONCAT is used with ORDER BY | DISTINCT |
1330 | and BLOB field count > 0. |
1331 | */ |
1332 | Blob_mem_storage *blob_storage; |
1333 | GRANT_INFO grant; |
1334 | /* |
1335 | The arena which the items for expressions from the table definition |
1336 | are associated with. |
1337 | Currently only the items of the expressions for virtual columns are |
1338 | associated with this arena. |
1339 | TODO: To attach the partitioning expressions to this arena. |
1340 | */ |
1341 | Query_arena *expr_arena; |
1342 | #ifdef WITH_PARTITION_STORAGE_ENGINE |
1343 | partition_info *part_info; /* Partition related information */ |
1344 | /* If true, all partitions have been pruned away */ |
1345 | bool all_partitions_pruned_away; |
1346 | #endif |
1347 | uint max_keys; /* Size of allocated key_info array. */ |
1348 | bool stats_is_read; /* Persistent statistics is read for the table */ |
1349 | bool histograms_are_read; |
1350 | MDL_ticket *mdl_ticket; |
1351 | |
1352 | /* |
1353 | This is used only for potentially splittable materialized tables and it |
1354 | points to the info used by the optimizer to apply splitting optimization |
1355 | */ |
1356 | SplM_opt_info *spl_opt_info; |
1357 | key_map keys_usable_for_splitting; |
1358 | |
1359 | void init(THD *thd, TABLE_LIST *tl); |
1360 | bool fill_item_list(List<Item> *item_list) const; |
1361 | void reset_item_list(List<Item> *item_list, uint skip) const; |
1362 | void clear_column_bitmaps(void); |
1363 | void prepare_for_position(void); |
1364 | MY_BITMAP *prepare_for_keyread(uint index, MY_BITMAP *map); |
1365 | MY_BITMAP *prepare_for_keyread(uint index) |
1366 | { return prepare_for_keyread(index, &tmp_set); } |
1367 | void mark_columns_used_by_index(uint index, MY_BITMAP *map); |
1368 | void mark_columns_used_by_index_no_reset(uint index, MY_BITMAP *map); |
1369 | void restore_column_maps_after_keyread(MY_BITMAP *backup); |
1370 | void mark_auto_increment_column(void); |
1371 | void mark_columns_needed_for_update(void); |
1372 | void mark_columns_needed_for_delete(void); |
1373 | void mark_columns_needed_for_insert(void); |
1374 | void mark_columns_per_binlog_row_image(void); |
1375 | bool mark_virtual_col(Field *field); |
1376 | bool mark_virtual_columns_for_write(bool insert_fl); |
1377 | bool check_virtual_columns_marked_for_read(); |
1378 | bool check_virtual_columns_marked_for_write(); |
1379 | void mark_default_fields_for_write(bool insert_fl); |
1380 | void mark_columns_used_by_check_constraints(void); |
1381 | void mark_check_constraint_columns_for_read(void); |
1382 | int verify_constraints(bool ignore_failure); |
1383 | inline void column_bitmaps_set(MY_BITMAP *read_set_arg) |
1384 | { |
1385 | read_set= read_set_arg; |
1386 | if (file) |
1387 | file->column_bitmaps_signal(); |
1388 | } |
1389 | inline void column_bitmaps_set(MY_BITMAP *read_set_arg, |
1390 | MY_BITMAP *write_set_arg) |
1391 | { |
1392 | read_set= read_set_arg; |
1393 | write_set= write_set_arg; |
1394 | if (file) |
1395 | file->column_bitmaps_signal(); |
1396 | } |
1397 | inline void column_bitmaps_set(MY_BITMAP *read_set_arg, |
1398 | MY_BITMAP *write_set_arg, |
1399 | MY_BITMAP *vcol_set_arg) |
1400 | { |
1401 | read_set= read_set_arg; |
1402 | write_set= write_set_arg; |
1403 | vcol_set= vcol_set_arg; |
1404 | if (file) |
1405 | file->column_bitmaps_signal(); |
1406 | } |
1407 | inline void column_bitmaps_set_no_signal(MY_BITMAP *read_set_arg, |
1408 | MY_BITMAP *write_set_arg) |
1409 | { |
1410 | read_set= read_set_arg; |
1411 | write_set= write_set_arg; |
1412 | } |
1413 | inline void column_bitmaps_set_no_signal(MY_BITMAP *read_set_arg, |
1414 | MY_BITMAP *write_set_arg, |
1415 | MY_BITMAP *vcol_set_arg) |
1416 | { |
1417 | read_set= read_set_arg; |
1418 | write_set= write_set_arg; |
1419 | vcol_set= vcol_set_arg; |
1420 | } |
1421 | inline void use_all_columns() |
1422 | { |
1423 | column_bitmaps_set(&s->all_set, &s->all_set); |
1424 | } |
1425 | inline void default_column_bitmaps() |
1426 | { |
1427 | read_set= &def_read_set; |
1428 | write_set= &def_write_set; |
1429 | vcol_set= def_vcol_set; /* Note that this may be 0 */ |
1430 | rpl_write_set= 0; |
1431 | } |
1432 | /** Should this instance of the table be reopened? */ |
1433 | inline bool needs_reopen() |
1434 | { return !db_stat || m_needs_reopen; } |
1435 | |
1436 | bool alloc_keys(uint key_count); |
1437 | bool check_tmp_key(uint key, uint key_parts, |
1438 | uint (*next_field_no) (uchar *), uchar *arg); |
1439 | bool add_tmp_key(uint key, uint key_parts, |
1440 | uint (*next_field_no) (uchar *), uchar *arg, |
1441 | bool unique); |
1442 | void create_key_part_by_field(KEY_PART_INFO *key_part_info, |
1443 | Field *field, uint fieldnr); |
1444 | void use_index(int key_to_save); |
1445 | void set_table_map(table_map map_arg, uint tablenr_arg) |
1446 | { |
1447 | map= map_arg; |
1448 | tablenr= tablenr_arg; |
1449 | } |
1450 | |
1451 | /// Return true if table is instantiated, and false otherwise. |
1452 | bool is_created() const { return created; } |
1453 | |
1454 | /** |
1455 | Set the table as "created", and enable flags in storage engine |
1456 | that could not be enabled without an instantiated table. |
1457 | */ |
1458 | void set_created() |
1459 | { |
1460 | if (created) |
1461 | return; |
1462 | if (file->keyread_enabled()) |
1463 | file->extra(HA_EXTRA_KEYREAD); |
1464 | created= true; |
1465 | } |
1466 | |
1467 | /* |
1468 | Returns TRUE if the table is filled at execution phase (and so, the |
1469 | optimizer must not do anything that depends on the contents of the table, |
1470 | like range analysis or constant table detection) |
1471 | */ |
1472 | bool is_filled_at_execution(); |
1473 | |
1474 | bool update_const_key_parts(COND *conds); |
1475 | |
1476 | my_ptrdiff_t default_values_offset() const |
1477 | { return (my_ptrdiff_t) (s->default_values - record[0]); } |
1478 | |
1479 | void move_fields(Field **ptr, const uchar *to, const uchar *from); |
1480 | |
1481 | uint actual_n_key_parts(KEY *keyinfo); |
1482 | ulong actual_key_flags(KEY *keyinfo); |
1483 | int update_virtual_field(Field *vf); |
1484 | int update_virtual_fields(handler *h, enum_vcol_update_mode update_mode); |
1485 | int update_default_fields(bool update, bool ignore_errors); |
1486 | void reset_default_fields(); |
1487 | inline ha_rows stat_records() { return used_stat_records; } |
1488 | |
1489 | void prepare_triggers_for_insert_stmt_or_event(); |
1490 | bool prepare_triggers_for_delete_stmt_or_event(); |
1491 | bool prepare_triggers_for_update_stmt_or_event(); |
1492 | |
1493 | Field **field_to_fill(); |
1494 | bool validate_default_values_of_unset_fields(THD *thd) const; |
1495 | |
1496 | bool insert_all_rows_into_tmp_table(THD *thd, |
1497 | TABLE *tmp_table, |
1498 | TMP_TABLE_PARAM *tmp_table_param, |
1499 | bool with_cleanup); |
1500 | Field *find_field_by_name(LEX_CSTRING *str) const; |
1501 | bool export_structure(THD *thd, class Row_definition_list *defs); |
1502 | bool is_splittable() { return spl_opt_info != NULL; } |
1503 | void set_spl_opt_info(SplM_opt_info *spl_info); |
1504 | void deny_splitting(); |
1505 | void add_splitting_info_for_key_field(struct KEY_FIELD *key_field); |
1506 | |
1507 | /** |
1508 | System Versioning support |
1509 | */ |
1510 | bool vers_write; |
1511 | |
1512 | bool versioned() const |
1513 | { |
1514 | DBUG_ASSERT(s); |
1515 | return s->versioned; |
1516 | } |
1517 | |
1518 | bool versioned(vers_sys_type_t type) const |
1519 | { |
1520 | DBUG_ASSERT(s); |
1521 | DBUG_ASSERT(type); |
1522 | return s->versioned == type; |
1523 | } |
1524 | |
1525 | bool versioned_write(vers_sys_type_t type= VERS_UNDEFINED) const |
1526 | { |
1527 | DBUG_ASSERT(versioned() || !vers_write); |
1528 | return versioned(type) ? vers_write : false; |
1529 | } |
1530 | |
1531 | Field *vers_start_field() const |
1532 | { |
1533 | DBUG_ASSERT(s && s->versioned); |
1534 | return field[s->row_start_field]; |
1535 | } |
1536 | |
1537 | Field *vers_end_field() const |
1538 | { |
1539 | DBUG_ASSERT(s && s->versioned); |
1540 | return field[s->row_end_field]; |
1541 | } |
1542 | |
1543 | ulonglong vers_start_id() const; |
1544 | ulonglong vers_end_id() const; |
1545 | |
1546 | int delete_row(); |
1547 | void vers_update_fields(); |
1548 | void vers_update_end(); |
1549 | |
1550 | /** Number of additional fields used in versioned tables */ |
1551 | #define VERSIONING_FIELDS 2 |
1552 | }; |
1553 | |
1554 | |
1555 | /** |
1556 | Helper class which specifies which members of TABLE are used for |
1557 | participation in the list of used/unused TABLE objects for the share. |
1558 | */ |
1559 | |
1560 | struct TABLE_share |
1561 | { |
1562 | static inline TABLE **next_ptr(TABLE *l) |
1563 | { |
1564 | return &l->next; |
1565 | } |
1566 | static inline TABLE ***prev_ptr(TABLE *l) |
1567 | { |
1568 | return (TABLE ***) &l->prev; |
1569 | } |
1570 | }; |
1571 | |
1572 | struct All_share_tables |
1573 | { |
1574 | static inline TABLE **next_ptr(TABLE *l) |
1575 | { |
1576 | return &l->share_all_next; |
1577 | } |
1578 | static inline TABLE ***prev_ptr(TABLE *l) |
1579 | { |
1580 | return &l->share_all_prev; |
1581 | } |
1582 | }; |
1583 | |
1584 | typedef I_P_List <TABLE, All_share_tables> All_share_tables_list; |
1585 | |
1586 | enum enum_schema_table_state |
1587 | { |
1588 | NOT_PROCESSED= 0, |
1589 | PROCESSED_BY_CREATE_SORT_INDEX, |
1590 | PROCESSED_BY_JOIN_EXEC |
1591 | }; |
1592 | |
1593 | enum enum_fk_option { FK_OPTION_UNDEF, FK_OPTION_RESTRICT, FK_OPTION_CASCADE, |
1594 | FK_OPTION_SET_NULL, FK_OPTION_NO_ACTION, FK_OPTION_SET_DEFAULT}; |
1595 | |
1596 | typedef struct st_foreign_key_info |
1597 | { |
1598 | LEX_CSTRING *foreign_id; |
1599 | LEX_CSTRING *foreign_db; |
1600 | LEX_CSTRING *foreign_table; |
1601 | LEX_CSTRING *referenced_db; |
1602 | LEX_CSTRING *referenced_table; |
1603 | enum_fk_option update_method; |
1604 | enum_fk_option delete_method; |
1605 | LEX_CSTRING *referenced_key_name; |
1606 | List<LEX_CSTRING> foreign_fields; |
1607 | List<LEX_CSTRING> referenced_fields; |
1608 | } FOREIGN_KEY_INFO; |
1609 | |
1610 | LEX_CSTRING *fk_option_name(enum_fk_option opt); |
1611 | bool fk_modifies_child(enum_fk_option opt); |
1612 | |
1613 | #define MY_I_S_MAYBE_NULL 1U |
1614 | #define MY_I_S_UNSIGNED 2U |
1615 | |
1616 | |
1617 | #define SKIP_OPEN_TABLE 0U // do not open table |
1618 | #define OPEN_FRM_ONLY 1U // open FRM file only |
1619 | #define OPEN_FULL_TABLE 2U // open FRM,MYD, MYI files |
1620 | |
1621 | typedef struct st_field_info |
1622 | { |
1623 | /** |
1624 | This is used as column name. |
1625 | */ |
1626 | const char* field_name; |
1627 | /** |
1628 | For string-type columns, this is the maximum number of |
1629 | characters. Otherwise, it is the 'display-length' for the column. |
1630 | */ |
1631 | uint field_length; |
1632 | /** |
1633 | This denotes data type for the column. For the most part, there seems to |
1634 | be one entry in the enum for each SQL data type, although there seem to |
1635 | be a number of additional entries in the enum. |
1636 | */ |
1637 | enum enum_field_types field_type; |
1638 | int value; |
1639 | /** |
1640 | This is used to set column attributes. By default, columns are @c NOT |
1641 | @c NULL and @c SIGNED, and you can deviate from the default |
1642 | by setting the appopriate flags. You can use either one of the flags |
1643 | @c MY_I_S_MAYBE_NULL and @cMY_I_S_UNSIGNED or |
1644 | combine them using the bitwise or operator @c |. Both flags are |
1645 | defined in table.h. |
1646 | */ |
1647 | uint field_flags; // Field atributes(maybe_null, signed, unsigned etc.) |
1648 | const char* old_name; |
1649 | /** |
1650 | This should be one of @c SKIP_OPEN_TABLE, |
1651 | @c OPEN_FRM_ONLY or @c OPEN_FULL_TABLE. |
1652 | */ |
1653 | uint open_method; |
1654 | } ST_FIELD_INFO; |
1655 | |
1656 | |
1657 | struct TABLE_LIST; |
1658 | typedef class Item COND; |
1659 | |
1660 | typedef struct st_schema_table |
1661 | { |
1662 | const char *table_name; |
1663 | ST_FIELD_INFO *fields_info; |
1664 | /* for FLUSH table_name */ |
1665 | int (*reset_table) (); |
1666 | /* Fill table with data */ |
1667 | int (*fill_table) (THD *thd, TABLE_LIST *tables, COND *cond); |
1668 | /* Handle fileds for old SHOW */ |
1669 | int (*old_format) (THD *thd, struct st_schema_table *schema_table); |
1670 | int (*process_table) (THD *thd, TABLE_LIST *tables, TABLE *table, |
1671 | bool res, const LEX_CSTRING *db_name, |
1672 | const LEX_CSTRING *table_name); |
1673 | int idx_field1, idx_field2; |
1674 | bool hidden; |
1675 | uint i_s_requested_object; /* the object we need to open(TABLE | VIEW) */ |
1676 | } ST_SCHEMA_TABLE; |
1677 | |
1678 | class IS_table_read_plan; |
1679 | |
1680 | /* |
1681 | Types of derived tables. The ending part is a bitmap of phases that are |
1682 | applicable to a derived table of the type. |
1683 | */ |
1684 | #define DTYPE_ALGORITHM_UNDEFINED 0U |
1685 | #define DTYPE_VIEW 1U |
1686 | #define DTYPE_TABLE 2U |
1687 | #define DTYPE_MERGE 4U |
1688 | #define DTYPE_MATERIALIZE 8U |
1689 | #define DTYPE_MULTITABLE 16U |
1690 | #define DTYPE_MASK (DTYPE_VIEW|DTYPE_TABLE|DTYPE_MULTITABLE) |
1691 | |
1692 | /* |
1693 | Phases of derived tables/views handling, see sql_derived.cc |
1694 | Values are used as parts of a bitmap attached to derived table types. |
1695 | */ |
1696 | #define DT_INIT 1U |
1697 | #define DT_PREPARE 2U |
1698 | #define DT_OPTIMIZE 4U |
1699 | #define DT_MERGE 8U |
1700 | #define DT_MERGE_FOR_INSERT 16U |
1701 | #define DT_CREATE 32U |
1702 | #define DT_FILL 64U |
1703 | #define DT_REINIT 128U |
1704 | #define DT_PHASES 8U |
1705 | /* Phases that are applicable to all derived tables. */ |
1706 | #define DT_COMMON (DT_INIT + DT_PREPARE + DT_REINIT + DT_OPTIMIZE) |
1707 | /* Phases that are applicable only to materialized derived tables. */ |
1708 | #define DT_MATERIALIZE (DT_CREATE + DT_FILL) |
1709 | |
1710 | #define DT_PHASES_MERGE (DT_COMMON | DT_MERGE | DT_MERGE_FOR_INSERT) |
1711 | #define DT_PHASES_MATERIALIZE (DT_COMMON | DT_MATERIALIZE) |
1712 | |
1713 | #define VIEW_ALGORITHM_UNDEFINED 0 |
1714 | /* Special value for ALTER VIEW: inherit original algorithm. */ |
1715 | #define VIEW_ALGORITHM_INHERIT DTYPE_VIEW |
1716 | #define VIEW_ALGORITHM_MERGE (DTYPE_VIEW | DTYPE_MERGE) |
1717 | #define VIEW_ALGORITHM_TMPTABLE (DTYPE_VIEW | DTYPE_MATERIALIZE) |
1718 | |
1719 | /* |
1720 | View algorithm values as stored in the FRM. Values differ from in-memory |
1721 | representation for backward compatibility. |
1722 | */ |
1723 | |
1724 | #define VIEW_ALGORITHM_UNDEFINED_FRM 0U |
1725 | #define VIEW_ALGORITHM_MERGE_FRM 1U |
1726 | #define VIEW_ALGORITHM_TMPTABLE_FRM 2U |
1727 | |
1728 | #define JOIN_TYPE_LEFT 1U |
1729 | #define JOIN_TYPE_RIGHT 2U |
1730 | #define JOIN_TYPE_OUTER 4U /* Marker that this is an outer join */ |
1731 | |
1732 | /* view WITH CHECK OPTION parameter options */ |
1733 | #define VIEW_CHECK_NONE 0 |
1734 | #define VIEW_CHECK_LOCAL 1 |
1735 | #define VIEW_CHECK_CASCADED 2 |
1736 | |
1737 | /* result of view WITH CHECK OPTION parameter check */ |
1738 | #define VIEW_CHECK_OK 0 |
1739 | #define VIEW_CHECK_ERROR 1 |
1740 | #define VIEW_CHECK_SKIP 2 |
1741 | |
1742 | /** The threshold size a blob field buffer before it is freed */ |
1743 | #define MAX_TDC_BLOB_SIZE 65536 |
1744 | |
1745 | class select_unit; |
1746 | class TMP_TABLE_PARAM; |
1747 | |
1748 | Item *create_view_field(THD *thd, TABLE_LIST *view, Item **field_ref, |
1749 | LEX_CSTRING *name); |
1750 | |
1751 | struct Field_translator |
1752 | { |
1753 | Item *item; |
1754 | LEX_CSTRING name; |
1755 | }; |
1756 | |
1757 | |
1758 | /* |
1759 | Column reference of a NATURAL/USING join. Since column references in |
1760 | joins can be both from views and stored tables, may point to either a |
1761 | Field (for tables), or a Field_translator (for views). |
1762 | */ |
1763 | |
1764 | class Natural_join_column: public Sql_alloc |
1765 | { |
1766 | public: |
1767 | Field_translator *view_field; /* Column reference of merge view. */ |
1768 | Item_field *table_field; /* Column reference of table or temp view. */ |
1769 | TABLE_LIST *table_ref; /* Original base table/view reference. */ |
1770 | /* |
1771 | True if a common join column of two NATURAL/USING join operands. Notice |
1772 | that when we have a hierarchy of nested NATURAL/USING joins, a column can |
1773 | be common at some level of nesting but it may not be common at higher |
1774 | levels of nesting. Thus this flag may change depending on at which level |
1775 | we are looking at some column. |
1776 | */ |
1777 | bool is_common; |
1778 | public: |
1779 | Natural_join_column(Field_translator *field_param, TABLE_LIST *tab); |
1780 | Natural_join_column(Item_field *field_param, TABLE_LIST *tab); |
1781 | LEX_CSTRING *name(); |
1782 | Item *create_item(THD *thd); |
1783 | Field *field(); |
1784 | const char *safe_table_name(); |
1785 | const char *safe_db_name(); |
1786 | GRANT_INFO *grant(); |
1787 | }; |
1788 | |
1789 | |
1790 | /** |
1791 | Type of table which can be open for an element of table list. |
1792 | */ |
1793 | |
1794 | enum enum_open_type |
1795 | { |
1796 | OT_TEMPORARY_OR_BASE= 0, OT_TEMPORARY_ONLY, OT_BASE_ONLY |
1797 | }; |
1798 | |
1799 | |
1800 | class SJ_MATERIALIZATION_INFO; |
1801 | class Index_hint; |
1802 | class Item_in_subselect; |
1803 | |
1804 | /* trivial class, for %union in sql_yacc.yy */ |
1805 | struct vers_history_point_t |
1806 | { |
1807 | vers_sys_type_t unit; |
1808 | Item *item; |
1809 | }; |
1810 | |
1811 | class Vers_history_point : public vers_history_point_t |
1812 | { |
1813 | void fix_item(); |
1814 | |
1815 | public: |
1816 | Vers_history_point() { empty(); } |
1817 | Vers_history_point(vers_sys_type_t unit_arg, Item *item_arg) |
1818 | { |
1819 | unit= unit_arg; |
1820 | item= item_arg; |
1821 | fix_item(); |
1822 | } |
1823 | Vers_history_point(vers_history_point_t p) |
1824 | { |
1825 | unit= p.unit; |
1826 | item= p.item; |
1827 | fix_item(); |
1828 | } |
1829 | void empty() { unit= VERS_UNDEFINED; item= NULL; } |
1830 | void print(String *str, enum_query_type, const char *prefix, size_t plen) const; |
1831 | bool resolve_unit(THD *thd); |
1832 | bool resolve_unit_trx_id(THD *thd) |
1833 | { |
1834 | if (unit == VERS_UNDEFINED) |
1835 | unit= VERS_TRX_ID; |
1836 | return false; |
1837 | } |
1838 | bool resolve_unit_timestamp(THD *thd) |
1839 | { |
1840 | if (unit == VERS_UNDEFINED) |
1841 | unit= VERS_TIMESTAMP; |
1842 | return false; |
1843 | } |
1844 | void bad_expression_data_type_error(const char *type) const; |
1845 | bool eq(const vers_history_point_t &point) const; |
1846 | }; |
1847 | |
1848 | struct vers_select_conds_t |
1849 | { |
1850 | vers_system_time_t type; |
1851 | bool from_query:1; |
1852 | bool used:1; |
1853 | Vers_history_point start; |
1854 | Vers_history_point end; |
1855 | |
1856 | void empty() |
1857 | { |
1858 | type= SYSTEM_TIME_UNSPECIFIED; |
1859 | used= from_query= false; |
1860 | start.empty(); |
1861 | end.empty(); |
1862 | } |
1863 | |
1864 | void init(vers_system_time_t _type, |
1865 | Vers_history_point _start= Vers_history_point(), |
1866 | Vers_history_point _end= Vers_history_point()) |
1867 | { |
1868 | type= _type; |
1869 | used= from_query= false; |
1870 | start= _start; |
1871 | end= _end; |
1872 | } |
1873 | |
1874 | void print(String *str, enum_query_type query_type) const; |
1875 | |
1876 | bool init_from_sysvar(THD *thd); |
1877 | |
1878 | bool is_set() const |
1879 | { |
1880 | return type != SYSTEM_TIME_UNSPECIFIED; |
1881 | } |
1882 | bool resolve_units(THD *thd); |
1883 | bool user_defined() const |
1884 | { |
1885 | return !from_query && type != SYSTEM_TIME_UNSPECIFIED; |
1886 | } |
1887 | bool eq(const vers_select_conds_t &conds) const; |
1888 | }; |
1889 | |
1890 | /* |
1891 | Table reference in the FROM clause. |
1892 | |
1893 | These table references can be of several types that correspond to |
1894 | different SQL elements. Below we list all types of TABLE_LISTs with |
1895 | the necessary conditions to determine when a TABLE_LIST instance |
1896 | belongs to a certain type. |
1897 | |
1898 | 1) table (TABLE_LIST::view == NULL) |
1899 | - base table |
1900 | (TABLE_LIST::derived == NULL) |
1901 | - FROM-clause subquery - TABLE_LIST::table is a temp table |
1902 | (TABLE_LIST::derived != NULL) |
1903 | - information schema table |
1904 | (TABLE_LIST::schema_table != NULL) |
1905 | NOTICE: for schema tables TABLE_LIST::field_translation may be != NULL |
1906 | 2) view (TABLE_LIST::view != NULL) |
1907 | - merge (TABLE_LIST::effective_algorithm == VIEW_ALGORITHM_MERGE) |
1908 | also (TABLE_LIST::field_translation != NULL) |
1909 | - tmptable (TABLE_LIST::effective_algorithm == VIEW_ALGORITHM_TMPTABLE) |
1910 | also (TABLE_LIST::field_translation == NULL) |
1911 | 2.5) TODO: Add derived tables description here |
1912 | 3) nested table reference (TABLE_LIST::nested_join != NULL) |
1913 | - table sequence - e.g. (t1, t2, t3) |
1914 | TODO: how to distinguish from a JOIN? |
1915 | - general JOIN |
1916 | TODO: how to distinguish from a table sequence? |
1917 | - NATURAL JOIN |
1918 | (TABLE_LIST::natural_join != NULL) |
1919 | - JOIN ... USING |
1920 | (TABLE_LIST::join_using_fields != NULL) |
1921 | - semi-join nest (sj_on_expr!= NULL && sj_subq_pred!=NULL) |
1922 | 4) jtbm semi-join (jtbm_subselect != NULL) |
1923 | */ |
1924 | |
1925 | /** last_leaf_for_name_resolutioning support. */ |
1926 | |
1927 | struct LEX; |
1928 | class Index_hint; |
1929 | struct TABLE_LIST |
1930 | { |
1931 | TABLE_LIST() {} /* Remove gcc warning */ |
1932 | |
1933 | enum prelocking_types |
1934 | { |
1935 | PRELOCK_NONE, PRELOCK_ROUTINE, PRELOCK_FK |
1936 | }; |
1937 | |
1938 | /** |
1939 | Prepare TABLE_LIST that consists of one table instance to use in |
1940 | open_and_lock_tables |
1941 | */ |
1942 | inline void init_one_table(const LEX_CSTRING *db_arg, |
1943 | const LEX_CSTRING *table_name_arg, |
1944 | const LEX_CSTRING *alias_arg, |
1945 | enum thr_lock_type lock_type_arg) |
1946 | { |
1947 | bzero((char*) this, sizeof(*this)); |
1948 | DBUG_ASSERT(!db_arg->str || strlen(db_arg->str) == db_arg->length); |
1949 | DBUG_ASSERT(!table_name_arg->str || strlen(table_name_arg->str) == table_name_arg->length); |
1950 | DBUG_ASSERT(!alias_arg || strlen(alias_arg->str) == alias_arg->length); |
1951 | db= *db_arg; |
1952 | table_name= *table_name_arg; |
1953 | alias= (alias_arg ? *alias_arg : *table_name_arg); |
1954 | lock_type= lock_type_arg; |
1955 | mdl_request.init(MDL_key::TABLE, db.str, table_name.str, |
1956 | (lock_type >= TL_WRITE_ALLOW_WRITE) ? |
1957 | MDL_SHARED_WRITE : MDL_SHARED_READ, |
1958 | MDL_TRANSACTION); |
1959 | } |
1960 | |
1961 | TABLE_LIST(TABLE *table_arg, thr_lock_type lock_type) |
1962 | { |
1963 | DBUG_ASSERT(table_arg->s); |
1964 | init_one_table(&table_arg->s->db, &table_arg->s->table_name, |
1965 | NULL, lock_type); |
1966 | table= table_arg; |
1967 | } |
1968 | |
1969 | inline void init_one_table_for_prelocking(const LEX_CSTRING *db_arg, |
1970 | const LEX_CSTRING *table_name_arg, |
1971 | const LEX_CSTRING *alias_arg, |
1972 | enum thr_lock_type lock_type_arg, |
1973 | prelocking_types prelocking_type, |
1974 | TABLE_LIST *belong_to_view_arg, |
1975 | uint8 trg_event_map_arg, |
1976 | TABLE_LIST ***last_ptr) |
1977 | |
1978 | { |
1979 | init_one_table(db_arg, table_name_arg, alias_arg, lock_type_arg); |
1980 | cacheable_table= 1; |
1981 | prelocking_placeholder= prelocking_type; |
1982 | open_type= (prelocking_type == PRELOCK_ROUTINE ? |
1983 | OT_TEMPORARY_OR_BASE : |
1984 | OT_BASE_ONLY); |
1985 | belong_to_view= belong_to_view_arg; |
1986 | trg_event_map= trg_event_map_arg; |
1987 | |
1988 | **last_ptr= this; |
1989 | prev_global= *last_ptr; |
1990 | *last_ptr= &next_global; |
1991 | } |
1992 | |
1993 | /* |
1994 | List of tables local to a subquery (used by SQL_I_List). Considers |
1995 | views as leaves (unlike 'next_leaf' below). Created at parse time |
1996 | in st_select_lex::add_table_to_list() -> table_list.link_in_list(). |
1997 | */ |
1998 | TABLE_LIST *next_local; |
1999 | /* link in a global list of all queries tables */ |
2000 | TABLE_LIST *next_global, **prev_global; |
2001 | LEX_CSTRING db; |
2002 | LEX_CSTRING table_name; |
2003 | LEX_CSTRING schema_table_name; |
2004 | LEX_CSTRING alias; |
2005 | const char *option; /* Used by cache index */ |
2006 | Item *on_expr; /* Used with outer join */ |
2007 | |
2008 | Item *sj_on_expr; |
2009 | /* |
2010 | (Valid only for semi-join nests) Bitmap of tables that are within the |
2011 | semi-join (this is different from bitmap of all nest's children because |
2012 | tables that were pulled out of the semi-join nest remain listed as |
2013 | nest's children). |
2014 | */ |
2015 | table_map sj_inner_tables; |
2016 | /* Number of IN-compared expressions */ |
2017 | uint sj_in_exprs; |
2018 | |
2019 | /* If this is a non-jtbm semi-join nest: corresponding subselect predicate */ |
2020 | Item_in_subselect *sj_subq_pred; |
2021 | |
2022 | table_map original_subq_pred_used_tables; |
2023 | |
2024 | /* If this is a jtbm semi-join object: corresponding subselect predicate */ |
2025 | Item_in_subselect *jtbm_subselect; |
2026 | /* TODO: check if this can be joined with tablenr_exec */ |
2027 | uint jtbm_table_no; |
2028 | |
2029 | SJ_MATERIALIZATION_INFO *sj_mat_info; |
2030 | |
2031 | /* |
2032 | The structure of ON expression presented in the member above |
2033 | can be changed during certain optimizations. This member |
2034 | contains a snapshot of AND-OR structure of the ON expression |
2035 | made after permanent transformations of the parse tree, and is |
2036 | used to restore ON clause before every reexecution of a prepared |
2037 | statement or stored procedure. |
2038 | */ |
2039 | Item *prep_on_expr; |
2040 | COND_EQUAL *cond_equal; /* Used with outer join */ |
2041 | /* |
2042 | During parsing - left operand of NATURAL/USING join where 'this' is |
2043 | the right operand. After parsing (this->natural_join == this) iff |
2044 | 'this' represents a NATURAL or USING join operation. Thus after |
2045 | parsing 'this' is a NATURAL/USING join iff (natural_join != NULL). |
2046 | */ |
2047 | TABLE_LIST *natural_join; |
2048 | /* |
2049 | True if 'this' represents a nested join that is a NATURAL JOIN. |
2050 | For one of the operands of 'this', the member 'natural_join' points |
2051 | to the other operand of 'this'. |
2052 | */ |
2053 | bool is_natural_join; |
2054 | /* Field names in a USING clause for JOIN ... USING. */ |
2055 | List<String> *join_using_fields; |
2056 | /* |
2057 | Explicitly store the result columns of either a NATURAL/USING join or |
2058 | an operand of such a join. |
2059 | */ |
2060 | List<Natural_join_column> *join_columns; |
2061 | /* TRUE if join_columns contains all columns of this table reference. */ |
2062 | bool is_join_columns_complete; |
2063 | |
2064 | /* |
2065 | List of nodes in a nested join tree, that should be considered as |
2066 | leaves with respect to name resolution. The leaves are: views, |
2067 | top-most nodes representing NATURAL/USING joins, subqueries, and |
2068 | base tables. All of these TABLE_LIST instances contain a |
2069 | materialized list of columns. The list is local to a subquery. |
2070 | */ |
2071 | TABLE_LIST *next_name_resolution_table; |
2072 | /* Index names in a "... JOIN ... USE/IGNORE INDEX ..." clause. */ |
2073 | List<Index_hint> *index_hints; |
2074 | TABLE *table; /* opened table */ |
2075 | uint table_id; /* table id (from binlog) for opened table */ |
2076 | /* |
2077 | select_result for derived table to pass it from table creation to table |
2078 | filling procedure |
2079 | */ |
2080 | select_unit *derived_result; |
2081 | /* Stub used for materialized derived tables. */ |
2082 | table_map map; /* ID bit of table (1,2,4,8,16...) */ |
2083 | table_map get_map() |
2084 | { |
2085 | return jtbm_subselect? table_map(1) << jtbm_table_no : table->map; |
2086 | } |
2087 | uint get_tablenr() |
2088 | { |
2089 | return jtbm_subselect? jtbm_table_no : table->tablenr; |
2090 | } |
2091 | void set_tablenr(uint new_tablenr) |
2092 | { |
2093 | if (jtbm_subselect) |
2094 | { |
2095 | jtbm_table_no= new_tablenr; |
2096 | } |
2097 | if (table) |
2098 | { |
2099 | table->tablenr= new_tablenr; |
2100 | table->map= table_map(1) << new_tablenr; |
2101 | } |
2102 | } |
2103 | /* |
2104 | Reference from aux_tables to local list entry of main select of |
2105 | multi-delete statement: |
2106 | delete t1 from t2,t1 where t1.a<'B' and t2.b=t1.b; |
2107 | here it will be reference of first occurrence of t1 to second (as you |
2108 | can see this lists can't be merged) |
2109 | */ |
2110 | TABLE_LIST *correspondent_table; |
2111 | /** |
2112 | @brief Normally, this field is non-null for anonymous derived tables only. |
2113 | |
2114 | @details This field is set to non-null for |
2115 | |
2116 | - Anonymous derived tables, In this case it points to the SELECT_LEX_UNIT |
2117 | representing the derived table. E.g. for a query |
2118 | |
2119 | @verbatim SELECT * FROM (SELECT a FROM t1) b @endverbatim |
2120 | |
2121 | For the @c TABLE_LIST representing the derived table @c b, @c derived |
2122 | points to the SELECT_LEX_UNIT representing the result of the query within |
2123 | parenteses. |
2124 | |
2125 | - Views. This is set for views with @verbatim ALGORITHM = TEMPTABLE |
2126 | @endverbatim by mysql_make_view(). |
2127 | |
2128 | @note Inside views, a subquery in the @c FROM clause is not allowed. |
2129 | @note Do not use this field to separate views/base tables/anonymous |
2130 | derived tables. Use TABLE_LIST::is_anonymous_derived_table(). |
2131 | */ |
2132 | st_select_lex_unit *derived; /* SELECT_LEX_UNIT of derived table */ |
2133 | With_element *with; /* With element defining this table (if any) */ |
2134 | /* Bitmap of the defining with element */ |
2135 | table_map with_internal_reference_map; |
2136 | TABLE_LIST * next_with_rec_ref; |
2137 | bool is_derived_with_recursive_reference; |
2138 | bool block_handle_derived; |
2139 | ST_SCHEMA_TABLE *schema_table; /* Information_schema table */ |
2140 | st_select_lex *schema_select_lex; |
2141 | /* |
2142 | True when the view field translation table is used to convert |
2143 | schema table fields for backwards compatibility with SHOW command. |
2144 | */ |
2145 | bool schema_table_reformed; |
2146 | TMP_TABLE_PARAM *schema_table_param; |
2147 | /* link to select_lex where this table was used */ |
2148 | st_select_lex *select_lex; |
2149 | LEX *view; /* link on VIEW lex for merging */ |
2150 | Field_translator *field_translation; /* array of VIEW fields */ |
2151 | /* pointer to element after last one in translation table above */ |
2152 | Field_translator *field_translation_end; |
2153 | bool field_translation_updated; |
2154 | /* |
2155 | List (based on next_local) of underlying tables of this view. I.e. it |
2156 | does not include the tables of subqueries used in the view. Is set only |
2157 | for merged views. |
2158 | */ |
2159 | TABLE_LIST *merge_underlying_list; |
2160 | /* |
2161 | - 0 for base tables |
2162 | - in case of the view it is the list of all (not only underlying |
2163 | tables but also used in subquery ones) tables of the view. |
2164 | */ |
2165 | List<TABLE_LIST> *view_tables; |
2166 | /* most upper view this table belongs to */ |
2167 | TABLE_LIST *belong_to_view; |
2168 | /* A derived table this table belongs to */ |
2169 | TABLE_LIST *belong_to_derived; |
2170 | /* |
2171 | The view directly referencing this table |
2172 | (non-zero only for merged underlying tables of a view). |
2173 | */ |
2174 | TABLE_LIST *referencing_view; |
2175 | |
2176 | table_map view_used_tables; |
2177 | table_map map_exec; |
2178 | /* TODO: check if this can be joined with jtbm_table_no */ |
2179 | uint tablenr_exec; |
2180 | uint maybe_null_exec; |
2181 | |
2182 | /* Ptr to parent MERGE table list item. See top comment in ha_myisammrg.cc */ |
2183 | TABLE_LIST *parent_l; |
2184 | /* |
2185 | Security context (non-zero only for tables which belong |
2186 | to view with SQL SECURITY DEFINER) |
2187 | */ |
2188 | Security_context *security_ctx; |
2189 | /* |
2190 | This view security context (non-zero only for views with |
2191 | SQL SECURITY DEFINER) |
2192 | */ |
2193 | Security_context *view_sctx; |
2194 | bool allowed_show; |
2195 | Item *where; /* VIEW WHERE clause condition */ |
2196 | Item *check_option; /* WITH CHECK OPTION condition */ |
2197 | LEX_STRING select_stmt; /* text of (CREATE/SELECT) statement */ |
2198 | LEX_CSTRING md5; /* md5 of query text */ |
2199 | LEX_CSTRING source; /* source of CREATE VIEW */ |
2200 | LEX_CSTRING view_db; /* saved view database */ |
2201 | LEX_CSTRING view_name; /* saved view name */ |
2202 | LEX_STRING timestamp; /* GMT time stamp of last operation */ |
2203 | LEX_USER definer; /* definer of view */ |
2204 | ulonglong file_version; /* version of file's field set */ |
2205 | ulonglong mariadb_version; /* version of server on creation */ |
2206 | ulonglong updatable_view; /* VIEW can be updated */ |
2207 | /** |
2208 | @brief The declared algorithm, if this is a view. |
2209 | @details One of |
2210 | - VIEW_ALGORITHM_UNDEFINED |
2211 | - VIEW_ALGORITHM_TMPTABLE |
2212 | - VIEW_ALGORITHM_MERGE |
2213 | @to do Replace with an enum |
2214 | */ |
2215 | ulonglong algorithm; |
2216 | ulonglong view_suid; /* view is suid (TRUE dy default) */ |
2217 | ulonglong with_check; /* WITH CHECK OPTION */ |
2218 | /* |
2219 | effective value of WITH CHECK OPTION (differ for temporary table |
2220 | algorithm) |
2221 | */ |
2222 | uint8 effective_with_check; |
2223 | /** |
2224 | @brief The view algorithm that is actually used, if this is a view. |
2225 | @details One of |
2226 | - VIEW_ALGORITHM_UNDEFINED |
2227 | - VIEW_ALGORITHM_TMPTABLE |
2228 | - VIEW_ALGORITHM_MERGE |
2229 | @to do Replace with an enum |
2230 | */ |
2231 | uint8 derived_type; |
2232 | GRANT_INFO grant; |
2233 | /* data need by some engines in query cache*/ |
2234 | ulonglong engine_data; |
2235 | /* call back function for asking handler about caching in query cache */ |
2236 | qc_engine_callback callback_func; |
2237 | thr_lock_type lock_type; |
2238 | uint outer_join; /* Which join type */ |
2239 | uint shared; /* Used in multi-upd */ |
2240 | bool updatable; /* VIEW/TABLE can be updated now */ |
2241 | bool straight; /* optimize with prev table */ |
2242 | bool updating; /* for replicate-do/ignore table */ |
2243 | bool force_index; /* prefer index over table scan */ |
2244 | bool ignore_leaves; /* preload only non-leaf nodes */ |
2245 | bool crashed; /* Table was found crashed */ |
2246 | table_map dep_tables; /* tables the table depends on */ |
2247 | table_map on_expr_dep_tables; /* tables on expression depends on */ |
2248 | struct st_nested_join *nested_join; /* if the element is a nested join */ |
2249 | TABLE_LIST *embedding; /* nested join containing the table */ |
2250 | List<TABLE_LIST> *join_list;/* join list the table belongs to */ |
2251 | bool lifted; /* set to true when the table is moved to |
2252 | the upper level at the parsing stage */ |
2253 | bool cacheable_table; /* stop PS caching */ |
2254 | /* used in multi-upd/views privilege check */ |
2255 | bool table_in_first_from_clause; |
2256 | /** |
2257 | Specifies which kind of table should be open for this element |
2258 | of table list. |
2259 | */ |
2260 | enum enum_open_type open_type; |
2261 | /* TRUE if this merged view contain auto_increment field */ |
2262 | bool contain_auto_increment; |
2263 | bool compact_view_format; /* Use compact format for SHOW CREATE VIEW */ |
2264 | /* view where processed */ |
2265 | bool where_processed; |
2266 | /* TRUE <=> VIEW CHECK OPTION expression has been processed */ |
2267 | bool check_option_processed; |
2268 | /* TABLE_TYPE_UNKNOWN if any type is acceptable */ |
2269 | Table_type required_type; |
2270 | handlerton *db_type; /* table_type for handler */ |
2271 | char timestamp_buffer[MAX_DATETIME_WIDTH + 1]; |
2272 | /* |
2273 | This TABLE_LIST object is just placeholder for prelocking, it will be |
2274 | used for implicit LOCK TABLES only and won't be used in real statement. |
2275 | */ |
2276 | prelocking_types prelocking_placeholder; |
2277 | /** |
2278 | Indicates that if TABLE_LIST object corresponds to the table/view |
2279 | which requires special handling. |
2280 | */ |
2281 | enum enum_open_strategy |
2282 | { |
2283 | /* Normal open. */ |
2284 | OPEN_NORMAL= 0, |
2285 | /* Associate a table share only if the the table exists. */ |
2286 | OPEN_IF_EXISTS, |
2287 | /* Don't associate a table share. */ |
2288 | OPEN_STUB |
2289 | } open_strategy; |
2290 | /** TRUE if an alias for this table was specified in the SQL. */ |
2291 | bool is_alias; |
2292 | /** TRUE if the table is referred to in the statement using a fully |
2293 | qualified name (<db_name>.<table_name>). |
2294 | */ |
2295 | bool is_fqtn; |
2296 | |
2297 | /* TRUE <=> derived table should be filled right after optimization. */ |
2298 | bool fill_me; |
2299 | /* TRUE <=> view/DT is merged. */ |
2300 | /* TODO: replace with derived_type */ |
2301 | bool merged; |
2302 | bool merged_for_insert; |
2303 | bool sequence; /* Part of NEXTVAL/CURVAL/LASTVAL */ |
2304 | |
2305 | /* |
2306 | Items created by create_view_field and collected to change them in case |
2307 | of materialization of the view/derived table |
2308 | */ |
2309 | List<Item> used_items; |
2310 | /* Sublist (tail) of persistent used_items */ |
2311 | List<Item> persistent_used_items; |
2312 | |
2313 | /* View creation context. */ |
2314 | |
2315 | View_creation_ctx *view_creation_ctx; |
2316 | |
2317 | /* |
2318 | Attributes to save/load view creation context in/from frm-file. |
2319 | |
2320 | Ther are required only to be able to use existing parser to load |
2321 | view-definition file. As soon as the parser parsed the file, view |
2322 | creation context is initialized and the attributes become redundant. |
2323 | |
2324 | These attributes MUST NOT be used for any purposes but the parsing. |
2325 | */ |
2326 | |
2327 | LEX_CSTRING view_client_cs_name; |
2328 | LEX_CSTRING view_connection_cl_name; |
2329 | |
2330 | /* |
2331 | View definition (SELECT-statement) in the UTF-form. |
2332 | */ |
2333 | |
2334 | LEX_CSTRING view_body_utf8; |
2335 | |
2336 | /* End of view definition context. */ |
2337 | |
2338 | /** |
2339 | Indicates what triggers we need to pre-load for this TABLE_LIST |
2340 | when opening an associated TABLE. This is filled after |
2341 | the parsed tree is created. |
2342 | */ |
2343 | uint8 trg_event_map; |
2344 | /* TRUE <=> this table is a const one and was optimized away. */ |
2345 | bool optimized_away; |
2346 | |
2347 | /** |
2348 | TRUE <=> already materialized. Valid only for materialized derived |
2349 | tables/views. |
2350 | */ |
2351 | bool materialized; |
2352 | /* I_S: Flags to open_table (e.g. OPEN_TABLE_ONLY or OPEN_VIEW_ONLY) */ |
2353 | uint i_s_requested_object; |
2354 | |
2355 | bool prohibit_cond_pushdown; |
2356 | |
2357 | /* |
2358 | I_S: how to read the tables (SKIP_OPEN_TABLE/OPEN_FRM_ONLY/OPEN_FULL_TABLE) |
2359 | */ |
2360 | uint table_open_method; |
2361 | /* |
2362 | I_S: where the schema table was filled |
2363 | (this is a hack. The code should be able to figure out whether reading |
2364 | from I_S should be done by create_sort_index() or by JOIN::exec.) |
2365 | */ |
2366 | enum enum_schema_table_state schema_table_state; |
2367 | |
2368 | /* Something like a "query plan" for reading INFORMATION_SCHEMA table */ |
2369 | IS_table_read_plan *is_table_read_plan; |
2370 | |
2371 | MDL_request mdl_request; |
2372 | |
2373 | #ifdef WITH_PARTITION_STORAGE_ENGINE |
2374 | /* List to carry partition names from PARTITION (...) clause in statement */ |
2375 | List<String> *partition_names; |
2376 | #endif /* WITH_PARTITION_STORAGE_ENGINE */ |
2377 | |
2378 | void calc_md5(const char *buffer); |
2379 | int view_check_option(THD *thd, bool ignore_failure); |
2380 | bool create_field_translation(THD *thd); |
2381 | bool setup_underlying(THD *thd); |
2382 | void cleanup_items(); |
2383 | bool placeholder() |
2384 | { |
2385 | return derived || view || schema_table || !table; |
2386 | } |
2387 | void print(THD *thd, table_map eliminated_tables, String *str, |
2388 | enum_query_type query_type); |
2389 | bool check_single_table(TABLE_LIST **table, table_map map, |
2390 | TABLE_LIST *view); |
2391 | bool set_insert_values(MEM_ROOT *mem_root); |
2392 | void hide_view_error(THD *thd); |
2393 | TABLE_LIST *find_underlying_table(TABLE *table); |
2394 | TABLE_LIST *first_leaf_for_name_resolution(); |
2395 | TABLE_LIST *last_leaf_for_name_resolution(); |
2396 | |
2397 | /* System Versioning */ |
2398 | vers_select_conds_t vers_conditions; |
2399 | |
2400 | /** |
2401 | @brief |
2402 | Find the bottom in the chain of embedded table VIEWs. |
2403 | |
2404 | @detail |
2405 | This is used for single-table UPDATE/DELETE when they are modifying a |
2406 | single-table VIEW. |
2407 | */ |
2408 | TABLE_LIST *find_table_for_update() |
2409 | { |
2410 | TABLE_LIST *tbl= this; |
2411 | while(!tbl->is_multitable() && tbl->single_table_updatable() && |
2412 | tbl->merge_underlying_list) |
2413 | { |
2414 | tbl= tbl->merge_underlying_list; |
2415 | } |
2416 | return tbl; |
2417 | } |
2418 | TABLE *get_real_join_table(); |
2419 | bool is_leaf_for_name_resolution(); |
2420 | inline TABLE_LIST *top_table() |
2421 | { return belong_to_view ? belong_to_view : this; } |
2422 | inline bool prepare_check_option(THD *thd) |
2423 | { |
2424 | bool res= FALSE; |
2425 | if (effective_with_check) |
2426 | res= prep_check_option(thd, effective_with_check); |
2427 | return res; |
2428 | } |
2429 | inline bool prepare_where(THD *thd, Item **conds, |
2430 | bool no_where_clause) |
2431 | { |
2432 | if (!view || is_merged_derived()) |
2433 | return prep_where(thd, conds, no_where_clause); |
2434 | return FALSE; |
2435 | } |
2436 | |
2437 | void register_want_access(ulong want_access); |
2438 | bool prepare_security(THD *thd); |
2439 | #ifndef NO_EMBEDDED_ACCESS_CHECKS |
2440 | Security_context *find_view_security_context(THD *thd); |
2441 | bool prepare_view_security_context(THD *thd); |
2442 | #endif |
2443 | /* |
2444 | Cleanup for re-execution in a prepared statement or a stored |
2445 | procedure. |
2446 | */ |
2447 | void reinit_before_use(THD *thd); |
2448 | Item_subselect *containing_subselect(); |
2449 | |
2450 | /* |
2451 | Compiles the tagged hints list and fills up TABLE::keys_in_use_for_query, |
2452 | TABLE::keys_in_use_for_group_by, TABLE::keys_in_use_for_order_by, |
2453 | TABLE::force_index and TABLE::covering_keys. |
2454 | */ |
2455 | bool process_index_hints(TABLE *table); |
2456 | |
2457 | /** |
2458 | Compare the version of metadata from the previous execution |
2459 | (if any) with values obtained from the current table |
2460 | definition cache element. |
2461 | |
2462 | @sa check_and_update_table_version() |
2463 | */ |
2464 | inline |
2465 | bool is_table_ref_id_equal(TABLE_SHARE *s) const |
2466 | { |
2467 | return (m_table_ref_type == s->get_table_ref_type() && |
2468 | m_table_ref_version == s->get_table_ref_version()); |
2469 | } |
2470 | |
2471 | /** |
2472 | Record the value of metadata version of the corresponding |
2473 | table definition cache element in this parse tree node. |
2474 | |
2475 | @sa check_and_update_table_version() |
2476 | */ |
2477 | inline |
2478 | void set_table_ref_id(TABLE_SHARE *s) |
2479 | { set_table_ref_id(s->get_table_ref_type(), s->get_table_ref_version()); } |
2480 | |
2481 | inline |
2482 | void set_table_ref_id(enum_table_ref_type table_ref_type_arg, |
2483 | ulong table_ref_version_arg) |
2484 | { |
2485 | m_table_ref_type= table_ref_type_arg; |
2486 | m_table_ref_version= table_ref_version_arg; |
2487 | } |
2488 | |
2489 | /* Set of functions returning/setting state of a derived table/view. */ |
2490 | inline bool is_non_derived() |
2491 | { |
2492 | return (!derived_type); |
2493 | } |
2494 | inline bool is_view_or_derived() |
2495 | { |
2496 | return (derived_type); |
2497 | } |
2498 | inline bool is_view() |
2499 | { |
2500 | return (derived_type & DTYPE_VIEW); |
2501 | } |
2502 | inline bool is_derived() |
2503 | { |
2504 | return (derived_type & DTYPE_TABLE); |
2505 | } |
2506 | bool is_with_table(); |
2507 | bool is_recursive_with_table(); |
2508 | bool is_with_table_recursive_reference(); |
2509 | void register_as_derived_with_rec_ref(With_element *rec_elem); |
2510 | bool is_nonrecursive_derived_with_rec_ref(); |
2511 | bool fill_recursive(THD *thd); |
2512 | |
2513 | inline void set_view() |
2514 | { |
2515 | derived_type= DTYPE_VIEW; |
2516 | } |
2517 | inline void set_derived() |
2518 | { |
2519 | derived_type= DTYPE_TABLE; |
2520 | } |
2521 | inline bool is_merged_derived() |
2522 | { |
2523 | return (derived_type & DTYPE_MERGE); |
2524 | } |
2525 | inline void set_merged_derived() |
2526 | { |
2527 | DBUG_ENTER("set_merged_derived" ); |
2528 | DBUG_PRINT("enter" , ("Alias: '%s' Unit: %p" , |
2529 | (alias.str ? alias.str : "<NULL>" ), |
2530 | get_unit())); |
2531 | derived_type= ((derived_type & DTYPE_MASK) | |
2532 | DTYPE_TABLE | DTYPE_MERGE); |
2533 | set_check_merged(); |
2534 | DBUG_VOID_RETURN; |
2535 | } |
2536 | inline bool is_materialized_derived() |
2537 | { |
2538 | return (derived_type & DTYPE_MATERIALIZE); |
2539 | } |
2540 | void set_materialized_derived() |
2541 | { |
2542 | DBUG_ENTER("set_materialized_derived" ); |
2543 | DBUG_PRINT("enter" , ("Alias: '%s' Unit: %p" , |
2544 | (alias.str ? alias.str : "<NULL>" ), |
2545 | get_unit())); |
2546 | derived= get_unit(); |
2547 | derived_type= ((derived_type & (derived ? DTYPE_MASK : DTYPE_VIEW)) | |
2548 | DTYPE_TABLE | DTYPE_MATERIALIZE); |
2549 | set_check_materialized(); |
2550 | DBUG_VOID_RETURN; |
2551 | } |
2552 | inline bool is_multitable() |
2553 | { |
2554 | return (derived_type & DTYPE_MULTITABLE); |
2555 | } |
2556 | inline void set_multitable() |
2557 | { |
2558 | derived_type|= DTYPE_MULTITABLE; |
2559 | } |
2560 | bool set_as_with_table(THD *thd, With_element *with_elem); |
2561 | void reset_const_table(); |
2562 | bool handle_derived(LEX *lex, uint phases); |
2563 | |
2564 | /** |
2565 | @brief True if this TABLE_LIST represents an anonymous derived table, |
2566 | i.e. the result of a subquery. |
2567 | */ |
2568 | bool is_anonymous_derived_table() const { return derived && !view; } |
2569 | |
2570 | /** |
2571 | @brief Returns the name of the database that the referenced table belongs |
2572 | to. |
2573 | */ |
2574 | const char *get_db_name() const { return view != NULL ? view_db.str : db.str; } |
2575 | |
2576 | /** |
2577 | @brief Returns the name of the table that this TABLE_LIST represents. |
2578 | |
2579 | @details The unqualified table name or view name for a table or view, |
2580 | respectively. |
2581 | */ |
2582 | const char *get_table_name() const { return view != NULL ? view_name.str : table_name.str; } |
2583 | bool is_active_sjm(); |
2584 | bool is_jtbm() { return MY_TEST(jtbm_subselect != NULL); } |
2585 | st_select_lex_unit *get_unit(); |
2586 | st_select_lex *get_single_select(); |
2587 | void wrap_into_nested_join(List<TABLE_LIST> &join_list); |
2588 | bool init_derived(THD *thd, bool init_view); |
2589 | int fetch_number_of_rows(); |
2590 | bool change_refs_to_fields(); |
2591 | |
2592 | bool single_table_updatable(); |
2593 | |
2594 | bool is_inner_table_of_outer_join() |
2595 | { |
2596 | for (TABLE_LIST *tbl= this; tbl; tbl= tbl->embedding) |
2597 | { |
2598 | if (tbl->outer_join) |
2599 | return true; |
2600 | } |
2601 | return false; |
2602 | } |
2603 | void set_lock_type(THD* thd, enum thr_lock_type lock); |
2604 | void check_pushable_cond_for_table(Item *cond); |
2605 | Item *build_pushable_cond_for_table(THD *thd, Item *cond); |
2606 | |
2607 | private: |
2608 | bool prep_check_option(THD *thd, uint8 check_opt_type); |
2609 | bool prep_where(THD *thd, Item **conds, bool no_where_clause); |
2610 | void set_check_materialized(); |
2611 | #ifndef DBUG_OFF |
2612 | void set_check_merged(); |
2613 | #else |
2614 | inline void set_check_merged() {} |
2615 | #endif |
2616 | /** See comments for set_table_ref_id() */ |
2617 | enum enum_table_ref_type m_table_ref_type; |
2618 | /** See comments for set_table_ref_id() */ |
2619 | ulong m_table_ref_version; |
2620 | }; |
2621 | |
2622 | class Item; |
2623 | |
2624 | /* |
2625 | Iterator over the fields of a generic table reference. |
2626 | */ |
2627 | |
2628 | class Field_iterator: public Sql_alloc |
2629 | { |
2630 | public: |
2631 | Field_iterator() {} /* Remove gcc warning */ |
2632 | virtual ~Field_iterator() {} |
2633 | virtual void set(TABLE_LIST *)= 0; |
2634 | virtual void next()= 0; |
2635 | virtual bool end_of_fields()= 0; /* Return 1 at end of list */ |
2636 | virtual LEX_CSTRING *name()= 0; |
2637 | virtual Item *create_item(THD *)= 0; |
2638 | virtual Field *field()= 0; |
2639 | }; |
2640 | |
2641 | |
2642 | /* |
2643 | Iterator over the fields of a base table, view with temporary |
2644 | table, or subquery. |
2645 | */ |
2646 | |
2647 | class Field_iterator_table: public Field_iterator |
2648 | { |
2649 | Field **ptr; |
2650 | public: |
2651 | Field_iterator_table() :ptr(0) {} |
2652 | void set(TABLE_LIST *table) { ptr= table->table->field; } |
2653 | void set_table(TABLE *table) { ptr= table->field; } |
2654 | void next() { ptr++; } |
2655 | bool end_of_fields() { return *ptr == 0; } |
2656 | LEX_CSTRING *name(); |
2657 | Item *create_item(THD *thd); |
2658 | Field *field() { return *ptr; } |
2659 | }; |
2660 | |
2661 | |
2662 | /* Iterator over the fields of a merge view. */ |
2663 | |
2664 | class Field_iterator_view: public Field_iterator |
2665 | { |
2666 | Field_translator *ptr, *array_end; |
2667 | TABLE_LIST *view; |
2668 | public: |
2669 | Field_iterator_view() :ptr(0), array_end(0) {} |
2670 | void set(TABLE_LIST *table); |
2671 | void next() { ptr++; } |
2672 | bool end_of_fields() { return ptr == array_end; } |
2673 | LEX_CSTRING *name(); |
2674 | Item *create_item(THD *thd); |
2675 | Item **item_ptr() {return &ptr->item; } |
2676 | Field *field() { return 0; } |
2677 | inline Item *item() { return ptr->item; } |
2678 | Field_translator *field_translator() { return ptr; } |
2679 | }; |
2680 | |
2681 | |
2682 | /* |
2683 | Field_iterator interface to the list of materialized fields of a |
2684 | NATURAL/USING join. |
2685 | */ |
2686 | |
2687 | class Field_iterator_natural_join: public Field_iterator |
2688 | { |
2689 | List_iterator_fast<Natural_join_column> column_ref_it; |
2690 | Natural_join_column *cur_column_ref; |
2691 | public: |
2692 | Field_iterator_natural_join() :cur_column_ref(NULL) {} |
2693 | ~Field_iterator_natural_join() {} |
2694 | void set(TABLE_LIST *table); |
2695 | void next(); |
2696 | bool end_of_fields() { return !cur_column_ref; } |
2697 | LEX_CSTRING *name() { return cur_column_ref->name(); } |
2698 | Item *create_item(THD *thd) { return cur_column_ref->create_item(thd); } |
2699 | Field *field() { return cur_column_ref->field(); } |
2700 | Natural_join_column *column_ref() { return cur_column_ref; } |
2701 | }; |
2702 | |
2703 | |
2704 | /* |
2705 | Generic iterator over the fields of an arbitrary table reference. |
2706 | |
2707 | DESCRIPTION |
2708 | This class unifies the various ways of iterating over the columns |
2709 | of a table reference depending on the type of SQL entity it |
2710 | represents. If such an entity represents a nested table reference, |
2711 | this iterator encapsulates the iteration over the columns of the |
2712 | members of the table reference. |
2713 | |
2714 | IMPLEMENTATION |
2715 | The implementation assumes that all underlying NATURAL/USING table |
2716 | references already contain their result columns and are linked into |
2717 | the list TABLE_LIST::next_name_resolution_table. |
2718 | */ |
2719 | |
2720 | class Field_iterator_table_ref: public Field_iterator |
2721 | { |
2722 | TABLE_LIST *table_ref, *first_leaf, *last_leaf; |
2723 | Field_iterator_table table_field_it; |
2724 | Field_iterator_view view_field_it; |
2725 | Field_iterator_natural_join natural_join_it; |
2726 | Field_iterator *field_it; |
2727 | void set_field_iterator(); |
2728 | public: |
2729 | Field_iterator_table_ref() :field_it(NULL) {} |
2730 | void set(TABLE_LIST *table); |
2731 | void next(); |
2732 | bool end_of_fields() |
2733 | { return (table_ref == last_leaf && field_it->end_of_fields()); } |
2734 | LEX_CSTRING *name() { return field_it->name(); } |
2735 | const char *get_table_name(); |
2736 | const char *get_db_name(); |
2737 | GRANT_INFO *grant(); |
2738 | Item *create_item(THD *thd) { return field_it->create_item(thd); } |
2739 | Field *field() { return field_it->field(); } |
2740 | Natural_join_column *get_or_create_column_ref(THD *thd, TABLE_LIST *parent_table_ref); |
2741 | Natural_join_column *get_natural_column_ref(); |
2742 | }; |
2743 | |
2744 | |
2745 | typedef struct st_nested_join |
2746 | { |
2747 | List<TABLE_LIST> join_list; /* list of elements in the nested join */ |
2748 | /* |
2749 | Bitmap of tables within this nested join (including those embedded within |
2750 | its children), including tables removed by table elimination. |
2751 | */ |
2752 | table_map used_tables; |
2753 | table_map not_null_tables; /* tables that rejects nulls */ |
2754 | /** |
2755 | Used for pointing out the first table in the plan being covered by this |
2756 | join nest. It is used exclusively within make_outerjoin_info(). |
2757 | */ |
2758 | struct st_join_table *first_nested; |
2759 | /* |
2760 | Used to count tables in the nested join in 2 isolated places: |
2761 | 1. In make_outerjoin_info(). |
2762 | 2. check_interleaving_with_nj/restore_prev_nj_state (these are called |
2763 | by the join optimizer. |
2764 | Before each use the counters are zeroed by reset_nj_counters. |
2765 | */ |
2766 | uint counter; |
2767 | /* |
2768 | Number of elements in join_list that were not (or contain table(s) that |
2769 | weren't) removed by table elimination. |
2770 | */ |
2771 | uint n_tables; |
2772 | nested_join_map nj_map; /* Bit used to identify this nested join*/ |
2773 | /* |
2774 | (Valid only for semi-join nests) Bitmap of tables outside the semi-join |
2775 | that are used within the semi-join's ON condition. |
2776 | */ |
2777 | table_map sj_depends_on; |
2778 | /* Outer non-trivially correlated tables */ |
2779 | table_map sj_corr_tables; |
2780 | List<Item_ptr> sj_outer_expr_list; |
2781 | /** |
2782 | True if this join nest node is completely covered by the query execution |
2783 | plan. This means two things. |
2784 | |
2785 | 1. All tables on its @c join_list are covered by the plan. |
2786 | |
2787 | 2. All child join nest nodes are fully covered. |
2788 | */ |
2789 | bool is_fully_covered() const { return n_tables == counter; } |
2790 | } NESTED_JOIN; |
2791 | |
2792 | |
2793 | typedef struct st_changed_table_list |
2794 | { |
2795 | struct st_changed_table_list *next; |
2796 | char *key; |
2797 | size_t key_length; |
2798 | } CHANGED_TABLE_LIST; |
2799 | |
2800 | |
2801 | typedef struct st_open_table_list{ |
2802 | struct st_open_table_list *next; |
2803 | char *db,*table; |
2804 | uint32 in_use,locked; |
2805 | } OPEN_TABLE_LIST; |
2806 | |
2807 | |
2808 | static inline my_bitmap_map *tmp_use_all_columns(TABLE *table, |
2809 | MY_BITMAP *bitmap) |
2810 | { |
2811 | my_bitmap_map *old= bitmap->bitmap; |
2812 | bitmap->bitmap= table->s->all_set.bitmap; |
2813 | return old; |
2814 | } |
2815 | |
2816 | |
2817 | static inline void tmp_restore_column_map(MY_BITMAP *bitmap, |
2818 | my_bitmap_map *old) |
2819 | { |
2820 | bitmap->bitmap= old; |
2821 | } |
2822 | |
2823 | /* The following is only needed for debugging */ |
2824 | |
2825 | static inline my_bitmap_map *dbug_tmp_use_all_columns(TABLE *table, |
2826 | MY_BITMAP *bitmap) |
2827 | { |
2828 | #ifdef DBUG_ASSERT_EXISTS |
2829 | return tmp_use_all_columns(table, bitmap); |
2830 | #else |
2831 | return 0; |
2832 | #endif |
2833 | } |
2834 | |
2835 | static inline void dbug_tmp_restore_column_map(MY_BITMAP *bitmap, |
2836 | my_bitmap_map *old) |
2837 | { |
2838 | #ifdef DBUG_ASSERT_EXISTS |
2839 | tmp_restore_column_map(bitmap, old); |
2840 | #endif |
2841 | } |
2842 | |
2843 | |
2844 | /* |
2845 | Variant of the above : handle both read and write sets. |
2846 | Provide for the possiblity of the read set being the same as the write set |
2847 | */ |
2848 | static inline void dbug_tmp_use_all_columns(TABLE *table, |
2849 | my_bitmap_map **save, |
2850 | MY_BITMAP *read_set, |
2851 | MY_BITMAP *write_set) |
2852 | { |
2853 | #ifdef DBUG_ASSERT_EXISTS |
2854 | save[0]= read_set->bitmap; |
2855 | save[1]= write_set->bitmap; |
2856 | (void) tmp_use_all_columns(table, read_set); |
2857 | (void) tmp_use_all_columns(table, write_set); |
2858 | #endif |
2859 | } |
2860 | |
2861 | |
2862 | static inline void dbug_tmp_restore_column_maps(MY_BITMAP *read_set, |
2863 | MY_BITMAP *write_set, |
2864 | my_bitmap_map **old) |
2865 | { |
2866 | #ifdef DBUG_ASSERT_EXISTS |
2867 | tmp_restore_column_map(read_set, old[0]); |
2868 | tmp_restore_column_map(write_set, old[1]); |
2869 | #endif |
2870 | } |
2871 | |
2872 | bool ok_for_lower_case_names(const char *names); |
2873 | |
2874 | enum get_table_share_flags { |
2875 | GTS_TABLE = 1, |
2876 | GTS_VIEW = 2, |
2877 | GTS_NOLOCK = 4, |
2878 | GTS_USE_DISCOVERY = 8, |
2879 | GTS_FORCE_DISCOVERY = 16 |
2880 | }; |
2881 | |
2882 | size_t max_row_length(TABLE *table, const uchar *data); |
2883 | |
2884 | void init_mdl_requests(TABLE_LIST *table_list); |
2885 | |
2886 | enum open_frm_error open_table_from_share(THD *thd, TABLE_SHARE *share, |
2887 | const LEX_CSTRING *alias, uint db_stat, uint prgflag, |
2888 | uint ha_open_flags, TABLE *outparam, |
2889 | bool is_create_table, |
2890 | List<String> *partitions_to_open= NULL); |
2891 | bool fix_session_vcol_expr(THD *thd, Virtual_column_info *vcol); |
2892 | bool fix_session_vcol_expr_for_read(THD *thd, Field *field, |
2893 | Virtual_column_info *vcol); |
2894 | bool parse_vcol_defs(THD *thd, MEM_ROOT *mem_root, TABLE *table, |
2895 | bool *error_reported); |
2896 | TABLE_SHARE *alloc_table_share(const char *db, const char *table_name, |
2897 | const char *key, uint key_length); |
2898 | void init_tmp_table_share(THD *thd, TABLE_SHARE *share, const char *key, |
2899 | uint key_length, |
2900 | const char *table_name, const char *path); |
2901 | void free_table_share(TABLE_SHARE *share); |
2902 | enum open_frm_error open_table_def(THD *thd, TABLE_SHARE *share, |
2903 | uint flags = GTS_TABLE); |
2904 | |
2905 | void open_table_error(TABLE_SHARE *share, enum open_frm_error error, |
2906 | int db_errno); |
2907 | void update_create_info_from_table(HA_CREATE_INFO *info, TABLE *form); |
2908 | bool check_db_name(LEX_STRING *db); |
2909 | bool check_column_name(const char *name); |
2910 | bool check_table_name(const char *name, size_t length, bool check_for_path_chars); |
2911 | int rename_file_ext(const char * from,const char * to,const char * ext); |
2912 | char *get_field(MEM_ROOT *mem, Field *field); |
2913 | bool get_field(MEM_ROOT *mem, Field *field, class String *res); |
2914 | |
2915 | bool (THD *thd, LEX_CSTRING *, size_t max_len, |
2916 | uint err_code, const char *name); |
2917 | |
2918 | int closefrm(TABLE *table); |
2919 | void free_blobs(TABLE *table); |
2920 | void free_field_buffers_larger_than(TABLE *table, uint32 size); |
2921 | ulong get_form_pos(File file, uchar *head, TYPELIB *save_names); |
2922 | void append_unescaped(String *res, const char *pos, size_t length); |
2923 | void (THD *thd, uint reclength, uchar *fileinfo, |
2924 | HA_CREATE_INFO *create_info, uint keys, KEY *key_info); |
2925 | const char *fn_frm_ext(const char *name); |
2926 | |
2927 | /* Check that the integer is in the internal */ |
2928 | static inline int set_zone(int nr,int min_zone,int max_zone) |
2929 | { |
2930 | if (nr <= min_zone) |
2931 | return min_zone; |
2932 | if (nr >= max_zone) |
2933 | return max_zone; |
2934 | return nr; |
2935 | } |
2936 | |
2937 | /* performance schema */ |
2938 | extern LEX_CSTRING PERFORMANCE_SCHEMA_DB_NAME; |
2939 | |
2940 | extern LEX_CSTRING GENERAL_LOG_NAME; |
2941 | extern LEX_CSTRING SLOW_LOG_NAME; |
2942 | extern LEX_CSTRING TRANSACTION_REG_NAME; |
2943 | |
2944 | /* information schema */ |
2945 | extern LEX_CSTRING INFORMATION_SCHEMA_NAME; |
2946 | extern LEX_CSTRING MYSQL_SCHEMA_NAME; |
2947 | |
2948 | /* table names */ |
2949 | extern LEX_CSTRING MYSQL_USER_NAME, MYSQL_DB_NAME, MYSQL_PROC_NAME; |
2950 | |
2951 | inline bool is_infoschema_db(const LEX_CSTRING *name) |
2952 | { |
2953 | return (INFORMATION_SCHEMA_NAME.length == name->length && |
2954 | !my_strcasecmp(system_charset_info, |
2955 | INFORMATION_SCHEMA_NAME.str, name->str)); |
2956 | } |
2957 | |
2958 | inline void mark_as_null_row(TABLE *table) |
2959 | { |
2960 | table->null_row=1; |
2961 | table->status|=STATUS_NULL_ROW; |
2962 | bfill(table->null_flags,table->s->null_bytes,255); |
2963 | } |
2964 | |
2965 | bool is_simple_order(ORDER *order); |
2966 | |
2967 | class Open_tables_backup; |
2968 | |
2969 | /** Transaction Registry Table (TRT) |
2970 | |
2971 | This table holds transaction IDs, their corresponding times and other |
2972 | transaction-related data which is used for transaction order resolution. |
2973 | When versioned table marks its records lifetime with transaction IDs, |
2974 | TRT is used to get their actual timestamps. */ |
2975 | |
2976 | class TR_table: public TABLE_LIST |
2977 | { |
2978 | THD *thd; |
2979 | Open_tables_backup *open_tables_backup; |
2980 | |
2981 | public: |
2982 | enum field_id_t { |
2983 | FLD_TRX_ID= 0, |
2984 | FLD_COMMIT_ID, |
2985 | FLD_BEGIN_TS, |
2986 | FLD_COMMIT_TS, |
2987 | FLD_ISO_LEVEL, |
2988 | FIELD_COUNT |
2989 | }; |
2990 | |
2991 | enum enabled {NO, MAYBE, YES}; |
2992 | static enum enabled use_transaction_registry; |
2993 | |
2994 | /** |
2995 | @param[in,out] Thread handle |
2996 | @param[in] Current transaction is read-write. |
2997 | */ |
2998 | TR_table(THD *_thd, bool rw= false); |
2999 | /** |
3000 | Opens a transaction_registry table. |
3001 | |
3002 | @retval true on error, false otherwise. |
3003 | */ |
3004 | bool open(); |
3005 | ~TR_table(); |
3006 | /** |
3007 | @retval current thd |
3008 | */ |
3009 | THD *get_thd() const { return thd; } |
3010 | /** |
3011 | Stores value to internal transaction_registry TABLE object. |
3012 | |
3013 | @param[in] field number in a TABLE |
3014 | @param[in] value to store |
3015 | */ |
3016 | void store(uint field_id, ulonglong val); |
3017 | /** |
3018 | Stores value to internal transaction_registry TABLE object. |
3019 | |
3020 | @param[in] field number in a TABLE |
3021 | @param[in] value to store |
3022 | */ |
3023 | void store(uint field_id, timeval ts); |
3024 | /** |
3025 | Update the transaction_registry right before commit. |
3026 | @param start_id transaction identifier at start |
3027 | @param end_id transaction identifier at commit |
3028 | |
3029 | @retval false on success |
3030 | @retval true on error (the transaction must be rolled back) |
3031 | */ |
3032 | bool update(ulonglong start_id, ulonglong end_id); |
3033 | // return true if found; false if not found or error |
3034 | bool query(ulonglong trx_id); |
3035 | /** |
3036 | Gets a row from transaction_registry with the closest commit_timestamp to |
3037 | first argument. We can search for a value which a lesser or greater than |
3038 | first argument. Also loads a row into an internal TABLE object. |
3039 | |
3040 | @param[in] timestamp |
3041 | @param[in] true if we search for a lesser timestamp, false if greater |
3042 | @retval true if exists, false it not exists or an error occured |
3043 | */ |
3044 | bool query(MYSQL_TIME &commit_time, bool backwards); |
3045 | /** |
3046 | Checks whether transaction1 sees transaction0. |
3047 | |
3048 | @param[out] true if transaction1 sees transaction0, undefined on error and |
3049 | when transaction1=transaction0 and false otherwise |
3050 | @param[in] transaction_id of transaction1 |
3051 | @param[in] transaction_id of transaction0 |
3052 | @param[in] commit time of transaction1 or 0 if we want it to be queried |
3053 | @param[in] isolation level (from handler.h) of transaction1 |
3054 | @param[in] commit time of transaction0 or 0 if we want it to be queried |
3055 | @retval true on error, false otherwise |
3056 | */ |
3057 | bool query_sees(bool &result, ulonglong trx_id1, ulonglong trx_id0, |
3058 | ulonglong commit_id1= 0, |
3059 | enum_tx_isolation iso_level1= ISO_READ_UNCOMMITTED, |
3060 | ulonglong commit_id0= 0); |
3061 | |
3062 | /** |
3063 | @retval transaction isolation level of a row from internal TABLE object. |
3064 | */ |
3065 | enum_tx_isolation iso_level() const; |
3066 | /** |
3067 | Stores transactioin isolation level to internal TABLE object. |
3068 | */ |
3069 | void store_iso_level(enum_tx_isolation iso_level) |
3070 | { |
3071 | DBUG_ASSERT(iso_level <= ISO_SERIALIZABLE); |
3072 | store(FLD_ISO_LEVEL, iso_level + 1); |
3073 | } |
3074 | |
3075 | /** |
3076 | Writes a message to MariaDB log about incorrect transaction_registry schema. |
3077 | |
3078 | @param[in] a message explained what's incorrect in schema |
3079 | */ |
3080 | void warn_schema_incorrect(const char *reason); |
3081 | /** |
3082 | Checks whether transaction_registry table has a correct schema. |
3083 | |
3084 | @retval true if schema is incorrect and false otherwise |
3085 | */ |
3086 | bool check(bool error); |
3087 | |
3088 | TABLE * operator-> () const |
3089 | { |
3090 | return table; |
3091 | } |
3092 | Field * operator[] (uint field_id) const |
3093 | { |
3094 | DBUG_ASSERT(field_id < FIELD_COUNT); |
3095 | return table->field[field_id]; |
3096 | } |
3097 | operator bool () const |
3098 | { |
3099 | return table; |
3100 | } |
3101 | bool operator== (const TABLE_LIST &subj) const |
3102 | { |
3103 | return (!cmp(&db, &subj.db) && !cmp(&table_name, &subj.table_name)); |
3104 | } |
3105 | bool operator!= (const TABLE_LIST &subj) const |
3106 | { |
3107 | return !(*this == subj); |
3108 | } |
3109 | }; |
3110 | |
3111 | #endif /* MYSQL_CLIENT */ |
3112 | |
3113 | #endif /* TABLE_INCLUDED */ |
3114 | |