PageRenderTime 26ms CodeModel.GetById 17ms RepoModel.GetById 1ms app.codeStats 0ms

/mysql-5.5.25a/storage/perfschema/pfs_engine_table.h

#
C Header | 316 lines | 176 code | 56 blank | 84 comment | 0 complexity | f1e76cf867688a68de06c94d2b396c42 MD5 | raw file
Possible License(s): GPL-2.0, BSD-3-Clause
  1. /* Copyright (c) 2008, 2010, Oracle and/or its affiliates. All rights reserved.
  2. This program is free software; you can redistribute it and/or modify
  3. it under the terms of the GNU General Public License as published by
  4. the Free Software Foundation; version 2 of the License.
  5. This program is distributed in the hope that it will be useful,
  6. but WITHOUT ANY WARRANTY; without even the implied warranty of
  7. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  8. GNU General Public License for more details.
  9. You should have received a copy of the GNU General Public License
  10. along with this program; if not, write to the Free Software Foundation,
  11. 51 Franklin Street, Suite 500, Boston, MA 02110-1335 USA */
  12. #ifndef PFS_ENGINE_TABLE_H
  13. #define PFS_ENGINE_TABLE_H
  14. #include "sql_acl.h" /* struct ACL_* */
  15. /**
  16. @file storage/perfschema/pfs_engine_table.h
  17. Performance schema tables (declarations).
  18. */
  19. class Field;
  20. struct PFS_engine_table_share;
  21. /**
  22. @addtogroup Performance_schema_engine
  23. @{
  24. */
  25. /**
  26. An abstract PERFORMANCE_SCHEMA table.
  27. Every table implemented in the performance schema schema and storage engine
  28. derives from this class.
  29. */
  30. class PFS_engine_table
  31. {
  32. public:
  33. static const PFS_engine_table_share*
  34. find_engine_table_share(const char *name);
  35. int read_row(TABLE *table, unsigned char *buf, Field **fields);
  36. int update_row(TABLE *table, const unsigned char *old_buf,
  37. unsigned char *new_buf, Field **fields);
  38. /** Fetch the next row in this cursor. */
  39. virtual int rnd_next(void)= 0;
  40. /**
  41. Fetch a row by position.
  42. @param pos position to fetch
  43. */
  44. virtual int rnd_pos(const void *pos)= 0;
  45. void get_position(void *ref);
  46. void set_position(const void *ref);
  47. virtual void reset_position(void)= 0;
  48. /** Destructor. */
  49. virtual ~PFS_engine_table()
  50. {}
  51. protected:
  52. /**
  53. Read the current row values.
  54. @param table Table handle
  55. @param buf row buffer
  56. @param fields Table fields
  57. @param read_all true if all columns are read.
  58. */
  59. virtual int read_row_values(TABLE *table, unsigned char *buf,
  60. Field **fields, bool read_all)= 0;
  61. /**
  62. Update the current row values.
  63. @param table Table handle
  64. @param old_buf old row buffer
  65. @param new_buf new row buffer
  66. @param fields Table fields
  67. */
  68. virtual int update_row_values(TABLE *table, const unsigned char *old_buf,
  69. unsigned char *new_buf, Field **fields);
  70. /**
  71. Constructor.
  72. @param share table share
  73. @param pos address of the m_pos position member
  74. */
  75. PFS_engine_table(const PFS_engine_table_share *share, void *pos)
  76. : m_share_ptr(share), m_pos_ptr(pos)
  77. {}
  78. void set_field_ulong(Field *f, ulong value);
  79. void set_field_ulonglong(Field *f, ulonglong value);
  80. void set_field_varchar_utf8(Field *f, const char* str, uint len);
  81. void set_field_enum(Field *f, ulonglong value);
  82. ulonglong get_field_enum(Field *f);
  83. /** Table share. */
  84. const PFS_engine_table_share *m_share_ptr;
  85. /** Opaque pointer to the m_pos position of this cursor. */
  86. void *m_pos_ptr;
  87. };
  88. /** Callback to open a table. */
  89. typedef PFS_engine_table* (*pfs_open_table_t)(void);
  90. /** Callback to write a row. */
  91. typedef int (*pfs_write_row_t)(TABLE *table,
  92. unsigned char *buf, Field **fields);
  93. /** Callback to delete all rows. */
  94. typedef int (*pfs_delete_all_rows_t)(void);
  95. /**
  96. A PERFORMANCE_SCHEMA table share.
  97. This data is shared by all the table handles opened on the same table.
  98. */
  99. struct PFS_engine_table_share
  100. {
  101. static void check_all_tables(THD *thd);
  102. void check_one_table(THD *thd);
  103. static void init_all_locks(void);
  104. static void delete_all_locks(void);
  105. /** Table name. */
  106. LEX_STRING m_name;
  107. /** Table ACL. */
  108. const ACL_internal_table_access *m_acl;
  109. /** Open table function. */
  110. pfs_open_table_t m_open_table;
  111. /** Write row function. */
  112. pfs_write_row_t m_write_row;
  113. /** Delete all rows function. */
  114. pfs_delete_all_rows_t m_delete_all_rows;
  115. /**
  116. Number or records.
  117. This number does not need to be precise,
  118. it is used by the optimizer to decide if the table
  119. has 0, 1, or many records.
  120. */
  121. ha_rows m_records;
  122. /** Length of the m_pos position structure. */
  123. uint m_ref_length;
  124. /** The lock, stored on behalf of the SQL layer. */
  125. THR_LOCK *m_thr_lock_ptr;
  126. /** Table fields definition. */
  127. TABLE_FIELD_DEF *m_field_def;
  128. /** Schema integrity flag. */
  129. bool m_checked;
  130. };
  131. class PFS_readonly_acl : public ACL_internal_table_access
  132. {
  133. public:
  134. PFS_readonly_acl()
  135. {}
  136. ~PFS_readonly_acl()
  137. {}
  138. ACL_internal_access_result check(ulong want_access, ulong *save_priv) const;
  139. };
  140. extern PFS_readonly_acl pfs_readonly_acl;
  141. class PFS_truncatable_acl : public ACL_internal_table_access
  142. {
  143. public:
  144. PFS_truncatable_acl()
  145. {}
  146. ~PFS_truncatable_acl()
  147. {}
  148. ACL_internal_access_result check(ulong want_access, ulong *save_priv) const;
  149. };
  150. extern PFS_truncatable_acl pfs_truncatable_acl;
  151. class PFS_updatable_acl : public ACL_internal_table_access
  152. {
  153. public:
  154. PFS_updatable_acl()
  155. {}
  156. ~PFS_updatable_acl()
  157. {}
  158. ACL_internal_access_result check(ulong want_access, ulong *save_priv) const;
  159. };
  160. extern PFS_updatable_acl pfs_updatable_acl;
  161. class PFS_editable_acl : public ACL_internal_table_access
  162. {
  163. public:
  164. PFS_editable_acl()
  165. {}
  166. ~PFS_editable_acl()
  167. {}
  168. ACL_internal_access_result check(ulong want_access, ulong *save_priv) const;
  169. };
  170. extern PFS_editable_acl pfs_editable_acl;
  171. class PFS_unknown_acl : public ACL_internal_table_access
  172. {
  173. public:
  174. PFS_unknown_acl()
  175. {}
  176. ~PFS_unknown_acl()
  177. {}
  178. ACL_internal_access_result check(ulong want_access, ulong *save_priv) const;
  179. };
  180. extern PFS_unknown_acl pfs_unknown_acl;
  181. /** Position of a cursor, for simple iterations. */
  182. struct PFS_simple_index
  183. {
  184. /** Current row index. */
  185. uint m_index;
  186. PFS_simple_index(uint index)
  187. : m_index(index)
  188. {}
  189. void set_at(const struct PFS_simple_index *other)
  190. { m_index= other->m_index; }
  191. void set_after(const struct PFS_simple_index *other)
  192. { m_index= other->m_index + 1; }
  193. void next(void)
  194. { m_index++; }
  195. };
  196. struct PFS_double_index
  197. {
  198. /** Outer index. */
  199. uint m_index_1;
  200. /** Current index within index_1. */
  201. uint m_index_2;
  202. PFS_double_index(uint index_1, uint index_2)
  203. : m_index_1(index_1), m_index_2(index_2)
  204. {}
  205. void set_at(const struct PFS_double_index *other)
  206. {
  207. m_index_1= other->m_index_1;
  208. m_index_2= other->m_index_2;
  209. }
  210. void set_after(const struct PFS_double_index *other)
  211. {
  212. m_index_1= other->m_index_1;
  213. m_index_2= other->m_index_2 + 1;
  214. }
  215. };
  216. struct PFS_triple_index
  217. {
  218. /** Outer index. */
  219. uint m_index_1;
  220. /** Current index within index_1. */
  221. uint m_index_2;
  222. /** Current index within index_2. */
  223. uint m_index_3;
  224. PFS_triple_index(uint index_1, uint index_2, uint index_3)
  225. : m_index_1(index_1), m_index_2(index_2), m_index_3(index_3)
  226. {}
  227. void set_at(const struct PFS_triple_index *other)
  228. {
  229. m_index_1= other->m_index_1;
  230. m_index_2= other->m_index_2;
  231. m_index_3= other->m_index_3;
  232. }
  233. void set_after(const struct PFS_triple_index *other)
  234. {
  235. m_index_1= other->m_index_1;
  236. m_index_2= other->m_index_2;
  237. m_index_3= other->m_index_3 + 1;
  238. }
  239. };
  240. struct PFS_instrument_view_constants
  241. {
  242. static const uint VIEW_MUTEX= 1;
  243. static const uint VIEW_RWLOCK= 2;
  244. static const uint VIEW_COND= 3;
  245. static const uint VIEW_FILE= 4;
  246. };
  247. struct PFS_object_view_constants
  248. {
  249. static const uint VIEW_TABLE= 1;
  250. static const uint VIEW_EVENT= 2;
  251. static const uint VIEW_PROCEDURE= 3;
  252. static const uint VIEW_FUNCTION= 4;
  253. };
  254. bool pfs_show_status(handlerton *hton, THD *thd,
  255. stat_print_fn *print, enum ha_stat_type stat);
  256. /** @} */
  257. #endif