1. struct TABLE_SHARE
  2. {
  3. TABLE_SHARE() {} /* Remove gcc warning */
  4.  
  5. /** Category of this table. */
  6. TABLE_CATEGORY table_category;
  7.  
  8. /* hash of field names (contains pointers to elements of field array) */
  9. HASH name_hash; /* hash of field names */
  10. MEM_ROOT mem_root;
  11. TYPELIB keynames; /* Pointers to keynames */
  12. TYPELIB fieldnames; /* Pointer to fieldnames */
  13. TYPELIB *intervals; /* pointer to interval info */
  14. mysql_mutex_t LOCK_ha_data; /* To protect access to ha_data */
  15. TABLE_SHARE *next, **prev; /* Link to unused shares */
  16.  
  17. /*
  18. Doubly-linked (back-linked) lists of used and unused TABLE objects
  19. for this share.
  20. */
  21. I_P_List <TABLE, TABLE_share> used_tables;
  22. I_P_List <TABLE, TABLE_share> free_tables;
  23.  
  24. /* The following is copied to each TABLE on OPEN */
  25. Field **field;
  26. Field **found_next_number_field;
  27. Field *timestamp_field; /* Used only during open */
  28. KEY *key_info; /* data of keys in database */
  29. uint *blob_field; /* Index to blobs in Field arrray*/
  30.  
  31. uchar *default_values; /* row with default values */
  32. LEX_STRING comment; /* Comment about table */
  33. CHARSET_INFO *table_charset; /* Default charset of string fields */
  34.  
  35. MY_BITMAP all_set;
  36. /*
  37. Key which is used for looking-up table in table cache and in the list
  38. of thread's temporary tables. Has the form of:
  39. "database_name\0table_name\0" + optional part for temporary tables.
  40.  
  41. Note that all three 'table_cache_key', 'db' and 'table_name' members
  42. must be set (and be non-zero) for tables in table cache. They also
  43. should correspond to each other.
  44. To ensure this one can use set_table_cache() methods.
  45. */
  46. LEX_STRING table_cache_key;
  47. LEX_STRING db; /* Pointer to db */
  48. LEX_STRING table_name; /* Table name (for open) */
  49. LEX_STRING path; /* Path to .frm file (from datadir) */
  50. LEX_STRING normalized_path; /* unpack_filename(path) */
  51. LEX_STRING connect_string;
  52.  
  53. /*
  54. Set of keys in use, implemented as a Bitmap.
  55. Excludes keys disabled by ALTER TABLE ... DISABLE KEYS.
  56. */
  57. key_map keys_in_use;
  58. key_map keys_for_keyread;
  59. ha_rows min_rows, max_rows; /* create information */
  60. ulong avg_row_length; /* create information */
  61. ulong version, mysql_version;
  62. ulong reclength; /* Recordlength */
  63.  
  64. plugin_ref db_plugin; /* storage engine plugin */
  65. inline handlerton *db_type() const /* table_type for handler */
  66. {
  67. // DBUG_ASSERT(db_plugin);
  68. return db_plugin ? plugin_data(db_plugin, handlerton*) : NULL;
  69. }
  70. enum row_type row_type; /* How rows are stored */
  71. enum tmp_table_type tmp_table;
  72.  
  73. uint ref_count; /* How many TABLE objects uses this */
  74. uint blob_ptr_size; /* 4 or 8 */
  75. uint key_block_size; /* create key_block_size, if used */
  76. uint null_bytes, last_null_bit_pos;
  77. uint fields; /* Number of fields */
  78. uint rec_buff_length; /* Size of table->record[] buffer */
  79. uint keys, key_parts;
  80. uint max_key_length, max_unique_length, total_key_length;
  81. uint uniques; /* Number of UNIQUE index */
  82. uint null_fields; /* number of null fields */
  83. uint blob_fields; /* number of blob fields */
  84. uint timestamp_field_offset; /* Field number for timestamp field */
  85. uint varchar_fields; /* number of varchar fields */
  86. uint db_create_options; /* Create options from database */
  87. uint db_options_in_use; /* Options in use */
  88. uint db_record_offset; /* if HA_REC_IN_SEQ */
  89. uint rowid_field_offset; /* Field_nr +1 to rowid field */
  90. /* Primary key index number, used in TABLE::key_info[] */
  91. uint primary_key;
  92. uint next_number_index; /* autoincrement key number */
  93. uint next_number_key_offset; /* autoinc keypart offset in a key */
  94. uint next_number_keypart; /* autoinc keypart number in a key */
  95. uint error, open_errno, errarg; /* error from open_table_def() */
  96. uint column_bitmap_size;
  97. uchar frm_version;
  98. bool null_field_first;
  99. bool system; /* Set if system table (one record) */
  100. bool crypted; /* If .frm file is crypted */
  101. bool db_low_byte_first; /* Portable row format */
  102. bool crashed;
  103. bool is_view;
  104. ulong table_map_id; /* for row-based replication */
  105.  
  106. /*
  107. Cache for row-based replication table share checks that does not
  108. need to be repeated. Possible values are: -1 when cache value is
  109. not calculated yet, 0 when table *shall not* be replicated, 1 when
  110. table *may* be replicated.
  111. */
  112. int cached_row_logging_check;
  113.  
  114. /*
  115. Storage media to use for this table (unless another storage
  116. media has been specified on an individual column - in versions
  117. where that is supported)
  118. */
  119. enum ha_storage_media default_storage_media;
  120.  
  121. /* Name of the tablespace used for this table */
  122. char *tablespace;
  123.  
  124. #ifdef WITH_PARTITION_STORAGE_ENGINE
  125. /* filled in when reading from frm */
  126. bool auto_partitioned;
  127. char *partition_info_str;
  128. uint partition_info_str_len;
  129. uint partition_info_buffer_size;
  130. handlerton *default_part_db_type;
  131. #endif
  132.  
  133. /**
  134. Cache the checked structure of this table.
  135.  
  136. The pointer data is used to describe the structure that
  137. a instance of the table must have. Each element of the
  138. array specifies a field that must exist on the table.
  139.  
  140. The pointer is cached in order to perform the check only
  141. once -- when the table is loaded from the disk.
  142. */
  143. const TABLE_FIELD_DEF *table_field_def_cache;
  144.  
  145. /** place to store storage engine specific data */
  146. void *ha_data;
  147. void (*ha_data_destroy)(void *); /* An optional destructor for ha_data */
  148.  
  149. #ifdef WITH_PARTITION_STORAGE_ENGINE
  150. /** place to store partition specific data, LOCK_ha_data hold while init. */
  151. HA_DATA_PARTITION *ha_part_data;
  152. /* Destructor for ha_part_data */
  153. void (*ha_part_data_destroy)(HA_DATA_PARTITION *);
  154. #endif
  155.  
  156. /** Instrumentation for this table share. */
  157. PSI_table_share *m_psi;
  158.  
  159. /**
  160. List of tickets representing threads waiting for the share to be flushed.
  161. */
  162. Wait_for_flush_list m_flush_tickets;
  163.  
  164. /*
  165. Set share's table cache key and update its db and table name appropriately.
  166.  
  167. SYNOPSIS
  168. set_table_cache_key()
  169. key_buff Buffer with already built table cache key to be
  170. referenced from share.
  171. key_length Key length.
  172.  
  173. NOTES
  174. Since 'key_buff' buffer will be referenced from share it should has same
  175. life-time as share itself.
  176. This method automatically ensures that TABLE_SHARE::table_name/db have
  177. appropriate values by using table cache key as their source.
  178. */
  179.  
  180. void set_table_cache_key(char *key_buff, uint key_length)
  181. {
  182. table_cache_key.str= key_buff;
  183. table_cache_key.length= key_length;
  184. /*
  185. Let us use the fact that the key is "db/0/table_name/0" + optional
  186. part for temporary tables.
  187. */
  188. db.str= table_cache_key.str;
  189. db.length= strlen(db.str);
  190. table_name.str= db.str + db.length + ;
  191. table_name.length= strlen(table_name.str);
  192. }
  193.  
  194. /*
  195. Set share's table cache key and update its db and table name appropriately.
  196.  
  197. SYNOPSIS
  198. set_table_cache_key()
  199. key_buff Buffer to be used as storage for table cache key
  200. (should be at least key_length bytes).
  201. key Value for table cache key.
  202. key_length Key length.
  203.  
  204. NOTE
  205. Since 'key_buff' buffer will be used as storage for table cache key
  206. it should has same life-time as share itself.
  207. */
  208.  
  209. void set_table_cache_key(char *key_buff, const char *key, uint key_length)
  210. {
  211. memcpy(key_buff, key, key_length);
  212. set_table_cache_key(key_buff, key_length);
  213. }
  214.  
  215. inline bool honor_global_locks()
  216. {
  217. return ((table_category == TABLE_CATEGORY_USER)
  218. || (table_category == TABLE_CATEGORY_SYSTEM));
  219. }
  220.  
  221. inline bool require_write_privileges()
  222. {
  223. return (table_category == TABLE_CATEGORY_LOG);
  224. }
  225.  
  226. inline ulong get_table_def_version()
  227. {
  228. return table_map_id;
  229. }
  230.  
  231. /** Is this table share being expelled from the table definition cache? */
  232. inline bool has_old_version() const
  233. {
  234. return version != refresh_version;
  235. }
  236. /**
  237. Convert unrelated members of TABLE_SHARE to one enum
  238. representing its type.
  239.  
  240. @todo perhaps we need to have a member instead of a function.
  241. */
  242. enum enum_table_ref_type get_table_ref_type() const
  243. {
  244. if (is_view)
  245. return TABLE_REF_VIEW;
  246. switch (tmp_table) {
  247. case NO_TMP_TABLE:
  248. return TABLE_REF_BASE_TABLE;
  249. case SYSTEM_TMP_TABLE:
  250. return TABLE_REF_I_S_TABLE;
  251. default:
  252. return TABLE_REF_TMP_TABLE;
  253. }
  254. }
  255. /**
  256. Return a table metadata version.
  257. * for base tables, we return table_map_id.
  258. It is assigned from a global counter incremented for each
  259. new table loaded into the table definition cache (TDC).
  260. * for temporary tables it's table_map_id again. But for
  261. temporary tables table_map_id is assigned from
  262. thd->query_id. The latter is assigned from a thread local
  263. counter incremented for every new SQL statement. Since
  264. temporary tables are thread-local, each temporary table
  265. gets a unique id.
  266. * for everything else (views, information schema tables),
  267. the version id is zero.
  268.  
  269. This choice of version id is a large compromise
  270. to have a working prepared statement validation in 5.1. In
  271. future version ids will be persistent, as described in WL#4180.
  272.  
  273. Let's try to explain why and how this limited solution allows
  274. to validate prepared statements.
  275.  
  276. Firstly, sets (in mathematical sense) of version numbers
  277. never intersect for different table types. Therefore,
  278. version id of a temporary table is never compared with
  279. a version id of a view, and vice versa.
  280.  
  281. Secondly, for base tables, we know that each DDL flushes the
  282. respective share from the TDC. This ensures that whenever
  283. a table is altered or dropped and recreated, it gets a new
  284. version id.
  285. Unfortunately, since elements of the TDC are also flushed on
  286. LRU basis, this choice of version ids leads to false positives.
  287. E.g. when the TDC size is too small, we may have a SELECT
  288. * FROM INFORMATION_SCHEMA.TABLES flush all its elements, which
  289. in turn will lead to a validation error and a subsequent
  290. reprepare of all prepared statements. This is
  291. considered acceptable, since as long as prepared statements are
  292. automatically reprepared, spurious invalidation is only
  293. a performance hit. Besides, no better simple solution exists.
  294.  
  295. For temporary tables, using thd->query_id ensures that if
  296. a temporary table was altered or recreated, a new version id is
  297. assigned. This suits validation needs very well and will perhaps
  298. never change.
  299.  
  300. Metadata of information schema tables never changes.
  301. Thus we can safely assume 0 for a good enough version id.
  302.  
  303. Views are a special and tricky case. A view is always inlined
  304. into the parse tree of a prepared statement at prepare.
  305. Thus, when we execute a prepared statement, the parse tree
  306. will not get modified even if the view is replaced with another
  307. view. Therefore, we can safely choose 0 for version id of
  308. views and effectively never invalidate a prepared statement
  309. when a view definition is altered. Note, that this leads to
  310. wrong binary log in statement-based replication, since we log
  311. prepared statement execution in form Query_log_events
  312. containing conventional statements. But since there is no
  313. metadata locking for views, the very same problem exists for
  314. conventional statements alone, as reported in Bug#25144. The only
  315. difference between prepared and conventional execution is,
  316. effectively, that for prepared statements the race condition
  317. window is much wider.
  318. In 6.0 we plan to support view metadata locking (WL#3726) and
  319. extend table definition cache to cache views (WL#4298).
  320. When this is done, views will be handled in the same fashion
  321. as the base tables.
  322.  
  323. Finally, by taking into account table type, we always
  324. track that a change has taken place when a view is replaced
  325. with a base table, a base table is replaced with a temporary
  326. table and so on.
  327.  
  328. @sa TABLE_LIST::is_table_ref_id_equal()
  329. */
  330. ulong get_table_ref_version() const
  331. {
  332. : table_map_id;
  333. }
  334.  
  335. bool visit_subgraph(Wait_for_flush *waiting_ticket,
  336. MDL_wait_for_graph_visitor *gvisitor);
  337.  
  338. bool wait_for_old_version(THD *thd, struct timespec *abstime,
  339. uint deadlock_weight);
  340. /** Release resources and free memory occupied by the table share. */
  341. void destroy();
  342. };

struct TABLE_SHARE的更多相关文章

  1. 结构体TABLE_share

    struct TABLE_share { static inline TABLE **next_ptr(TABLE *l) { return &l->share_next; } stat ...

  2. struct TABLE

    struct TABLE { TABLE() {} /* Remove gcc warning */ TABLE_SHARE *s; handler *file; TABLE *next, *prev ...

  3. 使用struct处理二进制

    有的时候需要用python处理二进制数据,比如,存取文件.socket操作时.这时候,可以使用python的struct模块来完成. struct模块中最重要的三个函数是pack(), unpack( ...

  4. golang struct扩展函数参数命名警告

    今天在使用VSCode编写golang代码时,定义一个struct,扩展几个方法,如下: package storage import ( "fmt" "github.c ...

  5. go-使用 unsafe 修改 struct 中的 field 的值

    以下是方法,不要纠结原理,等东西积累多了,你才有能力纠结原理: 首先,你需要有一个这样的函数,这是在 nsq 的源码里直接抄过来的: func unsafeValueOf(val reflect.Va ...

  6. C语言中struct位域的定义和使用

    位域的定义和使用 有些信息在存储时,并不需要占用一个完整的字节, 而只需占几个或一个二进制位.例如在存放一个开关量时,只有0和1 两种状态, 用一位二进位即可.为了节省存储空间,并使处理简便,C语言又 ...

  7. C# Struct结构体里数组长度的指定

    typedef struct Point{ unsigned short x; unsigned short y; }mPoint;//点坐标 typedef struct Line{ mPoint ...

  8. C 语言Struct 实现运行类型识别 RTTI

    通过RTTI,能够通过基类的指针或引用来检索其所指对象的实际类型.c++通过下面两个操作符提供RTTI. (1)typeid:返回指针或引用所指对象的实际类型.    (2)dynamic_cast: ...

  9. VC++ : error LNK2001: unresolved external symbol "__declspec(dllimport) public: __thiscall std::basic_string<wchar_t,struct std::char_traits<wchar_t>

    最近学习Google Breakpad,将其用在了自己的项目中,编译的版本为VS2010,没有什么问题.但是为了和之前的程序兼容,需要使用VS2008版本的程序,于是又编译了VS2008版本的代码,但 ...

随机推荐

  1. Android学习笔记:TabHost 和 FragmentTabHost(转)

    转自:http://www.cnblogs.com/asion/p/3339313.html   作者:Asion Tang   出处:http://asiontang.cnblogs.com   T ...

  2. LintCode-Hash Function

    In data structure Hash, hash function is used to convert a string(or any other type) into an integer ...

  3. android重写view和viewgroup的区别

    重写view: View类一般用于绘图操作,重写它的onDraw方法,但它不可以包含其他组件,没有addView(View view)方法. 重写viewgroup: ViewGroup是一个组件容器 ...

  4. 巨大bug

    //数据结构关于课程设计--------图书馆管理系统的设计 #include <stdio.h> #include <stdlib.h> #include <strin ...

  5. Jenkins入门-转

    reference : http://www.cnblogs.com/itech/archive/2011/11/23/2260009.html 在网上貌似没有找到Jenkins的中文的太多的文档,有 ...

  6. dede首页调用栏目内容{dedefield.content}的方法

    Dedecms的功能确实很强大,但是dedecms的全局变量有字节限制,使得我们在使用dedecms制作企业站的时候,首页无法调用大段大段的企业站. 其实dedecms还有另外一种调用大段内容的方法, ...

  7. bzoj 3907: 网格 组合数学

    3907: 网格 Time Limit: 1 Sec  Memory Limit: 256 MBSubmit: 13  Solved: 7[Submit][Status][Discuss] Descr ...

  8. .net发送邮件代码示例

    下面的代理已经调试过,用的是163的SMTP using System;using System.Collections.Generic;using System.Linq;using System. ...

  9. 关于vs2010 起始页

    vs2010 起始页不显示怎么解决 工具 ---> 选项---->环境---->启动---->启动时(选项框),然后点击框尾的下拉三角按钮,点选"显示起始页" ...

  10. POJ 1459 Power Network(网络最大流,dinic算法模板题)

    题意:给出n,np,nc,m,n为节点数,np为发电站数,nc为用电厂数,m为边的个数.      接下来给出m个数据(u,v)z,表示w(u,v)允许传输的最大电力为z:np个数据(u)z,表示发电 ...