-
Notifications
You must be signed in to change notification settings - Fork 1.6k
/
table.h
3409 lines (2951 loc) · 108 KB
/
table.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
#ifndef TABLE_INCLUDED
#define TABLE_INCLUDED
/* Copyright (c) 2000, 2017, Oracle and/or its affiliates.
Copyright (c) 2009, 2021, MariaDB
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; version 2 of the License.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1335 USA */
#include "sql_plist.h"
#include "sql_list.h" /* Sql_alloc */
#include "mdl.h"
#include "datadict.h"
#include "sql_string.h" /* String */
#include "lex_string.h"
#ifndef MYSQL_CLIENT
#include "my_cpu.h" /* LF_BACKOFF() */
#include "hash.h" /* HASH */
#include "handler.h" /* row_type, ha_choice, handler */
#include "mysql_com.h" /* enum_field_types */
#include "thr_lock.h" /* thr_lock_type */
#include "filesort_utils.h"
#include "parse_file.h"
#include "sql_i_s.h"
#include "sql_type.h" /* vers_kind_t */
#include "privilege.h" /* privilege_t */
/* Structs that defines the TABLE */
class Item; /* Needed by ORDER */
typedef Item (*Item_ptr);
class Item_subselect;
class Item_field;
class GRANT_TABLE;
class st_select_lex_unit;
class st_select_lex;
class partition_info;
class COND_EQUAL;
class Security_context;
struct TABLE_LIST;
class ACL_internal_schema_access;
class ACL_internal_table_access;
class Field;
class Table_statistics;
class With_element;
struct TDC_element;
class Virtual_column_info;
class Table_triggers_list;
class TMP_TABLE_PARAM;
class SEQUENCE;
class Range_rowid_filter_cost_info;
class derived_handler;
class Pushdown_derived;
struct Name_resolution_context;
class Table_function_json_table;
/*
Used to identify NESTED_JOIN structures within a join (applicable only to
structures that have not been simplified away and embed more the one
element)
*/
typedef ulonglong nested_join_map;
#define tmp_file_prefix "#sql" /**< Prefix for tmp tables */
#define tmp_file_prefix_length 4
#define TMP_TABLE_KEY_EXTRA 8
/**
Enumerate possible types of a table from re-execution
standpoint.
TABLE_LIST class has a member of this type.
At prepared statement prepare, this member is assigned a value
as of the current state of the database. Before (re-)execution
of a prepared statement, we check that the value recorded at
prepare matches the type of the object we obtained from the
table definition cache.
@sa check_and_update_table_version()
@sa Execute_observer
@sa Prepared_statement::reprepare()
*/
enum enum_table_ref_type
{
/** Initial value set by the parser */
TABLE_REF_NULL= 0,
TABLE_REF_VIEW,
TABLE_REF_BASE_TABLE,
TABLE_REF_I_S_TABLE,
TABLE_REF_TMP_TABLE
};
/*************************************************************************/
/**
Object_creation_ctx -- interface for creation context of database objects
(views, stored routines, events, triggers). Creation context -- is a set
of attributes, that should be fixed at the creation time and then be used
each time the object is parsed or executed.
*/
class Object_creation_ctx
{
public:
Object_creation_ctx *set_n_backup(THD *thd);
void restore_env(THD *thd, Object_creation_ctx *backup_ctx);
protected:
Object_creation_ctx() {}
virtual Object_creation_ctx *create_backup_ctx(THD *thd) const = 0;
virtual void change_env(THD *thd) const = 0;
public:
virtual ~Object_creation_ctx()
{ }
};
/*************************************************************************/
/**
Default_object_creation_ctx -- default implementation of
Object_creation_ctx.
*/
class Default_object_creation_ctx : public Object_creation_ctx
{
public:
CHARSET_INFO *get_client_cs()
{
return m_client_cs;
}
CHARSET_INFO *get_connection_cl()
{
return m_connection_cl;
}
protected:
Default_object_creation_ctx(THD *thd);
Default_object_creation_ctx(CHARSET_INFO *client_cs,
CHARSET_INFO *connection_cl);
protected:
virtual Object_creation_ctx *create_backup_ctx(THD *thd) const;
virtual void change_env(THD *thd) const;
protected:
/**
client_cs stores the value of character_set_client session variable.
The only character set attribute is used.
Client character set is included into query context, because we save
query in the original character set, which is client character set. So,
in order to parse the query properly we have to switch client character
set on parsing.
*/
CHARSET_INFO *m_client_cs;
/**
connection_cl stores the value of collation_connection session
variable. Both character set and collation attributes are used.
Connection collation is included into query context, becase it defines
the character set and collation of text literals in internal
representation of query (item-objects).
*/
CHARSET_INFO *m_connection_cl;
};
class Query_arena;
/*************************************************************************/
/**
View_creation_ctx -- creation context of view objects.
*/
class View_creation_ctx : public Default_object_creation_ctx,
public Sql_alloc
{
public:
static View_creation_ctx *create(THD *thd);
static View_creation_ctx *create(THD *thd,
TABLE_LIST *view);
private:
View_creation_ctx(THD *thd)
: Default_object_creation_ctx(thd)
{ }
};
/*************************************************************************/
/* Order clause list element */
typedef int (*fast_field_copier)(Field *to, Field *from);
typedef struct st_order {
struct st_order *next;
Item **item; /* Point at item in select fields */
Item *item_ptr; /* Storage for initial item */
/*
Reference to the function we are trying to optimize copy to
a temporary table
*/
fast_field_copier fast_field_copier_func;
/* Field for which above optimizer function setup */
Field *fast_field_copier_setup;
int counter; /* position in SELECT list, correct
only if counter_used is true*/
enum enum_order {
ORDER_NOT_RELEVANT,
ORDER_ASC,
ORDER_DESC
};
enum_order direction; /* Requested direction of ordering */
bool in_field_list; /* true if in select field list */
bool counter_used; /* parameter was counter of columns */
Field *field; /* If tmp-table group */
char *buff; /* If tmp-table group */
table_map used; /* NOTE: the below is only set to 0 but is still used by eq_ref_table */
table_map depend_map;
} ORDER;
/**
State information for internal tables grants.
This structure is part of the TABLE_LIST, and is updated
during the ACL check process.
@sa GRANT_INFO
*/
struct st_grant_internal_info
{
/** True if the internal lookup by schema name was done. */
bool m_schema_lookup_done;
/** Cached internal schema access. */
const ACL_internal_schema_access *m_schema_access;
/** True if the internal lookup by table name was done. */
bool m_table_lookup_done;
/** Cached internal table access. */
const ACL_internal_table_access *m_table_access;
};
typedef struct st_grant_internal_info GRANT_INTERNAL_INFO;
/**
@brief The current state of the privilege checking process for the current
user, SQL statement and SQL object.
@details The privilege checking process is divided into phases depending on
the level of the privilege to be checked and the type of object to be
accessed. Due to the mentioned scattering of privilege checking
functionality, it is necessary to keep track of the state of the
process. This information is stored in privilege, want_privilege, and
orig_want_privilege.
A GRANT_INFO also serves as a cache of the privilege hash tables. Relevant
members are grant_table and version.
*/
typedef struct st_grant_info
{
/**
@brief A copy of the privilege information regarding the current host,
database, object and user.
@details The version of this copy is found in GRANT_INFO::version.
*/
GRANT_TABLE *grant_table_user;
GRANT_TABLE *grant_table_role;
/**
@brief Used for cache invalidation when caching privilege information.
@details The privilege information is stored on disk, with dedicated
caches residing in memory: table-level and column-level privileges,
respectively, have their own dedicated caches.
The GRANT_INFO works as a level 1 cache with this member updated to the
current value of the global variable @c grant_version (@c static variable
in sql_acl.cc). It is updated Whenever the GRANT_INFO is refreshed from
the level 2 cache. The level 2 cache is the @c column_priv_hash structure
(@c static variable in sql_acl.cc)
@see grant_version
*/
uint version;
/**
@brief The set of privileges that the current user has fulfilled for a
certain host, database, and object.
@details This field is continually updated throughout the access checking
process. In each step the "wanted privilege" is checked against the
fulfilled privileges. When/if the intersection of these sets is empty,
access is granted.
The set is implemented as a bitmap, with the bits defined in sql_acl.h.
*/
privilege_t privilege;
/**
@brief the set of privileges that the current user needs to fulfil in
order to carry out the requested operation.
*/
privilege_t want_privilege;
/**
Stores the requested access acl of top level tables list. Is used to
check access rights to the underlying tables of a view.
*/
privilege_t orig_want_privilege;
/** The grant state for internal tables. */
GRANT_INTERNAL_INFO m_internal;
st_grant_info()
:privilege(NO_ACL),
want_privilege(NO_ACL),
orig_want_privilege(NO_ACL)
{ }
} GRANT_INFO;
enum tmp_table_type
{
NO_TMP_TABLE= 0, NON_TRANSACTIONAL_TMP_TABLE, TRANSACTIONAL_TMP_TABLE,
INTERNAL_TMP_TABLE, SYSTEM_TMP_TABLE
};
enum release_type { RELEASE_NORMAL, RELEASE_WAIT_FOR_DROP };
enum vcol_init_mode
{
VCOL_INIT_DEPENDENCY_FAILURE_IS_WARNING= 1,
VCOL_INIT_DEPENDENCY_FAILURE_IS_ERROR= 2
/*
There may be new flags here.
e.g. to automatically remove sql_mode dependency:
GENERATED ALWAYS AS (char_col) ->
GENERATED ALWAYS AS (RTRIM(char_col))
*/
};
enum enum_vcol_update_mode
{
VCOL_UPDATE_FOR_READ= 0,
VCOL_UPDATE_FOR_WRITE,
VCOL_UPDATE_FOR_DELETE,
VCOL_UPDATE_INDEXED,
VCOL_UPDATE_INDEXED_FOR_UPDATE,
VCOL_UPDATE_FOR_REPLACE
};
/* Field visibility enums */
enum __attribute__((packed)) field_visibility_t {
VISIBLE= 0,
INVISIBLE_USER,
/* automatically added by the server. Can be queried explicitly
in SELECT, otherwise invisible from anything" */
INVISIBLE_SYSTEM,
INVISIBLE_FULL
};
#define INVISIBLE_MAX_BITS 3
#define HA_HASH_FIELD_LENGTH 8
#define HA_HASH_KEY_LENGTH_WITHOUT_NULL 8
#define HA_HASH_KEY_LENGTH_WITH_NULL 9
int fields_in_hash_keyinfo(KEY *keyinfo);
void setup_keyinfo_hash(KEY *key_info);
void re_setup_keyinfo_hash(KEY *key_info);
/**
Category of table found in the table share.
*/
enum enum_table_category
{
/**
Unknown value.
*/
TABLE_UNKNOWN_CATEGORY=0,
/**
Temporary table.
The table is visible only in the session.
Therefore,
- FLUSH TABLES WITH READ LOCK
- SET GLOBAL READ_ONLY = ON
do not apply to this table.
Note that LOCK TABLE t FOR READ/WRITE
can be used on temporary tables.
Temporary tables are not part of the table cache.
*/
TABLE_CATEGORY_TEMPORARY=1,
/**
User table.
These tables do honor:
- LOCK TABLE t FOR READ/WRITE
- FLUSH TABLES WITH READ LOCK
- SET GLOBAL READ_ONLY = ON
User tables are cached in the table cache.
*/
TABLE_CATEGORY_USER=2,
/**
System table, maintained by the server.
These tables do honor:
- LOCK TABLE t FOR READ/WRITE
- FLUSH TABLES WITH READ LOCK
- SET GLOBAL READ_ONLY = ON
Typically, writes to system tables are performed by
the server implementation, not explicitly be a user.
System tables are cached in the table cache.
*/
TABLE_CATEGORY_SYSTEM=3,
/**
Log tables.
These tables are an interface provided by the system
to inspect the system logs.
These tables do *not* honor:
- LOCK TABLE t FOR READ/WRITE
- FLUSH TABLES WITH READ LOCK
- SET GLOBAL READ_ONLY = ON
as there is no point in locking explicitly
a LOG table.
An example of LOG tables are:
- mysql.slow_log
- mysql.general_log,
which *are* updated even when there is either
a GLOBAL READ LOCK or a GLOBAL READ_ONLY in effect.
User queries do not write directly to these tables
(there are exceptions for log tables).
The server implementation perform writes.
Log tables are cached in the table cache.
*/
TABLE_CATEGORY_LOG=4,
/*
Types below are read only tables, not affected by FLUSH TABLES or
MDL locks.
*/
/**
Information schema tables.
These tables are an interface provided by the system
to inspect the system metadata.
These tables do *not* honor:
- LOCK TABLE t FOR READ/WRITE
- FLUSH TABLES WITH READ LOCK
- SET GLOBAL READ_ONLY = ON
as there is no point in locking explicitly
an INFORMATION_SCHEMA table.
Nothing is directly written to information schema tables.
Note that this value is not used currently,
since information schema tables are not shared,
but implemented as session specific temporary tables.
*/
/*
TODO: Fixing the performance issues of I_S will lead
to I_S tables in the table cache, which should use
this table type.
*/
TABLE_CATEGORY_INFORMATION=5,
/**
Performance schema tables.
These tables are an interface provided by the system
to inspect the system performance data.
These tables do *not* honor:
- LOCK TABLE t FOR READ/WRITE
- FLUSH TABLES WITH READ LOCK
- SET GLOBAL READ_ONLY = ON
as there is no point in locking explicitly
a PERFORMANCE_SCHEMA table.
An example of PERFORMANCE_SCHEMA tables are:
- performance_schema.*
which *are* updated (but not using the handler interface)
even when there is either
a GLOBAL READ LOCK or a GLOBAL READ_ONLY in effect.
User queries do not write directly to these tables
(there are exceptions for SETUP_* tables).
The server implementation perform writes.
Performance tables are cached in the table cache.
*/
TABLE_CATEGORY_PERFORMANCE=6
};
typedef enum enum_table_category TABLE_CATEGORY;
TABLE_CATEGORY get_table_category(const LEX_CSTRING *db,
const LEX_CSTRING *name);
typedef struct st_table_field_type
{
LEX_CSTRING name;
LEX_CSTRING type;
LEX_CSTRING cset;
} TABLE_FIELD_TYPE;
typedef struct st_table_field_def
{
uint count;
const TABLE_FIELD_TYPE *field;
uint primary_key_parts;
const uint *primary_key_columns;
} TABLE_FIELD_DEF;
class Table_check_intact
{
protected:
bool has_keys;
virtual void report_error(uint code, const char *fmt, ...)= 0;
public:
Table_check_intact(bool keys= false) : has_keys(keys) {}
virtual ~Table_check_intact() {}
/** Checks whether a table is intact. */
bool check(TABLE *table, const TABLE_FIELD_DEF *table_def);
};
/*
If the table isn't valid, report the error to the server log only.
*/
class Table_check_intact_log_error : public Table_check_intact
{
protected:
void report_error(uint, const char *fmt, ...);
public:
Table_check_intact_log_error() : Table_check_intact(true) {}
};
/**
Class representing the fact that some thread waits for table
share to be flushed. Is used to represent information about
such waits in MDL deadlock detector.
*/
class Wait_for_flush : public MDL_wait_for_subgraph
{
MDL_context *m_ctx;
TABLE_SHARE *m_share;
uint m_deadlock_weight;
public:
Wait_for_flush(MDL_context *ctx_arg, TABLE_SHARE *share_arg,
uint deadlock_weight_arg)
: m_ctx(ctx_arg), m_share(share_arg),
m_deadlock_weight(deadlock_weight_arg)
{}
MDL_context *get_ctx() const { return m_ctx; }
virtual bool accept_visitor(MDL_wait_for_graph_visitor *dvisitor);
virtual uint get_deadlock_weight() const;
/**
Pointers for participating in the list of waiters for table share.
*/
Wait_for_flush *next_in_share;
Wait_for_flush **prev_in_share;
};
typedef I_P_List <Wait_for_flush,
I_P_List_adapter<Wait_for_flush,
&Wait_for_flush::next_in_share,
&Wait_for_flush::prev_in_share> >
Wait_for_flush_list;
enum open_frm_error {
OPEN_FRM_OK = 0,
OPEN_FRM_OPEN_ERROR,
OPEN_FRM_READ_ERROR,
OPEN_FRM_CORRUPTED,
OPEN_FRM_DISCOVER,
OPEN_FRM_ERROR_ALREADY_ISSUED,
OPEN_FRM_NOT_A_VIEW,
OPEN_FRM_NOT_A_TABLE,
OPEN_FRM_NEEDS_REBUILD
};
/**
Control block to access table statistics loaded
from persistent statistical tables
*/
class TABLE_STATISTICS_CB
{
class Statistics_state
{
enum state_codes
{
EMPTY, /** data is not loaded */
LOADING, /** data is being loaded in some connection */
READY /** data is loaded and available for use */
};
int32 state;
public:
/** No state copy */
Statistics_state &operator=(const Statistics_state &) { return *this; }
/** Checks if data loading have been completed */
bool is_ready() const
{
return my_atomic_load32_explicit(const_cast<int32*>(&state),
MY_MEMORY_ORDER_ACQUIRE) == READY;
}
/**
Sets mutual exclusion for data loading
If stats are in LOADING state, waits until state change.
@return
@retval true atomic EMPTY -> LOADING transfer completed, ok to load
@retval false stats are in READY state, no need to load
*/
bool start_load()
{
for (;;)
{
int32 expected= EMPTY;
if (my_atomic_cas32_weak_explicit(&state, &expected, LOADING,
MY_MEMORY_ORDER_RELAXED,
MY_MEMORY_ORDER_RELAXED))
return true;
if (expected == READY)
return false;
(void) LF_BACKOFF();
}
}
/** Marks data available for subsequent use */
void end_load()
{
DBUG_ASSERT(my_atomic_load32_explicit(&state, MY_MEMORY_ORDER_RELAXED) ==
LOADING);
my_atomic_store32_explicit(&state, READY, MY_MEMORY_ORDER_RELEASE);
}
/** Restores empty state on error (e.g. OOM) */
void abort_load()
{
DBUG_ASSERT(my_atomic_load32_explicit(&state, MY_MEMORY_ORDER_RELAXED) ==
LOADING);
my_atomic_store32_explicit(&state, EMPTY, MY_MEMORY_ORDER_RELAXED);
}
};
class Statistics_state stats_state;
class Statistics_state hist_state;
public:
MEM_ROOT mem_root; /* MEM_ROOT to allocate statistical data for the table */
Table_statistics *table_stats; /* Structure to access the statistical data */
ulong total_hist_size; /* Total size of all histograms */
bool histograms_are_ready() const
{
return !total_hist_size || hist_state.is_ready();
}
bool start_histograms_load()
{
return total_hist_size && hist_state.start_load();
}
void end_histograms_load() { hist_state.end_load(); }
void abort_histograms_load() { hist_state.abort_load(); }
bool stats_are_ready() const { return stats_state.is_ready(); }
bool start_stats_load() { return stats_state.start_load(); }
void end_stats_load() { stats_state.end_load(); }
void abort_stats_load() { stats_state.abort_load(); }
};
/**
This structure is shared between different table objects. There is one
instance of table share per one table in the database.
*/
struct TABLE_SHARE
{
TABLE_SHARE() {} /* Remove gcc warning */
/** Category of this table. */
TABLE_CATEGORY table_category;
/* hash of field names (contains pointers to elements of field array) */
HASH name_hash; /* hash of field names */
MEM_ROOT mem_root;
TYPELIB keynames; /* Pointers to keynames */
TYPELIB fieldnames; /* Pointer to fieldnames */
TYPELIB *intervals; /* pointer to interval info */
mysql_mutex_t LOCK_ha_data; /* To protect access to ha_data */
mysql_mutex_t LOCK_share; /* To protect TABLE_SHARE */
TDC_element *tdc;
LEX_CUSTRING tabledef_version;
engine_option_value *option_list; /* text options for table */
ha_table_option_struct *option_struct; /* structure with parsed options */
/* The following is copied to each TABLE on OPEN */
Field **field;
Field **found_next_number_field;
KEY *key_info; /* data of keys in database */
Virtual_column_info **check_constraints;
uint *blob_field; /* Index to blobs in Field arrray*/
LEX_CUSTRING vcol_defs; /* definitions of generated columns */
TABLE_STATISTICS_CB stats_cb;
uchar *default_values; /* row with default values */
LEX_CSTRING comment; /* Comment about table */
CHARSET_INFO *table_charset; /* Default charset of string fields */
MY_BITMAP *check_set; /* Fields used by check constrant */
MY_BITMAP all_set;
/*
Key which is used for looking-up table in table cache and in the list
of thread's temporary tables. Has the form of:
"database_name\0table_name\0" + optional part for temporary tables.
Note that all three 'table_cache_key', 'db' and 'table_name' members
must be set (and be non-zero) for tables in table cache. They also
should correspond to each other.
To ensure this one can use set_table_cache() methods.
*/
LEX_CSTRING table_cache_key;
LEX_CSTRING db; /* Pointer to db */
LEX_CSTRING table_name; /* Table name (for open) */
LEX_CSTRING path; /* Path to .frm file (from datadir) */
LEX_CSTRING normalized_path; /* unpack_filename(path) */
LEX_CSTRING connect_string;
/*
Set of keys in use, implemented as a Bitmap.
Excludes keys disabled by ALTER TABLE ... DISABLE KEYS.
*/
key_map keys_in_use;
/* The set of ignored indexes for a table. */
key_map ignored_indexes;
key_map keys_for_keyread;
ha_rows min_rows, max_rows; /* create information */
ulong avg_row_length; /* create information */
ulong mysql_version; /* 0 if .frm is created before 5.0 */
ulong reclength; /* Recordlength */
/* Stored record length. No generated-only virtual fields are included */
ulong stored_rec_length;
plugin_ref db_plugin; /* storage engine plugin */
inline handlerton *db_type() const /* table_type for handler */
{
return is_view ? view_pseudo_hton :
db_plugin ? plugin_hton(db_plugin) : NULL;
}
enum row_type row_type; /* How rows are stored */
enum Table_type table_type;
enum tmp_table_type tmp_table;
/** Transactional or not. */
enum ha_choice transactional;
/** Per-page checksums or not. */
enum ha_choice page_checksum;
uint key_block_size; /* create key_block_size, if used */
uint stats_sample_pages; /* number of pages to sample during
stats estimation, if used, otherwise 0. */
enum_stats_auto_recalc stats_auto_recalc; /* Automatic recalc of stats. */
uint null_bytes, last_null_bit_pos;
/*
Same as null_bytes, except that if there is only a 'delete-marker' in
the record then this value is 0.
*/
uint null_bytes_for_compare;
uint fields; /* number of fields */
/* number of stored fields, purely virtual not included */
uint stored_fields;
uint virtual_fields; /* number of purely virtual fields */
/* number of purely virtual not stored blobs */
uint virtual_not_stored_blob_fields;
uint null_fields; /* number of null fields */
uint blob_fields; /* number of blob fields */
uint varchar_fields; /* number of varchar fields */
uint default_fields; /* number of default fields */
uint visible_fields; /* number of visible fields */
uint default_expressions;
uint table_check_constraints, field_check_constraints;
uint rec_buff_length; /* Size of table->record[] buffer */
uint keys, key_parts;
uint ext_key_parts; /* Total number of key parts in extended keys */
uint max_key_length, max_unique_length;
uint uniques; /* Number of UNIQUE index */
uint db_create_options; /* Create options from database */
uint db_options_in_use; /* Options in use */
uint db_record_offset; /* if HA_REC_IN_SEQ */
uint rowid_field_offset; /* Field_nr +1 to rowid field */
/* Primary key index number, used in TABLE::key_info[] */
uint primary_key;
uint next_number_index; /* autoincrement key number */
uint next_number_key_offset; /* autoinc keypart offset in a key */
uint next_number_keypart; /* autoinc keypart number in a key */
enum open_frm_error error; /* error from open_table_def() */
uint open_errno; /* error from open_table_def() */
uint column_bitmap_size;
uchar frm_version;
enum enum_v_keys { NOT_INITIALIZED=0, NO_V_KEYS, V_KEYS };
enum_v_keys check_set_initialized;
bool use_ext_keys; /* Extended keys can be used */
bool null_field_first;
bool system; /* Set if system table (one record) */
bool not_usable_by_query_cache;
bool online_backup; /* Set if on-line backup supported */
/*
This is used by log tables, for tables that have their own internal
binary logging or for tables that doesn't support statement or row logging
*/
bool no_replicate;
bool crashed;
bool is_view;
bool can_cmp_whole_record;
/* This is set for temporary tables where CREATE was binary logged */
bool table_creation_was_logged;
bool non_determinstic_insert;
bool vcols_need_refixing;
bool has_update_default_function;
bool can_do_row_logging; /* 1 if table supports RBR */
bool long_unique_table;
ulong table_map_id; /* for row-based replication */
/*
Things that are incompatible between the stored version and the
current version. This is a set of HA_CREATE... bits that can be used
to modify create_info->used_fields for ALTER TABLE.
*/
ulong incompatible_version;
/**
For shares representing views File_parser object with view
definition read from .FRM file.
*/
const File_parser *view_def;
/* For sequence tables, the current sequence state */
SEQUENCE *sequence;
#ifdef WITH_PARTITION_STORAGE_ENGINE
/* filled in when reading from frm */
bool auto_partitioned;
char *partition_info_str;
uint partition_info_str_len;
uint partition_info_buffer_size;
plugin_ref default_part_plugin;
#endif
/**
System versioning and application-time periods support.
*/
struct period_info_t
{
field_index_t start_fieldno;
field_index_t end_fieldno;
Lex_ident name;
Lex_ident constr_name;
uint unique_keys;
Field *start_field(TABLE_SHARE *s) const
{
return s->field[start_fieldno];
}
Field *end_field(TABLE_SHARE *s) const
{
return s->field[end_fieldno];
}
};
vers_kind_t versioned;
period_info_t vers;
period_info_t period;
bool init_period_from_extra2(period_info_t *period, const uchar *data,
const uchar *end);
Field *vers_start_field()
{
DBUG_ASSERT(versioned);
return field[vers.start_fieldno];
}
Field *vers_end_field()
{
DBUG_ASSERT(versioned);
return field[vers.end_fieldno];
}
Field *period_start_field() const
{
DBUG_ASSERT(period.name);
return field[period.start_fieldno];
}
Field *period_end_field() const
{
DBUG_ASSERT(period.name);
return field[period.end_fieldno];
}
/**
Cache the checked structure of this table.
The pointer data is used to describe the structure that
a instance of the table must have. Each element of the
array specifies a field that must exist on the table.
The pointer is cached in order to perform the check only
once -- when the table is loaded from the disk.
*/
const TABLE_FIELD_DEF *table_field_def_cache;
/** Main handler's share */
Handler_share *ha_share;
/** Instrumentation for this table share. */
PSI_table_share *m_psi;
inline void reset() { bzero((void*)this, sizeof(*this)); }
/*
Set share's table cache key and update its db and table name appropriately.
SYNOPSIS
set_table_cache_key()
key_buff Buffer with already built table cache key to be
referenced from share.
key_length Key length.
NOTES
Since 'key_buff' buffer will be referenced from share it should has same
life-time as share itself.
This method automatically ensures that TABLE_SHARE::table_name/db have
appropriate values by using table cache key as their source.
*/
void set_table_cache_key(char *key_buff, uint key_length)
{
table_cache_key.str= key_buff;
table_cache_key.length= key_length;
/*
Let us use the fact that the key is "db/0/table_name/0" + optional
part for temporary tables.
*/
db.str= table_cache_key.str;
db.length= strlen(db.str);
table_name.str= db.str + db.length + 1;
table_name.length= strlen(table_name.str);
}
/*
Set share's table cache key and update its db and table name appropriately.
SYNOPSIS
set_table_cache_key()
key_buff Buffer to be used as storage for table cache key
(should be at least key_length bytes).
key Value for table cache key.
key_length Key length.