Debian Codegraph @

storage/innobase/handler/i_s.cc

raw
1 /*****************************************************************************
2
3 Copyright (c) 2007, 2026, Oracle and/or its affiliates.
4
5 This program is free software; you can redistribute it and/or modify it under
6 the terms of the GNU General Public License, version 2.0, as published by the
7 Free Software Foundation.
8
9 This program is designed to work with certain software (including
10 but not limited to OpenSSL) that is licensed under separate terms,
11 as designated in a particular file or component or in included license
12 documentation. The authors of MySQL hereby grant you an additional
13 permission to link the program and your derivative works with the
14 separately licensed software that they have either included with
15 the program or referenced in the documentation.
16
17 This program is distributed in the hope that it will be useful, but WITHOUT
18 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
19 FOR A PARTICULAR PURPOSE. See the GNU General Public License, version 2.0,
20 for more details.
21
22 You should have received a copy of the GNU General Public License along with
23 this program; if not, write to the Free Software Foundation, Inc.,
24 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
25
26 *****************************************************************************/
27
28 /** @file handler/i_s.cc
29 InnoDB INFORMATION SCHEMA tables interface to MySQL.
30
31 Created July 18, 2007 Vasil Dimov
32 *******************************************************/
33
34 #include "storage/innobase/handler/i_s.h"
35
36 #include <field.h>
37 #include <sql_acl.h>
38 #include <sql_show.h>
39 #include <sql_time.h>
40 #include <sys/types.h>
41 #include <time.h>
42 #include <string_view>
43 #include <unordered_map>
44
45 #include "auth_acls.h"
46 #include "btr0btr.h"
47 #include "btr0pcur.h"
48 #include "btr0types.h"
49 #include "buf0buddy.h"
50 #include "buf0buf.h"
51 #include "buf0stats.h"
52 #include "dict0crea.h"
53 #include "dict0dd.h"
54 #include "dict0dict.h"
55 #include "dict0load.h"
56 #include "dict0mem.h"
57 #include "dict0types.h"
58 #include "fsp0sysspace.h"
59 #include "fts0opt.h"
60 #include "fts0priv.h"
61 #include "fts0types.h"
62 #include "fut0fut.h"
63 #include "ha_prototypes.h"
64 #include "ibuf0ibuf.h"
65 #include "mysql/plugin.h"
66 #include "page0zip.h"
67 #include "pars0pars.h"
68 #include "sql/sql_class.h" /* For THD */
69 #include "srv0mon.h"
70 #include "srv0start.h"
71 #include "srv0tmp.h"
72 #include "trx0i_s.h"
73 #include "trx0trx.h"
74 #include "ut0new.h"
75
76 #include "my_dbug.h"
77
78 extern mysql_mutex_t LOCK_global_system_variables;
79
80 constexpr char plugin_author[] = PLUGIN_AUTHOR_ORACLE;
81
82 /** structure associates a name string with a file page type and/or buffer
83 page state. */
84 struct buf_page_desc_t {
85 const char *type_str; /*!< String explain the page
86 type/state */
87 size_t type_value; /*!< Page type or page state */
88 };
89
90 /** We also define I_S_PAGE_TYPE_INDEX as the Index Page's position
91 in i_s_page_type[] array */
92 constexpr size_t I_S_PAGE_TYPE_INDEX = 1;
93
94 /** Any unassigned FIL_PAGE_TYPE will be treated as unknown. */
95 constexpr auto I_S_PAGE_TYPE_UNKNOWN = FIL_PAGE_TYPE_UNKNOWN;
96
97 /** R-tree index page */
98 constexpr auto I_S_PAGE_TYPE_RTREE = (FIL_PAGE_TYPE_LAST + 1);
99
100 /** Change buffer B-tree page */
101 constexpr auto I_S_PAGE_TYPE_IBUF = (FIL_PAGE_TYPE_LAST + 2);
102
103 /** SDI B-tree page */
104 constexpr auto I_S_PAGE_TYPE_SDI = (FIL_PAGE_TYPE_LAST + 3);
105
106 constexpr auto I_S_PAGE_TYPE_LAST = I_S_PAGE_TYPE_SDI;
107
108 constexpr auto I_S_PAGE_TYPE_BITS = 6;
109
110 /** I_S.innodb_* views version postfix. Every time the define of any InnoDB I_S
111 table is changed, this value has to be increased accordingly */
112 constexpr uint8_t i_s_innodb_plugin_version_postfix = 2;
113
114 /** I_S.innodb_* views version. It would be X.Y and X should be the server major
115 version while Y is the InnoDB I_S views version, starting from 1 */
116 constexpr uint64_t i_s_innodb_plugin_version =
117 (INNODB_VERSION_MAJOR << 8 | i_s_innodb_plugin_version_postfix);
118
119 /* Check if we can hold all page types */
120 static_assert(I_S_PAGE_TYPE_LAST < (1 << I_S_PAGE_TYPE_BITS),
121 "i_s_page_type[] is too large");
122
123 namespace {
124 const char *state_str(buf_page_state state) {
125 const std::string_view state_str = buf_page_state_str.at(state);
126 if (state_str.length() == 0) {
127 return nullptr;
128 }
129 return state_str.data();
130 }
131
132 const std::unordered_map<buf_io_fix, std::string_view> buf_io_fix_str{
133 {BUF_IO_NONE, "IO_NONE"},
134 {BUF_IO_READ, "IO_READ"},
135 {BUF_IO_WRITE, "IO_WRITE"},
136 {BUF_IO_PIN, "IO_PIN"},
137 };
138
139 const char *io_fix_str(buf_io_fix io_fix) {
140 return buf_io_fix_str.at(io_fix).data();
141 }
142
143 const std::unordered_map<buf_page_state, std::string_view>
144 buf_lru_page_state_str{/* Compressed page */
145 {BUF_BLOCK_ZIP_PAGE, "YES"},
146 {BUF_BLOCK_ZIP_DIRTY, "YES"},
147 /* Uncompressed page */
148 {BUF_BLOCK_FILE_PAGE, "NO"},
149 /* We should not see following states */
150 {BUF_BLOCK_POOL_WATCH, ""},
151 {BUF_BLOCK_READY_FOR_USE, ""},
152 {BUF_BLOCK_NOT_USED, ""},
153 {BUF_BLOCK_MEMORY, ""},
154 {BUF_BLOCK_REMOVE_HASH, ""}};
155
156 const char *lru_page_state_str(buf_page_state lru_state) {
157 const std::string_view lru_state_str = buf_lru_page_state_str.at(lru_state);
158 if (lru_state_str.length() == 0) {
159 return nullptr;
160 }
161 return lru_state_str.data();
162 }
163 } // namespace
164
165 /** Name string for File Page Types */
166 static buf_page_desc_t i_s_page_type[] = {
167 {"ALLOCATED", FIL_PAGE_TYPE_ALLOCATED},
168 {"INDEX", FIL_PAGE_INDEX},
169 {"UNDO_LOG", FIL_PAGE_UNDO_LOG},
170 {"INODE", FIL_PAGE_INODE},
171 {"IBUF_FREE_LIST", FIL_PAGE_IBUF_FREE_LIST},
172 {"IBUF_BITMAP", FIL_PAGE_IBUF_BITMAP},
173 {"SYSTEM", FIL_PAGE_TYPE_SYS},
174 {"TRX_SYSTEM", FIL_PAGE_TYPE_TRX_SYS},
175 {"FILE_SPACE_HEADER", FIL_PAGE_TYPE_FSP_HDR},
176 {"EXTENT_DESCRIPTOR", FIL_PAGE_TYPE_XDES},
177 {"BLOB", FIL_PAGE_TYPE_BLOB},
178 {"COMPRESSED_BLOB", FIL_PAGE_TYPE_ZBLOB},
179 {"COMPRESSED_BLOB2", FIL_PAGE_TYPE_ZBLOB2},
180 {"UNKNOWN", I_S_PAGE_TYPE_UNKNOWN},
181 {"PAGE_IO_COMPRESSED", FIL_PAGE_COMPRESSED},
182 {"PAGE_IO_ENCRYPTED", FIL_PAGE_ENCRYPTED},
183 {"PAGE_IO_COMPRESSED_ENCRYPTED", FIL_PAGE_COMPRESSED_AND_ENCRYPTED},
184 {"ENCRYPTED_RTREE", FIL_PAGE_ENCRYPTED_RTREE},
185 {"SDI_BLOB", FIL_PAGE_SDI_BLOB},
186 {"SDI_COMPRESSED_BLOB", FIL_PAGE_SDI_ZBLOB},
187 {"FIL_PAGE_TYPE_LEGACY_DBLWR", FIL_PAGE_TYPE_LEGACY_DBLWR},
188 {"RSEG_ARRAY", FIL_PAGE_TYPE_RSEG_ARRAY},
189 {"LOB_INDEX", FIL_PAGE_TYPE_LOB_INDEX},
190 {"LOB_DATA", FIL_PAGE_TYPE_LOB_DATA},
191 {"LOB_FIRST", FIL_PAGE_TYPE_LOB_FIRST},
192 {"ZLOB_FIRST", FIL_PAGE_TYPE_ZLOB_FIRST},
193 {"ZLOB_DATA", FIL_PAGE_TYPE_ZLOB_DATA},
194 {"ZLOB_INDEX", FIL_PAGE_TYPE_ZLOB_INDEX},
195 {"ZLOB_FRAG", FIL_PAGE_TYPE_ZLOB_FRAG},
196 {"ZLOB_FRAG_ENTRY", FIL_PAGE_TYPE_ZLOB_FRAG_ENTRY},
197 {"RTREE_INDEX", I_S_PAGE_TYPE_RTREE},
198 {"IBUF_INDEX", I_S_PAGE_TYPE_IBUF},
199 {"SDI_INDEX", I_S_PAGE_TYPE_SDI}};
200
201 /** This structure defines information we will fetch from pages
202 currently cached in the buffer pool. It will be used to populate
203 table INFORMATION_SCHEMA.INNODB_BUFFER_PAGE */
204 struct buf_page_info_t {
205 /** Buffer Pool block ID */
206 size_t block_id;
207 /** Tablespace ID */
208 space_id_t space_id;
209 /** Page number, translating to offset in tablespace file. */
210 page_no_t page_num;
211 /** Log sequence number of the most recent modification. */
212 lsn_t newest_mod;
213 /** Log sequence number of the oldest modification. */
214 lsn_t oldest_mod;
215 /** Index ID if a index page. */
216 space_index_t index_id;
217 /** Time of first access. */
218 uint32_t access_time;
219 /** Count of how many-fold this block is buffer-fixed. */
220 uint32_t fix_count;
221 /** The value of buf_pool->freed_page_clock. */
222 uint32_t freed_page_clock;
223
224 /* The following two fields should fit 32 bits. */
225
226 /** Number of records on the page. */
227 uint32_t num_recs : UNIV_PAGE_SIZE_SHIFT_MAX - 2;
228 /** Sum of the sizes of the records. */
229 uint32_t data_size : UNIV_PAGE_SIZE_SHIFT_MAX;
230
231 /* The following fields are a few bits long, should fit in 16 bits. */
232
233 /** True if the page was already stale - a page from a already deleted
234 tablespace. */
235 uint16_t is_stale : 1;
236 /** Last flush request type. */
237 uint16_t flush_type : 2;
238 /** Type of pending I/O operation. */
239 uint16_t io_fix : 2;
240 /** Whether hash index has been built on this page. */
241 uint16_t hashed : 1;
242 /** True if the block is in the old blocks in buf_pool->LRU_old. */
243 uint16_t is_old : 1;
244 /** Compressed page size. */
245 uint16_t zip_ssize : PAGE_ZIP_SSIZE_BITS;
246 /** Buffer Pool ID. Must be less than MAX_BUFFER_POOLS. */
247
248 uint8_t pool_id;
249 /** Page state. */
250 buf_page_state page_state;
251 /** Page type. */
252 uint8_t page_type;
253 };
254
255 /** Maximum number of buffer page info we would cache. */
256 const ulint MAX_BUF_INFO_CACHED = 10000;
257
258 #define OK(expr) \
259 if ((expr) != 0) { \
260 return 1; \
261 }
262
263 #if !defined __STRICT_ANSI__ && defined __GNUC__ && !defined __clang__
264 #define STRUCT_FLD(name, value) \
265 name: \
266 value
267 #else
268 #define STRUCT_FLD(name, value) value
269 #endif
270
271 /* Don't use a static const variable here, as some C++ compilers (notably
272 HPUX aCC: HP ANSI C++ B3910B A.03.65) can't handle it. */
273 #define END_OF_ST_FIELD_INFO \
274 { \
275 STRUCT_FLD(field_name, NULL), STRUCT_FLD(field_length, 0), \
276 STRUCT_FLD(field_type, MYSQL_TYPE_NULL), STRUCT_FLD(value, 0), \
277 STRUCT_FLD(field_flags, 0), STRUCT_FLD(old_name, ""), \
278 STRUCT_FLD(open_method, 0) \
279 }
280
281 /*
282 Use the following types mapping:
283
284 C type ST_FIELD_INFO::field_type
285 ---------------------------------
286 long MYSQL_TYPE_LONGLONG
287 (field_length=MY_INT64_NUM_DECIMAL_DIGITS)
288
289 long unsigned MYSQL_TYPE_LONGLONG
290 (field_length=MY_INT64_NUM_DECIMAL_DIGITS, field_flags=MY_I_S_UNSIGNED)
291
292 char* MYSQL_TYPE_STRING
293 (field_length=n)
294
295 float MYSQL_TYPE_FLOAT
296 (field_length=0 is ignored)
297
298 void* MYSQL_TYPE_LONGLONG
299 (field_length=MY_INT64_NUM_DECIMAL_DIGITS, field_flags=MY_I_S_UNSIGNED)
300
301 boolean (if else) MYSQL_TYPE_LONG
302 (field_length=1)
303
304 time_t MYSQL_TYPE_DATETIME
305 (field_length=0 ignored)
306 ---------------------------------
307 */
308
309 /** Common function to fill any of the dynamic tables:
310 INFORMATION_SCHEMA.innodb_trx
311 @return 0 on success */
312 static int trx_i_s_common_fill_table(
313 THD *thd, /*!< in: thread */
314 Table_ref *tables, /*!< in/out: tables to fill */
315 Item *); /*!< in: condition (not used) */
316
317 /** Unbind a dynamic INFORMATION_SCHEMA table.
318 @return 0 on success */
319 static int i_s_common_deinit(void *p); /*!< in/out: table schema object */
320 /** Auxiliary function to store time_t value in MYSQL_TYPE_DATETIME
321 field.
322 @return 0 on success */
323 static int field_store_time_t(
324 Field *field, /*!< in/out: target field for storage */
325 time_t time) /*!< in: value to store */
326 {
327 MYSQL_TIME my_time;
328 struct tm tm_time;
329
330 if (time) {
331 #if 0
332 /* use this if you are sure that `variables' and `time_zone'
333 are always initialized */
334 thd->variables.time_zone->gmt_sec_to_TIME(
335 &my_time, (my_time_t) time);
336 #else
337 localtime_r(&time, &tm_time);
338 localtime_to_TIME(&my_time, &tm_time);
339 my_time.time_type = MYSQL_TIMESTAMP_DATETIME;
340 #endif
341 } else {
342 memset(&my_time, 0, sizeof(my_time));
343 }
344
345 return (field->store_time(&my_time, MYSQL_TIMESTAMP_DATETIME));
346 }
347
348 /** Auxiliary function to store char* value in MYSQL_TYPE_STRING field.
349 @return 0 on success */
350 static int field_store_string(
351 Field *field, /*!< in/out: target field for storage */
352 const char *str) /*!< in: NUL-terminated utf-8 string,
353 or NULL */
354 {
355 int ret;
356
357 if (str != nullptr) {
358 ret =
359 field->store(str, static_cast<uint>(strlen(str)), system_charset_info);
360 field->set_notnull();
361 } else {
362 ret = 0; /* success */
363 field->set_null();
364 }
365
366 return (ret);
367 }
368
369 /** Store the name of an index in a MYSQL_TYPE_VARCHAR field.
370 Handles the names of incomplete secondary indexes.
371 @return 0 on success */
372 static int field_store_index_name(
373 Field *field, /*!< in/out: target field for
374 storage */
375 const char *index_name) /*!< in: NUL-terminated utf-8
376 index name, possibly starting with
377 TEMP_INDEX_PREFIX */
378 {
379 int ret;
380
381 ut_ad(index_name != nullptr);
382 ut_ad(field->real_type() == MYSQL_TYPE_VARCHAR);
383
384 /* Since TEMP_INDEX_PREFIX is not a valid UTF8MB3, we need to convert
385 it to something else. */
386 if (*index_name == *TEMP_INDEX_PREFIX_STR) {
387 char buf[NAME_LEN + 1];
388 buf[0] = '?';
389 memcpy(buf + 1, index_name + 1, strlen(index_name));
390 ret =
391 field->store(buf, static_cast<uint>(strlen(buf)), system_charset_info);
392 } else {
393 ret = field->store(index_name, static_cast<uint>(strlen(index_name)),
394 system_charset_info);
395 }
396
397 field->set_notnull();
398
399 return (ret);
400 }
401
402 /* Fields of the dynamic table INFORMATION_SCHEMA.innodb_trx
403 Every time any column gets changed, added or removed, please remember
404 to change i_s_innodb_plugin_version_postfix accordingly, so that
405 the change can be propagated to server */
406 static ST_FIELD_INFO innodb_trx_fields_info[] = {
407 #define IDX_TRX_ID 0
408 {STRUCT_FLD(field_name, "trx_id"),
409 STRUCT_FLD(field_length, MY_INT64_NUM_DECIMAL_DIGITS),
410 STRUCT_FLD(field_type, MYSQL_TYPE_LONGLONG), STRUCT_FLD(value, 0),
411 STRUCT_FLD(field_flags, MY_I_S_UNSIGNED), STRUCT_FLD(old_name, ""),
412 STRUCT_FLD(open_method, 0)},
413
414 #define IDX_TRX_STATE 1
415 {STRUCT_FLD(field_name, "trx_state"),
416 STRUCT_FLD(field_length, TRX_QUE_STATE_STR_MAX_LEN + 1),
417 STRUCT_FLD(field_type, MYSQL_TYPE_STRING), STRUCT_FLD(value, 0),
418 STRUCT_FLD(field_flags, 0), STRUCT_FLD(old_name, ""),
419 STRUCT_FLD(open_method, 0)},
420
421 #define IDX_TRX_STARTED 2
422 {STRUCT_FLD(field_name, "trx_started"), STRUCT_FLD(field_length, 0),
423 STRUCT_FLD(field_type, MYSQL_TYPE_DATETIME), STRUCT_FLD(value, 0),
424 STRUCT_FLD(field_flags, 0), STRUCT_FLD(old_name, ""),
425 STRUCT_FLD(open_method, 0)},
426
427 #define IDX_TRX_REQUESTED_LOCK_ID 3
428 {STRUCT_FLD(field_name, "trx_requested_lock_id"),
429 STRUCT_FLD(field_length, TRX_I_S_LOCK_ID_MAX_LEN + 1),
430 STRUCT_FLD(field_type, MYSQL_TYPE_STRING), STRUCT_FLD(value, 0),
431 STRUCT_FLD(field_flags, MY_I_S_MAYBE_NULL), STRUCT_FLD(old_name, ""),
432 STRUCT_FLD(open_method, 0)},
433
434 #define IDX_TRX_WAIT_STARTED 4
435 {STRUCT_FLD(field_name, "trx_wait_started"), STRUCT_FLD(field_length, 0),
436 STRUCT_FLD(field_type, MYSQL_TYPE_DATETIME), STRUCT_FLD(value, 0),
437 STRUCT_FLD(field_flags, MY_I_S_MAYBE_NULL), STRUCT_FLD(old_name, ""),
438 STRUCT_FLD(open_method, 0)},
439
440 #define IDX_TRX_WEIGHT 5
441 {STRUCT_FLD(field_name, "trx_weight"),
442 STRUCT_FLD(field_length, MY_INT64_NUM_DECIMAL_DIGITS),
443 STRUCT_FLD(field_type, MYSQL_TYPE_LONGLONG), STRUCT_FLD(value, 0),
444 STRUCT_FLD(field_flags, MY_I_S_UNSIGNED), STRUCT_FLD(old_name, ""),
445 STRUCT_FLD(open_method, 0)},
446
447 #define IDX_TRX_MYSQL_THREAD_ID 6
448 {STRUCT_FLD(field_name, "trx_mysql_thread_id"),
449 STRUCT_FLD(field_length, MY_INT64_NUM_DECIMAL_DIGITS),
450 STRUCT_FLD(field_type, MYSQL_TYPE_LONGLONG), STRUCT_FLD(value, 0),
451 STRUCT_FLD(field_flags, MY_I_S_UNSIGNED), STRUCT_FLD(old_name, ""),
452 STRUCT_FLD(open_method, 0)},
453
454 #define IDX_TRX_QUERY 7
455 {STRUCT_FLD(field_name, "trx_query"),
456 STRUCT_FLD(field_length, TRX_I_S_TRX_QUERY_MAX_LEN),
457 STRUCT_FLD(field_type, MYSQL_TYPE_STRING), STRUCT_FLD(value, 0),
458 STRUCT_FLD(field_flags, MY_I_S_MAYBE_NULL), STRUCT_FLD(old_name, ""),
459 STRUCT_FLD(open_method, 0)},
460
461 #define IDX_TRX_OPERATION_STATE 8
462 {STRUCT_FLD(field_name, "trx_operation_state"),
463 STRUCT_FLD(field_length, TRX_I_S_TRX_OP_STATE_MAX_LEN),
464 STRUCT_FLD(field_type, MYSQL_TYPE_STRING), STRUCT_FLD(value, 0),
465 STRUCT_FLD(field_flags, MY_I_S_MAYBE_NULL), STRUCT_FLD(old_name, ""),
466 STRUCT_FLD(open_method, 0)},
467
468 #define IDX_TRX_TABLES_IN_USE 9
469 {STRUCT_FLD(field_name, "trx_tables_in_use"),
470 STRUCT_FLD(field_length, MY_INT64_NUM_DECIMAL_DIGITS),
471 STRUCT_FLD(field_type, MYSQL_TYPE_LONGLONG), STRUCT_FLD(value, 0),
472 STRUCT_FLD(field_flags, MY_I_S_UNSIGNED), STRUCT_FLD(old_name, ""),
473 STRUCT_FLD(open_method, 0)},
474
475 #define IDX_TRX_TABLES_LOCKED 10
476 {STRUCT_FLD(field_name, "trx_tables_locked"),
477 STRUCT_FLD(field_length, MY_INT64_NUM_DECIMAL_DIGITS),
478 STRUCT_FLD(field_type, MYSQL_TYPE_LONGLONG), STRUCT_FLD(value, 0),
479 STRUCT_FLD(field_flags, MY_I_S_UNSIGNED), STRUCT_FLD(old_name, ""),
480 STRUCT_FLD(open_method, 0)},
481
482 #define IDX_TRX_LOCK_STRUCTS 11
483 {STRUCT_FLD(field_name, "trx_lock_structs"),
484 STRUCT_FLD(field_length, MY_INT64_NUM_DECIMAL_DIGITS),
485 STRUCT_FLD(field_type, MYSQL_TYPE_LONGLONG), STRUCT_FLD(value, 0),
486 STRUCT_FLD(field_flags, MY_I_S_UNSIGNED), STRUCT_FLD(old_name, ""),
487 STRUCT_FLD(open_method, 0)},
488
489 #define IDX_TRX_LOCK_MEMORY_BYTES 12
490 {STRUCT_FLD(field_name, "trx_lock_memory_bytes"),
491 STRUCT_FLD(field_length, MY_INT64_NUM_DECIMAL_DIGITS),
492 STRUCT_FLD(field_type, MYSQL_TYPE_LONGLONG), STRUCT_FLD(value, 0),
493 STRUCT_FLD(field_flags, MY_I_S_UNSIGNED), STRUCT_FLD(old_name, ""),
494 STRUCT_FLD(open_method, 0)},
495
496 #define IDX_TRX_ROWS_LOCKED 13
497 {STRUCT_FLD(field_name, "trx_rows_locked"),
498 STRUCT_FLD(field_length, MY_INT64_NUM_DECIMAL_DIGITS),
499 STRUCT_FLD(field_type, MYSQL_TYPE_LONGLONG), STRUCT_FLD(value, 0),
500 STRUCT_FLD(field_flags, MY_I_S_UNSIGNED), STRUCT_FLD(old_name, ""),
501 STRUCT_FLD(open_method, 0)},
502
503 #define IDX_TRX_ROWS_MODIFIED 14
504 {STRUCT_FLD(field_name, "trx_rows_modified"),
505 STRUCT_FLD(field_length, MY_INT64_NUM_DECIMAL_DIGITS),
506 STRUCT_FLD(field_type, MYSQL_TYPE_LONGLONG), STRUCT_FLD(value, 0),
507 STRUCT_FLD(field_flags, MY_I_S_UNSIGNED), STRUCT_FLD(old_name, ""),
508 STRUCT_FLD(open_method, 0)},
509
510 #define IDX_TRX_CONNCURRENCY_TICKETS 15
511 {STRUCT_FLD(field_name, "trx_concurrency_tickets"),
512 STRUCT_FLD(field_length, MY_INT64_NUM_DECIMAL_DIGITS),
513 STRUCT_FLD(field_type, MYSQL_TYPE_LONGLONG), STRUCT_FLD(value, 0),
514 STRUCT_FLD(field_flags, MY_I_S_UNSIGNED), STRUCT_FLD(old_name, ""),
515 STRUCT_FLD(open_method, 0)},
516
517 #define IDX_TRX_ISOLATION_LEVEL 16
518 {STRUCT_FLD(field_name, "trx_isolation_level"),
519 STRUCT_FLD(field_length, TRX_I_S_TRX_ISOLATION_LEVEL_MAX_LEN),
520 STRUCT_FLD(field_type, MYSQL_TYPE_STRING), STRUCT_FLD(value, 0),
521 STRUCT_FLD(field_flags, 0), STRUCT_FLD(old_name, ""),
522 STRUCT_FLD(open_method, 0)},
523
524 #define IDX_TRX_UNIQUE_CHECKS 17
525 {STRUCT_FLD(field_name, "trx_unique_checks"), STRUCT_FLD(field_length, 1),
526 STRUCT_FLD(field_type, MYSQL_TYPE_LONG), STRUCT_FLD(value, 1),
527 STRUCT_FLD(field_flags, 0), STRUCT_FLD(old_name, ""),
528 STRUCT_FLD(open_method, 0)},
529
530 #define IDX_TRX_FOREIGN_KEY_CHECKS 18
531 {STRUCT_FLD(field_name, "trx_foreign_key_checks"),
532 STRUCT_FLD(field_length, 1), STRUCT_FLD(field_type, MYSQL_TYPE_LONG),
533 STRUCT_FLD(value, 1), STRUCT_FLD(field_flags, 0), STRUCT_FLD(old_name, ""),
534 STRUCT_FLD(open_method, 0)},
535
536 #define IDX_TRX_LAST_FOREIGN_KEY_ERROR 19
537 {STRUCT_FLD(field_name, "trx_last_foreign_key_error"),
538 STRUCT_FLD(field_length, TRX_I_S_TRX_FK_ERROR_MAX_LEN),
539 STRUCT_FLD(field_type, MYSQL_TYPE_STRING), STRUCT_FLD(value, 0),
540 STRUCT_FLD(field_flags, MY_I_S_MAYBE_NULL), STRUCT_FLD(old_name, ""),
541 STRUCT_FLD(open_method, 0)},
542
543 #define IDX_TRX_ADAPTIVE_HASH_LATCHED 20
544 {STRUCT_FLD(field_name, "trx_adaptive_hash_latched"),
545 STRUCT_FLD(field_length, 1), STRUCT_FLD(field_type, MYSQL_TYPE_LONG),
546 STRUCT_FLD(value, 0), STRUCT_FLD(field_flags, 0), STRUCT_FLD(old_name, ""),
547 STRUCT_FLD(open_method, 0)},
548
549 #define IDX_TRX_ADAPTIVE_HASH_TIMEOUT 21
550 {STRUCT_FLD(field_name, "trx_adaptive_hash_timeout"),
551 STRUCT_FLD(field_length, MY_INT64_NUM_DECIMAL_DIGITS),
552 STRUCT_FLD(field_type, MYSQL_TYPE_LONGLONG), STRUCT_FLD(value, 0),
553 STRUCT_FLD(field_flags, MY_I_S_UNSIGNED), STRUCT_FLD(old_name, ""),
554 STRUCT_FLD(open_method, 0)},
555
556 #define IDX_TRX_READ_ONLY 22
557 {STRUCT_FLD(field_name, "trx_is_read_only"), STRUCT_FLD(field_length, 1),
558 STRUCT_FLD(field_type, MYSQL_TYPE_LONG), STRUCT_FLD(value, 0),
559 STRUCT_FLD(field_flags, 0), STRUCT_FLD(old_name, ""),
560 STRUCT_FLD(open_method, 0)},
561
562 #define IDX_TRX_AUTOCOMMIT_NON_LOCKING 23
563 {STRUCT_FLD(field_name, "trx_autocommit_non_locking"),
564 STRUCT_FLD(field_length, 1), STRUCT_FLD(field_type, MYSQL_TYPE_LONG),
565 STRUCT_FLD(value, 0), STRUCT_FLD(field_flags, 0), STRUCT_FLD(old_name, ""),
566 STRUCT_FLD(open_method, 0)},
567
568 #define IDX_TRX_SCHEDULE_WEIGHT 24
569 {STRUCT_FLD(field_name, "trx_schedule_weight"),
570 STRUCT_FLD(field_length, MY_INT64_NUM_DECIMAL_DIGITS),
571 STRUCT_FLD(field_type, MYSQL_TYPE_LONGLONG), STRUCT_FLD(value, 0),
572 STRUCT_FLD(field_flags, MY_I_S_UNSIGNED | MY_I_S_MAYBE_NULL),
573 STRUCT_FLD(old_name, ""), STRUCT_FLD(open_method, 0)},
574
575 END_OF_ST_FIELD_INFO};
576
577 /** Read data from cache buffer and fill the INFORMATION_SCHEMA.innodb_trx
578 table with it.
579 @return 0 on success */
580 static int fill_innodb_trx_from_cache(
581 trx_i_s_cache_t *cache, /*!< in: cache to read from */
582 THD *thd, /*!< in: used to call
583 schema_table_store_record() */
584 TABLE *table) /*!< in/out: fill this table */
585 {
586 Field **fields;
587 ulint rows_num;
588 char lock_id[TRX_I_S_LOCK_ID_MAX_LEN + 1];
589 ulint i;
590
591 DBUG_TRACE;
592
593 fields = table->field;
594
595 rows_num = trx_i_s_cache_get_rows_used(cache, I_S_INNODB_TRX);
596
597 for (i = 0; i < rows_num; i++) {
598 i_s_trx_row_t *row;
599
600 row = (i_s_trx_row_t *)trx_i_s_cache_get_nth_row(cache, I_S_INNODB_TRX, i);
601
602 /* trx_id */
603 OK(fields[IDX_TRX_ID]->store(row->trx_id, true));
604
605 /* trx_state */
606 OK(field_store_string(fields[IDX_TRX_STATE], row->trx_state));
607
608 /* trx_started */
609 OK(field_store_time_t(
610 fields[IDX_TRX_STARTED],
611 std::chrono::system_clock::to_time_t(row->trx_started)));
612
613 /* trx_requested_lock_id */
614 /* trx_wait_started */
615 if (row->trx_wait_started != std::chrono::system_clock::time_point{}) {
616 OK(field_store_string(fields[IDX_TRX_REQUESTED_LOCK_ID],
617 trx_i_s_create_lock_id(*row->requested_lock_row,
618 lock_id, sizeof(lock_id))));
619 /* field_store_string() sets it no notnull */
620
621 OK(field_store_time_t(
622 fields[IDX_TRX_WAIT_STARTED],
623 std::chrono::system_clock::to_time_t(row->trx_wait_started)));
624 fields[IDX_TRX_WAIT_STARTED]->set_notnull();
625 } else {
626 fields[IDX_TRX_REQUESTED_LOCK_ID]->set_null();
627 fields[IDX_TRX_WAIT_STARTED]->set_null();
628 }
629
630 /* trx_weight */
631 OK(fields[IDX_TRX_WEIGHT]->store(row->trx_weight, true));
632
633 /* trx_mysql_thread_id */
634 OK(fields[IDX_TRX_MYSQL_THREAD_ID]->store(row->trx_mysql_thread_id, true));
635
636 /* trx_query */
637 if (row->trx_query) {
638 /* store will do appropriate character set
639 conversion check */
640 fields[IDX_TRX_QUERY]->store(row->trx_query,
641 static_cast<uint>(strlen(row->trx_query)),
642 row->trx_query_cs);
643 fields[IDX_TRX_QUERY]->set_notnull();
644 } else {
645 fields[IDX_TRX_QUERY]->set_null();
646 }
647
648 /* trx_operation_state */
649 OK(field_store_string(fields[IDX_TRX_OPERATION_STATE],
650 row->trx_operation_state));
651
652 /* trx_tables_in_use */
653 OK(fields[IDX_TRX_TABLES_IN_USE]->store(row->trx_tables_in_use, true));
654
655 /* trx_tables_locked */
656 OK(fields[IDX_TRX_TABLES_LOCKED]->store(row->trx_tables_locked, true));
657
658 /* trx_lock_structs */
659 OK(fields[IDX_TRX_LOCK_STRUCTS]->store(row->trx_lock_structs, true));
660
661 /* trx_lock_memory_bytes */
662 OK(fields[IDX_TRX_LOCK_MEMORY_BYTES]->store(row->trx_lock_memory_bytes,
663 true));
664
665 /* trx_rows_locked */
666 OK(fields[IDX_TRX_ROWS_LOCKED]->store(row->trx_rows_locked, true));
667
668 /* trx_rows_modified */
669 OK(fields[IDX_TRX_ROWS_MODIFIED]->store(row->trx_rows_modified, true));
670
671 /* trx_concurrency_tickets */
672 OK(fields[IDX_TRX_CONNCURRENCY_TICKETS]->store(row->trx_concurrency_tickets,
673 true));
674
675 /* trx_isolation_level */
676 OK(field_store_string(fields[IDX_TRX_ISOLATION_LEVEL],
677 row->trx_isolation_level));
678
679 /* trx_unique_checks */
680 OK(fields[IDX_TRX_UNIQUE_CHECKS]->store(row->trx_unique_checks, true));
681
682 /* trx_foreign_key_checks */
683 OK(fields[IDX_TRX_FOREIGN_KEY_CHECKS]->store(row->trx_foreign_key_checks,
684 true));
685
686 /* trx_last_foreign_key_error */
687 OK(field_store_string(fields[IDX_TRX_LAST_FOREIGN_KEY_ERROR],
688 row->trx_foreign_key_error));
689
690 /* trx_adaptive_hash_latched */
691 OK(fields[IDX_TRX_ADAPTIVE_HASH_LATCHED]->store(row->trx_has_search_latch,
692 true));
693
694 /* trx_is_read_only*/
695 OK(fields[IDX_TRX_READ_ONLY]->store(row->trx_is_read_only, true));
696
697 /* trx_is_autocommit_non_locking */
698 OK(fields[IDX_TRX_AUTOCOMMIT_NON_LOCKING]->store(
699 (longlong)row->trx_is_autocommit_non_locking, true));
700
701 /* trx_schedule_weight */
702 if (row->trx_schedule_weight.first) {
703 OK(fields[IDX_TRX_SCHEDULE_WEIGHT]->store(row->trx_schedule_weight.second,
704 true));
705 fields[IDX_TRX_SCHEDULE_WEIGHT]->set_notnull();
706 } else {
707 fields[IDX_TRX_SCHEDULE_WEIGHT]->set_null();
708 }
709
710 OK(schema_table_store_record(thd, table));
711 }
712
713 return 0;
714 }
715
716 /** Bind the dynamic table INFORMATION_SCHEMA.innodb_trx
717 @return 0 on success */
718 static int innodb_trx_init(void *p) /*!< in/out: table schema object */
719 {
720 ST_SCHEMA_TABLE *schema;
721
722 DBUG_TRACE;
723
724 schema = (ST_SCHEMA_TABLE *)p;
725
726 schema->fields_info = innodb_trx_fields_info;
727 schema->fill_table = trx_i_s_common_fill_table;
728
729 return 0;
730 }
731
732 static struct st_mysql_information_schema i_s_info = {
733 MYSQL_INFORMATION_SCHEMA_INTERFACE_VERSION};
734
735 struct st_mysql_plugin i_s_innodb_trx = {
736 /* the plugin type (a MYSQL_XXX_PLUGIN value) */
737 /* int */
738 STRUCT_FLD(type, MYSQL_INFORMATION_SCHEMA_PLUGIN),
739
740 /* pointer to type-specific plugin descriptor */
741 /* void* */
742 STRUCT_FLD(info, &i_s_info),
743
744 /* plugin name */
745 /* const char* */
746 STRUCT_FLD(name, "INNODB_TRX"),
747
748 /* plugin author (for SHOW PLUGINS) */
749 /* const char* */
750 STRUCT_FLD(author, plugin_author),
751
752 /* general descriptive text (for SHOW PLUGINS) */
753 /* const char* */
754 STRUCT_FLD(descr, "InnoDB transactions"),
755
756 /* the plugin license (PLUGIN_LICENSE_XXX) */
757 /* int */
758 STRUCT_FLD(license, PLUGIN_LICENSE_GPL),
759
760 /* the function to invoke when plugin is loaded */
761 /* int (*)(void*); */
762 STRUCT_FLD(init, innodb_trx_init),
763
764 /* the function to invoke when plugin is un installed */
765 /* int (*)(void*); */
766 STRUCT_FLD(check_uninstall, nullptr),
767
768 /* the function to invoke when plugin is unloaded */
769 /* int (*)(void*); */
770 STRUCT_FLD(deinit, i_s_common_deinit),
771
772 /* plugin version (for SHOW PLUGINS) */
773 /* unsigned int */
774 STRUCT_FLD(version, i_s_innodb_plugin_version),
775
776 /* SHOW_VAR* */
777 STRUCT_FLD(status_vars, nullptr),
778
779 /* SYS_VAR** */
780 STRUCT_FLD(system_vars, nullptr),
781
782 /* reserved for dependency checking */
783 /* void* */
784 STRUCT_FLD(__reserved1, nullptr),
785
786 /* Plugin flags */
787 /* unsigned long */
788 STRUCT_FLD(flags, 0UL),
789 };
790
791 /** Common function to fill any of the dynamic tables:
792 INFORMATION_SCHEMA.innodb_trx
793 @return 0 on success */
794 static int trx_i_s_common_fill_table(
795 THD *thd, /*!< in: thread */
796 Table_ref *tables, /*!< in/out: tables to fill */
797 Item *) /*!< in: condition (not used) */
798 {
799 const char *table_name;
800 int ret [[maybe_unused]];
801 trx_i_s_cache_t *cache;
802
803 DBUG_TRACE;
804
805 /* deny access to non-superusers */
806 if (check_global_access(thd, PROCESS_ACL)) {
807 return 0;
808 }
809
810 /* minimize the number of places where global variables are
811 referenced */
812 cache = trx_i_s_cache;
813
814 /* which table we have to fill? */
815 table_name = tables->table_name;
816 /* or table_name = tables->schema_table->table_name; */
817
818 /* update the cache */
819 trx_i_s_cache_start_write(cache);
820 trx_i_s_possibly_fetch_data_into_cache(cache);
821 trx_i_s_cache_end_write(cache);
822
823 if (trx_i_s_cache_is_truncated(cache)) {
824 ib::warn(ER_IB_MSG_599) << "Data in " << table_name
825 << " truncated due to"
826 " memory limit of "
827 << TRX_I_S_MEM_LIMIT << " bytes";
828 }
829
830 ret = 0;
831
832 trx_i_s_cache_start_read(cache);
833
834 if (innobase_strcasecmp(table_name, "innodb_trx") == 0) {
835 if (fill_innodb_trx_from_cache(cache, thd, tables->table) != 0) {
836 ret = 1;
837 }
838
839 } else {
840 ib::error(ER_IB_MSG_600) << "trx_i_s_common_fill_table() was"
841 " called to fill unknown table: "
842 << table_name
843 << "."
844 " This function only knows how to fill"
845 " innodb_trx, innodb_locks and"
846 " innodb_lock_waits tables.";
847
848 ret = 1;
849 }
850
851 trx_i_s_cache_end_read(cache);
852
853 #if 0
854 return ret;
855 #else
856 /* if this function returns something else than 0 then a
857 deadlock occurs between the mysqld server and mysql client,
858 see http://bugs.mysql.com/29900 ; when that bug is resolved
859 we can enable the return ret above */
860 return 0;
861 #endif
862 }
863
864 /* Fields of the dynamic table information_schema.innodb_cmp.
865 Every time any column gets changed, added or removed, please remember
866 to change i_s_innodb_plugin_version_postfix accordingly, so that
867 the change can be propagated to server */
868 static ST_FIELD_INFO i_s_cmp_fields_info[] = {
869 {STRUCT_FLD(field_name, "page_size"), STRUCT_FLD(field_length, 5),
870 STRUCT_FLD(field_type, MYSQL_TYPE_LONG), STRUCT_FLD(value, 0),
871 STRUCT_FLD(field_flags, 0), STRUCT_FLD(old_name, "Compressed Page Size"),
872 STRUCT_FLD(open_method, 0)},
873
874 {STRUCT_FLD(field_name, "compress_ops"),
875 STRUCT_FLD(field_length, MY_INT32_NUM_DECIMAL_DIGITS),
876 STRUCT_FLD(field_type, MYSQL_TYPE_LONG), STRUCT_FLD(value, 0),
877 STRUCT_FLD(field_flags, 0),
878 STRUCT_FLD(old_name, "Total Number of Compressions"),
879 STRUCT_FLD(open_method, 0)},
880
881 {STRUCT_FLD(field_name, "compress_ops_ok"),
882 STRUCT_FLD(field_length, MY_INT32_NUM_DECIMAL_DIGITS),
883 STRUCT_FLD(field_type, MYSQL_TYPE_LONG), STRUCT_FLD(value, 0),
884 STRUCT_FLD(field_flags, 0),
885 STRUCT_FLD(old_name,
886 "Total Number of"
887 " Successful Compressions"),
888 STRUCT_FLD(open_method, 0)},
889
890 {STRUCT_FLD(field_name, "compress_time"),
891 STRUCT_FLD(field_length, MY_INT32_NUM_DECIMAL_DIGITS),
892 STRUCT_FLD(field_type, MYSQL_TYPE_LONG), STRUCT_FLD(value, 0),
893 STRUCT_FLD(field_flags, 0),
894 STRUCT_FLD(old_name,
895 "Total Duration of Compressions,"
896 " in Seconds"),
897 STRUCT_FLD(open_method, 0)},
898
899 {STRUCT_FLD(field_name, "uncompress_ops"),
900 STRUCT_FLD(field_length, MY_INT32_NUM_DECIMAL_DIGITS),
901 STRUCT_FLD(field_type, MYSQL_TYPE_LONG), STRUCT_FLD(value, 0),
902 STRUCT_FLD(field_flags, 0),
903 STRUCT_FLD(old_name, "Total Number of Decompressions"),
904 STRUCT_FLD(open_method, 0)},
905
906 {STRUCT_FLD(field_name, "uncompress_time"),
907 STRUCT_FLD(field_length, MY_INT32_NUM_DECIMAL_DIGITS),
908 STRUCT_FLD(field_type, MYSQL_TYPE_LONG), STRUCT_FLD(value, 0),
909 STRUCT_FLD(field_flags, 0),
910 STRUCT_FLD(old_name,
911 "Total Duration of Decompressions,"
912 " in Seconds"),
913 STRUCT_FLD(open_method, 0)},
914
915 END_OF_ST_FIELD_INFO};
916
917 /** Fill the dynamic table information_schema.innodb_cmp or
918 innodb_cmp_reset.
919 @return 0 on success, 1 on failure */
920 static int i_s_cmp_fill_low(THD *thd, /*!< in: thread */
921 Table_ref *tables, /*!< in/out: tables to fill */
922 Item *, /*!< in: condition (ignored) */
923 bool reset) /*!< in: true=reset cumulated counts */
924 {
925 TABLE *table = (TABLE *)tables->table;
926 int status = 0;
927
928 DBUG_TRACE;
929
930 /* deny access to non-superusers */
931 if (check_global_access(thd, PROCESS_ACL)) {
932 return 0;
933 }
934
935 for (uint i = 0; i < PAGE_ZIP_SSIZE_MAX; i++) {
936 page_zip_stat_t *zip_stat = &page_zip_stat[i];
937
938 table->field[0]->store(UNIV_ZIP_SIZE_MIN << i);
939
940 /* The cumulated counts are not protected by any
941 mutex. Thus, some operation in page0zip.cc could
942 increment a counter between the time we read it and
943 clear it. We could introduce mutex protection, but it
944 could cause a measurable performance hit in
945 page0zip.cc. */
946 table->field[1]->store(zip_stat->compressed, true);
947 table->field[2]->store(zip_stat->compressed_ok, true);
948 table->field[3]->store(std::chrono::duration_cast<std::chrono::seconds>(
949 zip_stat->compress_time)
950 .count(),
951 true);
952 table->field[4]->store(zip_stat->decompressed, true);
953 table->field[5]->store(std::chrono::duration_cast<std::chrono::seconds>(
954 zip_stat->decompress_time)
955 .count(),
956 true);
957
958 if (reset) {
959 new (zip_stat) page_zip_stat_t();
960 }
961
962 if (schema_table_store_record(thd, table)) {
963 status = 1;
964 break;
965 }
966 }
967
968 return status;
969 }
970
971 /** Fill the dynamic table information_schema.innodb_cmp.
972 @return 0 on success, 1 on failure */
973 static int i_s_cmp_fill(THD *thd, /*!< in: thread */
974 Table_ref *tables, /*!< in/out: tables to fill */
975 Item *cond) /*!< in: condition (ignored) */
976 {
977 return (i_s_cmp_fill_low(thd, tables, cond, false));
978 }
979
980 /** Fill the dynamic table information_schema.innodb_cmp_reset.
981 @return 0 on success, 1 on failure */
982 static int i_s_cmp_reset_fill(THD *thd, /*!< in: thread */
983 Table_ref *tables, /*!< in/out: tables to fill */
984 Item *cond) /*!< in: condition (ignored) */
985 {
986 return (i_s_cmp_fill_low(thd, tables, cond, true));
987 }
988
989 /** Bind the dynamic table information_schema.innodb_cmp.
990 @return 0 on success */
991 static int i_s_cmp_init(void *p) /*!< in/out: table schema object */
992 {
993 DBUG_TRACE;
994 ST_SCHEMA_TABLE *schema = (ST_SCHEMA_TABLE *)p;
995
996 schema->fields_info = i_s_cmp_fields_info;
997 schema->fill_table = i_s_cmp_fill;
998
999 return 0;
1000 }
1001
1002 /** Bind the dynamic table information_schema.innodb_cmp_reset.
1003 @return 0 on success */
1004 static int i_s_cmp_reset_init(void *p) /*!< in/out: table schema object */
1005 {
1006 DBUG_TRACE;
1007 ST_SCHEMA_TABLE *schema = (ST_SCHEMA_TABLE *)p;
1008
1009 schema->fields_info = i_s_cmp_fields_info;
1010 schema->fill_table = i_s_cmp_reset_fill;
1011
1012 return 0;
1013 }
1014
1015 struct st_mysql_plugin i_s_innodb_cmp = {
1016 /* the plugin type (a MYSQL_XXX_PLUGIN value) */
1017 /* int */
1018 STRUCT_FLD(type, MYSQL_INFORMATION_SCHEMA_PLUGIN),
1019
1020 /* pointer to type-specific plugin descriptor */
1021 /* void* */
1022 STRUCT_FLD(info, &i_s_info),
1023
1024 /* plugin name */
1025 /* const char* */
1026 STRUCT_FLD(name, "INNODB_CMP"),
1027
1028 /* plugin author (for SHOW PLUGINS) */
1029 /* const char* */
1030 STRUCT_FLD(author, plugin_author),
1031
1032 /* general descriptive text (for SHOW PLUGINS) */
1033 /* const char* */
1034 STRUCT_FLD(descr, "Statistics for the InnoDB compression"),
1035
1036 /* the plugin license (PLUGIN_LICENSE_XXX) */
1037 /* int */
1038 STRUCT_FLD(license, PLUGIN_LICENSE_GPL),
1039
1040 /* the function to invoke when plugin is loaded */
1041 /* int (*)(void*); */
1042 STRUCT_FLD(init, i_s_cmp_init),
1043
1044 /* the function to invoke when plugin is un installed */
1045 /* int (*)(void*); */
1046 STRUCT_FLD(check_uninstall, nullptr),
1047
1048 /* the function to invoke when plugin is unloaded */
1049 /* int (*)(void*); */
1050 STRUCT_FLD(deinit, i_s_common_deinit),
1051
1052 /* plugin version (for SHOW PLUGINS) */
1053 /* unsigned int */
1054 STRUCT_FLD(version, i_s_innodb_plugin_version),
1055
1056 /* SHOW_VAR* */
1057 STRUCT_FLD(status_vars, nullptr),
1058
1059 /* SYS_VAR** */
1060 STRUCT_FLD(system_vars, nullptr),
1061
1062 /* reserved for dependency checking */
1063 /* void* */
1064 STRUCT_FLD(__reserved1, nullptr),
1065
1066 /* Plugin flags */
1067 /* unsigned long */
1068 STRUCT_FLD(flags, 0UL),
1069 };
1070
1071 struct st_mysql_plugin i_s_innodb_cmp_reset = {
1072 /* the plugin type (a MYSQL_XXX_PLUGIN value) */
1073 /* int */
1074 STRUCT_FLD(type, MYSQL_INFORMATION_SCHEMA_PLUGIN),
1075
1076 /* pointer to type-specific plugin descriptor */
1077 /* void* */
1078 STRUCT_FLD(info, &i_s_info),
1079
1080 /* plugin name */
1081 /* const char* */
1082 STRUCT_FLD(name, "INNODB_CMP_RESET"),
1083
1084 /* plugin author (for SHOW PLUGINS) */
1085 /* const char* */
1086 STRUCT_FLD(author, plugin_author),
1087
1088 /* general descriptive text (for SHOW PLUGINS) */
1089 /* const char* */
1090 STRUCT_FLD(descr,
1091 "Statistics for the InnoDB compression;"
1092 " reset cumulated counts"),
1093
1094 /* the plugin license (PLUGIN_LICENSE_XXX) */
1095 /* int */
1096 STRUCT_FLD(license, PLUGIN_LICENSE_GPL),
1097
1098 /* the function to invoke when plugin is loaded */
1099 /* int (*)(void*); */
1100 STRUCT_FLD(init, i_s_cmp_reset_init),
1101
1102 /* the function to invoke when plugin is un installed */
1103 /* int (*)(void*); */
1104 STRUCT_FLD(check_uninstall, nullptr),
1105
1106 /* the function to invoke when plugin is unloaded */
1107 /* int (*)(void*); */
1108 STRUCT_FLD(deinit, i_s_common_deinit),
1109
1110 /* plugin version (for SHOW PLUGINS) */
1111 /* unsigned int */
1112 STRUCT_FLD(version, i_s_innodb_plugin_version),
1113
1114 /* SHOW_VAR* */
1115 STRUCT_FLD(status_vars, nullptr),
1116
1117 /* SYS_VAR** */
1118 STRUCT_FLD(system_vars, nullptr),
1119
1120 /* reserved for dependency checking */
1121 /* void* */
1122 STRUCT_FLD(__reserved1, nullptr),
1123
1124 /* Plugin flags */
1125 /* unsigned long */
1126 STRUCT_FLD(flags, 0UL),
1127 };
1128
1129 /* Fields of the dynamic tables
1130 information_schema.innodb_cmp_per_index and
1131 information_schema.innodb_cmp_per_index_reset.
1132 Every time any column gets changed, added or removed, please remember
1133 to change i_s_innodb_plugin_version_postfix accordingly, so that
1134 the change can be propagated to server */
1135 static ST_FIELD_INFO i_s_cmp_per_index_fields_info[] = {
1136 #define IDX_DATABASE_NAME 0
1137 {STRUCT_FLD(field_name, "database_name"), STRUCT_FLD(field_length, 192),
1138 STRUCT_FLD(field_type, MYSQL_TYPE_STRING), STRUCT_FLD(value, 0),
1139 STRUCT_FLD(field_flags, 0), STRUCT_FLD(old_name, ""),
1140 STRUCT_FLD(open_method, 0)},
1141
1142 #define IDX_TABLE_NAME 1
1143 {STRUCT_FLD(field_name, "table_name"), STRUCT_FLD(field_length, 192),
1144 STRUCT_FLD(field_type, MYSQL_TYPE_STRING), STRUCT_FLD(value, 0),
1145 STRUCT_FLD(field_flags, 0), STRUCT_FLD(old_name, ""),
1146 STRUCT_FLD(open_method, 0)},
1147
1148 #define IDX_INDEX_NAME 2
1149 {STRUCT_FLD(field_name, "index_name"), STRUCT_FLD(field_length, 192),
1150 STRUCT_FLD(field_type, MYSQL_TYPE_STRING), STRUCT_FLD(value, 0),
1151 STRUCT_FLD(field_flags, 0), STRUCT_FLD(old_name, ""),
1152 STRUCT_FLD(open_method, 0)},
1153
1154 #define IDX_COMPRESS_OPS 3
1155 {STRUCT_FLD(field_name, "compress_ops"),
1156 STRUCT_FLD(field_length, MY_INT32_NUM_DECIMAL_DIGITS),
1157 STRUCT_FLD(field_type, MYSQL_TYPE_LONG), STRUCT_FLD(value, 0),
1158 STRUCT_FLD(field_flags, 0), STRUCT_FLD(old_name, ""),
1159 STRUCT_FLD(open_method, 0)},
1160
1161 #define IDX_COMPRESS_OPS_OK 4
1162 {STRUCT_FLD(field_name, "compress_ops_ok"),
1163 STRUCT_FLD(field_length, MY_INT32_NUM_DECIMAL_DIGITS),
1164 STRUCT_FLD(field_type, MYSQL_TYPE_LONG), STRUCT_FLD(value, 0),
1165 STRUCT_FLD(field_flags, 0), STRUCT_FLD(old_name, ""),
1166 STRUCT_FLD(open_method, 0)},
1167
1168 #define IDX_COMPRESS_TIME 5
1169 {STRUCT_FLD(field_name, "compress_time"),
1170 STRUCT_FLD(field_length, MY_INT32_NUM_DECIMAL_DIGITS),
1171 STRUCT_FLD(field_type, MYSQL_TYPE_LONG), STRUCT_FLD(value, 0),
1172 STRUCT_FLD(field_flags, 0), STRUCT_FLD(old_name, ""),
1173 STRUCT_FLD(open_method, 0)},
1174
1175 #define IDX_UNCOMPRESS_OPS 6
1176 {STRUCT_FLD(field_name, "uncompress_ops"),
1177 STRUCT_FLD(field_length, MY_INT32_NUM_DECIMAL_DIGITS),
1178 STRUCT_FLD(field_type, MYSQL_TYPE_LONG), STRUCT_FLD(value, 0),
1179 STRUCT_FLD(field_flags, 0), STRUCT_FLD(old_name, ""),
1180 STRUCT_FLD(open_method, 0)},
1181
1182 #define IDX_UNCOMPRESS_TIME 7
1183 {STRUCT_FLD(field_name, "uncompress_time"),
1184 STRUCT_FLD(field_length, MY_INT32_NUM_DECIMAL_DIGITS),
1185 STRUCT_FLD(field_type, MYSQL_TYPE_LONG), STRUCT_FLD(value, 0),
1186 STRUCT_FLD(field_flags, 0), STRUCT_FLD(old_name, ""),
1187 STRUCT_FLD(open_method, 0)},
1188
1189 END_OF_ST_FIELD_INFO};
1190
1191 /** Fill the dynamic table
1192 information_schema.innodb_cmp_per_index or
1193 information_schema.innodb_cmp_per_index_reset.
1194 @return 0 on success, 1 on failure */
1195 static int i_s_cmp_per_index_fill_low(
1196 THD *thd, /*!< in: thread */
1197 Table_ref *tables, /*!< in/out: tables to fill */
1198 Item *, /*!< in: condition (ignored) */
1199 bool reset) /*!< in: true=reset cumulated counts */
1200 {
1201 TABLE *table = tables->table;
1202 Field **fields = table->field;
1203 int status = 0;
1204
1205 DBUG_TRACE;
1206
1207 /* deny access to non-superusers */
1208 if (check_global_access(thd, PROCESS_ACL)) {
1209 return 0;
1210 }
1211
1212 /* Create a snapshot of the stats so we do not bump into lock
1213 order violations with dict_sys->mutex below. */
1214 mutex_enter(&page_zip_stat_per_index_mutex);
1215 page_zip_stat_per_index_t snap(page_zip_stat_per_index);
1216 mutex_exit(&page_zip_stat_per_index_mutex);
1217
1218 dict_sys_mutex_enter();
1219
1220 page_zip_stat_per_index_t::iterator iter;
1221 ulint i;
1222
1223 for (iter = snap.begin(), i = 0; iter != snap.end(); iter++, i++) {
1224 char name[NAME_LEN];
1225 const dict_index_t *index = dict_index_find(iter->first);
1226
1227 if (index != nullptr) {
1228 if (dict_index_is_sdi(index)) {
1229 continue;
1230 }
1231 char db_utf8mb3[dict_name::MAX_DB_UTF8MB3_LEN];
1232 char table_utf8mb3[dict_name::MAX_TABLE_UTF8MB3_LEN];
1233
1234 dict_fs2utf8(index->table_name, db_utf8mb3, sizeof(db_utf8mb3),
1235 table_utf8mb3, sizeof(table_utf8mb3));
1236
1237 field_store_string(fields[IDX_DATABASE_NAME], db_utf8mb3);
1238 field_store_string(fields[IDX_TABLE_NAME], table_utf8mb3);
1239 field_store_index_name(fields[IDX_INDEX_NAME], index->name);
1240 } else {
1241 /* index not found */
1242 snprintf(name, sizeof(name), "index_id:" IB_ID_FMT,
1243 iter->first.m_index_id);
1244 field_store_string(fields[IDX_DATABASE_NAME], "unknown");
1245 field_store_string(fields[IDX_TABLE_NAME], "unknown");
1246 field_store_string(fields[IDX_INDEX_NAME], name);
1247 }
1248
1249 fields[IDX_COMPRESS_OPS]->store(iter->second.compressed, true);
1250
1251 fields[IDX_COMPRESS_OPS_OK]->store(iter->second.compressed_ok, true);
1252
1253 fields[IDX_COMPRESS_TIME]->store(
1254 std::chrono::duration_cast<std::chrono::seconds>(
1255 iter->second.compress_time)
1256 .count(),
1257 true);
1258
1259 fields[IDX_UNCOMPRESS_OPS]->store(iter->second.decompressed, true);
1260
1261 fields[IDX_UNCOMPRESS_TIME]->store(
1262 std::chrono::duration_cast<std::chrono::seconds>(
1263 iter->second.decompress_time)
1264 .count(),
1265 true);
1266
1267 auto error = schema_table_store_record2(thd, table, false);
1268 if (error) {
1269 dict_sys_mutex_exit();
1270 if (convert_heap_table_to_ondisk(thd, table, error) != 0) {
1271 status = 1;
1272 goto err;
1273 }
1274 dict_sys_mutex_enter();
1275 }
1276
1277 /* Release and reacquire the dict mutex to allow other
1278 threads to proceed. This could eventually result in the
1279 contents of INFORMATION_SCHEMA.innodb_cmp_per_index being
1280 inconsistent, but it is an acceptable compromise. */
1281 if (i % 1000 == 0) {
1282 dict_sys_mutex_exit();
1283 std::this_thread::yield();
1284 dict_sys_mutex_enter();
1285 }
1286 }
1287
1288 dict_sys_mutex_exit();
1289 err:
1290
1291 if (reset) {
1292 page_zip_reset_stat_per_index();
1293 }
1294
1295 return status;
1296 }
1297
1298 /** Fill the dynamic table information_schema.innodb_cmp_per_index.
1299 @return 0 on success, 1 on failure */
1300 static int i_s_cmp_per_index_fill(
1301 THD *thd, /*!< in: thread */
1302 Table_ref *tables, /*!< in/out: tables to fill */
1303 Item *cond) /*!< in: condition (ignored) */
1304 {
1305 return (i_s_cmp_per_index_fill_low(thd, tables, cond, false));
1306 }
1307
1308 /** Fill the dynamic table information_schema.innodb_cmp_per_index_reset.
1309 @return 0 on success, 1 on failure */
1310 static int i_s_cmp_per_index_reset_fill(
1311 THD *thd, /*!< in: thread */
1312 Table_ref *tables, /*!< in/out: tables to fill */
1313 Item *cond) /*!< in: condition (ignored) */
1314 {
1315 return (i_s_cmp_per_index_fill_low(thd, tables, cond, true));
1316 }
1317
1318 /** Bind the dynamic table information_schema.innodb_cmp_per_index.
1319 @return 0 on success */
1320 static int i_s_cmp_per_index_init(void *p) /*!< in/out: table schema object */
1321 {
1322 DBUG_TRACE;
1323 ST_SCHEMA_TABLE *schema = (ST_SCHEMA_TABLE *)p;
1324
1325 schema->fields_info = i_s_cmp_per_index_fields_info;
1326 schema->fill_table = i_s_cmp_per_index_fill;
1327
1328 return 0;
1329 }
1330
1331 /** Bind the dynamic table information_schema.innodb_cmp_per_index_reset.
1332 @return 0 on success */
1333 static int i_s_cmp_per_index_reset_init(
1334 void *p) /*!< in/out: table schema object */
1335 {
1336 DBUG_TRACE;
1337 ST_SCHEMA_TABLE *schema = (ST_SCHEMA_TABLE *)p;
1338
1339 schema->fields_info = i_s_cmp_per_index_fields_info;
1340 schema->fill_table = i_s_cmp_per_index_reset_fill;
1341
1342 return 0;
1343 }
1344
1345 struct st_mysql_plugin i_s_innodb_cmp_per_index = {
1346 /* the plugin type (a MYSQL_XXX_PLUGIN value) */
1347 /* int */
1348 STRUCT_FLD(type, MYSQL_INFORMATION_SCHEMA_PLUGIN),
1349
1350 /* pointer to type-specific plugin descriptor */
1351 /* void* */
1352 STRUCT_FLD(info, &i_s_info),
1353
1354 /* plugin name */
1355 /* const char* */
1356 STRUCT_FLD(name, "INNODB_CMP_PER_INDEX"),
1357
1358 /* plugin author (for SHOW PLUGINS) */
1359 /* const char* */
1360 STRUCT_FLD(author, plugin_author),
1361
1362 /* general descriptive text (for SHOW PLUGINS) */
1363 /* const char* */
1364 STRUCT_FLD(descr, "Statistics for the InnoDB compression (per index)"),
1365
1366 /* the plugin license (PLUGIN_LICENSE_XXX) */
1367 /* int */
1368 STRUCT_FLD(license, PLUGIN_LICENSE_GPL),
1369
1370 /* the function to invoke when plugin is loaded */
1371 /* int (*)(void*); */
1372 STRUCT_FLD(init, i_s_cmp_per_index_init),
1373
1374 /* the function to invoke when plugin is un installed */
1375 /* int (*)(void*); */
1376 STRUCT_FLD(check_uninstall, nullptr),
1377
1378 /* the function to invoke when plugin is unloaded */
1379 /* int (*)(void*); */
1380 STRUCT_FLD(deinit, i_s_common_deinit),
1381
1382 /* plugin version (for SHOW PLUGINS) */
1383 /* unsigned int */
1384 STRUCT_FLD(version, i_s_innodb_plugin_version),
1385
1386 /* SHOW_VAR* */
1387 STRUCT_FLD(status_vars, nullptr),
1388
1389 /* SYS_VAR** */
1390 STRUCT_FLD(system_vars, nullptr),
1391
1392 /* reserved for dependency checking */
1393 /* void* */
1394 STRUCT_FLD(__reserved1, nullptr),
1395
1396 /* Plugin flags */
1397 /* unsigned long */
1398 STRUCT_FLD(flags, 0UL),
1399 };
1400
1401 struct st_mysql_plugin i_s_innodb_cmp_per_index_reset = {
1402 /* the plugin type (a MYSQL_XXX_PLUGIN value) */
1403 /* int */
1404 STRUCT_FLD(type, MYSQL_INFORMATION_SCHEMA_PLUGIN),
1405
1406 /* pointer to type-specific plugin descriptor */
1407 /* void* */
1408 STRUCT_FLD(info, &i_s_info),
1409
1410 /* plugin name */
1411 /* const char* */
1412 STRUCT_FLD(name, "INNODB_CMP_PER_INDEX_RESET"),
1413
1414 /* plugin author (for SHOW PLUGINS) */
1415 /* const char* */
1416 STRUCT_FLD(author, plugin_author),
1417
1418 /* general descriptive text (for SHOW PLUGINS) */
1419 /* const char* */
1420 STRUCT_FLD(descr,
1421 "Statistics for the InnoDB compression (per index);"
1422 " reset cumulated counts"),
1423
1424 /* the plugin license (PLUGIN_LICENSE_XXX) */
1425 /* int */
1426 STRUCT_FLD(license, PLUGIN_LICENSE_GPL),
1427
1428 /* the function to invoke when plugin is loaded */
1429 /* int (*)(void*); */
1430 STRUCT_FLD(init, i_s_cmp_per_index_reset_init),
1431
1432 /* the function to invoke when plugin is un installed */
1433 /* int (*)(void*); */
1434 STRUCT_FLD(check_uninstall, nullptr),
1435
1436 /* the function to invoke when plugin is unloaded */
1437 /* int (*)(void*); */
1438 STRUCT_FLD(deinit, i_s_common_deinit),
1439
1440 /* plugin version (for SHOW PLUGINS) */
1441 /* unsigned int */
1442 STRUCT_FLD(version, i_s_innodb_plugin_version),
1443
1444 /* SHOW_VAR* */
1445 STRUCT_FLD(status_vars, nullptr),
1446
1447 /* SYS_VAR** */
1448 STRUCT_FLD(system_vars, nullptr),
1449
1450 /* reserved for dependency checking */
1451 /* void* */
1452 STRUCT_FLD(__reserved1, nullptr),
1453
1454 /* Plugin flags */
1455 /* unsigned long */
1456 STRUCT_FLD(flags, 0UL),
1457 };
1458
1459 /* Fields of the dynamic table information_schema.innodb_cmpmem.
1460 Every time any column gets changed, added or removed, please remember
1461 to change i_s_innodb_plugin_version_postfix accordingly, so that
1462 the change can be propagated to server */
1463 static ST_FIELD_INFO i_s_cmpmem_fields_info[] = {
1464 {STRUCT_FLD(field_name, "page_size"), STRUCT_FLD(field_length, 5),
1465 STRUCT_FLD(field_type, MYSQL_TYPE_LONG), STRUCT_FLD(value, 0),
1466 STRUCT_FLD(field_flags, 0), STRUCT_FLD(old_name, "Buddy Block Size"),
1467 STRUCT_FLD(open_method, 0)},
1468
1469 {STRUCT_FLD(field_name, "buffer_pool_instance"),
1470 STRUCT_FLD(field_length, MY_INT32_NUM_DECIMAL_DIGITS),
1471 STRUCT_FLD(field_type, MYSQL_TYPE_LONG), STRUCT_FLD(value, 0),
1472 STRUCT_FLD(field_flags, 0), STRUCT_FLD(old_name, "Buffer Pool Id"),
1473 STRUCT_FLD(open_method, 0)},
1474
1475 {STRUCT_FLD(field_name, "pages_used"),
1476 STRUCT_FLD(field_length, MY_INT32_NUM_DECIMAL_DIGITS),
1477 STRUCT_FLD(field_type, MYSQL_TYPE_LONG), STRUCT_FLD(value, 0),
1478 STRUCT_FLD(field_flags, 0), STRUCT_FLD(old_name, "Currently in Use"),
1479 STRUCT_FLD(open_method, 0)},
1480
1481 {STRUCT_FLD(field_name, "pages_free"),
1482 STRUCT_FLD(field_length, MY_INT32_NUM_DECIMAL_DIGITS),
1483 STRUCT_FLD(field_type, MYSQL_TYPE_LONG), STRUCT_FLD(value, 0),
1484 STRUCT_FLD(field_flags, 0), STRUCT_FLD(old_name, "Currently Available"),
1485 STRUCT_FLD(open_method, 0)},
1486
1487 {STRUCT_FLD(field_name, "relocation_ops"),
1488 STRUCT_FLD(field_length, MY_INT64_NUM_DECIMAL_DIGITS),
1489 STRUCT_FLD(field_type, MYSQL_TYPE_LONGLONG), STRUCT_FLD(value, 0),
1490 STRUCT_FLD(field_flags, 0),
1491 STRUCT_FLD(old_name, "Total Number of Relocations"),
1492 STRUCT_FLD(open_method, 0)},
1493
1494 {STRUCT_FLD(field_name, "relocation_time"),
1495 STRUCT_FLD(field_length, MY_INT32_NUM_DECIMAL_DIGITS),
1496 STRUCT_FLD(field_type, MYSQL_TYPE_LONG), STRUCT_FLD(value, 0),
1497 STRUCT_FLD(field_flags, 0),
1498 STRUCT_FLD(old_name,
1499 "Total Duration of Relocations,"
1500 " in Seconds"),
1501 STRUCT_FLD(open_method, 0)},
1502
1503 END_OF_ST_FIELD_INFO};
1504
1505 /** Fill the dynamic table information_schema.innodb_cmpmem or
1506 innodb_cmpmem_reset.
1507 @param[in] thd thread
1508 @param[in,out] tables tables to fill
1509 @param[in] reset true=reset cumulated counts
1510 @return 0 on success, 1 on failure */
1511 static int i_s_cmpmem_fill_low(THD *thd, Table_ref *tables, bool reset) {
1512 int status = 0;
1513 TABLE *table = (TABLE *)tables->table;
1514
1515 DBUG_TRACE;
1516
1517 /* deny access to non-superusers */
1518 if (check_global_access(thd, PROCESS_ACL)) {
1519 return 0;
1520 }
1521
1522 for (ulint i = 0; i < srv_buf_pool_instances; i++) {
1523 buf_pool_t *buf_pool;
1524 ulint zip_free_len_local[BUF_BUDDY_SIZES_MAX + 1];
1525 buf_buddy_stat_t::snapshot_t buddy_stat_local[BUF_BUDDY_SIZES_MAX + 1];
1526
1527 status = 0;
1528
1529 buf_pool = buf_pool_from_array(i);
1530
1531 mutex_enter(&buf_pool->zip_free_mutex);
1532
1533 /* Save buddy stats for buffer pool in local variables. */
1534 for (uint x = 0; x <= BUF_BUDDY_SIZES; x++) {
1535 zip_free_len_local[x] =
1536 (x < BUF_BUDDY_SIZES) ? UT_LIST_GET_LEN(buf_pool->zip_free[x]) : 0;
1537
1538 os_rmb;
1539 buddy_stat_local[x] = buf_pool->buddy_stat[x].take_snapshot();
1540
1541 if (reset) {
1542 /* This is protected by buf_pool->zip_free_mutex. */
1543 buf_pool->buddy_stat[x].relocated = 0;
1544 buf_pool->buddy_stat[x].relocated_duration =
1545 std::chrono::seconds::zero();
1546 }
1547 }
1548
1549 mutex_exit(&buf_pool->zip_free_mutex);
1550
1551 for (uint x = 0; x <= BUF_BUDDY_SIZES; x++) {
1552 const buf_buddy_stat_t::snapshot_t *buddy_stat = &buddy_stat_local[x];
1553
1554 table->field[0]->store(BUF_BUDDY_LOW << x);
1555 table->field[1]->store(i, true);
1556 table->field[2]->store(buddy_stat->used, true);
1557 table->field[3]->store(zip_free_len_local[x], true);
1558 table->field[4]->store(buddy_stat->relocated, true);
1559 table->field[5]->store(std::chrono::duration_cast<std::chrono::seconds>(
1560 buddy_stat->relocated_duration)
1561 .count(),
1562 true);
1563
1564 if (schema_table_store_record(thd, table)) {
1565 status = 1;
1566 break;
1567 }
1568 }
1569
1570 if (status) {
1571 break;
1572 }
1573 }
1574
1575 return status;
1576 }
1577
1578 /** Fill the dynamic table information_schema.innodb_cmpmem.
1579 @return 0 on success, 1 on failure */
1580 static int i_s_cmpmem_fill(THD *thd, /*!< in: thread */
1581 Table_ref *tables, /*!< in/out: tables to fill */
1582 Item *) /*!< in: condition (ignored) */
1583 {
1584 return (i_s_cmpmem_fill_low(thd, tables, false));
1585 }
1586
1587 /** Fill the dynamic table information_schema.innodb_cmpmem_reset.
1588 @return 0 on success, 1 on failure */
1589 static int i_s_cmpmem_reset_fill(
1590 THD *thd, /*!< in: thread */
1591 Table_ref *tables, /*!< in/out: tables to fill */
1592 Item *) /*!< in: condition (ignored) */
1593 {
1594 return (i_s_cmpmem_fill_low(thd, tables, true));
1595 }
1596
1597 /** Bind the dynamic table information_schema.innodb_cmpmem.
1598 @return 0 on success */
1599 static int i_s_cmpmem_init(void *p) /*!< in/out: table schema object */
1600 {
1601 DBUG_TRACE;
1602 ST_SCHEMA_TABLE *schema = (ST_SCHEMA_TABLE *)p;
1603
1604 schema->fields_info = i_s_cmpmem_fields_info;
1605 schema->fill_table = i_s_cmpmem_fill;
1606
1607 return 0;
1608 }
1609
1610 /** Bind the dynamic table information_schema.innodb_cmpmem_reset.
1611 @return 0 on success */
1612 static int i_s_cmpmem_reset_init(void *p) /*!< in/out: table schema object */
1613 {
1614 DBUG_TRACE;
1615 ST_SCHEMA_TABLE *schema = (ST_SCHEMA_TABLE *)p;
1616
1617 schema->fields_info = i_s_cmpmem_fields_info;
1618 schema->fill_table = i_s_cmpmem_reset_fill;
1619
1620 return 0;
1621 }
1622
1623 struct st_mysql_plugin i_s_innodb_cmpmem = {
1624 /* the plugin type (a MYSQL_XXX_PLUGIN value) */
1625 /* int */
1626 STRUCT_FLD(type, MYSQL_INFORMATION_SCHEMA_PLUGIN),
1627
1628 /* pointer to type-specific plugin descriptor */
1629 /* void* */
1630 STRUCT_FLD(info, &i_s_info),
1631
1632 /* plugin name */
1633 /* const char* */
1634 STRUCT_FLD(name, "INNODB_CMPMEM"),
1635
1636 /* plugin author (for SHOW PLUGINS) */
1637 /* const char* */
1638 STRUCT_FLD(author, plugin_author),
1639
1640 /* general descriptive text (for SHOW PLUGINS) */
1641 /* const char* */
1642 STRUCT_FLD(descr, "Statistics for the InnoDB compressed buffer pool"),
1643
1644 /* the plugin license (PLUGIN_LICENSE_XXX) */
1645 /* int */
1646 STRUCT_FLD(license, PLUGIN_LICENSE_GPL),
1647
1648 /* the function to invoke when plugin is loaded */
1649 /* int (*)(void*); */
1650 STRUCT_FLD(init, i_s_cmpmem_init),
1651
1652 /* the function to invoke when plugin is un installed */
1653 /* int (*)(void*); */
1654 STRUCT_FLD(check_uninstall, nullptr),
1655
1656 /* the function to invoke when plugin is unloaded */
1657 /* int (*)(void*); */
1658 STRUCT_FLD(deinit, i_s_common_deinit),
1659
1660 /* plugin version (for SHOW PLUGINS) */
1661 /* unsigned int */
1662 STRUCT_FLD(version, i_s_innodb_plugin_version),
1663
1664 /* SHOW_VAR* */
1665 STRUCT_FLD(status_vars, nullptr),
1666
1667 /* SYS_VAR** */
1668 STRUCT_FLD(system_vars, nullptr),
1669
1670 /* reserved for dependency checking */
1671 /* void* */
1672 STRUCT_FLD(__reserved1, nullptr),
1673
1674 /* Plugin flags */
1675 /* unsigned long */
1676 STRUCT_FLD(flags, 0UL),
1677 };
1678
1679 struct st_mysql_plugin i_s_innodb_cmpmem_reset = {
1680 /* the plugin type (a MYSQL_XXX_PLUGIN value) */
1681 /* int */
1682 STRUCT_FLD(type, MYSQL_INFORMATION_SCHEMA_PLUGIN),
1683
1684 /* pointer to type-specific plugin descriptor */
1685 /* void* */
1686 STRUCT_FLD(info, &i_s_info),
1687
1688 /* plugin name */
1689 /* const char* */
1690 STRUCT_FLD(name, "INNODB_CMPMEM_RESET"),
1691
1692 /* plugin author (for SHOW PLUGINS) */
1693 /* const char* */
1694 STRUCT_FLD(author, plugin_author),
1695
1696 /* general descriptive text (for SHOW PLUGINS) */
1697 /* const char* */
1698 STRUCT_FLD(descr,
1699 "Statistics for the InnoDB compressed buffer pool;"
1700 " reset cumulated counts"),
1701
1702 /* the plugin license (PLUGIN_LICENSE_XXX) */
1703 /* int */
1704 STRUCT_FLD(license, PLUGIN_LICENSE_GPL),
1705
1706 /* the function to invoke when plugin is loaded */
1707 /* int (*)(void*); */
1708 STRUCT_FLD(init, i_s_cmpmem_reset_init),
1709
1710 /* the function to invoke when plugin is un installed */
1711 /* int (*)(void*); */
1712 STRUCT_FLD(check_uninstall, nullptr),
1713
1714 /* the function to invoke when plugin is unloaded */
1715 /* int (*)(void*); */
1716 STRUCT_FLD(deinit, i_s_common_deinit),
1717
1718 /* plugin version (for SHOW PLUGINS) */
1719 /* unsigned int */
1720 STRUCT_FLD(version, i_s_innodb_plugin_version),
1721
1722 /* SHOW_VAR* */
1723 STRUCT_FLD(status_vars, nullptr),
1724
1725 /* SYS_VAR** */
1726 STRUCT_FLD(system_vars, nullptr),
1727
1728 /* reserved for dependency checking */
1729 /* void* */
1730 STRUCT_FLD(__reserved1, nullptr),
1731
1732 /* Plugin flags */
1733 /* unsigned long */
1734 STRUCT_FLD(flags, 0UL),
1735 };
1736
1737 /* Fields of the dynamic table INFORMATION_SCHEMA.innodb_metrics
1738 Every time any column gets changed, added or removed, please remember
1739 to change i_s_innodb_plugin_version_postfix accordingly, so that
1740 the change can be propagated to server */
1741 static ST_FIELD_INFO innodb_metrics_fields_info[] = {
1742 #define METRIC_NAME 0
1743 {STRUCT_FLD(field_name, "NAME"), STRUCT_FLD(field_length, NAME_LEN + 1),
1744 STRUCT_FLD(field_type, MYSQL_TYPE_STRING), STRUCT_FLD(value, 0),
1745 STRUCT_FLD(field_flags, 0), STRUCT_FLD(old_name, ""),
1746 STRUCT_FLD(open_method, 0)},
1747
1748 #define METRIC_SUBSYS 1
1749 {STRUCT_FLD(field_name, "SUBSYSTEM"),
1750 STRUCT_FLD(field_length, NAME_LEN + 1),
1751 STRUCT_FLD(field_type, MYSQL_TYPE_STRING), STRUCT_FLD(value, 0),
1752 STRUCT_FLD(field_flags, 0), STRUCT_FLD(old_name, ""),
1753 STRUCT_FLD(open_method, 0)},
1754
1755 #define METRIC_VALUE_START 2
1756 {STRUCT_FLD(field_name, "COUNT"),
1757 STRUCT_FLD(field_length, MY_INT64_NUM_DECIMAL_DIGITS),
1758 STRUCT_FLD(field_type, MYSQL_TYPE_LONGLONG), STRUCT_FLD(value, 0),
1759 STRUCT_FLD(field_flags, 0), STRUCT_FLD(old_name, ""),
1760 STRUCT_FLD(open_method, 0)},
1761
1762 #define METRIC_MAX_VALUE_START 3
1763 {STRUCT_FLD(field_name, "MAX_COUNT"),
1764 STRUCT_FLD(field_length, MY_INT64_NUM_DECIMAL_DIGITS),
1765 STRUCT_FLD(field_type, MYSQL_TYPE_LONGLONG), STRUCT_FLD(value, 0),
1766 STRUCT_FLD(field_flags, MY_I_S_MAYBE_NULL), STRUCT_FLD(old_name, ""),
1767 STRUCT_FLD(open_method, 0)},
1768
1769 #define METRIC_MIN_VALUE_START 4
1770 {STRUCT_FLD(field_name, "MIN_COUNT"),
1771 STRUCT_FLD(field_length, MY_INT64_NUM_DECIMAL_DIGITS),
1772 STRUCT_FLD(field_type, MYSQL_TYPE_LONGLONG), STRUCT_FLD(value, 0),
1773 STRUCT_FLD(field_flags, MY_I_S_MAYBE_NULL), STRUCT_FLD(old_name, ""),
1774 STRUCT_FLD(open_method, 0)},
1775
1776 #define METRIC_AVG_VALUE_START 5
1777 {STRUCT_FLD(field_name, "AVG_COUNT"),
1778 STRUCT_FLD(field_length, MAX_FLOAT_STR_LENGTH),
1779 STRUCT_FLD(field_type, MYSQL_TYPE_FLOAT), STRUCT_FLD(value, 0),
1780 STRUCT_FLD(field_flags, MY_I_S_MAYBE_NULL), STRUCT_FLD(old_name, ""),
1781 STRUCT_FLD(open_method, 0)},
1782
1783 #define METRIC_VALUE_RESET 6
1784 {STRUCT_FLD(field_name, "COUNT_RESET"),
1785 STRUCT_FLD(field_length, MY_INT64_NUM_DECIMAL_DIGITS),
1786 STRUCT_FLD(field_type, MYSQL_TYPE_LONGLONG), STRUCT_FLD(value, 0),
1787 STRUCT_FLD(field_flags, 0), STRUCT_FLD(old_name, ""),
1788 STRUCT_FLD(open_method, 0)},
1789
1790 #define METRIC_MAX_VALUE_RESET 7
1791 {STRUCT_FLD(field_name, "MAX_COUNT_RESET"),
1792 STRUCT_FLD(field_length, MY_INT64_NUM_DECIMAL_DIGITS),
1793 STRUCT_FLD(field_type, MYSQL_TYPE_LONGLONG), STRUCT_FLD(value, 0),
1794 STRUCT_FLD(field_flags, MY_I_S_MAYBE_NULL), STRUCT_FLD(old_name, ""),
1795 STRUCT_FLD(open_method, 0)},
1796
1797 #define METRIC_MIN_VALUE_RESET 8
1798 {STRUCT_FLD(field_name, "MIN_COUNT_RESET"),
1799 STRUCT_FLD(field_length, MY_INT64_NUM_DECIMAL_DIGITS),
1800 STRUCT_FLD(field_type, MYSQL_TYPE_LONGLONG), STRUCT_FLD(value, 0),
1801 STRUCT_FLD(field_flags, MY_I_S_MAYBE_NULL), STRUCT_FLD(old_name, ""),
1802 STRUCT_FLD(open_method, 0)},
1803
1804 #define METRIC_AVG_VALUE_RESET 9
1805 {STRUCT_FLD(field_name, "AVG_COUNT_RESET"),
1806 STRUCT_FLD(field_length, MAX_FLOAT_STR_LENGTH),
1807 STRUCT_FLD(field_type, MYSQL_TYPE_FLOAT), STRUCT_FLD(value, 0),
1808 STRUCT_FLD(field_flags, MY_I_S_MAYBE_NULL), STRUCT_FLD(old_name, ""),
1809 STRUCT_FLD(open_method, 0)},
1810
1811 #define METRIC_START_TIME 10
1812 {STRUCT_FLD(field_name, "TIME_ENABLED"), STRUCT_FLD(field_length, 0),
1813 STRUCT_FLD(field_type, MYSQL_TYPE_DATETIME), STRUCT_FLD(value, 0),
1814 STRUCT_FLD(field_flags, MY_I_S_MAYBE_NULL), STRUCT_FLD(old_name, ""),
1815 STRUCT_FLD(open_method, 0)},
1816
1817 #define METRIC_STOP_TIME 11
1818 {STRUCT_FLD(field_name, "TIME_DISABLED"), STRUCT_FLD(field_length, 0),
1819 STRUCT_FLD(field_type, MYSQL_TYPE_DATETIME), STRUCT_FLD(value, 0),
1820 STRUCT_FLD(field_flags, MY_I_S_MAYBE_NULL), STRUCT_FLD(old_name, ""),
1821 STRUCT_FLD(open_method, 0)},
1822
1823 #define METRIC_TIME_ELAPSED 12
1824 {STRUCT_FLD(field_name, "TIME_ELAPSED"),
1825 STRUCT_FLD(field_length, MY_INT64_NUM_DECIMAL_DIGITS),
1826 STRUCT_FLD(field_type, MYSQL_TYPE_LONGLONG), STRUCT_FLD(value, 0),
1827 STRUCT_FLD(field_flags, MY_I_S_MAYBE_NULL), STRUCT_FLD(old_name, ""),
1828 STRUCT_FLD(open_method, 0)},
1829
1830 #define METRIC_RESET_TIME 13
1831 {STRUCT_FLD(field_name, "TIME_RESET"), STRUCT_FLD(field_length, 0),
1832 STRUCT_FLD(field_type, MYSQL_TYPE_DATETIME), STRUCT_FLD(value, 0),
1833 STRUCT_FLD(field_flags, MY_I_S_MAYBE_NULL), STRUCT_FLD(old_name, ""),
1834 STRUCT_FLD(open_method, 0)},
1835
1836 #define METRIC_STATUS 14
1837 {STRUCT_FLD(field_name, "STATUS"), STRUCT_FLD(field_length, NAME_LEN + 1),
1838 STRUCT_FLD(field_type, MYSQL_TYPE_STRING), STRUCT_FLD(value, 0),
1839 STRUCT_FLD(field_flags, 0), STRUCT_FLD(old_name, ""),
1840 STRUCT_FLD(open_method, 0)},
1841
1842 #define METRIC_TYPE 15
1843 {STRUCT_FLD(field_name, "TYPE"), STRUCT_FLD(field_length, NAME_LEN + 1),
1844 STRUCT_FLD(field_type, MYSQL_TYPE_STRING), STRUCT_FLD(value, 0),
1845 STRUCT_FLD(field_flags, 0), STRUCT_FLD(old_name, ""),
1846 STRUCT_FLD(open_method, 0)},
1847
1848 #define METRIC_DESC 16
1849 {STRUCT_FLD(field_name, "COMMENT"), STRUCT_FLD(field_length, NAME_LEN + 1),
1850 STRUCT_FLD(field_type, MYSQL_TYPE_STRING), STRUCT_FLD(value, 0),
1851 STRUCT_FLD(field_flags, 0), STRUCT_FLD(old_name, ""),
1852 STRUCT_FLD(open_method, 0)},
1853
1854 END_OF_ST_FIELD_INFO};
1855
1856 /** Fill the information schema metrics table.
1857 @return 0 on success */
1858 static int i_s_metrics_fill(
1859 THD *thd, /*!< in: thread */
1860 TABLE *table_to_fill) /*!< in/out: fill this table */
1861 {
1862 int count;
1863 Field **fields;
1864 double time_diff = 0;
1865 monitor_info_t *monitor_info;
1866 mon_type_t min_val;
1867 mon_type_t max_val;
1868
1869 DBUG_TRACE;
1870 fields = table_to_fill->field;
1871
1872 for (count = 0; count < NUM_MONITOR; count++) {
1873 monitor_info = srv_mon_get_info((monitor_id_t)count);
1874
1875 /* A good place to sanity check the Monitor ID */
1876 ut_a(count == monitor_info->monitor_id);
1877
1878 /* If the item refers to a Module, nothing to fill,
1879 continue. */
1880 if ((monitor_info->monitor_type & MONITOR_MODULE) ||
1881 (monitor_info->monitor_type & MONITOR_HIDDEN)) {
1882 continue;
1883 }
1884
1885 /* If this is an existing "status variable", and
1886 its corresponding counter is still on, we need
1887 to calculate the result from its corresponding
1888 counter. */
1889 if (monitor_info->monitor_type & MONITOR_EXISTING && MONITOR_IS_ON(count)) {
1890 srv_mon_process_existing_counter((monitor_id_t)count, MONITOR_GET_VALUE);
1891 }
1892
1893 /* Fill in counter's basic information */
1894 ut_a(strlen(monitor_info->monitor_name) <= NAME_LEN);
1895
1896 OK(field_store_string(fields[METRIC_NAME], monitor_info->monitor_name));
1897
1898 ut_a(strlen(monitor_info->monitor_module) <= NAME_LEN);
1899
1900 OK(field_store_string(fields[METRIC_SUBSYS], monitor_info->monitor_module));
1901
1902 ut_a(strlen(monitor_info->monitor_desc) <= NAME_LEN);
1903
1904 OK(field_store_string(fields[METRIC_DESC], monitor_info->monitor_desc));
1905
1906 /* Fill in counter values */
1907 OK(fields[METRIC_VALUE_RESET]->store(MONITOR_VALUE(count), false));
1908
1909 OK(fields[METRIC_VALUE_START]->store(MONITOR_VALUE_SINCE_START(count),
1910 false));
1911
1912 /* If the max value is MAX_RESERVED, counter max
1913 value has not been updated. Set the column value
1914 to NULL. */
1915 if (MONITOR_MAX_VALUE(count) == MAX_RESERVED ||
1916 MONITOR_MAX_MIN_NOT_INIT(count)) {
1917 fields[METRIC_MAX_VALUE_RESET]->set_null();
1918 } else {
1919 OK(fields[METRIC_MAX_VALUE_RESET]->store(MONITOR_MAX_VALUE(count),
1920 false));
1921 fields[METRIC_MAX_VALUE_RESET]->set_notnull();
1922 }
1923
1924 /* If the min value is MAX_RESERVED, counter min
1925 value has not been updated. Set the column value
1926 to NULL. */
1927 if (MONITOR_MIN_VALUE(count) == MIN_RESERVED ||
1928 MONITOR_MAX_MIN_NOT_INIT(count)) {
1929 fields[METRIC_MIN_VALUE_RESET]->set_null();
1930 } else {
1931 OK(fields[METRIC_MIN_VALUE_RESET]->store(MONITOR_MIN_VALUE(count),
1932 false));
1933 fields[METRIC_MIN_VALUE_RESET]->set_notnull();
1934 }
1935
1936 /* Calculate the max value since counter started */
1937 max_val = srv_mon_calc_max_since_start((monitor_id_t)count);
1938
1939 if (max_val == MAX_RESERVED || MONITOR_MAX_MIN_NOT_INIT(count)) {
1940 fields[METRIC_MAX_VALUE_START]->set_null();
1941 } else {
1942 OK(fields[METRIC_MAX_VALUE_START]->store(max_val, false));
1943 fields[METRIC_MAX_VALUE_START]->set_notnull();
1944 }
1945
1946 /* Calculate the min value since counter started */
1947 min_val = srv_mon_calc_min_since_start((monitor_id_t)count);
1948
1949 if (min_val == MIN_RESERVED || MONITOR_MAX_MIN_NOT_INIT(count)) {
1950 fields[METRIC_MIN_VALUE_START]->set_null();
1951 } else {
1952 OK(fields[METRIC_MIN_VALUE_START]->store(min_val, false));
1953
1954 fields[METRIC_MIN_VALUE_START]->set_notnull();
1955 }
1956
1957 /* If monitor has been enabled (no matter it is disabled
1958 or not now), fill METRIC_START_TIME and METRIC_TIME_ELAPSED
1959 field */
1960 if (MONITOR_FIELD(count, mon_start_time) !=
1961 std::chrono::system_clock::time_point{}) {
1962 OK(field_store_time_t(fields[METRIC_START_TIME],
1963 std::chrono::system_clock::to_time_t(
1964 MONITOR_FIELD(count, mon_start_time))));
1965 fields[METRIC_START_TIME]->set_notnull();
1966
1967 /* If monitor is enabled, the TIME_ELAPSED is the
1968 time difference between current and time when monitor
1969 is enabled. Otherwise, it is the time difference
1970 between time when monitor is enabled and time
1971 when it is disabled */
1972 if (MONITOR_IS_ON(count)) {
1973 time_diff = std::chrono::duration_cast<std::chrono::duration<double>>(
1974 std::chrono::system_clock::now() -
1975 MONITOR_FIELD(count, mon_start_time))
1976 .count();
1977 } else {
1978 time_diff = std::chrono::duration_cast<std::chrono::duration<double>>(
1979 MONITOR_FIELD(count, mon_stop_time) -
1980 MONITOR_FIELD(count, mon_start_time))
1981 .count();
1982 }
1983
1984 OK(fields[METRIC_TIME_ELAPSED]->store(time_diff));
1985 fields[METRIC_TIME_ELAPSED]->set_notnull();
1986 } else {
1987 fields[METRIC_START_TIME]->set_null();
1988 fields[METRIC_TIME_ELAPSED]->set_null();
1989 time_diff = 0;
1990 }
1991
1992 /* Unless MONITOR_NO_AVERAGE is marked, we will need
1993 to calculate the average value. If this is a monitor set
1994 owner marked by MONITOR_SET_OWNER, divide
1995 the value by another counter (number of calls) designated
1996 by monitor_info->monitor_related_id.
1997 Otherwise average the counter value by the time between the
1998 time that the counter is enabled and time it is disabled
1999 or time it is sampled. */
2000 if (!(monitor_info->monitor_type & MONITOR_NO_AVERAGE) &&
2001 (monitor_info->monitor_type & MONITOR_SET_OWNER) &&
2002 monitor_info->monitor_related_id) {
2003 mon_type_t value_start =
2004 MONITOR_VALUE_SINCE_START(monitor_info->monitor_related_id);
2005
2006 if (value_start) {
2007 OK(fields[METRIC_AVG_VALUE_START]->store(
2008 MONITOR_VALUE_SINCE_START(count) / value_start, false));
2009
2010 fields[METRIC_AVG_VALUE_START]->set_notnull();
2011 } else {
2012 fields[METRIC_AVG_VALUE_START]->set_null();
2013 }
2014
2015 if (MONITOR_VALUE(monitor_info->monitor_related_id)) {
2016 OK(fields[METRIC_AVG_VALUE_RESET]->store(
2017 MONITOR_VALUE(count) /
2018 MONITOR_VALUE(monitor_info->monitor_related_id),
2019 false));
2020 fields[METRIC_AVG_VALUE_RESET]->set_notnull();
2021 } else {
2022 fields[METRIC_AVG_VALUE_RESET]->set_null();
2023 }
2024 } else if (!(monitor_info->monitor_type & MONITOR_NO_AVERAGE) &&
2025 !(monitor_info->monitor_type & MONITOR_DISPLAY_CURRENT)) {
2026 if (time_diff) {
2027 OK(fields[METRIC_AVG_VALUE_START]->store(
2028 (double)MONITOR_VALUE_SINCE_START(count) / time_diff));
2029 fields[METRIC_AVG_VALUE_START]->set_notnull();
2030 } else {
2031 fields[METRIC_AVG_VALUE_START]->set_null();
2032 }
2033
2034 if (MONITOR_FIELD(count, mon_reset_time) !=
2035 std::chrono::system_clock::time_point{}) {
2036 /* calculate the time difference since last
2037 reset */
2038 if (MONITOR_IS_ON(count)) {
2039 time_diff = std::chrono::duration_cast<std::chrono::duration<double>>(
2040 std::chrono::system_clock::now() -
2041 MONITOR_FIELD(count, mon_reset_time))
2042 .count();
2043 } else {
2044 time_diff = std::chrono::duration_cast<std::chrono::duration<double>>(
2045 MONITOR_FIELD(count, mon_stop_time) -
2046 MONITOR_FIELD(count, mon_reset_time))
2047 .count();
2048 }
2049 } else {
2050 time_diff = 0;
2051 }
2052
2053 if (time_diff) {
2054 OK(fields[METRIC_AVG_VALUE_RESET]->store(
2055 static_cast<double>(MONITOR_VALUE(count) / time_diff)));
2056 fields[METRIC_AVG_VALUE_RESET]->set_notnull();
2057 } else {
2058 fields[METRIC_AVG_VALUE_RESET]->set_null();
2059 }
2060 } else {
2061 fields[METRIC_AVG_VALUE_START]->set_null();
2062 fields[METRIC_AVG_VALUE_RESET]->set_null();
2063 }
2064
2065 if (MONITOR_IS_ON(count)) {
2066 /* If monitor is on, the stop time will set to NULL */
2067 fields[METRIC_STOP_TIME]->set_null();
2068
2069 /* Display latest Monitor Reset Time only if Monitor
2070 counter is on. */
2071 if (MONITOR_FIELD(count, mon_reset_time) !=
2072 std::chrono::system_clock::time_point{}) {
2073 OK(field_store_time_t(fields[METRIC_RESET_TIME],
2074 std::chrono::system_clock::to_time_t(
2075 MONITOR_FIELD(count, mon_reset_time))));
2076 fields[METRIC_RESET_TIME]->set_notnull();
2077 } else {
2078 fields[METRIC_RESET_TIME]->set_null();
2079 }
2080
2081 /* Display the monitor status as "enabled" */
2082 OK(field_store_string(fields[METRIC_STATUS], "enabled"));
2083 } else {
2084 if (MONITOR_FIELD(count, mon_stop_time) !=
2085 std::chrono::system_clock::time_point{}) {
2086 OK(field_store_time_t(fields[METRIC_STOP_TIME],
2087 std::chrono::system_clock::to_time_t(
2088 MONITOR_FIELD(count, mon_stop_time))));
2089 fields[METRIC_STOP_TIME]->set_notnull();
2090 } else {
2091 fields[METRIC_STOP_TIME]->set_null();
2092 }
2093
2094 fields[METRIC_RESET_TIME]->set_null();
2095
2096 OK(field_store_string(fields[METRIC_STATUS], "disabled"));
2097 }
2098
2099 if (monitor_info->monitor_type & MONITOR_DISPLAY_CURRENT) {
2100 OK(field_store_string(fields[METRIC_TYPE], "value"));
2101 } else if (monitor_info->monitor_type & MONITOR_EXISTING) {
2102 OK(field_store_string(fields[METRIC_TYPE], "status_counter"));
2103 } else if (monitor_info->monitor_type & MONITOR_SET_OWNER) {
2104 OK(field_store_string(fields[METRIC_TYPE], "set_owner"));
2105 } else if (monitor_info->monitor_type & MONITOR_SET_MEMBER) {
2106 OK(field_store_string(fields[METRIC_TYPE], "set_member"));
2107 } else {
2108 OK(field_store_string(fields[METRIC_TYPE], "counter"));
2109 }
2110
2111 OK(schema_table_store_record(thd, table_to_fill));
2112 }
2113
2114 return 0;
2115 }
2116
2117 /** Function to fill information schema metrics tables.
2118 @return 0 on success */
2119 static int i_s_metrics_fill_table(
2120 THD *thd, /*!< in: thread */
2121 Table_ref *tables, /*!< in/out: tables to fill */
2122 Item *) /*!< in: condition (not used) */
2123 {
2124 DBUG_TRACE;
2125
2126 /* deny access to non-superusers */
2127 if (check_global_access(thd, PROCESS_ACL)) {
2128 return 0;
2129 }
2130
2131 i_s_metrics_fill(thd, tables->table);
2132
2133 return 0;
2134 }
2135 /** Bind the dynamic table INFORMATION_SCHEMA.innodb_metrics
2136 @return 0 on success */
2137 static int innodb_metrics_init(void *p) /*!< in/out: table schema object */
2138 {
2139 ST_SCHEMA_TABLE *schema;
2140
2141 DBUG_TRACE;
2142
2143 schema = (ST_SCHEMA_TABLE *)p;
2144
2145 schema->fields_info = innodb_metrics_fields_info;
2146 schema->fill_table = i_s_metrics_fill_table;
2147
2148 return 0;
2149 }
2150
2151 struct st_mysql_plugin i_s_innodb_metrics = {
2152 /* the plugin type (a MYSQL_XXX_PLUGIN value) */
2153 /* int */
2154 STRUCT_FLD(type, MYSQL_INFORMATION_SCHEMA_PLUGIN),
2155
2156 /* pointer to type-specific plugin descriptor */
2157 /* void* */
2158 STRUCT_FLD(info, &i_s_info),
2159
2160 /* plugin name */
2161 /* const char* */
2162 STRUCT_FLD(name, "INNODB_METRICS"),
2163
2164 /* plugin author (for SHOW PLUGINS) */
2165 /* const char* */
2166 STRUCT_FLD(author, plugin_author),
2167
2168 /* general descriptive text (for SHOW PLUGINS) */
2169 /* const char* */
2170 STRUCT_FLD(descr, "InnoDB Metrics Info"),
2171
2172 /* the plugin license (PLUGIN_LICENSE_XXX) */
2173 /* int */
2174 STRUCT_FLD(license, PLUGIN_LICENSE_GPL),
2175
2176 /* the function to invoke when plugin is loaded */
2177 /* int (*)(void*); */
2178 STRUCT_FLD(init, innodb_metrics_init),
2179
2180 /* the function to invoke when plugin is un installed */
2181 /* int (*)(void*); */
2182 STRUCT_FLD(check_uninstall, nullptr),
2183
2184 /* the function to invoke when plugin is unloaded */
2185 /* int (*)(void*); */
2186 STRUCT_FLD(deinit, i_s_common_deinit),
2187
2188 /* plugin version (for SHOW PLUGINS) */
2189 /* unsigned int */
2190 STRUCT_FLD(version, i_s_innodb_plugin_version),
2191
2192 /* SHOW_VAR* */
2193 STRUCT_FLD(status_vars, nullptr),
2194
2195 /* SYS_VAR** */
2196 STRUCT_FLD(system_vars, nullptr),
2197
2198 /* reserved for dependency checking */
2199 /* void* */
2200 STRUCT_FLD(__reserved1, nullptr),
2201
2202 /* Plugin flags */
2203 /* unsigned long */
2204 STRUCT_FLD(flags, 0UL),
2205 };
2206 /* Fields of the dynamic table INFORMATION_SCHEMA.innodb_ft_default_stopword
2207 Every time any column gets changed, added or removed, please remember
2208 to change i_s_innodb_plugin_version_postfix accordingly, so that
2209 the change can be propagated to server */
2210 static ST_FIELD_INFO i_s_stopword_fields_info[] = {
2211 #define STOPWORD_VALUE 0
2212 {STRUCT_FLD(field_name, "value"), STRUCT_FLD(field_length, 18),
2213 STRUCT_FLD(field_type, MYSQL_TYPE_STRING), STRUCT_FLD(value, 0),
2214 STRUCT_FLD(field_flags, 0), STRUCT_FLD(old_name, ""),
2215 STRUCT_FLD(open_method, 0)},
2216
2217 END_OF_ST_FIELD_INFO};
2218
2219 /** Fill the dynamic table information_schema.innodb_ft_default_stopword.
2220 @return 0 on success, 1 on failure */
2221 static int i_s_stopword_fill(THD *thd, /*!< in: thread */
2222 Table_ref *tables, /*!< in/out: tables to fill */
2223 Item *) /*!< in: condition (not used) */
2224 {
2225 Field **fields;
2226 ulint i = 0;
2227 TABLE *table = (TABLE *)tables->table;
2228
2229 DBUG_TRACE;
2230
2231 fields = table->field;
2232
2233 /* Fill with server default stopword list in array
2234 fts_default_stopword */
2235 while (fts_default_stopword[i]) {
2236 OK(field_store_string(fields[STOPWORD_VALUE], fts_default_stopword[i]));
2237
2238 OK(schema_table_store_record(thd, table));
2239 i++;
2240 }
2241
2242 return 0;
2243 }
2244
2245 /** Bind the dynamic table information_schema.innodb_ft_default_stopword.
2246 @return 0 on success */
2247 static int i_s_stopword_init(void *p) /*!< in/out: table schema object */
2248 {
2249 DBUG_TRACE;
2250 ST_SCHEMA_TABLE *schema = (ST_SCHEMA_TABLE *)p;
2251
2252 schema->fields_info = i_s_stopword_fields_info;
2253 schema->fill_table = i_s_stopword_fill;
2254
2255 return 0;
2256 }
2257
2258 struct st_mysql_plugin i_s_innodb_ft_default_stopword = {
2259 /* the plugin type (a MYSQL_XXX_PLUGIN value) */
2260 /* int */
2261 STRUCT_FLD(type, MYSQL_INFORMATION_SCHEMA_PLUGIN),
2262
2263 /* pointer to type-specific plugin descriptor */
2264 /* void* */
2265 STRUCT_FLD(info, &i_s_info),
2266
2267 /* plugin name */
2268 /* const char* */
2269 STRUCT_FLD(name, "INNODB_FT_DEFAULT_STOPWORD"),
2270
2271 /* plugin author (for SHOW PLUGINS) */
2272 /* const char* */
2273 STRUCT_FLD(author, plugin_author),
2274
2275 /* general descriptive text (for SHOW PLUGINS) */
2276 /* const char* */
2277 STRUCT_FLD(descr, "Default stopword list for InnDB Full Text Search"),
2278
2279 /* the plugin license (PLUGIN_LICENSE_XXX) */
2280 /* int */
2281 STRUCT_FLD(license, PLUGIN_LICENSE_GPL),
2282
2283 /* the function to invoke when plugin is loaded */
2284 /* int (*)(void*); */
2285 STRUCT_FLD(init, i_s_stopword_init),
2286
2287 /* the function to invoke when plugin is un installed */
2288 /* int (*)(void*); */
2289 STRUCT_FLD(check_uninstall, nullptr),
2290
2291 /* the function to invoke when plugin is unloaded */
2292 /* int (*)(void*); */
2293 STRUCT_FLD(deinit, i_s_common_deinit),
2294
2295 /* plugin version (for SHOW PLUGINS) */
2296 /* unsigned int */
2297 STRUCT_FLD(version, i_s_innodb_plugin_version),
2298
2299 /* SHOW_VAR* */
2300 STRUCT_FLD(status_vars, nullptr),
2301
2302 /* SYS_VAR** */
2303 STRUCT_FLD(system_vars, nullptr),
2304
2305 /* reserved for dependency checking */
2306 /* void* */
2307 STRUCT_FLD(__reserved1, nullptr),
2308
2309 /* Plugin flags */
2310 /* unsigned long */
2311 STRUCT_FLD(flags, 0UL),
2312 };
2313
2314 /* Fields of the dynamic table INFORMATION_SCHEMA.INNODB_FT_DELETED
2315 INFORMATION_SCHEMA.INNODB_FT_BEING_DELETED
2316 Every time any column gets changed, added or removed, please remember
2317 to change i_s_innodb_plugin_version_postfix accordingly, so that
2318 the change can be propagated to server */
2319 static ST_FIELD_INFO i_s_fts_doc_fields_info[] = {
2320 #define I_S_FTS_DOC_ID 0
2321 {STRUCT_FLD(field_name, "DOC_ID"),
2322 STRUCT_FLD(field_length, MY_INT64_NUM_DECIMAL_DIGITS),
2323 STRUCT_FLD(field_type, MYSQL_TYPE_LONGLONG), STRUCT_FLD(value, 0),
2324 STRUCT_FLD(field_flags, MY_I_S_UNSIGNED), STRUCT_FLD(old_name, ""),
2325 STRUCT_FLD(open_method, 0)},
2326
2327 END_OF_ST_FIELD_INFO};
2328
2329 /** Fill the dynamic table INFORMATION_SCHEMA.INNODB_FT_DELETED or
2330 INFORMATION_SCHEMA.INNODB_FT_BEING_DELETED
2331 @return 0 on success, 1 on failure */
2332 static int i_s_fts_deleted_generic_fill(
2333 THD *thd, /*!< in: thread */
2334 Table_ref *tables, /*!< in/out: tables to fill */
2335 bool being_deleted) /*!< in: BEING_DELTED table */
2336 {
2337 Field **fields;
2338 TABLE *table = (TABLE *)tables->table;
2339 trx_t *trx;
2340 fts_table_t fts_table;
2341 fts_doc_ids_t *deleted;
2342 dict_table_t *user_table;
2343 MDL_ticket *mdl = nullptr;
2344 char local_name[MAX_FULL_NAME_LEN];
2345
2346 DBUG_TRACE;
2347
2348 /* deny access to non-superusers */
2349 if (check_global_access(thd, PROCESS_ACL)) {
2350 return 0;
2351 }
2352
2353 mysql_mutex_lock(&LOCK_global_system_variables);
2354
2355 if (!fts_internal_tbl_name) {
2356 mysql_mutex_unlock(&LOCK_global_system_variables);
2357 return 0;
2358 }
2359
2360 ut_strcpy(local_name, fts_internal_tbl_name);
2361
2362 mysql_mutex_unlock(&LOCK_global_system_variables);
2363
2364 /* Prevent DDL to drop fts aux tables. */
2365 rw_lock_s_lock(dict_operation_lock, UT_LOCATION_HERE);
2366
2367 user_table =
2368 dd_table_open_on_name(thd, &mdl, local_name, false, DICT_ERR_IGNORE_NONE);
2369
2370 if (!user_table) {
2371 rw_lock_s_unlock(dict_operation_lock);
2372
2373 return 0;
2374 } else if (!dict_table_has_fts_index(user_table)) {
2375 dd_table_close(user_table, thd, &mdl, false);
2376
2377 rw_lock_s_unlock(dict_operation_lock);
2378
2379 return 0;
2380 }
2381
2382 deleted = fts_doc_ids_create();
2383
2384 trx = trx_allocate_for_background();
2385 trx->op_info = "Select for FTS DELETE TABLE";
2386
2387 FTS_INIT_FTS_TABLE(
2388 &fts_table,
2389 (being_deleted) ? FTS_SUFFIX_BEING_DELETED : FTS_SUFFIX_DELETED,
2390 FTS_COMMON_TABLE, user_table);
2391
2392 fts_table_fetch_doc_ids(trx, &fts_table, deleted);
2393
2394 fields = table->field;
2395
2396 for (ulint j = 0; j < ib_vector_size(deleted->doc_ids); ++j) {
2397 doc_id_t doc_id;
2398
2399 doc_id = *(doc_id_t *)ib_vector_get_const(deleted->doc_ids, j);
2400
2401 OK(fields[I_S_FTS_DOC_ID]->store(doc_id, true));
2402
2403 OK(schema_table_store_record(thd, table));
2404 }
2405
2406 trx_free_for_background(trx);
2407
2408 fts_doc_ids_free(deleted);
2409
2410 dd_table_close(user_table, thd, &mdl, false);
2411
2412 rw_lock_s_unlock(dict_operation_lock);
2413
2414 return 0;
2415 }
2416
2417 /** Fill the dynamic table INFORMATION_SCHEMA.INNODB_FT_DELETED
2418 @return 0 on success, 1 on failure */
2419 static int i_s_fts_deleted_fill(
2420 THD *thd, /*!< in: thread */
2421 Table_ref *tables, /*!< in/out: tables to fill */
2422 Item *) /*!< in: condition (ignored) */
2423 {
2424 DBUG_TRACE;
2425
2426 return i_s_fts_deleted_generic_fill(thd, tables, false);
2427 }
2428
2429 /** Bind the dynamic table INFORMATION_SCHEMA.INNODB_FT_DELETED
2430 @return 0 on success */
2431 static int i_s_fts_deleted_init(void *p) /*!< in/out: table schema object */
2432 {
2433 DBUG_TRACE;
2434 ST_SCHEMA_TABLE *schema = (ST_SCHEMA_TABLE *)p;
2435
2436 schema->fields_info = i_s_fts_doc_fields_info;
2437 schema->fill_table = i_s_fts_deleted_fill;
2438
2439 return 0;
2440 }
2441
2442 struct st_mysql_plugin i_s_innodb_ft_deleted = {
2443 /* the plugin type (a MYSQL_XXX_PLUGIN value) */
2444 /* int */
2445 STRUCT_FLD(type, MYSQL_INFORMATION_SCHEMA_PLUGIN),
2446
2447 /* pointer to type-specific plugin descriptor */
2448 /* void* */
2449 STRUCT_FLD(info, &i_s_info),
2450
2451 /* plugin name */
2452 /* const char* */
2453 STRUCT_FLD(name, "INNODB_FT_DELETED"),
2454
2455 /* plugin author (for SHOW PLUGINS) */
2456 /* const char* */
2457 STRUCT_FLD(author, plugin_author),
2458
2459 /* general descriptive text (for SHOW PLUGINS) */
2460 /* const char* */
2461 STRUCT_FLD(descr, "INNODB AUXILIARY FTS DELETED TABLE"),
2462
2463 /* the plugin license (PLUGIN_LICENSE_XXX) */
2464 /* int */
2465 STRUCT_FLD(license, PLUGIN_LICENSE_GPL),
2466
2467 /* the function to invoke when plugin is loaded */
2468 /* int (*)(void*); */
2469 STRUCT_FLD(init, i_s_fts_deleted_init),
2470
2471 /* the function to invoke when plugin is un installed */
2472 /* int (*)(void*); */
2473 STRUCT_FLD(check_uninstall, nullptr),
2474
2475 /* the function to invoke when plugin is unloaded */
2476 /* int (*)(void*); */
2477 STRUCT_FLD(deinit, i_s_common_deinit),
2478
2479 /* plugin version (for SHOW PLUGINS) */
2480 /* unsigned int */
2481 STRUCT_FLD(version, i_s_innodb_plugin_version),
2482
2483 /* SHOW_VAR* */
2484 STRUCT_FLD(status_vars, nullptr),
2485
2486 /* SYS_VAR** */
2487 STRUCT_FLD(system_vars, nullptr),
2488
2489 /* reserved for dependency checking */
2490 /* void* */
2491 STRUCT_FLD(__reserved1, nullptr),
2492
2493 /* Plugin flags */
2494 /* unsigned long */
2495 STRUCT_FLD(flags, 0UL),
2496 };
2497
2498 /** Fill the dynamic table INFORMATION_SCHEMA.INNODB_FT_BEING_DELETED
2499 @return 0 on success, 1 on failure */
2500 static int i_s_fts_being_deleted_fill(
2501 THD *thd, /*!< in: thread */
2502 Table_ref *tables, /*!< in/out: tables to fill */
2503 Item *) /*!< in: condition (ignored) */
2504 {
2505 DBUG_TRACE;
2506
2507 return i_s_fts_deleted_generic_fill(thd, tables, true);
2508 }
2509
2510 /** Bind the dynamic table INFORMATION_SCHEMA.INNODB_FT_BEING_DELETED
2511 @return 0 on success */
2512 static int i_s_fts_being_deleted_init(
2513 void *p) /*!< in/out: table schema object */
2514 {
2515 DBUG_TRACE;
2516 ST_SCHEMA_TABLE *schema = (ST_SCHEMA_TABLE *)p;
2517
2518 schema->fields_info = i_s_fts_doc_fields_info;
2519 schema->fill_table = i_s_fts_being_deleted_fill;
2520
2521 return 0;
2522 }
2523
2524 struct st_mysql_plugin i_s_innodb_ft_being_deleted = {
2525 /* the plugin type (a MYSQL_XXX_PLUGIN value) */
2526 /* int */
2527 STRUCT_FLD(type, MYSQL_INFORMATION_SCHEMA_PLUGIN),
2528
2529 /* pointer to type-specific plugin descriptor */
2530 /* void* */
2531 STRUCT_FLD(info, &i_s_info),
2532
2533 /* plugin name */
2534 /* const char* */
2535 STRUCT_FLD(name, "INNODB_FT_BEING_DELETED"),
2536
2537 /* plugin author (for SHOW PLUGINS) */
2538 /* const char* */
2539 STRUCT_FLD(author, plugin_author),
2540
2541 /* general descriptive text (for SHOW PLUGINS) */
2542 /* const char* */
2543 STRUCT_FLD(descr, "INNODB AUXILIARY FTS BEING DELETED TABLE"),
2544
2545 /* the plugin license (PLUGIN_LICENSE_XXX) */
2546 /* int */
2547 STRUCT_FLD(license, PLUGIN_LICENSE_GPL),
2548
2549 /* the function to invoke when plugin is loaded */
2550 /* int (*)(void*); */
2551 STRUCT_FLD(init, i_s_fts_being_deleted_init),
2552
2553 /* the function to invoke when plugin is un installed */
2554 /* int (*)(void*); */
2555 STRUCT_FLD(check_uninstall, nullptr),
2556
2557 /* the function to invoke when plugin is unloaded */
2558 /* int (*)(void*); */
2559 STRUCT_FLD(deinit, i_s_common_deinit),
2560
2561 /* plugin version (for SHOW PLUGINS) */
2562 /* unsigned int */
2563 STRUCT_FLD(version, i_s_innodb_plugin_version),
2564
2565 /* SHOW_VAR* */
2566 STRUCT_FLD(status_vars, nullptr),
2567
2568 /* SYS_VAR** */
2569 STRUCT_FLD(system_vars, nullptr),
2570
2571 /* reserved for dependency checking */
2572 /* void* */
2573 STRUCT_FLD(__reserved1, nullptr),
2574
2575 /* Plugin flags */
2576 /* unsigned long */
2577 STRUCT_FLD(flags, 0UL),
2578 };
2579
2580 /* Fields of the dynamic table INFORMATION_SCHEMA.INNODB_FT_INDEX_CACHED and
2581 INFORMATION_SCHEMA.INNODB_FT_INDEX_TABLE
2582 Every time any column gets changed, added or removed, please remember
2583 to change i_s_innodb_plugin_version_postfix accordingly, so that
2584 the change can be propagated to server */
2585 static ST_FIELD_INFO i_s_fts_index_fields_info[] = {
2586 #define I_S_FTS_WORD 0
2587 {STRUCT_FLD(field_name, "WORD"),
2588 STRUCT_FLD(field_length, FTS_MAX_WORD_LEN + 1),
2589 STRUCT_FLD(field_type, MYSQL_TYPE_STRING), STRUCT_FLD(value, 0),
2590 STRUCT_FLD(field_flags, 0), STRUCT_FLD(old_name, ""),
2591 STRUCT_FLD(open_method, 0)},
2592
2593 #define I_S_FTS_FIRST_DOC_ID 1
2594 {STRUCT_FLD(field_name, "FIRST_DOC_ID"),
2595 STRUCT_FLD(field_length, MY_INT64_NUM_DECIMAL_DIGITS),
2596 STRUCT_FLD(field_type, MYSQL_TYPE_LONGLONG), STRUCT_FLD(value, 0),
2597 STRUCT_FLD(field_flags, MY_I_S_UNSIGNED), STRUCT_FLD(old_name, ""),
2598 STRUCT_FLD(open_method, 0)},
2599
2600 #define I_S_FTS_LAST_DOC_ID 2
2601 {STRUCT_FLD(field_name, "LAST_DOC_ID"),
2602 STRUCT_FLD(field_length, MY_INT64_NUM_DECIMAL_DIGITS),
2603 STRUCT_FLD(field_type, MYSQL_TYPE_LONGLONG), STRUCT_FLD(value, 0),
2604 STRUCT_FLD(field_flags, MY_I_S_UNSIGNED), STRUCT_FLD(old_name, ""),
2605 STRUCT_FLD(open_method, 0)},
2606
2607 #define I_S_FTS_DOC_COUNT 3
2608 {STRUCT_FLD(field_name, "DOC_COUNT"),
2609 STRUCT_FLD(field_length, MY_INT64_NUM_DECIMAL_DIGITS),
2610 STRUCT_FLD(field_type, MYSQL_TYPE_LONGLONG), STRUCT_FLD(value, 0),
2611 STRUCT_FLD(field_flags, MY_I_S_UNSIGNED), STRUCT_FLD(old_name, ""),
2612 STRUCT_FLD(open_method, 0)},
2613
2614 #define I_S_FTS_ILIST_DOC_ID 4
2615 {STRUCT_FLD(field_name, "DOC_ID"),
2616 STRUCT_FLD(field_length, MY_INT64_NUM_DECIMAL_DIGITS),
2617 STRUCT_FLD(field_type, MYSQL_TYPE_LONGLONG), STRUCT_FLD(value, 0),
2618 STRUCT_FLD(field_flags, MY_I_S_UNSIGNED), STRUCT_FLD(old_name, ""),
2619 STRUCT_FLD(open_method, 0)},
2620
2621 #define I_S_FTS_ILIST_DOC_POS 5
2622 {STRUCT_FLD(field_name, "POSITION"),
2623 STRUCT_FLD(field_length, MY_INT64_NUM_DECIMAL_DIGITS),
2624 STRUCT_FLD(field_type, MYSQL_TYPE_LONGLONG), STRUCT_FLD(value, 0),
2625 STRUCT_FLD(field_flags, MY_I_S_UNSIGNED), STRUCT_FLD(old_name, ""),
2626 STRUCT_FLD(open_method, 0)},
2627
2628 END_OF_ST_FIELD_INFO};
2629
2630 /** Go through the Doc Node and its ilist, fill the dynamic table
2631 INFORMATION_SCHEMA.INNODB_FT_INDEX_CACHED for one FTS index on the table.
2632 @return 0 on success, 1 on failure */
2633 static int i_s_fts_index_cache_fill_one_index(
2634 fts_index_cache_t *index_cache, /*!< in: FTS index cache */
2635 THD *thd, /*!< in: thread */
2636 Table_ref *tables) /*!< in/out: tables to fill */
2637 {
2638 TABLE *table = (TABLE *)tables->table;
2639 Field **fields;
2640 CHARSET_INFO *index_charset;
2641 const ib_rbt_node_t *rbt_node;
2642 fts_string_t conv_str;
2643 uint dummy_errors;
2644 char *word_str;
2645
2646 DBUG_TRACE;
2647
2648 fields = table->field;
2649
2650 index_charset = index_cache->charset;
2651 conv_str.f_len = system_charset_info->mbmaxlen * FTS_MAX_WORD_LEN_IN_CHAR;
2652 conv_str.f_str = static_cast<byte *>(
2653 ut::malloc_withkey(UT_NEW_THIS_FILE_PSI_KEY, conv_str.f_len));
2654 conv_str.f_n_char = 0;
2655
2656 /* Go through each word in the index cache */
2657 for (rbt_node = rbt_first(index_cache->words); rbt_node;
2658 rbt_node = rbt_next(index_cache->words, rbt_node)) {
2659 fts_tokenizer_word_t *word;
2660
2661 word = rbt_value(fts_tokenizer_word_t, rbt_node);
2662
2663 /* Convert word from index charset to system_charset_info */
2664 if (index_charset->cset != system_charset_info->cset) {
2665 conv_str.f_n_char = my_convert(
2666 reinterpret_cast<char *>(conv_str.f_str),
2667 static_cast<uint32>(conv_str.f_len), system_charset_info,
2668 reinterpret_cast<char *>(word->text.f_str),
2669 static_cast<uint32>(word->text.f_len), index_charset, &dummy_errors);
2670 ut_ad(conv_str.f_n_char <= conv_str.f_len);
2671 conv_str.f_str[conv_str.f_n_char] = 0;
2672 word_str = reinterpret_cast<char *>(conv_str.f_str);
2673 } else {
2674 word_str = reinterpret_cast<char *>(word->text.f_str);
2675 }
2676
2677 /* Decrypt the ilist, and display Dod ID and word position */
2678 for (ulint i = 0; i < ib_vector_size(word->nodes); i++) {
2679 fts_node_t *node;
2680 byte *ptr;
2681 ulint decoded = 0;
2682 doc_id_t doc_id = 0;
2683
2684 node = static_cast<fts_node_t *>(ib_vector_get(word->nodes, i));
2685
2686 ptr = node->ilist;
2687
2688 while (decoded < node->ilist_size) {
2689 const uint64_t delta = fts_decode_vlc(&ptr);
2690
2691 doc_id += delta;
2692
2693 /* Get position info */
2694 while (*ptr) {
2695 const auto decoded_pos = fts_decode_vlc(&ptr);
2696 ut_ad(decoded_pos <= std::numeric_limits<ulint>::max());
2697 const auto pos = static_cast<ulint>(decoded_pos);
2698
2699 OK(field_store_string(fields[I_S_FTS_WORD], word_str));
2700
2701 OK(fields[I_S_FTS_FIRST_DOC_ID]->store(node->first_doc_id, true));
2702
2703 OK(fields[I_S_FTS_LAST_DOC_ID]->store(node->last_doc_id, true));
2704
2705 OK(fields[I_S_FTS_DOC_COUNT]->store(node->doc_count, true));
2706
2707 OK(fields[I_S_FTS_ILIST_DOC_ID]->store(doc_id, true));
2708
2709 OK(fields[I_S_FTS_ILIST_DOC_POS]->store(pos, true));
2710
2711 OK(schema_table_store_record(thd, table));
2712 }
2713
2714 ++ptr;
2715
2716 decoded = ptr - (byte *)node->ilist;
2717 }
2718 }
2719 }
2720
2721 ut::free(conv_str.f_str);
2722
2723 return 0;
2724 }
2725 /** Fill the dynamic table INFORMATION_SCHEMA.INNODB_FT_INDEX_CACHED
2726 @return 0 on success, 1 on failure */
2727 static int i_s_fts_index_cache_fill(
2728 THD *thd, /*!< in: thread */
2729 Table_ref *tables, /*!< in/out: tables to fill */
2730 Item *) /*!< in: condition (ignored) */
2731 {
2732 dict_table_t *user_table;
2733 fts_cache_t *cache;
2734 MDL_ticket *mdl = nullptr;
2735 char local_name[MAX_FULL_NAME_LEN];
2736
2737 DBUG_TRACE;
2738
2739 /* deny access to non-superusers */
2740 if (check_global_access(thd, PROCESS_ACL)) {
2741 return 0;
2742 }
2743
2744 mysql_mutex_lock(&LOCK_global_system_variables);
2745 if (!fts_internal_tbl_name) {
2746 mysql_mutex_unlock(&LOCK_global_system_variables);
2747 return 0;
2748 }
2749
2750 ut_strcpy(local_name, fts_internal_tbl_name);
2751
2752 mysql_mutex_unlock(&LOCK_global_system_variables);
2753
2754 user_table =
2755 dd_table_open_on_name(thd, &mdl, local_name, false, DICT_ERR_IGNORE_NONE);
2756
2757 if (!user_table) {
2758 return 0;
2759 }
2760
2761 if (user_table->fts == nullptr || user_table->fts->cache == nullptr) {
2762 dd_table_close(user_table, thd, &mdl, false);
2763
2764 return 0;
2765 }
2766
2767 cache = user_table->fts->cache;
2768
2769 ut_a(cache);
2770
2771 /* Check if cache is being synced.
2772 Note: we wait till cache is being synced. */
2773 while (cache->sync->in_progress) {
2774 os_event_wait(cache->sync->event);
2775 }
2776
2777 for (ulint i = 0; i < ib_vector_size(cache->indexes); i++) {
2778 fts_index_cache_t *index_cache;
2779
2780 index_cache =
2781 static_cast<fts_index_cache_t *>(ib_vector_get(cache->indexes, i));
2782
2783 i_s_fts_index_cache_fill_one_index(index_cache, thd, tables);
2784 }
2785
2786 dd_table_close(user_table, thd, &mdl, false);
2787
2788 return 0;
2789 }
2790
2791 /** Bind the dynamic table INFORMATION_SCHEMA.INNODB_FT_INDEX_CACHE
2792 @return 0 on success */
2793 static int i_s_fts_index_cache_init(void *p) /*!< in/out: table schema object */
2794 {
2795 DBUG_TRACE;
2796 ST_SCHEMA_TABLE *schema = (ST_SCHEMA_TABLE *)p;
2797
2798 schema->fields_info = i_s_fts_index_fields_info;
2799 schema->fill_table = i_s_fts_index_cache_fill;
2800
2801 return 0;
2802 }
2803
2804 struct st_mysql_plugin i_s_innodb_ft_index_cache = {
2805 /* the plugin type (a MYSQL_XXX_PLUGIN value) */
2806 /* int */
2807 STRUCT_FLD(type, MYSQL_INFORMATION_SCHEMA_PLUGIN),
2808
2809 /* pointer to type-specific plugin descriptor */
2810 /* void* */
2811 STRUCT_FLD(info, &i_s_info),
2812
2813 /* plugin name */
2814 /* const char* */
2815 STRUCT_FLD(name, "INNODB_FT_INDEX_CACHE"),
2816
2817 /* plugin author (for SHOW PLUGINS) */
2818 /* const char* */
2819 STRUCT_FLD(author, plugin_author),
2820
2821 /* general descriptive text (for SHOW PLUGINS) */
2822 /* const char* */
2823 STRUCT_FLD(descr, "INNODB AUXILIARY FTS INDEX CACHED"),
2824
2825 /* the plugin license (PLUGIN_LICENSE_XXX) */
2826 /* int */
2827 STRUCT_FLD(license, PLUGIN_LICENSE_GPL),
2828
2829 /* the function to invoke when plugin is loaded */
2830 /* int (*)(void*); */
2831 STRUCT_FLD(init, i_s_fts_index_cache_init),
2832
2833 /* the function to invoke when plugin is un installed */
2834 /* int (*)(void*); */
2835 STRUCT_FLD(check_uninstall, nullptr),
2836
2837 /* the function to invoke when plugin is unloaded */
2838 /* int (*)(void*); */
2839 STRUCT_FLD(deinit, i_s_common_deinit),
2840
2841 /* plugin version (for SHOW PLUGINS) */
2842 /* unsigned int */
2843 STRUCT_FLD(version, i_s_innodb_plugin_version),
2844
2845 /* SHOW_VAR* */
2846 STRUCT_FLD(status_vars, nullptr),
2847
2848 /* SYS_VAR** */
2849 STRUCT_FLD(system_vars, nullptr),
2850
2851 /* reserved for dependency checking */
2852 /* void* */
2853 STRUCT_FLD(__reserved1, nullptr),
2854
2855 /* Plugin flags */
2856 /* unsigned long */
2857 STRUCT_FLD(flags, 0UL),
2858 };
2859
2860 /** Go through a FTS index auxiliary table, fetch its rows and fill
2861 FTS word cache structure.
2862 @return DB_SUCCESS on success, otherwise error code */
2863 static dberr_t i_s_fts_index_table_fill_selected(
2864 dict_index_t *index, /*!< in: FTS index */
2865 ib_vector_t *words, /*!< in/out: vector to hold
2866 fetched words */
2867 ulint selected, /*!< in: selected FTS index */
2868 fts_string_t *word) /*!< in: word to select */
2869 {
2870 pars_info_t *info;
2871 fts_table_t fts_table;
2872 trx_t *trx;
2873 que_t *graph;
2874 dberr_t error;
2875 fts_fetch_t fetch;
2876 char table_name[MAX_FULL_NAME_LEN];
2877
2878 info = pars_info_create();
2879
2880 fetch.read_arg = words;
2881 fetch.read_record = fts_optimize_index_fetch_node;
2882 fetch.total_memory = 0;
2883
2884 DBUG_EXECUTE_IF("fts_instrument_result_cache_limit",
2885 fts_result_cache_limit = 8192;);
2886
2887 trx = trx_allocate_for_background();
2888
2889 trx->op_info = "fetching FTS index nodes";
2890
2891 pars_info_bind_function(info, "my_func", fetch.read_record, &fetch);
2892 pars_info_bind_varchar_literal(info, "word", word->f_str, word->f_len);
2893
2894 FTS_INIT_INDEX_TABLE(&fts_table, fts_get_suffix(selected), FTS_INDEX_TABLE,
2895 index);
2896 fts_get_table_name(&fts_table, table_name);
2897 pars_info_bind_id(info, true, "table_name", table_name);
2898
2899 graph = fts_parse_sql(&fts_table, info,
2900 "DECLARE FUNCTION my_func;\n"
2901 "DECLARE CURSOR c IS"
2902 " SELECT word, doc_count, first_doc_id, last_doc_id,"
2903 " ilist\n"
2904 " FROM $table_name WHERE word >= :word;\n"
2905 "BEGIN\n"
2906 "\n"
2907 "OPEN c;\n"
2908 "WHILE 1 = 1 LOOP\n"
2909 " FETCH c INTO my_func();\n"
2910 " IF c % NOTFOUND THEN\n"
2911 " EXIT;\n"
2912 " END IF;\n"
2913 "END LOOP;\n"
2914 "CLOSE c;");
2915
2916 for (;;) {
2917 error = fts_eval_sql(trx, graph);
2918
2919 if (error == DB_SUCCESS) {
2920 fts_sql_commit(trx);
2921
2922 break;
2923 } else {
2924 fts_sql_rollback(trx);
2925
2926 if (error == DB_LOCK_WAIT_TIMEOUT) {
2927 ib::warn(ER_IB_MSG_601) << "Lock wait timeout reading"
2928 " FTS index. Retrying!";
2929
2930 trx->error_state = DB_SUCCESS;
2931 } else {
2932 ib::error(ER_IB_MSG_602) << "Error occurred while reading"
2933 " FTS index: "
2934 << ut_strerr(error);
2935 break;
2936 }
2937 }
2938 }
2939
2940 que_graph_free(graph);
2941
2942 trx_free_for_background(trx);
2943
2944 if (fetch.total_memory >= fts_result_cache_limit) {
2945 error = DB_FTS_EXCEED_RESULT_CACHE_LIMIT;
2946 }
2947
2948 return (error);
2949 }
2950
2951 /** Free words. */
2952 static void i_s_fts_index_table_free_one_fetch(
2953 ib_vector_t *words) /*!< in: words fetched */
2954 {
2955 for (ulint i = 0; i < ib_vector_size(words); i++) {
2956 fts_word_t *word;
2957
2958 word = static_cast<fts_word_t *>(ib_vector_get(words, i));
2959
2960 for (ulint j = 0; j < ib_vector_size(word->nodes); j++) {
2961 fts_node_t *node;
2962
2963 node = static_cast<fts_node_t *>(ib_vector_get(word->nodes, j));
2964 ut::free(node->ilist);
2965 }
2966
2967 fts_word_free(word);
2968 }
2969
2970 ib_vector_reset(words);
2971 }
2972
2973 /** Go through words, fill INFORMATION_SCHEMA.INNODB_FT_INDEX_TABLE.
2974 @return 0 on success, 1 on failure */
2975 static int i_s_fts_index_table_fill_one_fetch(
2976 CHARSET_INFO *index_charset, /*!< in: FTS index charset */
2977 THD *thd, /*!< in: thread */
2978 Table_ref *tables, /*!< in/out: tables to fill */
2979 ib_vector_t *words, /*!< in: words fetched */
2980 fts_string_t *conv_str, /*!< in: string for conversion*/
2981 bool has_more) /*!< in: has more to fetch */
2982 {
2983 TABLE *table = (TABLE *)tables->table;
2984 Field **fields;
2985 uint dummy_errors;
2986 char *word_str;
2987 ulint words_size;
2988 int ret = 0;
2989
2990 DBUG_TRACE;
2991
2992 fields = table->field;
2993
2994 words_size = ib_vector_size(words);
2995 if (has_more) {
2996 /* the last word is not fetched completely. */
2997 ut_ad(words_size > 1);
2998 words_size -= 1;
2999 }
3000
3001 /* Go through each word in the index cache */
3002 for (ulint i = 0; i < words_size; i++) {
3003 fts_word_t *word;
3004
3005 word = static_cast<fts_word_t *>(ib_vector_get(words, i));
3006
3007 word->text.f_str[word->text.f_len] = 0;
3008
3009 /* Convert word from index charset to system_charset_info */
3010 if (index_charset->cset != system_charset_info->cset) {
3011 conv_str->f_n_char = my_convert(
3012 reinterpret_cast<char *>(conv_str->f_str),
3013 static_cast<uint32>(conv_str->f_len), system_charset_info,
3014 reinterpret_cast<char *>(word->text.f_str),
3015 static_cast<uint32>(word->text.f_len), index_charset, &dummy_errors);
3016 ut_ad(conv_str->f_n_char <= conv_str->f_len);
3017 conv_str->f_str[conv_str->f_n_char] = 0;
3018 word_str = reinterpret_cast<char *>(conv_str->f_str);
3019 } else {
3020 word_str = reinterpret_cast<char *>(word->text.f_str);
3021 }
3022
3023 /* Decrypt the ilist, and display Dod ID and word position */
3024 for (ulint i = 0; i < ib_vector_size(word->nodes); i++) {
3025 fts_node_t *node;
3026 byte *ptr;
3027 ulint decoded = 0;
3028 doc_id_t doc_id = 0;
3029
3030 node = static_cast<fts_node_t *>(ib_vector_get(word->nodes, i));
3031
3032 ptr = node->ilist;
3033
3034 while (decoded < node->ilist_size) {
3035 const uint64_t delta = fts_decode_vlc(&ptr);
3036
3037 doc_id += delta;
3038
3039 /* Get position info */
3040 while (*ptr) {
3041 const auto decoded_pos = fts_decode_vlc(&ptr);
3042 ut_ad(decoded_pos <= std::numeric_limits<ulint>::max());
3043 const auto pos = static_cast<ulint>(decoded_pos);
3044
3045 OK(field_store_string(fields[I_S_FTS_WORD], word_str));
3046
3047 OK(fields[I_S_FTS_FIRST_DOC_ID]->store(node->first_doc_id, true));
3048
3049 OK(fields[I_S_FTS_LAST_DOC_ID]->store(node->last_doc_id, true));
3050
3051 OK(fields[I_S_FTS_DOC_COUNT]->store(node->doc_count, true));
3052
3053 OK(fields[I_S_FTS_ILIST_DOC_ID]->store(doc_id, true));
3054
3055 OK(fields[I_S_FTS_ILIST_DOC_POS]->store(pos, true));
3056
3057 OK(schema_table_store_record(thd, table));
3058 }
3059
3060 ++ptr;
3061
3062 decoded = ptr - (byte *)node->ilist;
3063 }
3064 }
3065 }
3066
3067 i_s_fts_index_table_free_one_fetch(words);
3068
3069 return ret;
3070 }
3071
3072 /** Go through a FTS index and its auxiliary tables, fetch rows in each table
3073 and fill INFORMATION_SCHEMA.INNODB_FT_INDEX_TABLE.
3074 @return 0 on success, 1 on failure */
3075 static int i_s_fts_index_table_fill_one_index(
3076 dict_index_t *index, /*!< in: FTS index */
3077 THD *thd, /*!< in: thread */
3078 Table_ref *tables) /*!< in/out: tables to fill */
3079 {
3080 ib_vector_t *words;
3081 mem_heap_t *heap;
3082 CHARSET_INFO *index_charset;
3083 fts_string_t conv_str;
3084 dberr_t error;
3085 int ret = 0;
3086
3087 DBUG_TRACE;
3088 assert(!dict_index_is_online_ddl(index));
3089
3090 heap = mem_heap_create(1024, UT_LOCATION_HERE);
3091
3092 words =
3093 ib_vector_create(ib_heap_allocator_create(heap), sizeof(fts_word_t), 256);
3094
3095 index_charset = fts_index_get_charset(index);
3096 conv_str.f_len = system_charset_info->mbmaxlen * FTS_MAX_WORD_LEN_IN_CHAR;
3097 conv_str.f_str = static_cast<byte *>(
3098 ut::malloc_withkey(UT_NEW_THIS_FILE_PSI_KEY, conv_str.f_len));
3099 conv_str.f_n_char = 0;
3100
3101 /* Iterate through each auxiliary table as described in
3102 fts_index_selector */
3103 for (ulint selected = 0; selected < FTS_NUM_AUX_INDEX; selected++) {
3104 fts_string_t word;
3105 bool has_more = false;
3106
3107 word.f_str = nullptr;
3108 word.f_len = 0;
3109 word.f_n_char = 0;
3110
3111 do {
3112 /* Fetch from index */
3113 error = i_s_fts_index_table_fill_selected(index, words, selected, &word);
3114
3115 if (error == DB_SUCCESS) {
3116 has_more = false;
3117 } else if (error == DB_FTS_EXCEED_RESULT_CACHE_LIMIT) {
3118 has_more = true;
3119 } else {
3120 i_s_fts_index_table_free_one_fetch(words);
3121 ret = 1;
3122 goto func_exit;
3123 }
3124
3125 if (has_more) {
3126 fts_word_t *last_word;
3127
3128 /* Prepare start point for next fetch */
3129 last_word = static_cast<fts_word_t *>(ib_vector_last(words));
3130 ut_ad(last_word != nullptr);
3131 fts_string_dup(&word, &last_word->text, heap);
3132 }
3133
3134 /* Fill into tables */
3135 ret = i_s_fts_index_table_fill_one_fetch(index_charset, thd, tables,
3136 words, &conv_str, has_more);
3137
3138 if (ret != 0) {
3139 i_s_fts_index_table_free_one_fetch(words);
3140 goto func_exit;
3141 }
3142 } while (has_more);
3143 }
3144
3145 func_exit:
3146 ut::free(conv_str.f_str);
3147 mem_heap_free(heap);
3148
3149 return ret;
3150 }
3151 /** Fill the dynamic table INFORMATION_SCHEMA.INNODB_FT_INDEX_TABLE
3152 @return 0 on success, 1 on failure */
3153 static int i_s_fts_index_table_fill(
3154 THD *thd, /*!< in: thread */
3155 Table_ref *tables, /*!< in/out: tables to fill */
3156 Item *) /*!< in: condition (ignored) */
3157 {
3158 dict_table_t *user_table;
3159 dict_index_t *index;
3160 MDL_ticket *mdl = nullptr;
3161 char local_name[MAX_FULL_NAME_LEN];
3162
3163 DBUG_TRACE;
3164
3165 /* deny access to non-superusers */
3166 if (check_global_access(thd, PROCESS_ACL)) {
3167 return 0;
3168 }
3169
3170 mysql_mutex_lock(&LOCK_global_system_variables);
3171 if (!fts_internal_tbl_name) {
3172 mysql_mutex_unlock(&LOCK_global_system_variables);
3173 return 0;
3174 }
3175
3176 ut_strcpy(local_name, fts_internal_tbl_name);
3177 mysql_mutex_unlock(&LOCK_global_system_variables);
3178
3179 /* Prevent DDL to drop fts aux tables. */
3180 rw_lock_s_lock(dict_operation_lock, UT_LOCATION_HERE);
3181
3182 user_table =
3183 dd_table_open_on_name(thd, &mdl, local_name, false, DICT_ERR_IGNORE_NONE);
3184
3185 if (!user_table) {
3186 rw_lock_s_unlock(dict_operation_lock);
3187
3188 return 0;
3189 }
3190
3191 for (index = user_table->first_index(); index; index = index->next()) {
3192 if (index->type & DICT_FTS) {
3193 i_s_fts_index_table_fill_one_index(index, thd, tables);
3194 }
3195 }
3196
3197 dd_table_close(user_table, thd, &mdl, false);
3198
3199 rw_lock_s_unlock(dict_operation_lock);
3200
3201 return 0;
3202 }
3203
3204 /** Bind the dynamic table INFORMATION_SCHEMA.INNODB_FT_INDEX_TABLE
3205 @return 0 on success */
3206 static int i_s_fts_index_table_init(void *p) /*!< in/out: table schema object */
3207 {
3208 DBUG_TRACE;
3209 ST_SCHEMA_TABLE *schema = (ST_SCHEMA_TABLE *)p;
3210
3211 schema->fields_info = i_s_fts_index_fields_info;
3212 schema->fill_table = i_s_fts_index_table_fill;
3213
3214 return 0;
3215 }
3216
3217 struct st_mysql_plugin i_s_innodb_ft_index_table = {
3218 /* the plugin type (a MYSQL_XXX_PLUGIN value) */
3219 /* int */
3220 STRUCT_FLD(type, MYSQL_INFORMATION_SCHEMA_PLUGIN),
3221
3222 /* pointer to type-specific plugin descriptor */
3223 /* void* */
3224 STRUCT_FLD(info, &i_s_info),
3225
3226 /* plugin name */
3227 /* const char* */
3228 STRUCT_FLD(name, "INNODB_FT_INDEX_TABLE"),
3229
3230 /* plugin author (for SHOW PLUGINS) */
3231 /* const char* */
3232 STRUCT_FLD(author, plugin_author),
3233
3234 /* general descriptive text (for SHOW PLUGINS) */
3235 /* const char* */
3236 STRUCT_FLD(descr, "INNODB AUXILIARY FTS INDEX TABLE"),
3237
3238 /* the plugin license (PLUGIN_LICENSE_XXX) */
3239 /* int */
3240 STRUCT_FLD(license, PLUGIN_LICENSE_GPL),
3241
3242 /* the function to invoke when plugin is loaded */
3243 /* int (*)(void*); */
3244 STRUCT_FLD(init, i_s_fts_index_table_init),
3245
3246 /* the function to invoke when plugin is un installed */
3247 /* int (*)(void*); */
3248 STRUCT_FLD(check_uninstall, nullptr),
3249
3250 /* the function to invoke when plugin is unloaded */
3251 /* int (*)(void*); */
3252 STRUCT_FLD(deinit, i_s_common_deinit),
3253
3254 /* plugin version (for SHOW PLUGINS) */
3255 /* unsigned int */
3256 STRUCT_FLD(version, i_s_innodb_plugin_version),
3257
3258 /* SHOW_VAR* */
3259 STRUCT_FLD(status_vars, nullptr),
3260
3261 /* SYS_VAR** */
3262 STRUCT_FLD(system_vars, nullptr),
3263
3264 /* reserved for dependency checking */
3265 /* void* */
3266 STRUCT_FLD(__reserved1, nullptr),
3267
3268 /* Plugin flags */
3269 /* unsigned long */
3270 STRUCT_FLD(flags, 0UL),
3271 };
3272
3273 /* Fields of the dynamic table INFORMATION_SCHEMA.INNODB_FT_CONFIG
3274 Every time any column gets changed, added or removed, please remember
3275 to change i_s_innodb_plugin_version_postfix accordingly, so that
3276 the change can be propagated to server */
3277 static ST_FIELD_INFO i_s_fts_config_fields_info[] = {
3278 #define FTS_CONFIG_KEY 0
3279 {STRUCT_FLD(field_name, "KEY"), STRUCT_FLD(field_length, NAME_LEN + 1),
3280 STRUCT_FLD(field_type, MYSQL_TYPE_STRING), STRUCT_FLD(value, 0),
3281 STRUCT_FLD(field_flags, 0), STRUCT_FLD(old_name, ""),
3282 STRUCT_FLD(open_method, 0)},
3283
3284 #define FTS_CONFIG_VALUE 1
3285 {STRUCT_FLD(field_name, "VALUE"), STRUCT_FLD(field_length, NAME_LEN + 1),
3286 STRUCT_FLD(field_type, MYSQL_TYPE_STRING), STRUCT_FLD(value, 0),
3287 STRUCT_FLD(field_flags, 0), STRUCT_FLD(old_name, ""),
3288 STRUCT_FLD(open_method, 0)},
3289
3290 END_OF_ST_FIELD_INFO};
3291
3292 static const char *fts_config_key[] = {
3293 FTS_OPTIMIZE_LIMIT_IN_SECS, FTS_SYNCED_DOC_ID, FTS_STOPWORD_TABLE_NAME,
3294 FTS_USE_STOPWORD, nullptr};
3295
3296 /** Fill the dynamic table INFORMATION_SCHEMA.INNODB_FT_CONFIG
3297 @return 0 on success, 1 on failure */
3298 static int i_s_fts_config_fill(THD *thd, /*!< in: thread */
3299 Table_ref *tables, /*!< in/out: tables to fill */
3300 Item *) /*!< in: condition (ignored) */
3301 {
3302 Field **fields;
3303 TABLE *table = (TABLE *)tables->table;
3304 trx_t *trx;
3305 fts_table_t fts_table;
3306 dict_table_t *user_table;
3307 ulint i = 0;
3308 dict_index_t *index = nullptr;
3309 unsigned char str[FTS_MAX_CONFIG_VALUE_LEN + 1];
3310 MDL_ticket *mdl = nullptr;
3311 char local_name[MAX_FULL_NAME_LEN];
3312
3313 DBUG_TRACE;
3314
3315 /* deny access to non-superusers */
3316 if (check_global_access(thd, PROCESS_ACL)) {
3317 return 0;
3318 }
3319
3320 mysql_mutex_lock(&LOCK_global_system_variables);
3321 if (!fts_internal_tbl_name) {
3322 mysql_mutex_unlock(&LOCK_global_system_variables);
3323 return 0;
3324 }
3325
3326 ut_strcpy(local_name, fts_internal_tbl_name);
3327 mysql_mutex_unlock(&LOCK_global_system_variables);
3328
3329 DEBUG_SYNC_C("i_s_fts_config_fille_check");
3330
3331 fields = table->field;
3332
3333 if (innobase_strcasecmp(local_name, "default") == 0) {
3334 return 0;
3335 }
3336
3337 /* Prevent DDL to drop fts aux tables. */
3338 rw_lock_s_lock(dict_operation_lock, UT_LOCATION_HERE);
3339
3340 user_table =
3341 dd_table_open_on_name(thd, &mdl, local_name, false, DICT_ERR_IGNORE_NONE);
3342
3343 if (!user_table) {
3344 rw_lock_s_unlock(dict_operation_lock);
3345
3346 return 0;
3347 } else if (!dict_table_has_fts_index(user_table)) {
3348 dd_table_close(user_table, thd, &mdl, false);
3349
3350 rw_lock_s_unlock(dict_operation_lock);
3351
3352 return 0;
3353 }
3354
3355 trx = trx_allocate_for_background();
3356 trx->op_info = "Select for FTS CONFIG TABLE";
3357
3358 FTS_INIT_FTS_TABLE(&fts_table, FTS_SUFFIX_CONFIG, FTS_COMMON_TABLE,
3359 user_table);
3360
3361 if (!ib_vector_is_empty(user_table->fts->indexes)) {
3362 index = (dict_index_t *)ib_vector_getp_const(user_table->fts->indexes, 0);
3363 assert(!dict_index_is_online_ddl(index));
3364 }
3365
3366 while (fts_config_key[i]) {
3367 fts_string_t value;
3368 char *key_name;
3369 ulint allocated = false;
3370
3371 value.f_len = FTS_MAX_CONFIG_VALUE_LEN;
3372
3373 value.f_str = str;
3374
3375 if (index && strcmp(fts_config_key[i], FTS_TOTAL_WORD_COUNT) == 0) {
3376 key_name = fts_config_create_index_param_name(fts_config_key[i], index);
3377 allocated = true;
3378 } else {
3379 key_name = (char *)fts_config_key[i];
3380 }
3381
3382 fts_config_get_value(trx, &fts_table, key_name, &value);
3383
3384 if (allocated) {
3385 ut::free(key_name);
3386 }
3387
3388 OK(field_store_string(fields[FTS_CONFIG_KEY], fts_config_key[i]));
3389
3390 OK(field_store_string(fields[FTS_CONFIG_VALUE], (const char *)value.f_str));
3391
3392 OK(schema_table_store_record(thd, table));
3393
3394 i++;
3395 }
3396
3397 fts_sql_commit(trx);
3398
3399 trx_free_for_background(trx);
3400
3401 dd_table_close(user_table, thd, &mdl, false);
3402
3403 rw_lock_s_unlock(dict_operation_lock);
3404
3405 return 0;
3406 }
3407
3408 /** Bind the dynamic table INFORMATION_SCHEMA.INNODB_FT_CONFIG
3409 @return 0 on success */
3410 static int i_s_fts_config_init(void *p) /*!< in/out: table schema object */
3411 {
3412 DBUG_TRACE;
3413 ST_SCHEMA_TABLE *schema = (ST_SCHEMA_TABLE *)p;
3414
3415 schema->fields_info = i_s_fts_config_fields_info;
3416 schema->fill_table = i_s_fts_config_fill;
3417
3418 return 0;
3419 }
3420
3421 struct st_mysql_plugin i_s_innodb_ft_config = {
3422 /* the plugin type (a MYSQL_XXX_PLUGIN value) */
3423 /* int */
3424 STRUCT_FLD(type, MYSQL_INFORMATION_SCHEMA_PLUGIN),
3425
3426 /* pointer to type-specific plugin descriptor */
3427 /* void* */
3428 STRUCT_FLD(info, &i_s_info),
3429
3430 /* plugin name */
3431 /* const char* */
3432 STRUCT_FLD(name, "INNODB_FT_CONFIG"),
3433
3434 /* plugin author (for SHOW PLUGINS) */
3435 /* const char* */
3436 STRUCT_FLD(author, plugin_author),
3437
3438 /* general descriptive text (for SHOW PLUGINS) */
3439 /* const char* */
3440 STRUCT_FLD(descr, "INNODB AUXILIARY FTS CONFIG TABLE"),
3441
3442 /* the plugin license (PLUGIN_LICENSE_XXX) */
3443 /* int */
3444 STRUCT_FLD(license, PLUGIN_LICENSE_GPL),
3445
3446 /* the function to invoke when plugin is loaded */
3447 /* int (*)(void*); */
3448 STRUCT_FLD(init, i_s_fts_config_init),
3449
3450 /* the function to invoke when plugin is un installed */
3451 /* int (*)(void*); */
3452 STRUCT_FLD(check_uninstall, nullptr),
3453
3454 /* the function to invoke when plugin is unloaded */
3455 /* int (*)(void*); */
3456 STRUCT_FLD(deinit, i_s_common_deinit),
3457
3458 /* plugin version (for SHOW PLUGINS) */
3459 /* unsigned int */
3460 STRUCT_FLD(version, i_s_innodb_plugin_version),
3461
3462 /* SHOW_VAR* */
3463 STRUCT_FLD(status_vars, nullptr),
3464
3465 /* SYS_VAR** */
3466 STRUCT_FLD(system_vars, nullptr),
3467
3468 /* reserved for dependency checking */
3469 /* void* */
3470 STRUCT_FLD(__reserved1, nullptr),
3471
3472 /* Plugin flags */
3473 /* unsigned long */
3474 STRUCT_FLD(flags, 0UL),
3475 };
3476
3477 /* Fields of the dynamic table INNODB_TEMP_TABLE_INFO.
3478 Every time any column gets changed, added or removed, please remember
3479 to change i_s_innodb_plugin_version_postfix accordingly, so that
3480 the change can be propagated to server */
3481 static ST_FIELD_INFO i_s_innodb_temp_table_info_fields_info[] = {
3482 #define IDX_TEMP_TABLE_ID 0
3483 {STRUCT_FLD(field_name, "TABLE_ID"),
3484 STRUCT_FLD(field_length, MY_INT64_NUM_DECIMAL_DIGITS),
3485 STRUCT_FLD(field_type, MYSQL_TYPE_LONGLONG), STRUCT_FLD(value, 0),
3486 STRUCT_FLD(field_flags, MY_I_S_UNSIGNED), STRUCT_FLD(old_name, ""),
3487 STRUCT_FLD(open_method, 0)},
3488
3489 #define IDX_TEMP_TABLE_NAME 1
3490 {STRUCT_FLD(field_name, "NAME"), STRUCT_FLD(field_length, NAME_CHAR_LEN),
3491 STRUCT_FLD(field_type, MYSQL_TYPE_STRING), STRUCT_FLD(value, 0),
3492 STRUCT_FLD(field_flags, MY_I_S_MAYBE_NULL), STRUCT_FLD(old_name, ""),
3493 STRUCT_FLD(open_method, 0)},
3494
3495 #define IDX_TEMP_TABLE_N_COLS 2
3496 {STRUCT_FLD(field_name, "N_COLS"),
3497 STRUCT_FLD(field_length, MY_INT32_NUM_DECIMAL_DIGITS),
3498 STRUCT_FLD(field_type, MYSQL_TYPE_LONG), STRUCT_FLD(value, 0),
3499 STRUCT_FLD(field_flags, MY_I_S_UNSIGNED), STRUCT_FLD(old_name, ""),
3500 STRUCT_FLD(open_method, 0)},
3501
3502 #define IDX_TEMP_TABLE_SPACE_ID 3
3503 {STRUCT_FLD(field_name, "SPACE"),
3504 STRUCT_FLD(field_length, MY_INT32_NUM_DECIMAL_DIGITS),
3505 STRUCT_FLD(field_type, MYSQL_TYPE_LONG), STRUCT_FLD(value, 0),
3506 STRUCT_FLD(field_flags, MY_I_S_UNSIGNED), STRUCT_FLD(old_name, ""),
3507 STRUCT_FLD(open_method, 0)},
3508 END_OF_ST_FIELD_INFO};
3509
3510 struct temp_table_info_t {
3511 table_id_t m_table_id;
3512 char m_table_name[NAME_LEN + 1];
3513 unsigned m_n_cols;
3514 unsigned m_space_id;
3515 };
3516
3517 typedef std::vector<temp_table_info_t, ut::allocator<temp_table_info_t>>
3518 temp_table_info_cache_t;
3519
3520 /** Fill Information Schema table INNODB_TEMP_TABLE_INFO for a particular
3521 temp-table
3522 @return 0 on success, 1 on failure */
3523 static int i_s_innodb_temp_table_info_fill(
3524 THD *thd, /*!< in: thread */
3525 Table_ref *tables, /*!< in/out: tables
3526 to fill */
3527 const temp_table_info_t *info) /*!< in: temp-table
3528 information */
3529 {
3530 TABLE *table;
3531 Field **fields;
3532
3533 DBUG_TRACE;
3534
3535 table = tables->table;
3536
3537 fields = table->field;
3538
3539 OK(fields[IDX_TEMP_TABLE_ID]->store(info->m_table_id, true));
3540
3541 OK(field_store_string(fields[IDX_TEMP_TABLE_NAME], info->m_table_name));
3542
3543 OK(fields[IDX_TEMP_TABLE_N_COLS]->store(info->m_n_cols));
3544
3545 OK(fields[IDX_TEMP_TABLE_SPACE_ID]->store(info->m_space_id));
3546
3547 return schema_table_store_record(thd, table);
3548 }
3549
3550 /** Populate current table information to cache
3551 @param[in] table table
3552 @param[in,out] cache populate data in this cache */
3553 static void innodb_temp_table_populate_cache(const dict_table_t *table,
3554 temp_table_info_t *cache) {
3555 cache->m_table_id = table->id;
3556
3557 char db_utf8mb3[dict_name::MAX_DB_UTF8MB3_LEN];
3558 char table_utf8mb3[dict_name::MAX_TABLE_UTF8MB3_LEN];
3559
3560 dict_fs2utf8(table->name.m_name, db_utf8mb3, sizeof(db_utf8mb3),
3561 table_utf8mb3, sizeof(table_utf8mb3));
3562 strcpy(cache->m_table_name, table_utf8mb3);
3563
3564 cache->m_n_cols = table->n_cols;
3565
3566 cache->m_space_id = table->space;
3567 }
3568
3569 /** This function will iterate over all available table and will fill
3570 stats for temp-tables to INNODB_TEMP_TABLE_INFO.
3571 @return 0 on success, 1 on failure */
3572 static int i_s_innodb_temp_table_info_fill_table(
3573 THD *thd, /*!< in: thread */
3574 Table_ref *tables, /*!< in/out: tables to fill */
3575 Item *) /*!< in: condition (ignored) */
3576 {
3577 int status = 0;
3578
3579 DBUG_TRACE;
3580
3581 /* Only allow the PROCESS privilege holder to access the stats */
3582 if (check_global_access(thd, PROCESS_ACL)) {
3583 return 0;
3584 }
3585
3586 /* First populate all temp-table info by acquiring dict_sys->mutex.
3587 Note: Scan is being done on NON-LRU list which mainly has system
3588 table entries and temp-table entries. This means 2 things: list
3589 is smaller so processing would be faster and most of the data
3590 is relevant */
3591 temp_table_info_cache_t all_temp_info_cache;
3592 all_temp_info_cache.reserve(UT_LIST_GET_LEN(dict_sys->table_non_LRU));
3593
3594 dict_sys_mutex_enter();
3595 for (auto table : dict_sys->table_non_LRU) {
3596 if (!table->is_temporary()) {
3597 continue;
3598 }
3599
3600 temp_table_info_t current_temp_table_info;
3601
3602 innodb_temp_table_populate_cache(table, &current_temp_table_info);
3603
3604 all_temp_info_cache.push_back(current_temp_table_info);
3605 }
3606 dict_sys_mutex_exit();
3607
3608 /* Now populate the info to MySQL table */
3609 for (const auto &info : all_temp_info_cache) {
3610 status = i_s_innodb_temp_table_info_fill(thd, tables, &info);
3611 if (status) {
3612 break;
3613 }
3614 }
3615
3616 return status;
3617 }
3618
3619 /** Bind the dynamic table INFORMATION_SCHEMA.INNODB_TEMP_TABLE_INFO.
3620 @return 0 on success, 1 on failure */
3621 static int i_s_innodb_temp_table_info_init(
3622 void *p) /*!< in/out: table schema object */
3623 {
3624 ST_SCHEMA_TABLE *schema;
3625
3626 DBUG_TRACE;
3627
3628 schema = reinterpret_cast<ST_SCHEMA_TABLE *>(p);
3629
3630 schema->fields_info = i_s_innodb_temp_table_info_fields_info;
3631 schema->fill_table = i_s_innodb_temp_table_info_fill_table;
3632
3633 return 0;
3634 }
3635
3636 struct st_mysql_plugin i_s_innodb_temp_table_info = {
3637 /* the plugin type (a MYSQL_XXX_PLUGIN value) */
3638 /* int */
3639 STRUCT_FLD(type, MYSQL_INFORMATION_SCHEMA_PLUGIN),
3640
3641 /* pointer to type-specific plugin descriptor */
3642 /* void* */
3643 STRUCT_FLD(info, &i_s_info),
3644
3645 /* plugin name */
3646 /* const char* */
3647 STRUCT_FLD(name, "INNODB_TEMP_TABLE_INFO"),
3648
3649 /* plugin author (for SHOW PLUGINS) */
3650 /* const char* */
3651 STRUCT_FLD(author, plugin_author),
3652
3653 /* general descriptive text (for SHOW PLUGINS) */
3654 /* const char* */
3655 STRUCT_FLD(descr, "InnoDB Temp Table Stats"),
3656
3657 /* the plugin license (PLUGIN_LICENSE_XXX) */
3658 /* int */
3659 STRUCT_FLD(license, PLUGIN_LICENSE_GPL),
3660
3661 /* the function to invoke when plugin is loaded */
3662 /* int (*)(void*); */
3663 STRUCT_FLD(init, i_s_innodb_temp_table_info_init),
3664
3665 /* the function to invoke when plugin is un installed */
3666 /* int (*)(void*); */
3667 STRUCT_FLD(check_uninstall, nullptr),
3668
3669 /* the function to invoke when plugin is unloaded */
3670 /* int (*)(void*); */
3671 STRUCT_FLD(deinit, i_s_common_deinit),
3672
3673 /* plugin version (for SHOW PLUGINS) */
3674 /* unsigned int */
3675 STRUCT_FLD(version, i_s_innodb_plugin_version),
3676
3677 /* SHOW_VAR* */
3678 STRUCT_FLD(status_vars, nullptr),
3679
3680 /* SYS_VAR** */
3681 STRUCT_FLD(system_vars, nullptr),
3682
3683 /* reserved for dependency checking */
3684 /* void* */
3685 STRUCT_FLD(__reserved1, nullptr),
3686
3687 /* Plugin flags */
3688 /* unsigned long */
3689 STRUCT_FLD(flags, 0UL),
3690 };
3691
3692 /* Fields of the dynamic table INNODB_BUFFER_POOL_STATS.
3693 Every time any column gets changed, added or removed, please remember
3694 to change i_s_innodb_plugin_version_postfix accordingly, so that
3695 the change can be propagated to server */
3696 static ST_FIELD_INFO i_s_innodb_buffer_stats_fields_info[] = {
3697 #define IDX_BUF_STATS_POOL_ID 0
3698 {STRUCT_FLD(field_name, "POOL_ID"),
3699 STRUCT_FLD(field_length, MY_INT64_NUM_DECIMAL_DIGITS),
3700 STRUCT_FLD(field_type, MYSQL_TYPE_LONGLONG), STRUCT_FLD(value, 0),
3701 STRUCT_FLD(field_flags, MY_I_S_UNSIGNED), STRUCT_FLD(old_name, ""),
3702 STRUCT_FLD(open_method, 0)},
3703
3704 #define IDX_BUF_STATS_POOL_SIZE 1
3705 {STRUCT_FLD(field_name, "POOL_SIZE"),
3706 STRUCT_FLD(field_length, MY_INT64_NUM_DECIMAL_DIGITS),
3707 STRUCT_FLD(field_type, MYSQL_TYPE_LONGLONG), STRUCT_FLD(value, 0),
3708 STRUCT_FLD(field_flags, MY_I_S_UNSIGNED), STRUCT_FLD(old_name, ""),
3709 STRUCT_FLD(open_method, 0)},
3710
3711 #define IDX_BUF_STATS_FREE_BUFFERS 2
3712 {STRUCT_FLD(field_name, "FREE_BUFFERS"),
3713 STRUCT_FLD(field_length, MY_INT64_NUM_DECIMAL_DIGITS),
3714 STRUCT_FLD(field_type, MYSQL_TYPE_LONGLONG), STRUCT_FLD(value, 0),
3715 STRUCT_FLD(field_flags, MY_I_S_UNSIGNED), STRUCT_FLD(old_name, ""),
3716 STRUCT_FLD(open_method, 0)},
3717
3718 #define IDX_BUF_STATS_LRU_LEN 3
3719 {STRUCT_FLD(field_name, "DATABASE_PAGES"),
3720 STRUCT_FLD(field_length, MY_INT64_NUM_DECIMAL_DIGITS),
3721 STRUCT_FLD(field_type, MYSQL_TYPE_LONGLONG), STRUCT_FLD(value, 0),
3722 STRUCT_FLD(field_flags, MY_I_S_UNSIGNED), STRUCT_FLD(old_name, ""),
3723 STRUCT_FLD(open_method, 0)},
3724
3725 #define IDX_BUF_STATS_OLD_LRU_LEN 4
3726 {STRUCT_FLD(field_name, "OLD_DATABASE_PAGES"),
3727 STRUCT_FLD(field_length, MY_INT64_NUM_DECIMAL_DIGITS),
3728 STRUCT_FLD(field_type, MYSQL_TYPE_LONGLONG), STRUCT_FLD(value, 0),
3729 STRUCT_FLD(field_flags, MY_I_S_UNSIGNED), STRUCT_FLD(old_name, ""),
3730 STRUCT_FLD(open_method, 0)},
3731
3732 #define IDX_BUF_STATS_FLUSH_LIST_LEN 5
3733 {STRUCT_FLD(field_name, "MODIFIED_DATABASE_PAGES"),
3734 STRUCT_FLD(field_length, MY_INT64_NUM_DECIMAL_DIGITS),
3735 STRUCT_FLD(field_type, MYSQL_TYPE_LONGLONG), STRUCT_FLD(value, 0),
3736 STRUCT_FLD(field_flags, MY_I_S_UNSIGNED), STRUCT_FLD(old_name, ""),
3737 STRUCT_FLD(open_method, 0)},
3738
3739 #define IDX_BUF_STATS_PENDING_ZIP 6
3740 {STRUCT_FLD(field_name, "PENDING_DECOMPRESS"),
3741 STRUCT_FLD(field_length, MY_INT64_NUM_DECIMAL_DIGITS),
3742 STRUCT_FLD(field_type, MYSQL_TYPE_LONGLONG), STRUCT_FLD(value, 0),
3743 STRUCT_FLD(field_flags, MY_I_S_UNSIGNED), STRUCT_FLD(old_name, ""),
3744 STRUCT_FLD(open_method, 0)},
3745
3746 #define IDX_BUF_STATS_PENDING_READ 7
3747 {STRUCT_FLD(field_name, "PENDING_READS"),
3748 STRUCT_FLD(field_length, MY_INT64_NUM_DECIMAL_DIGITS),
3749 STRUCT_FLD(field_type, MYSQL_TYPE_LONGLONG), STRUCT_FLD(value, 0),
3750 STRUCT_FLD(field_flags, MY_I_S_UNSIGNED), STRUCT_FLD(old_name, ""),
3751 STRUCT_FLD(open_method, 0)},
3752
3753 #define IDX_BUF_STATS_FLUSH_LRU 8
3754 {STRUCT_FLD(field_name, "PENDING_FLUSH_LRU"),
3755 STRUCT_FLD(field_length, MY_INT64_NUM_DECIMAL_DIGITS),
3756 STRUCT_FLD(field_type, MYSQL_TYPE_LONGLONG), STRUCT_FLD(value, 0),
3757 STRUCT_FLD(field_flags, MY_I_S_UNSIGNED), STRUCT_FLD(old_name, ""),
3758 STRUCT_FLD(open_method, 0)},
3759
3760 #define IDX_BUF_STATS_FLUSH_LIST 9
3761 {STRUCT_FLD(field_name, "PENDING_FLUSH_LIST"),
3762 STRUCT_FLD(field_length, MY_INT64_NUM_DECIMAL_DIGITS),
3763 STRUCT_FLD(field_type, MYSQL_TYPE_LONGLONG), STRUCT_FLD(value, 0),
3764 STRUCT_FLD(field_flags, MY_I_S_UNSIGNED), STRUCT_FLD(old_name, ""),
3765 STRUCT_FLD(open_method, 0)},
3766
3767 #define IDX_BUF_STATS_PAGE_YOUNG 10
3768 {STRUCT_FLD(field_name, "PAGES_MADE_YOUNG"),
3769 STRUCT_FLD(field_length, MY_INT64_NUM_DECIMAL_DIGITS),
3770 STRUCT_FLD(field_type, MYSQL_TYPE_LONGLONG), STRUCT_FLD(value, 0),
3771 STRUCT_FLD(field_flags, MY_I_S_UNSIGNED), STRUCT_FLD(old_name, ""),
3772 STRUCT_FLD(open_method, 0)},
3773
3774 #define IDX_BUF_STATS_PAGE_NOT_YOUNG 11
3775 {STRUCT_FLD(field_name, "PAGES_NOT_MADE_YOUNG"),
3776 STRUCT_FLD(field_length, MY_INT64_NUM_DECIMAL_DIGITS),
3777 STRUCT_FLD(field_type, MYSQL_TYPE_LONGLONG), STRUCT_FLD(value, 0),
3778 STRUCT_FLD(field_flags, MY_I_S_UNSIGNED), STRUCT_FLD(old_name, ""),
3779 STRUCT_FLD(open_method, 0)},
3780
3781 #define IDX_BUF_STATS_PAGE_YOUNG_RATE 12
3782 {STRUCT_FLD(field_name, "PAGES_MADE_YOUNG_RATE"),
3783 STRUCT_FLD(field_length, MAX_FLOAT_STR_LENGTH),
3784 STRUCT_FLD(field_type, MYSQL_TYPE_FLOAT), STRUCT_FLD(value, 0),
3785 STRUCT_FLD(field_flags, 0), STRUCT_FLD(old_name, ""),
3786 STRUCT_FLD(open_method, 0)},
3787
3788 #define IDX_BUF_STATS_PAGE_NOT_YOUNG_RATE 13
3789 {STRUCT_FLD(field_name, "PAGES_MADE_NOT_YOUNG_RATE"),
3790 STRUCT_FLD(field_length, MAX_FLOAT_STR_LENGTH),
3791 STRUCT_FLD(field_type, MYSQL_TYPE_FLOAT), STRUCT_FLD(value, 0),
3792 STRUCT_FLD(field_flags, 0), STRUCT_FLD(old_name, ""),
3793 STRUCT_FLD(open_method, 0)},
3794
3795 #define IDX_BUF_STATS_PAGE_READ 14
3796 {STRUCT_FLD(field_name, "NUMBER_PAGES_READ"),
3797 STRUCT_FLD(field_length, MY_INT64_NUM_DECIMAL_DIGITS),
3798 STRUCT_FLD(field_type, MYSQL_TYPE_LONGLONG), STRUCT_FLD(value, 0),
3799 STRUCT_FLD(field_flags, MY_I_S_UNSIGNED), STRUCT_FLD(old_name, ""),
3800 STRUCT_FLD(open_method, 0)},
3801
3802 #define IDX_BUF_STATS_PAGE_CREATED 15
3803 {STRUCT_FLD(field_name, "NUMBER_PAGES_CREATED"),
3804 STRUCT_FLD(field_length, MY_INT64_NUM_DECIMAL_DIGITS),
3805 STRUCT_FLD(field_type, MYSQL_TYPE_LONGLONG), STRUCT_FLD(value, 0),
3806 STRUCT_FLD(field_flags, MY_I_S_UNSIGNED), STRUCT_FLD(old_name, ""),
3807 STRUCT_FLD(open_method, 0)},
3808
3809 #define IDX_BUF_STATS_PAGE_WRITTEN 16
3810 {STRUCT_FLD(field_name, "NUMBER_PAGES_WRITTEN"),
3811 STRUCT_FLD(field_length, MY_INT64_NUM_DECIMAL_DIGITS),
3812 STRUCT_FLD(field_type, MYSQL_TYPE_LONGLONG), STRUCT_FLD(value, 0),
3813 STRUCT_FLD(field_flags, MY_I_S_UNSIGNED), STRUCT_FLD(old_name, ""),
3814 STRUCT_FLD(open_method, 0)},
3815
3816 #define IDX_BUF_STATS_PAGE_READ_RATE 17
3817 {STRUCT_FLD(field_name, "PAGES_READ_RATE"),
3818 STRUCT_FLD(field_length, MAX_FLOAT_STR_LENGTH),
3819 STRUCT_FLD(field_type, MYSQL_TYPE_FLOAT), STRUCT_FLD(value, 0),
3820 STRUCT_FLD(field_flags, 0), STRUCT_FLD(old_name, ""),
3821 STRUCT_FLD(open_method, 0)},
3822
3823 #define IDX_BUF_STATS_PAGE_CREATE_RATE 18
3824 {STRUCT_FLD(field_name, "PAGES_CREATE_RATE"),
3825 STRUCT_FLD(field_length, MAX_FLOAT_STR_LENGTH),
3826 STRUCT_FLD(field_type, MYSQL_TYPE_FLOAT), STRUCT_FLD(value, 0),
3827 STRUCT_FLD(field_flags, 0), STRUCT_FLD(old_name, ""),
3828 STRUCT_FLD(open_method, 0)},
3829
3830 #define IDX_BUF_STATS_PAGE_WRITTEN_RATE 19
3831 {STRUCT_FLD(field_name, "PAGES_WRITTEN_RATE"),
3832 STRUCT_FLD(field_length, MAX_FLOAT_STR_LENGTH),
3833 STRUCT_FLD(field_type, MYSQL_TYPE_FLOAT), STRUCT_FLD(value, 0),
3834 STRUCT_FLD(field_flags, 0), STRUCT_FLD(old_name, ""),
3835 STRUCT_FLD(open_method, 0)},
3836
3837 #define IDX_BUF_STATS_GET 20
3838 {STRUCT_FLD(field_name, "NUMBER_PAGES_GET"),
3839 STRUCT_FLD(field_length, MY_INT64_NUM_DECIMAL_DIGITS),
3840 STRUCT_FLD(field_type, MYSQL_TYPE_LONGLONG), STRUCT_FLD(value, 0),
3841 STRUCT_FLD(field_flags, MY_I_S_UNSIGNED), STRUCT_FLD(old_name, ""),
3842 STRUCT_FLD(open_method, 0)},
3843
3844 #define IDX_BUF_STATS_HIT_RATE 21
3845 {STRUCT_FLD(field_name, "HIT_RATE"),
3846 STRUCT_FLD(field_length, MY_INT64_NUM_DECIMAL_DIGITS),
3847 STRUCT_FLD(field_type, MYSQL_TYPE_LONGLONG), STRUCT_FLD(value, 0),
3848 STRUCT_FLD(field_flags, MY_I_S_UNSIGNED), STRUCT_FLD(old_name, ""),
3849 STRUCT_FLD(open_method, 0)},
3850
3851 #define IDX_BUF_STATS_MADE_YOUNG_PCT 22
3852 {STRUCT_FLD(field_name, "YOUNG_MAKE_PER_THOUSAND_GETS"),
3853 STRUCT_FLD(field_length, MY_INT64_NUM_DECIMAL_DIGITS),
3854 STRUCT_FLD(field_type, MYSQL_TYPE_LONGLONG), STRUCT_FLD(value, 0),
3855 STRUCT_FLD(field_flags, MY_I_S_UNSIGNED), STRUCT_FLD(old_name, ""),
3856 STRUCT_FLD(open_method, 0)},
3857
3858 #define IDX_BUF_STATS_NOT_MADE_YOUNG_PCT 23
3859 {STRUCT_FLD(field_name, "NOT_YOUNG_MAKE_PER_THOUSAND_GETS"),
3860 STRUCT_FLD(field_length, MY_INT64_NUM_DECIMAL_DIGITS),
3861 STRUCT_FLD(field_type, MYSQL_TYPE_LONGLONG), STRUCT_FLD(value, 0),
3862 STRUCT_FLD(field_flags, MY_I_S_UNSIGNED), STRUCT_FLD(old_name, ""),
3863 STRUCT_FLD(open_method, 0)},
3864
3865 #define IDX_BUF_STATS_READ_AHREAD 24
3866 {STRUCT_FLD(field_name, "NUMBER_PAGES_READ_AHEAD"),
3867 STRUCT_FLD(field_length, MY_INT64_NUM_DECIMAL_DIGITS),
3868 STRUCT_FLD(field_type, MYSQL_TYPE_LONGLONG), STRUCT_FLD(value, 0),
3869 STRUCT_FLD(field_flags, MY_I_S_UNSIGNED), STRUCT_FLD(old_name, ""),
3870 STRUCT_FLD(open_method, 0)},
3871
3872 #define IDX_BUF_STATS_READ_AHEAD_EVICTED 25
3873 {STRUCT_FLD(field_name, "NUMBER_READ_AHEAD_EVICTED"),
3874 STRUCT_FLD(field_length, MY_INT64_NUM_DECIMAL_DIGITS),
3875 STRUCT_FLD(field_type, MYSQL_TYPE_LONGLONG), STRUCT_FLD(value, 0),
3876 STRUCT_FLD(field_flags, MY_I_S_UNSIGNED), STRUCT_FLD(old_name, ""),
3877 STRUCT_FLD(open_method, 0)},
3878
3879 #define IDX_BUF_STATS_READ_AHEAD_RATE 26
3880 {STRUCT_FLD(field_name, "READ_AHEAD_RATE"),
3881 STRUCT_FLD(field_length, MAX_FLOAT_STR_LENGTH),
3882 STRUCT_FLD(field_type, MYSQL_TYPE_FLOAT), STRUCT_FLD(value, 0),
3883 STRUCT_FLD(field_flags, 0), STRUCT_FLD(old_name, ""),
3884 STRUCT_FLD(open_method, 0)},
3885
3886 #define IDX_BUF_STATS_READ_AHEAD_EVICT_RATE 27
3887 {STRUCT_FLD(field_name, "READ_AHEAD_EVICTED_RATE"),
3888 STRUCT_FLD(field_length, MAX_FLOAT_STR_LENGTH),
3889 STRUCT_FLD(field_type, MYSQL_TYPE_FLOAT), STRUCT_FLD(value, 0),
3890 STRUCT_FLD(field_flags, 0), STRUCT_FLD(old_name, ""),
3891 STRUCT_FLD(open_method, 0)},
3892
3893 #define IDX_BUF_STATS_LRU_IO_SUM 28
3894 {STRUCT_FLD(field_name, "LRU_IO_TOTAL"),
3895 STRUCT_FLD(field_length, MY_INT64_NUM_DECIMAL_DIGITS),
3896 STRUCT_FLD(field_type, MYSQL_TYPE_LONGLONG), STRUCT_FLD(value, 0),
3897 STRUCT_FLD(field_flags, MY_I_S_UNSIGNED), STRUCT_FLD(old_name, ""),
3898 STRUCT_FLD(open_method, 0)},
3899
3900 #define IDX_BUF_STATS_LRU_IO_CUR 29
3901 {STRUCT_FLD(field_name, "LRU_IO_CURRENT"),
3902 STRUCT_FLD(field_length, MY_INT64_NUM_DECIMAL_DIGITS),
3903 STRUCT_FLD(field_type, MYSQL_TYPE_LONGLONG), STRUCT_FLD(value, 0),
3904 STRUCT_FLD(field_flags, MY_I_S_UNSIGNED), STRUCT_FLD(old_name, ""),
3905 STRUCT_FLD(open_method, 0)},
3906
3907 #define IDX_BUF_STATS_UNZIP_SUM 30
3908 {STRUCT_FLD(field_name, "UNCOMPRESS_TOTAL"),
3909 STRUCT_FLD(field_length, MY_INT64_NUM_DECIMAL_DIGITS),
3910 STRUCT_FLD(field_type, MYSQL_TYPE_LONGLONG), STRUCT_FLD(value, 0),
3911 STRUCT_FLD(field_flags, MY_I_S_UNSIGNED), STRUCT_FLD(old_name, ""),
3912 STRUCT_FLD(open_method, 0)},
3913
3914 #define IDX_BUF_STATS_UNZIP_CUR 31
3915 {STRUCT_FLD(field_name, "UNCOMPRESS_CURRENT"),
3916 STRUCT_FLD(field_length, MY_INT64_NUM_DECIMAL_DIGITS),
3917 STRUCT_FLD(field_type, MYSQL_TYPE_LONGLONG), STRUCT_FLD(value, 0),
3918 STRUCT_FLD(field_flags, MY_I_S_UNSIGNED), STRUCT_FLD(old_name, ""),
3919 STRUCT_FLD(open_method, 0)},
3920
3921 END_OF_ST_FIELD_INFO};
3922
3923 /** Fill Information Schema table INNODB_BUFFER_POOL_STATS for a particular
3924 buffer pool
3925 @return 0 on success, 1 on failure */
3926 static int i_s_innodb_stats_fill(
3927 THD *thd, /*!< in: thread */
3928 Table_ref *tables, /*!< in/out: tables to fill */
3929 const buf_pool_info_t *info) /*!< in: buffer pool
3930 information */
3931 {
3932 TABLE *table;
3933 Field **fields;
3934
3935 DBUG_TRACE;
3936
3937 table = tables->table;
3938
3939 fields = table->field;
3940
3941 OK(fields[IDX_BUF_STATS_POOL_ID]->store(info->pool_unique_id, true));
3942
3943 OK(fields[IDX_BUF_STATS_POOL_SIZE]->store(info->pool_size, true));
3944
3945 OK(fields[IDX_BUF_STATS_LRU_LEN]->store(info->lru_len, true));
3946
3947 OK(fields[IDX_BUF_STATS_OLD_LRU_LEN]->store(info->old_lru_len, true));
3948
3949 OK(fields[IDX_BUF_STATS_FREE_BUFFERS]->store(info->free_list_len, true));
3950
3951 OK(fields[IDX_BUF_STATS_FLUSH_LIST_LEN]->store(info->flush_list_len, true));
3952
3953 OK(fields[IDX_BUF_STATS_PENDING_ZIP]->store(info->n_pend_unzip, true));
3954
3955 OK(fields[IDX_BUF_STATS_PENDING_READ]->store(info->n_pend_reads, true));
3956
3957 OK(fields[IDX_BUF_STATS_FLUSH_LRU]->store(info->n_pending_flush_lru, true));
3958
3959 OK(fields[IDX_BUF_STATS_FLUSH_LIST]->store(info->n_pending_flush_list, true));
3960
3961 OK(fields[IDX_BUF_STATS_PAGE_YOUNG]->store(info->n_pages_made_young, true));
3962
3963 OK(fields[IDX_BUF_STATS_PAGE_NOT_YOUNG]->store(info->n_pages_not_made_young,
3964 true));
3965
3966 OK(fields[IDX_BUF_STATS_PAGE_YOUNG_RATE]->store(info->page_made_young_rate));
3967
3968 OK(fields[IDX_BUF_STATS_PAGE_NOT_YOUNG_RATE]->store(
3969 info->page_not_made_young_rate));
3970
3971 OK(fields[IDX_BUF_STATS_PAGE_READ]->store(info->n_pages_read, true));
3972
3973 OK(fields[IDX_BUF_STATS_PAGE_CREATED]->store(info->n_pages_created, true));
3974
3975 OK(fields[IDX_BUF_STATS_PAGE_WRITTEN]->store(info->n_pages_written, true));
3976
3977 OK(fields[IDX_BUF_STATS_GET]->store(info->n_page_gets, true));
3978
3979 OK(fields[IDX_BUF_STATS_PAGE_READ_RATE]->store(info->pages_read_rate));
3980
3981 OK(fields[IDX_BUF_STATS_PAGE_CREATE_RATE]->store(info->pages_created_rate));
3982
3983 OK(fields[IDX_BUF_STATS_PAGE_WRITTEN_RATE]->store(info->pages_written_rate));
3984
3985 if (info->n_page_get_delta) {
3986 OK(fields[IDX_BUF_STATS_HIT_RATE]->store(
3987 1000 - (1000 * info->page_read_delta / info->n_page_get_delta), true));
3988
3989 OK(fields[IDX_BUF_STATS_MADE_YOUNG_PCT]->store(
3990 1000 * info->young_making_delta / info->n_page_get_delta, true));
3991
3992 OK(fields[IDX_BUF_STATS_NOT_MADE_YOUNG_PCT]->store(
3993 1000 * info->not_young_making_delta / info->n_page_get_delta, true));
3994 } else {
3995 OK(fields[IDX_BUF_STATS_HIT_RATE]->store(0, true));
3996 OK(fields[IDX_BUF_STATS_MADE_YOUNG_PCT]->store(0, true));
3997 OK(fields[IDX_BUF_STATS_NOT_MADE_YOUNG_PCT]->store(0, true));
3998 }
3999
4000 OK(fields[IDX_BUF_STATS_READ_AHREAD]->store(info->n_ra_pages_read, true));
4001
4002 OK(fields[IDX_BUF_STATS_READ_AHEAD_EVICTED]->store(info->n_ra_pages_evicted,
4003 true));
4004
4005 OK(fields[IDX_BUF_STATS_READ_AHEAD_RATE]->store(info->pages_readahead_rate));
4006
4007 OK(fields[IDX_BUF_STATS_READ_AHEAD_EVICT_RATE]->store(
4008 info->pages_evicted_rate));
4009
4010 OK(fields[IDX_BUF_STATS_LRU_IO_SUM]->store(info->io_sum, true));
4011
4012 OK(fields[IDX_BUF_STATS_LRU_IO_CUR]->store(info->io_cur, true));
4013
4014 OK(fields[IDX_BUF_STATS_UNZIP_SUM]->store(info->unzip_sum, true));
4015
4016 OK(fields[IDX_BUF_STATS_UNZIP_CUR]->store(info->unzip_cur, true));
4017
4018 return schema_table_store_record(thd, table);
4019 }
4020
4021 /** This is the function that loops through each buffer pool and fetch buffer
4022 pool stats to information schema table: I_S_INNODB_BUFFER_POOL_STATS
4023 @return 0 on success, 1 on failure */
4024 static int i_s_innodb_buffer_stats_fill_table(
4025 THD *thd, /*!< in: thread */
4026 Table_ref *tables, /*!< in/out: tables to fill */
4027 Item *) /*!< in: condition (ignored) */
4028 {
4029 int status = 0;
4030 buf_pool_info_t *pool_info;
4031
4032 DBUG_TRACE;
4033
4034 /* Only allow the PROCESS privilege holder to access the stats */
4035 if (check_global_access(thd, PROCESS_ACL)) {
4036 return 0;
4037 }
4038
4039 pool_info = (buf_pool_info_t *)ut::zalloc_withkey(
4040 UT_NEW_THIS_FILE_PSI_KEY, srv_buf_pool_instances * sizeof *pool_info);
4041
4042 /* Walk through each buffer pool */
4043 for (ulint i = 0; i < srv_buf_pool_instances; i++) {
4044 buf_pool_t *buf_pool;
4045
4046 buf_pool = buf_pool_from_array(i);
4047
4048 /* Fetch individual buffer pool info */
4049 buf_stats_get_pool_info(buf_pool, i, pool_info);
4050
4051 status = i_s_innodb_stats_fill(thd, tables, &pool_info[i]);
4052
4053 /* If something goes wrong, break and return */
4054 if (status) {
4055 break;
4056 }
4057 }
4058
4059 ut::free(pool_info);
4060
4061 return status;
4062 }
4063
4064 /** Bind the dynamic table INFORMATION_SCHEMA.INNODB_BUFFER_POOL_STATS.
4065 @return 0 on success, 1 on failure */
4066 static int i_s_innodb_buffer_pool_stats_init(
4067 void *p) /*!< in/out: table schema object */
4068 {
4069 ST_SCHEMA_TABLE *schema;
4070
4071 DBUG_TRACE;
4072
4073 schema = reinterpret_cast<ST_SCHEMA_TABLE *>(p);
4074
4075 schema->fields_info = i_s_innodb_buffer_stats_fields_info;
4076 schema->fill_table = i_s_innodb_buffer_stats_fill_table;
4077
4078 return 0;
4079 }
4080
4081 struct st_mysql_plugin i_s_innodb_buffer_stats = {
4082 /* the plugin type (a MYSQL_XXX_PLUGIN value) */
4083 /* int */
4084 STRUCT_FLD(type, MYSQL_INFORMATION_SCHEMA_PLUGIN),
4085
4086 /* pointer to type-specific plugin descriptor */
4087 /* void* */
4088 STRUCT_FLD(info, &i_s_info),
4089
4090 /* plugin name */
4091 /* const char* */
4092 STRUCT_FLD(name, "INNODB_BUFFER_POOL_STATS"),
4093
4094 /* plugin author (for SHOW PLUGINS) */
4095 /* const char* */
4096 STRUCT_FLD(author, plugin_author),
4097
4098 /* general descriptive text (for SHOW PLUGINS) */
4099 /* const char* */
4100 STRUCT_FLD(descr, "InnoDB Buffer Pool Statistics Information "),
4101
4102 /* the plugin license (PLUGIN_LICENSE_XXX) */
4103 /* int */
4104 STRUCT_FLD(license, PLUGIN_LICENSE_GPL),
4105
4106 /* the function to invoke when plugin is loaded */
4107 /* int (*)(void*); */
4108 STRUCT_FLD(init, i_s_innodb_buffer_pool_stats_init),
4109
4110 /* the function to invoke when plugin is un installed */
4111 /* int (*)(void*); */
4112 STRUCT_FLD(check_uninstall, nullptr),
4113
4114 /* the function to invoke when plugin is unloaded */
4115 /* int (*)(void*); */
4116 STRUCT_FLD(deinit, i_s_common_deinit),
4117
4118 /* plugin version (for SHOW PLUGINS) */
4119 /* unsigned int */
4120 STRUCT_FLD(version, i_s_innodb_plugin_version),
4121
4122 /* SHOW_VAR* */
4123 STRUCT_FLD(status_vars, nullptr),
4124
4125 /* SYS_VAR** */
4126 STRUCT_FLD(system_vars, nullptr),
4127
4128 /* reserved for dependency checking */
4129 /* void* */
4130 STRUCT_FLD(__reserved1, nullptr),
4131
4132 /* Plugin flags */
4133 /* unsigned long */
4134 STRUCT_FLD(flags, 0UL),
4135 };
4136
4137 /* Fields of the dynamic table INNODB_BUFFER_POOL_PAGE.
4138 Every time any column gets changed, added or removed, please remember
4139 to change i_s_innodb_plugin_version_postfix accordingly, so that
4140 the change can be propagated to server */
4141 static ST_FIELD_INFO i_s_innodb_buffer_page_fields_info[] = {
4142 #define IDX_BUFFER_POOL_ID 0
4143 {STRUCT_FLD(field_name, "POOL_ID"),
4144 STRUCT_FLD(field_length, MY_INT64_NUM_DECIMAL_DIGITS),
4145 STRUCT_FLD(field_type, MYSQL_TYPE_LONGLONG), STRUCT_FLD(value, 0),
4146 STRUCT_FLD(field_flags, MY_I_S_UNSIGNED), STRUCT_FLD(old_name, ""),
4147 STRUCT_FLD(open_method, 0)},
4148
4149 #define IDX_BUFFER_BLOCK_ID 1
4150 {STRUCT_FLD(field_name, "BLOCK_ID"),
4151 STRUCT_FLD(field_length, MY_INT64_NUM_DECIMAL_DIGITS),
4152 STRUCT_FLD(field_type, MYSQL_TYPE_LONGLONG), STRUCT_FLD(value, 0),
4153 STRUCT_FLD(field_flags, MY_I_S_UNSIGNED), STRUCT_FLD(old_name, ""),
4154 STRUCT_FLD(open_method, 0)},
4155
4156 #define IDX_BUFFER_PAGE_SPACE 2
4157 {STRUCT_FLD(field_name, "SPACE"),
4158 STRUCT_FLD(field_length, MY_INT64_NUM_DECIMAL_DIGITS),
4159 STRUCT_FLD(field_type, MYSQL_TYPE_LONGLONG), STRUCT_FLD(value, 0),
4160 STRUCT_FLD(field_flags, MY_I_S_UNSIGNED), STRUCT_FLD(old_name, ""),
4161 STRUCT_FLD(open_method, 0)},
4162
4163 #define IDX_BUFFER_PAGE_NUM 3
4164 {STRUCT_FLD(field_name, "PAGE_NUMBER"),
4165 STRUCT_FLD(field_length, MY_INT64_NUM_DECIMAL_DIGITS),
4166 STRUCT_FLD(field_type, MYSQL_TYPE_LONGLONG), STRUCT_FLD(value, 0),
4167 STRUCT_FLD(field_flags, MY_I_S_UNSIGNED), STRUCT_FLD(old_name, ""),
4168 STRUCT_FLD(open_method, 0)},
4169
4170 #define IDX_BUFFER_PAGE_TYPE 4
4171 {STRUCT_FLD(field_name, "PAGE_TYPE"), STRUCT_FLD(field_length, 64),
4172 STRUCT_FLD(field_type, MYSQL_TYPE_STRING), STRUCT_FLD(value, 0),
4173 STRUCT_FLD(field_flags, MY_I_S_MAYBE_NULL), STRUCT_FLD(old_name, ""),
4174 STRUCT_FLD(open_method, 0)},
4175
4176 #define IDX_BUFFER_PAGE_FLUSH_TYPE 5
4177 {STRUCT_FLD(field_name, "FLUSH_TYPE"),
4178 STRUCT_FLD(field_length, MY_INT64_NUM_DECIMAL_DIGITS),
4179 STRUCT_FLD(field_type, MYSQL_TYPE_LONGLONG), STRUCT_FLD(value, 0),
4180 STRUCT_FLD(field_flags, MY_I_S_UNSIGNED), STRUCT_FLD(old_name, ""),
4181 STRUCT_FLD(open_method, 0)},
4182
4183 #define IDX_BUFFER_PAGE_FIX_COUNT 6
4184 {STRUCT_FLD(field_name, "FIX_COUNT"),
4185 STRUCT_FLD(field_length, MY_INT64_NUM_DECIMAL_DIGITS),
4186 STRUCT_FLD(field_type, MYSQL_TYPE_LONGLONG), STRUCT_FLD(value, 0),
4187 STRUCT_FLD(field_flags, MY_I_S_UNSIGNED), STRUCT_FLD(old_name, ""),
4188 STRUCT_FLD(open_method, 0)},
4189
4190 #define IDX_BUFFER_PAGE_HASHED 7
4191 {STRUCT_FLD(field_name, "IS_HASHED"), STRUCT_FLD(field_length, 3),
4192 STRUCT_FLD(field_type, MYSQL_TYPE_STRING), STRUCT_FLD(value, 0),
4193 STRUCT_FLD(field_flags, MY_I_S_MAYBE_NULL), STRUCT_FLD(old_name, ""),
4194 STRUCT_FLD(open_method, 0)},
4195
4196 #define IDX_BUFFER_PAGE_NEWEST_MOD 8
4197 {STRUCT_FLD(field_name, "NEWEST_MODIFICATION"),
4198 STRUCT_FLD(field_length, MY_INT64_NUM_DECIMAL_DIGITS),
4199 STRUCT_FLD(field_type, MYSQL_TYPE_LONGLONG), STRUCT_FLD(value, 0),
4200 STRUCT_FLD(field_flags, MY_I_S_UNSIGNED), STRUCT_FLD(old_name, ""),
4201 STRUCT_FLD(open_method, 0)},
4202
4203 #define IDX_BUFFER_PAGE_OLDEST_MOD 9
4204 {STRUCT_FLD(field_name, "OLDEST_MODIFICATION"),
4205 STRUCT_FLD(field_length, MY_INT64_NUM_DECIMAL_DIGITS),
4206 STRUCT_FLD(field_type, MYSQL_TYPE_LONGLONG), STRUCT_FLD(value, 0),
4207 STRUCT_FLD(field_flags, MY_I_S_UNSIGNED), STRUCT_FLD(old_name, ""),
4208 STRUCT_FLD(open_method, 0)},
4209
4210 #define IDX_BUFFER_PAGE_ACCESS_TIME 10
4211 {STRUCT_FLD(field_name, "ACCESS_TIME"),
4212 STRUCT_FLD(field_length, MY_INT64_NUM_DECIMAL_DIGITS),
4213 STRUCT_FLD(field_type, MYSQL_TYPE_LONGLONG), STRUCT_FLD(value, 0),
4214 STRUCT_FLD(field_flags, MY_I_S_UNSIGNED), STRUCT_FLD(old_name, ""),
4215 STRUCT_FLD(open_method, 0)},
4216
4217 #define IDX_BUFFER_PAGE_TABLE_NAME 11
4218 {STRUCT_FLD(field_name, "TABLE_NAME"), STRUCT_FLD(field_length, 1024),
4219 STRUCT_FLD(field_type, MYSQL_TYPE_STRING), STRUCT_FLD(value, 0),
4220 STRUCT_FLD(field_flags, MY_I_S_MAYBE_NULL), STRUCT_FLD(old_name, ""),
4221 STRUCT_FLD(open_method, 0)},
4222
4223 #define IDX_BUFFER_PAGE_INDEX_NAME 12
4224 {STRUCT_FLD(field_name, "INDEX_NAME"), STRUCT_FLD(field_length, 1024),
4225 STRUCT_FLD(field_type, MYSQL_TYPE_STRING), STRUCT_FLD(value, 0),
4226 STRUCT_FLD(field_flags, MY_I_S_MAYBE_NULL), STRUCT_FLD(old_name, ""),
4227 STRUCT_FLD(open_method, 0)},
4228
4229 #define IDX_BUFFER_PAGE_NUM_RECS 13
4230 {STRUCT_FLD(field_name, "NUMBER_RECORDS"),
4231 STRUCT_FLD(field_length, MY_INT64_NUM_DECIMAL_DIGITS),
4232 STRUCT_FLD(field_type, MYSQL_TYPE_LONGLONG), STRUCT_FLD(value, 0),
4233 STRUCT_FLD(field_flags, MY_I_S_UNSIGNED), STRUCT_FLD(old_name, ""),
4234 STRUCT_FLD(open_method, 0)},
4235
4236 #define IDX_BUFFER_PAGE_DATA_SIZE 14
4237 {STRUCT_FLD(field_name, "DATA_SIZE"),
4238 STRUCT_FLD(field_length, MY_INT64_NUM_DECIMAL_DIGITS),
4239 STRUCT_FLD(field_type, MYSQL_TYPE_LONGLONG), STRUCT_FLD(value, 0),
4240 STRUCT_FLD(field_flags, MY_I_S_UNSIGNED), STRUCT_FLD(old_name, ""),
4241 STRUCT_FLD(open_method, 0)},
4242
4243 #define IDX_BUFFER_PAGE_ZIP_SIZE 15
4244 {STRUCT_FLD(field_name, "COMPRESSED_SIZE"),
4245 STRUCT_FLD(field_length, MY_INT64_NUM_DECIMAL_DIGITS),
4246 STRUCT_FLD(field_type, MYSQL_TYPE_LONGLONG), STRUCT_FLD(value, 0),
4247 STRUCT_FLD(field_flags, MY_I_S_UNSIGNED), STRUCT_FLD(old_name, ""),
4248 STRUCT_FLD(open_method, 0)},
4249
4250 #define IDX_BUFFER_PAGE_STATE 16
4251 {STRUCT_FLD(field_name, "PAGE_STATE"), STRUCT_FLD(field_length, 64),
4252 STRUCT_FLD(field_type, MYSQL_TYPE_STRING), STRUCT_FLD(value, 0),
4253 STRUCT_FLD(field_flags, MY_I_S_MAYBE_NULL), STRUCT_FLD(old_name, ""),
4254 STRUCT_FLD(open_method, 0)},
4255
4256 #define IDX_BUFFER_PAGE_IO_FIX 17
4257 {STRUCT_FLD(field_name, "IO_FIX"), STRUCT_FLD(field_length, 64),
4258 STRUCT_FLD(field_type, MYSQL_TYPE_STRING), STRUCT_FLD(value, 0),
4259 STRUCT_FLD(field_flags, MY_I_S_MAYBE_NULL), STRUCT_FLD(old_name, ""),
4260 STRUCT_FLD(open_method, 0)},
4261
4262 #define IDX_BUFFER_PAGE_IS_OLD 18
4263 {STRUCT_FLD(field_name, "IS_OLD"), STRUCT_FLD(field_length, 3),
4264 STRUCT_FLD(field_type, MYSQL_TYPE_STRING), STRUCT_FLD(value, 0),
4265 STRUCT_FLD(field_flags, MY_I_S_MAYBE_NULL), STRUCT_FLD(old_name, ""),
4266 STRUCT_FLD(open_method, 0)},
4267
4268 #define IDX_BUFFER_PAGE_FREE_CLOCK 19
4269 {STRUCT_FLD(field_name, "FREE_PAGE_CLOCK"),
4270 STRUCT_FLD(field_length, MY_INT64_NUM_DECIMAL_DIGITS),
4271 STRUCT_FLD(field_type, MYSQL_TYPE_LONGLONG), STRUCT_FLD(value, 0),
4272 STRUCT_FLD(field_flags, MY_I_S_UNSIGNED), STRUCT_FLD(old_name, ""),
4273 STRUCT_FLD(open_method, 0)},
4274
4275 #define IDX_BUFFER_PAGE_IS_STALE 20
4276 {STRUCT_FLD(field_name, "IS_STALE"), STRUCT_FLD(field_length, 3),
4277 STRUCT_FLD(field_type, MYSQL_TYPE_STRING), STRUCT_FLD(value, 0),
4278 STRUCT_FLD(field_flags, MY_I_S_MAYBE_NULL), STRUCT_FLD(old_name, ""),
4279 STRUCT_FLD(open_method, 0)},
4280
4281 END_OF_ST_FIELD_INFO};
4282
4283 /** Fill Information Schema table INNODB_BUFFER_PAGE with information
4284 cached in the buf_page_info_t array
4285 @return 0 on success, 1 on failure */
4286 static int i_s_innodb_buffer_page_fill(
4287 THD *thd, /*!< in: thread */
4288 Table_ref *tables, /*!< in/out: tables to fill */
4289 const buf_page_info_t *info_array, /*!< in: array cached page
4290 info */
4291 ulint num_page) /*!< in: number of page info
4292 cached */
4293 {
4294 TABLE *table;
4295 Field **fields;
4296
4297 DBUG_TRACE;
4298
4299 table = tables->table;
4300
4301 fields = table->field;
4302
4303 /* Iterate through the cached array and fill the I_S table rows */
4304 for (ulint i = 0; i < num_page; i++) {
4305 const buf_page_info_t *page_info;
4306 char table_name[MAX_FULL_NAME_LEN + 1];
4307 const char *table_name_end = nullptr;
4308
4309 page_info = info_array + i;
4310
4311 OK(fields[IDX_BUFFER_POOL_ID]->store(page_info->pool_id, true));
4312
4313 OK(fields[IDX_BUFFER_BLOCK_ID]->store(page_info->block_id, true));
4314
4315 OK(fields[IDX_BUFFER_PAGE_SPACE]->store(page_info->space_id, true));
4316
4317 OK(fields[IDX_BUFFER_PAGE_NUM]->store(page_info->page_num, true));
4318
4319 OK(field_store_string(fields[IDX_BUFFER_PAGE_TYPE],
4320 i_s_page_type[page_info->page_type].type_str));
4321
4322 OK(fields[IDX_BUFFER_PAGE_FLUSH_TYPE]->store(page_info->flush_type));
4323
4324 OK(fields[IDX_BUFFER_PAGE_FIX_COUNT]->store(page_info->fix_count));
4325
4326 if (page_info->hashed) {
4327 OK(field_store_string(fields[IDX_BUFFER_PAGE_HASHED], "YES"));
4328 } else {
4329 OK(field_store_string(fields[IDX_BUFFER_PAGE_HASHED], "NO"));
4330 }
4331
4332 OK(fields[IDX_BUFFER_PAGE_NEWEST_MOD]->store(page_info->newest_mod, true));
4333
4334 OK(fields[IDX_BUFFER_PAGE_OLDEST_MOD]->store(page_info->oldest_mod, true));
4335
4336 OK(fields[IDX_BUFFER_PAGE_ACCESS_TIME]->store(page_info->access_time));
4337
4338 fields[IDX_BUFFER_PAGE_TABLE_NAME]->set_null();
4339
4340 fields[IDX_BUFFER_PAGE_INDEX_NAME]->set_null();
4341
4342 /* If this is an index page, fetch the index name
4343 and table name */
4344 switch (page_info->page_type) {
4345 const dict_index_t *index;
4346
4347 case I_S_PAGE_TYPE_INDEX:
4348 case I_S_PAGE_TYPE_RTREE:
4349 case I_S_PAGE_TYPE_SDI: {
4350 index_id_t id(page_info->space_id, page_info->index_id);
4351
4352 dict_sys_mutex_enter();
4353 index = dict_index_find(id);
4354 }
4355
4356 if (index) {
4357 table_name_end = innobase_convert_name(
4358 table_name, sizeof(table_name), index->table_name,
4359 strlen(index->table_name), thd);
4360
4361 OK(fields[IDX_BUFFER_PAGE_TABLE_NAME]->store(
4362 table_name, static_cast<size_t>(table_name_end - table_name),
4363 system_charset_info));
4364 fields[IDX_BUFFER_PAGE_TABLE_NAME]->set_notnull();
4365
4366 OK(field_store_index_name(fields[IDX_BUFFER_PAGE_INDEX_NAME],
4367 index->name));
4368 }
4369
4370 dict_sys_mutex_exit();
4371 }
4372
4373 OK(fields[IDX_BUFFER_PAGE_NUM_RECS]->store(page_info->num_recs, true));
4374
4375 OK(fields[IDX_BUFFER_PAGE_DATA_SIZE]->store(page_info->data_size, true));
4376
4377 OK(fields[IDX_BUFFER_PAGE_ZIP_SIZE]->store(
4378 page_info->zip_ssize ? (UNIV_ZIP_SIZE_MIN >> 1) << page_info->zip_ssize
4379 : 0,
4380 true));
4381
4382 static_assert(BUF_PAGE_STATE_BITS <= 3,
4383 "BUF_PAGE_STATE_BITS > 3, please ensure that all "
4384 "1<<BUF_PAGE_STATE_BITS values are checked for");
4385
4386 OK(field_store_string(
4387 fields[IDX_BUFFER_PAGE_STATE],
4388 state_str(static_cast<enum buf_page_state>(page_info->page_state))));
4389
4390 OK(field_store_string(
4391 fields[IDX_BUFFER_PAGE_IO_FIX],
4392 io_fix_str(static_cast<enum buf_io_fix>(page_info->io_fix))));
4393
4394 OK(field_store_string(fields[IDX_BUFFER_PAGE_IS_OLD],
4395 (page_info->is_old) ? "YES" : "NO"));
4396
4397 OK(fields[IDX_BUFFER_PAGE_FREE_CLOCK]->store(page_info->freed_page_clock,
4398 true));
4399
4400 OK(field_store_string(fields[IDX_BUFFER_PAGE_IS_STALE],
4401 (page_info->is_stale) ? "YES" : "NO"));
4402
4403 if (schema_table_store_record(thd, table)) {
4404 return 1;
4405 }
4406 }
4407
4408 return 0;
4409 }
4410
4411 /** Set appropriate page type to a buf_page_info_t structure */
4412 static void i_s_innodb_set_page_type(
4413 buf_page_info_t *page_info, /*!< in/out: structure to fill with
4414 scanned info */
4415 ulint page_type, /*!< in: page type */
4416 const byte *frame) /*!< in: buffer frame */
4417 {
4418 if (fil_page_type_is_index(page_type)) {
4419 const page_t *page = (const page_t *)frame;
4420
4421 page_info->index_id = btr_page_get_index_id(page);
4422
4423 /* FIL_PAGE_INDEX and FIL_PAGE_RTREE are a bit special,
4424 their values are defined as 17855 and 17854, so we cannot
4425 use them to index into i_s_page_type[] array, its array index
4426 in the i_s_page_type[] array is I_S_PAGE_TYPE_INDEX
4427 (1) for index pages or I_S_PAGE_TYPE_IBUF for
4428 change buffer index pages */
4429 if (page_info->index_id ==
4430 static_cast<space_index_t>(DICT_IBUF_ID_MIN + IBUF_SPACE_ID)) {
4431 page_info->page_type = I_S_PAGE_TYPE_IBUF;
4432 } else if (page_type == FIL_PAGE_RTREE) {
4433 page_info->page_type = I_S_PAGE_TYPE_RTREE;
4434 } else if (page_type == FIL_PAGE_SDI) {
4435 page_info->page_type = I_S_PAGE_TYPE_SDI;
4436 } else {
4437 page_info->page_type = I_S_PAGE_TYPE_INDEX;
4438 }
4439
4440 page_info->data_size =
4441 (ulint)(page_header_get_field(page, PAGE_HEAP_TOP) -
4442 (page_is_comp(page) ? PAGE_NEW_SUPREMUM_END
4443 : PAGE_OLD_SUPREMUM_END) -
4444 page_header_get_field(page, PAGE_GARBAGE));
4445
4446 page_info->num_recs = page_get_n_recs(page);
4447 } else if (page_type > FIL_PAGE_TYPE_LAST) {
4448 /* Encountered an unknown page type */
4449 page_info->page_type = I_S_PAGE_TYPE_UNKNOWN;
4450 } else {
4451 /* Make sure we get the right index into the
4452 i_s_page_type[] array */
4453 ut_a(page_type == i_s_page_type[page_type].type_value);
4454
4455 page_info->page_type = page_type;
4456 }
4457
4458 switch (page_info->page_type) {
4459 case FIL_PAGE_TYPE_ZBLOB:
4460 case FIL_PAGE_TYPE_ZBLOB2:
4461 case FIL_PAGE_SDI_ZBLOB:
4462 case FIL_PAGE_TYPE_LOB_INDEX:
4463 case FIL_PAGE_TYPE_LOB_DATA:
4464 case FIL_PAGE_TYPE_LOB_FIRST:
4465 case FIL_PAGE_TYPE_ZLOB_FIRST:
4466 case FIL_PAGE_TYPE_ZLOB_DATA:
4467 case FIL_PAGE_TYPE_ZLOB_INDEX:
4468 case FIL_PAGE_TYPE_ZLOB_FRAG:
4469 case FIL_PAGE_TYPE_ZLOB_FRAG_ENTRY:
4470 page_info->page_num = mach_read_from_4(frame + FIL_PAGE_OFFSET);
4471 page_info->space_id =
4472 mach_read_from_4(frame + FIL_PAGE_ARCH_LOG_NO_OR_SPACE_ID);
4473 }
4474 }
4475 /** Scans pages in the buffer cache, and collect their general information
4476 into the buf_page_info_t array which is zero-filled. So any fields
4477 that are not initialized in the function will default to 0 */
4478 static void i_s_innodb_buffer_page_get_info(
4479 const buf_page_t *bpage, /*!< in: buffer pool page to scan */
4480 ulint pool_id, /*!< in: buffer pool id */
4481 ulint pos, /*!< in: buffer block position in
4482 buffer pool or in the LRU list */
4483 buf_page_info_t *page_info) /*!< in: zero filled info structure;
4484 out: structure filled with scanned
4485 info */
4486 {
4487 BPageMutex *mutex = buf_page_get_mutex(bpage);
4488
4489 ut_ad(pool_id < MAX_BUFFER_POOLS);
4490
4491 page_info->pool_id = pool_id;
4492
4493 page_info->block_id = pos;
4494
4495 mutex_enter(mutex);
4496
4497 page_info->page_state = buf_page_get_state(bpage);
4498
4499 /* Only fetch information for buffers that map to a tablespace,
4500 that is, buffer page with state BUF_BLOCK_ZIP_PAGE,
4501 BUF_BLOCK_ZIP_DIRTY or BUF_BLOCK_FILE_PAGE */
4502 if (buf_page_in_file(bpage)) {
4503 const byte *frame;
4504
4505 page_info->space_id = bpage->id.space();
4506
4507 page_info->page_num = bpage->id.page_no();
4508
4509 page_info->flush_type = bpage->flush_type;
4510
4511 page_info->fix_count = bpage->buf_fix_count;
4512
4513 page_info->newest_mod = bpage->get_newest_lsn();
4514
4515 page_info->oldest_mod = bpage->get_oldest_lsn();
4516
4517 /* Note: this is not an UNIX timestamp, it is an arbitrary number, cut to
4518 32bits. */
4519 page_info->access_time =
4520 std::chrono::duration_cast<std::chrono::milliseconds>(
4521 bpage->access_time - std::chrono::steady_clock::time_point{})
4522 .count();
4523
4524 page_info->zip_ssize = bpage->zip.ssize;
4525
4526 page_info->io_fix = bpage->get_io_fix();
4527
4528 page_info->is_old = bpage->old;
4529
4530 page_info->freed_page_clock = bpage->freed_page_clock;
4531
4532 page_info->is_stale = bpage->was_stale();
4533
4534 switch (buf_page_get_io_fix(bpage)) {
4535 case BUF_IO_NONE:
4536 case BUF_IO_WRITE:
4537 case BUF_IO_PIN:
4538 break;
4539 case BUF_IO_READ:
4540 page_info->page_type = I_S_PAGE_TYPE_UNKNOWN;
4541 mutex_exit(mutex);
4542 return;
4543 }
4544
4545 if (page_info->page_state == BUF_BLOCK_FILE_PAGE) {
4546 const buf_block_t *block;
4547
4548 block = reinterpret_cast<const buf_block_t *>(bpage);
4549 frame = block->frame;
4550 /* Note: this may be a false positive, that
4551 is, block->ahi.index will not always be set to
4552 nullptr when the last adaptive hash index
4553 reference is dropped. */
4554 page_info->hashed = (block->ahi.index.load() != nullptr);
4555 } else {
4556 ut_ad(page_info->zip_ssize);
4557 frame = bpage->zip.data;
4558 }
4559
4560 auto page_type = fil_page_get_type(frame);
4561
4562 i_s_innodb_set_page_type(page_info, page_type, frame);
4563 } else {
4564 page_info->page_type = I_S_PAGE_TYPE_UNKNOWN;
4565 }
4566
4567 mutex_exit(mutex);
4568 }
4569
4570 /** This is the function that goes through each block of the buffer pool
4571 and fetch information to information schema tables: INNODB_BUFFER_PAGE.
4572 @return 0 on success, 1 on failure */
4573 static int i_s_innodb_fill_buffer_pool(
4574 THD *thd, /*!< in: thread */
4575 Table_ref *tables, /*!< in/out: tables to fill */
4576 buf_pool_t *buf_pool, /*!< in: buffer pool to scan */
4577 const ulint pool_id) /*!< in: buffer pool id */
4578 {
4579 int status = 0;
4580 mem_heap_t *heap;
4581
4582 DBUG_TRACE;
4583
4584 heap = mem_heap_create(100, UT_LOCATION_HERE);
4585
4586 /* Go through each chunk of buffer pool. Currently, we only
4587 have one single chunk for each buffer pool */
4588 for (ulint n = 0; n < std::min(buf_pool->n_chunks, buf_pool->n_chunks_new);
4589 n++) {
4590 const buf_block_t *block;
4591 ulint n_blocks;
4592 buf_page_info_t *info_buffer;
4593 ulint num_page;
4594 ulint mem_size;
4595 ulint chunk_size;
4596 ulint num_to_process = 0;
4597 ulint block_id = 0;
4598
4599 /* Get buffer block of the nth chunk */
4600 block = buf_get_nth_chunk_block(buf_pool, n, &chunk_size);
4601 num_page = 0;
4602
4603 while (chunk_size > 0) {
4604 /* we cache maximum MAX_BUF_INFO_CACHED number of
4605 buffer page info */
4606 num_to_process = std::min(chunk_size, MAX_BUF_INFO_CACHED);
4607
4608 mem_size = num_to_process * sizeof(buf_page_info_t);
4609
4610 /* For each chunk, we'll pre-allocate information
4611 structures to cache the page information read from
4612 the buffer pool */
4613 info_buffer = (buf_page_info_t *)mem_heap_zalloc(heap, mem_size);
4614
4615 /* GO through each block in the chunk */
4616 for (n_blocks = num_to_process; n_blocks--; block++) {
4617 i_s_innodb_buffer_page_get_info(&block->page, pool_id, block_id,
4618 info_buffer + num_page);
4619 block_id++;
4620 num_page++;
4621 }
4622
4623 /* Fill in information schema table with information
4624 just collected from the buffer chunk scan */
4625 status = i_s_innodb_buffer_page_fill(thd, tables, info_buffer, num_page);
4626
4627 /* If something goes wrong, break and return */
4628 if (status) {
4629 break;
4630 }
4631
4632 mem_heap_empty(heap);
4633 chunk_size -= num_to_process;
4634 num_page = 0;
4635 }
4636 }
4637
4638 mem_heap_free(heap);
4639
4640 return status;
4641 }
4642
4643 /** Fill page information for pages in InnoDB buffer pool to the
4644 dynamic table INFORMATION_SCHEMA.INNODB_BUFFER_PAGE
4645 @return 0 on success, 1 on failure */
4646 static int i_s_innodb_buffer_page_fill_table(
4647 THD *thd, /*!< in: thread */
4648 Table_ref *tables, /*!< in/out: tables to fill */
4649 Item *) /*!< in: condition (ignored) */
4650 {
4651 int status = 0;
4652
4653 DBUG_TRACE;
4654
4655 /* deny access to user without PROCESS privilege */
4656 if (check_global_access(thd, PROCESS_ACL)) {
4657 return 0;
4658 }
4659
4660 /* Walk through each buffer pool */
4661 for (ulint i = 0; i < srv_buf_pool_instances; i++) {
4662 buf_pool_t *buf_pool;
4663
4664 buf_pool = buf_pool_from_array(i);
4665
4666 /* Fetch information from pages in this buffer pool,
4667 and fill the corresponding I_S table */
4668 status = i_s_innodb_fill_buffer_pool(thd, tables, buf_pool, i);
4669
4670 /* If something wrong, break and return */
4671 if (status) {
4672 break;
4673 }
4674 }
4675
4676 return status;
4677 }
4678
4679 /** Bind the dynamic table INFORMATION_SCHEMA.INNODB_BUFFER_PAGE.
4680 @return 0 on success, 1 on failure */
4681 static int i_s_innodb_buffer_page_init(
4682 void *p) /*!< in/out: table schema object */
4683 {
4684 ST_SCHEMA_TABLE *schema;
4685
4686 DBUG_TRACE;
4687
4688 schema = reinterpret_cast<ST_SCHEMA_TABLE *>(p);
4689
4690 schema->fields_info = i_s_innodb_buffer_page_fields_info;
4691 schema->fill_table = i_s_innodb_buffer_page_fill_table;
4692
4693 return 0;
4694 }
4695
4696 struct st_mysql_plugin i_s_innodb_buffer_page = {
4697 /* the plugin type (a MYSQL_XXX_PLUGIN value) */
4698 /* int */
4699 STRUCT_FLD(type, MYSQL_INFORMATION_SCHEMA_PLUGIN),
4700
4701 /* pointer to type-specific plugin descriptor */
4702 /* void* */
4703 STRUCT_FLD(info, &i_s_info),
4704
4705 /* plugin name */
4706 /* const char* */
4707 STRUCT_FLD(name, "INNODB_BUFFER_PAGE"),
4708
4709 /* plugin author (for SHOW PLUGINS) */
4710 /* const char* */
4711 STRUCT_FLD(author, plugin_author),
4712
4713 /* general descriptive text (for SHOW PLUGINS) */
4714 /* const char* */
4715 STRUCT_FLD(descr, "InnoDB Buffer Page Information"),
4716
4717 /* the plugin license (PLUGIN_LICENSE_XXX) */
4718 /* int */
4719 STRUCT_FLD(license, PLUGIN_LICENSE_GPL),
4720
4721 /* the function to invoke when plugin is loaded */
4722 /* int (*)(void*); */
4723 STRUCT_FLD(init, i_s_innodb_buffer_page_init),
4724
4725 /* the function to invoke when plugin is un installed */
4726 /* int (*)(void*); */
4727 STRUCT_FLD(check_uninstall, nullptr),
4728
4729 /* the function to invoke when plugin is unloaded */
4730 /* int (*)(void*); */
4731 STRUCT_FLD(deinit, i_s_common_deinit),
4732
4733 /* plugin version (for SHOW PLUGINS) */
4734 /* unsigned int */
4735 STRUCT_FLD(version, i_s_innodb_plugin_version),
4736
4737 /* SHOW_VAR* */
4738 STRUCT_FLD(status_vars, nullptr),
4739
4740 /* SYS_VAR** */
4741 STRUCT_FLD(system_vars, nullptr),
4742
4743 /* reserved for dependency checking */
4744 /* void* */
4745 STRUCT_FLD(__reserved1, nullptr),
4746
4747 /* Plugin flags */
4748 /* unsigned long */
4749 STRUCT_FLD(flags, 0UL),
4750 };
4751
4752 /* Every time any column gets changed, added or removed, please remember
4753 to change i_s_innodb_plugin_version_postfix accordingly, so that
4754 the change can be propagated to server */
4755 static ST_FIELD_INFO i_s_innodb_buf_page_lru_fields_info[] = {
4756 #define IDX_BUF_LRU_POOL_ID 0
4757 {STRUCT_FLD(field_name, "POOL_ID"),
4758 STRUCT_FLD(field_length, MY_INT64_NUM_DECIMAL_DIGITS),
4759 STRUCT_FLD(field_type, MYSQL_TYPE_LONGLONG), STRUCT_FLD(value, 0),
4760 STRUCT_FLD(field_flags, MY_I_S_UNSIGNED), STRUCT_FLD(old_name, ""),
4761 STRUCT_FLD(open_method, 0)},
4762
4763 #define IDX_BUF_LRU_POS 1
4764 {STRUCT_FLD(field_name, "LRU_POSITION"),
4765 STRUCT_FLD(field_length, MY_INT64_NUM_DECIMAL_DIGITS),
4766 STRUCT_FLD(field_type, MYSQL_TYPE_LONGLONG), STRUCT_FLD(value, 0),
4767 STRUCT_FLD(field_flags, MY_I_S_UNSIGNED), STRUCT_FLD(old_name, ""),
4768 STRUCT_FLD(open_method, 0)},
4769
4770 #define IDX_BUF_LRU_PAGE_SPACE 2
4771 {STRUCT_FLD(field_name, "SPACE"),
4772 STRUCT_FLD(field_length, MY_INT64_NUM_DECIMAL_DIGITS),
4773 STRUCT_FLD(field_type, MYSQL_TYPE_LONGLONG), STRUCT_FLD(value, 0),
4774 STRUCT_FLD(field_flags, MY_I_S_UNSIGNED), STRUCT_FLD(old_name, ""),
4775 STRUCT_FLD(open_method, 0)},
4776
4777 #define IDX_BUF_LRU_PAGE_NUM 3
4778 {STRUCT_FLD(field_name, "PAGE_NUMBER"),
4779 STRUCT_FLD(field_length, MY_INT64_NUM_DECIMAL_DIGITS),
4780 STRUCT_FLD(field_type, MYSQL_TYPE_LONGLONG), STRUCT_FLD(value, 0),
4781 STRUCT_FLD(field_flags, MY_I_S_UNSIGNED), STRUCT_FLD(old_name, ""),
4782 STRUCT_FLD(open_method, 0)},
4783
4784 #define IDX_BUF_LRU_PAGE_TYPE 4
4785 {STRUCT_FLD(field_name, "PAGE_TYPE"), STRUCT_FLD(field_length, 64),
4786 STRUCT_FLD(field_type, MYSQL_TYPE_STRING), STRUCT_FLD(value, 0),
4787 STRUCT_FLD(field_flags, MY_I_S_MAYBE_NULL), STRUCT_FLD(old_name, ""),
4788 STRUCT_FLD(open_method, 0)},
4789
4790 #define IDX_BUF_LRU_PAGE_FLUSH_TYPE 5
4791 {STRUCT_FLD(field_name, "FLUSH_TYPE"),
4792 STRUCT_FLD(field_length, MY_INT64_NUM_DECIMAL_DIGITS),
4793 STRUCT_FLD(field_type, MYSQL_TYPE_LONGLONG), STRUCT_FLD(value, 0),
4794 STRUCT_FLD(field_flags, MY_I_S_UNSIGNED), STRUCT_FLD(old_name, ""),
4795 STRUCT_FLD(open_method, 0)},
4796
4797 #define IDX_BUF_LRU_PAGE_FIX_COUNT 6
4798 {STRUCT_FLD(field_name, "FIX_COUNT"),
4799 STRUCT_FLD(field_length, MY_INT64_NUM_DECIMAL_DIGITS),
4800 STRUCT_FLD(field_type, MYSQL_TYPE_LONGLONG), STRUCT_FLD(value, 0),
4801 STRUCT_FLD(field_flags, MY_I_S_UNSIGNED), STRUCT_FLD(old_name, ""),
4802 STRUCT_FLD(open_method, 0)},
4803
4804 #define IDX_BUF_LRU_PAGE_HASHED 7
4805 {STRUCT_FLD(field_name, "IS_HASHED"), STRUCT_FLD(field_length, 3),
4806 STRUCT_FLD(field_type, MYSQL_TYPE_STRING), STRUCT_FLD(value, 0),
4807 STRUCT_FLD(field_flags, MY_I_S_MAYBE_NULL), STRUCT_FLD(old_name, ""),
4808 STRUCT_FLD(open_method, 0)},
4809
4810 #define IDX_BUF_LRU_PAGE_NEWEST_MOD 8
4811 {STRUCT_FLD(field_name, "NEWEST_MODIFICATION"),
4812 STRUCT_FLD(field_length, MY_INT64_NUM_DECIMAL_DIGITS),
4813 STRUCT_FLD(field_type, MYSQL_TYPE_LONGLONG), STRUCT_FLD(value, 0),
4814 STRUCT_FLD(field_flags, MY_I_S_UNSIGNED), STRUCT_FLD(old_name, ""),
4815 STRUCT_FLD(open_method, 0)},
4816
4817 #define IDX_BUF_LRU_PAGE_OLDEST_MOD 9
4818 {STRUCT_FLD(field_name, "OLDEST_MODIFICATION"),
4819 STRUCT_FLD(field_length, MY_INT64_NUM_DECIMAL_DIGITS),
4820 STRUCT_FLD(field_type, MYSQL_TYPE_LONGLONG), STRUCT_FLD(value, 0),
4821 STRUCT_FLD(field_flags, MY_I_S_UNSIGNED), STRUCT_FLD(old_name, ""),
4822 STRUCT_FLD(open_method, 0)},
4823
4824 #define IDX_BUF_LRU_PAGE_ACCESS_TIME 10
4825 {STRUCT_FLD(field_name, "ACCESS_TIME"),
4826 STRUCT_FLD(field_length, MY_INT64_NUM_DECIMAL_DIGITS),
4827 STRUCT_FLD(field_type, MYSQL_TYPE_LONGLONG), STRUCT_FLD(value, 0),
4828 STRUCT_FLD(field_flags, MY_I_S_UNSIGNED), STRUCT_FLD(old_name, ""),
4829 STRUCT_FLD(open_method, 0)},
4830
4831 #define IDX_BUF_LRU_PAGE_TABLE_NAME 11
4832 {STRUCT_FLD(field_name, "TABLE_NAME"), STRUCT_FLD(field_length, 1024),
4833 STRUCT_FLD(field_type, MYSQL_TYPE_STRING), STRUCT_FLD(value, 0),
4834 STRUCT_FLD(field_flags, MY_I_S_MAYBE_NULL), STRUCT_FLD(old_name, ""),
4835 STRUCT_FLD(open_method, 0)},
4836
4837 #define IDX_BUF_LRU_PAGE_INDEX_NAME 12
4838 {STRUCT_FLD(field_name, "INDEX_NAME"), STRUCT_FLD(field_length, 1024),
4839 STRUCT_FLD(field_type, MYSQL_TYPE_STRING), STRUCT_FLD(value, 0),
4840 STRUCT_FLD(field_flags, MY_I_S_MAYBE_NULL), STRUCT_FLD(old_name, ""),
4841 STRUCT_FLD(open_method, 0)},
4842
4843 #define IDX_BUF_LRU_PAGE_NUM_RECS 13
4844 {STRUCT_FLD(field_name, "NUMBER_RECORDS"),
4845 STRUCT_FLD(field_length, MY_INT64_NUM_DECIMAL_DIGITS),
4846 STRUCT_FLD(field_type, MYSQL_TYPE_LONGLONG), STRUCT_FLD(value, 0),
4847 STRUCT_FLD(field_flags, MY_I_S_UNSIGNED), STRUCT_FLD(old_name, ""),
4848 STRUCT_FLD(open_method, 0)},
4849
4850 #define IDX_BUF_LRU_PAGE_DATA_SIZE 14
4851 {STRUCT_FLD(field_name, "DATA_SIZE"),
4852 STRUCT_FLD(field_length, MY_INT64_NUM_DECIMAL_DIGITS),
4853 STRUCT_FLD(field_type, MYSQL_TYPE_LONGLONG), STRUCT_FLD(value, 0),
4854 STRUCT_FLD(field_flags, MY_I_S_UNSIGNED), STRUCT_FLD(old_name, ""),
4855 STRUCT_FLD(open_method, 0)},
4856
4857 #define IDX_BUF_LRU_PAGE_ZIP_SIZE 15
4858 {STRUCT_FLD(field_name, "COMPRESSED_SIZE"),
4859 STRUCT_FLD(field_length, MY_INT64_NUM_DECIMAL_DIGITS),
4860 STRUCT_FLD(field_type, MYSQL_TYPE_LONGLONG), STRUCT_FLD(value, 0),
4861 STRUCT_FLD(field_flags, MY_I_S_UNSIGNED), STRUCT_FLD(old_name, ""),
4862 STRUCT_FLD(open_method, 0)},
4863
4864 #define IDX_BUF_LRU_PAGE_STATE 16
4865 {STRUCT_FLD(field_name, "COMPRESSED"), STRUCT_FLD(field_length, 3),
4866 STRUCT_FLD(field_type, MYSQL_TYPE_STRING), STRUCT_FLD(value, 0),
4867 STRUCT_FLD(field_flags, MY_I_S_MAYBE_NULL), STRUCT_FLD(old_name, ""),
4868 STRUCT_FLD(open_method, 0)},
4869
4870 #define IDX_BUF_LRU_PAGE_IO_FIX 17
4871 {STRUCT_FLD(field_name, "IO_FIX"), STRUCT_FLD(field_length, 64),
4872 STRUCT_FLD(field_type, MYSQL_TYPE_STRING), STRUCT_FLD(value, 0),
4873 STRUCT_FLD(field_flags, MY_I_S_MAYBE_NULL), STRUCT_FLD(old_name, ""),
4874 STRUCT_FLD(open_method, 0)},
4875
4876 #define IDX_BUF_LRU_PAGE_IS_OLD 18
4877 {STRUCT_FLD(field_name, "IS_OLD"), STRUCT_FLD(field_length, 3),
4878 STRUCT_FLD(field_type, MYSQL_TYPE_STRING), STRUCT_FLD(value, 0),
4879 STRUCT_FLD(field_flags, MY_I_S_MAYBE_NULL), STRUCT_FLD(old_name, ""),
4880 STRUCT_FLD(open_method, 0)},
4881
4882 #define IDX_BUF_LRU_PAGE_FREE_CLOCK 19
4883 {STRUCT_FLD(field_name, "FREE_PAGE_CLOCK"),
4884 STRUCT_FLD(field_length, MY_INT64_NUM_DECIMAL_DIGITS),
4885 STRUCT_FLD(field_type, MYSQL_TYPE_LONGLONG), STRUCT_FLD(value, 0),
4886 STRUCT_FLD(field_flags, MY_I_S_UNSIGNED), STRUCT_FLD(old_name, ""),
4887 STRUCT_FLD(open_method, 0)},
4888
4889 END_OF_ST_FIELD_INFO};
4890
4891 /** Fill Information Schema table INNODB_BUFFER_PAGE_LRU with information
4892 cached in the buf_page_info_t array
4893 @return 0 on success, 1 on failure */
4894 static int i_s_innodb_buf_page_lru_fill(
4895 THD *thd, /*!< in: thread */
4896 Table_ref *tables, /*!< in/out: tables to fill */
4897 const buf_page_info_t *info_array, /*!< in: array cached page
4898 info */
4899 ulint num_page) /*!< in: number of page info
4900 cached */
4901 {
4902 TABLE *table;
4903 Field **fields;
4904 mem_heap_t *heap;
4905
4906 DBUG_TRACE;
4907
4908 table = tables->table;
4909
4910 fields = table->field;
4911
4912 heap = mem_heap_create(100, UT_LOCATION_HERE);
4913
4914 /* Iterate through the cached array and fill the I_S table rows */
4915 for (ulint i = 0; i < num_page; i++) {
4916 const buf_page_info_t *page_info;
4917 char table_name[MAX_FULL_NAME_LEN + 1];
4918 const char *table_name_end = nullptr;
4919
4920 page_info = info_array + i;
4921
4922 OK(fields[IDX_BUF_LRU_POOL_ID]->store(page_info->pool_id, true));
4923
4924 OK(fields[IDX_BUF_LRU_POS]->store(page_info->block_id, true));
4925
4926 OK(fields[IDX_BUF_LRU_PAGE_SPACE]->store(page_info->space_id, true));
4927
4928 OK(fields[IDX_BUF_LRU_PAGE_NUM]->store(page_info->page_num, true));
4929
4930 OK(field_store_string(fields[IDX_BUF_LRU_PAGE_TYPE],
4931 i_s_page_type[page_info->page_type].type_str));
4932
4933 OK(fields[IDX_BUF_LRU_PAGE_FLUSH_TYPE]->store(page_info->flush_type, true));
4934
4935 OK(fields[IDX_BUF_LRU_PAGE_FIX_COUNT]->store(page_info->fix_count, true));
4936
4937 if (page_info->hashed) {
4938 OK(field_store_string(fields[IDX_BUF_LRU_PAGE_HASHED], "YES"));
4939 } else {
4940 OK(field_store_string(fields[IDX_BUF_LRU_PAGE_HASHED], "NO"));
4941 }
4942
4943 OK(fields[IDX_BUF_LRU_PAGE_NEWEST_MOD]->store(page_info->newest_mod, true));
4944
4945 OK(fields[IDX_BUF_LRU_PAGE_OLDEST_MOD]->store(page_info->oldest_mod, true));
4946
4947 OK(fields[IDX_BUF_LRU_PAGE_ACCESS_TIME]->store(page_info->access_time,
4948 true));
4949
4950 fields[IDX_BUF_LRU_PAGE_TABLE_NAME]->set_null();
4951
4952 fields[IDX_BUF_LRU_PAGE_INDEX_NAME]->set_null();
4953
4954 /* If this is an index page, fetch the index name
4955 and table name */
4956 if (page_info->page_type == I_S_PAGE_TYPE_INDEX) {
4957 index_id_t id(page_info->space_id, page_info->index_id);
4958 const dict_index_t *index;
4959
4960 dict_sys_mutex_enter();
4961 index = dict_index_find(id);
4962
4963 if (index) {
4964 table_name_end = innobase_convert_name(table_name, sizeof(table_name),
4965 index->table_name,
4966 strlen(index->table_name), thd);
4967
4968 OK(fields[IDX_BUF_LRU_PAGE_TABLE_NAME]->store(
4969 table_name, static_cast<size_t>(table_name_end - table_name),
4970 system_charset_info));
4971 fields[IDX_BUF_LRU_PAGE_TABLE_NAME]->set_notnull();
4972
4973 OK(field_store_index_name(fields[IDX_BUF_LRU_PAGE_INDEX_NAME],
4974 index->name));
4975 }
4976
4977 dict_sys_mutex_exit();
4978 }
4979
4980 OK(fields[IDX_BUF_LRU_PAGE_NUM_RECS]->store(page_info->num_recs, true));
4981
4982 OK(fields[IDX_BUF_LRU_PAGE_DATA_SIZE]->store(page_info->data_size, true));
4983
4984 OK(fields[IDX_BUF_LRU_PAGE_ZIP_SIZE]->store(
4985 page_info->zip_ssize ? 512 << page_info->zip_ssize : 0, true));
4986
4987 OK(field_store_string(fields[IDX_BUF_LRU_PAGE_STATE],
4988 lru_page_state_str(static_cast<enum buf_page_state>(
4989 page_info->page_state))));
4990
4991 OK(field_store_string(
4992 fields[IDX_BUF_LRU_PAGE_IO_FIX],
4993 io_fix_str(static_cast<enum buf_io_fix>(page_info->io_fix))));
4994
4995 OK(field_store_string(fields[IDX_BUF_LRU_PAGE_IS_OLD],
4996 (page_info->is_old) ? "YES" : "NO"));
4997
4998 OK(fields[IDX_BUF_LRU_PAGE_FREE_CLOCK]->store(page_info->freed_page_clock,
4999 true));
5000
5001 if (schema_table_store_record(thd, table)) {
5002 mem_heap_free(heap);
5003 return 1;
5004 }
5005
5006 mem_heap_empty(heap);
5007 }
5008
5009 mem_heap_free(heap);
5010
5011 return 0;
5012 }
5013
5014 /** This is the function that goes through buffer pool's LRU list
5015 and fetch information to INFORMATION_SCHEMA.INNODB_BUFFER_PAGE_LRU.
5016 @param[in] thd thread
5017 @param[in,out] tables tables to fill
5018 @param[in] buf_pool buffer pool to scan
5019 @param[in] pool_id buffer pool id
5020 @return 0 on success, 1 on failure */
5021 static int i_s_innodb_fill_buffer_lru(THD *thd, Table_ref *tables,
5022 buf_pool_t *buf_pool,
5023 const ulint pool_id) {
5024 int status = 0;
5025 buf_page_info_t *info_buffer;
5026 ulint lru_pos = 0;
5027 const buf_page_t *bpage;
5028 ulint lru_len;
5029
5030 DBUG_TRACE;
5031
5032 /* Obtain buf_pool->LRU_list_mutex before allocate info_buffer, since
5033 UT_LIST_GET_LEN(buf_pool->LRU) could change */
5034 mutex_enter(&buf_pool->LRU_list_mutex);
5035
5036 lru_len = UT_LIST_GET_LEN(buf_pool->LRU);
5037
5038 /* Print error message if malloc fail */
5039 info_buffer = (buf_page_info_t *)my_malloc(
5040 PSI_INSTRUMENT_ME, lru_len * sizeof *info_buffer, MYF(MY_WME));
5041
5042 if (!info_buffer) {
5043 status = 1;
5044 goto exit;
5045 }
5046
5047 memset(info_buffer, 0, lru_len * sizeof *info_buffer);
5048
5049 /* Walk through Pool's LRU list and print the buffer page
5050 information */
5051 bpage = UT_LIST_GET_LAST(buf_pool->LRU);
5052
5053 while (bpage != nullptr) {
5054 /* Use the same function that collect buffer info for
5055 INNODB_BUFFER_PAGE to get buffer page info */
5056 i_s_innodb_buffer_page_get_info(bpage, pool_id, lru_pos,
5057 (info_buffer + lru_pos));
5058
5059 bpage = UT_LIST_GET_PREV(LRU, bpage);
5060
5061 lru_pos++;
5062 }
5063
5064 ut_ad(lru_pos == lru_len);
5065 ut_ad(lru_pos == UT_LIST_GET_LEN(buf_pool->LRU));
5066
5067 exit:
5068 mutex_exit(&buf_pool->LRU_list_mutex);
5069
5070 if (info_buffer) {
5071 status = i_s_innodb_buf_page_lru_fill(thd, tables, info_buffer, lru_len);
5072
5073 my_free(info_buffer);
5074 }
5075
5076 return status;
5077 }
5078
5079 /** Fill page information for pages in InnoDB buffer pool to the
5080 dynamic table INFORMATION_SCHEMA.INNODB_BUFFER_PAGE_LRU
5081 @return 0 on success, 1 on failure */
5082 static int i_s_innodb_buf_page_lru_fill_table(
5083 THD *thd, /*!< in: thread */
5084 Table_ref *tables, /*!< in/out: tables to fill */
5085 Item *) /*!< in: condition (ignored) */
5086 {
5087 int status = 0;
5088
5089 DBUG_TRACE;
5090
5091 /* deny access to any users that do not hold PROCESS_ACL */
5092 if (check_global_access(thd, PROCESS_ACL)) {
5093 return 0;
5094 }
5095
5096 /* Walk through each buffer pool */
5097 for (ulint i = 0; i < srv_buf_pool_instances; i++) {
5098 buf_pool_t *buf_pool;
5099
5100 buf_pool = buf_pool_from_array(i);
5101
5102 /* Fetch information from pages in this buffer pool's LRU list,
5103 and fill the corresponding I_S table */
5104 status = i_s_innodb_fill_buffer_lru(thd, tables, buf_pool, i);
5105
5106 /* If something wrong, break and return */
5107 if (status) {
5108 break;
5109 }
5110 }
5111
5112 return status;
5113 }
5114
5115 /** Bind the dynamic table INFORMATION_SCHEMA.INNODB_BUFFER_PAGE_LRU.
5116 @return 0 on success, 1 on failure */
5117 static int i_s_innodb_buffer_page_lru_init(
5118 void *p) /*!< in/out: table schema object */
5119 {
5120 ST_SCHEMA_TABLE *schema;
5121
5122 DBUG_TRACE;
5123
5124 schema = reinterpret_cast<ST_SCHEMA_TABLE *>(p);
5125
5126 schema->fields_info = i_s_innodb_buf_page_lru_fields_info;
5127 schema->fill_table = i_s_innodb_buf_page_lru_fill_table;
5128
5129 return 0;
5130 }
5131
5132 struct st_mysql_plugin i_s_innodb_buffer_page_lru = {
5133 /* the plugin type (a MYSQL_XXX_PLUGIN value) */
5134 /* int */
5135 STRUCT_FLD(type, MYSQL_INFORMATION_SCHEMA_PLUGIN),
5136
5137 /* pointer to type-specific plugin descriptor */
5138 /* void* */
5139 STRUCT_FLD(info, &i_s_info),
5140
5141 /* plugin name */
5142 /* const char* */
5143 STRUCT_FLD(name, "INNODB_BUFFER_PAGE_LRU"),
5144
5145 /* plugin author (for SHOW PLUGINS) */
5146 /* const char* */
5147 STRUCT_FLD(author, plugin_author),
5148
5149 /* general descriptive text (for SHOW PLUGINS) */
5150 /* const char* */
5151 STRUCT_FLD(descr, "InnoDB Buffer Page in LRU"),
5152
5153 /* the plugin license (PLUGIN_LICENSE_XXX) */
5154 /* int */
5155 STRUCT_FLD(license, PLUGIN_LICENSE_GPL),
5156
5157 /* the function to invoke when plugin is loaded */
5158 /* int (*)(void*); */
5159 STRUCT_FLD(init, i_s_innodb_buffer_page_lru_init),
5160
5161 /* the function to invoke when plugin is un installed */
5162 /* int (*)(void*); */
5163 STRUCT_FLD(check_uninstall, nullptr),
5164
5165 /* the function to invoke when plugin is unloaded */
5166 /* int (*)(void*); */
5167 STRUCT_FLD(deinit, i_s_common_deinit),
5168
5169 /* plugin version (for SHOW PLUGINS) */
5170 /* unsigned int */
5171 STRUCT_FLD(version, i_s_innodb_plugin_version),
5172
5173 /* SHOW_VAR* */
5174 STRUCT_FLD(status_vars, nullptr),
5175
5176 /* SYS_VAR** */
5177 STRUCT_FLD(system_vars, nullptr),
5178
5179 /* reserved for dependency checking */
5180 /* void* */
5181 STRUCT_FLD(__reserved1, nullptr),
5182
5183 /* Plugin flags */
5184 /* unsigned long */
5185 STRUCT_FLD(flags, 0UL),
5186 };
5187
5188 /** Unbind a dynamic INFORMATION_SCHEMA table.
5189 @return 0 on success */
5190 static int i_s_common_deinit(void *) /*!< in/out: table schema object */
5191 {
5192 DBUG_TRACE;
5193
5194 /* Do nothing */
5195
5196 return 0;
5197 }
5198
5199 /** INNODB_TABLES ***************************************************/
5200 /* Fields of the dynamic table INFORMATION_SCHEMA.INNODB_TABLES
5201 Every time any column gets changed, added or removed, please remember
5202 to change i_s_innodb_plugin_version_postfix accordingly, so that
5203 the change can be propagated to server */
5204 static ST_FIELD_INFO innodb_tables_fields_info[] = {
5205 #define INNODB_TABLES_ID 0
5206 {STRUCT_FLD(field_name, "TABLE_ID"),
5207 STRUCT_FLD(field_length, MY_INT64_NUM_DECIMAL_DIGITS),
5208 STRUCT_FLD(field_type, MYSQL_TYPE_LONGLONG), STRUCT_FLD(value, 0),
5209 STRUCT_FLD(field_flags, MY_I_S_UNSIGNED), STRUCT_FLD(old_name, ""),
5210 STRUCT_FLD(open_method, 0)},
5211
5212 #define INNODB_TABLES_NAME 1
5213 {STRUCT_FLD(field_name, "NAME"),
5214 STRUCT_FLD(field_length, MAX_FULL_NAME_LEN + 1),
5215 STRUCT_FLD(field_type, MYSQL_TYPE_STRING), STRUCT_FLD(value, 0),
5216 STRUCT_FLD(field_flags, 0), STRUCT_FLD(old_name, ""),
5217 STRUCT_FLD(open_method, 0)},
5218
5219 #define INNODB_TABLES_FLAG 2
5220 {STRUCT_FLD(field_name, "FLAG"),
5221 STRUCT_FLD(field_length, MY_INT32_NUM_DECIMAL_DIGITS),
5222 STRUCT_FLD(field_type, MYSQL_TYPE_LONG), STRUCT_FLD(value, 0),
5223 STRUCT_FLD(field_flags, 0), STRUCT_FLD(old_name, ""),
5224 STRUCT_FLD(open_method, 0)},
5225
5226 #define INNODB_TABLES_NUM_COLUMN 3
5227 {STRUCT_FLD(field_name, "N_COLS"),
5228 STRUCT_FLD(field_length, MY_INT32_NUM_DECIMAL_DIGITS),
5229 STRUCT_FLD(field_type, MYSQL_TYPE_LONG), STRUCT_FLD(value, 0),
5230 STRUCT_FLD(field_flags, 0), STRUCT_FLD(old_name, ""),
5231 STRUCT_FLD(open_method, 0)},
5232
5233 #define INNODB_TABLES_SPACE 4
5234 {STRUCT_FLD(field_name, "SPACE"),
5235 STRUCT_FLD(field_length, MY_INT64_NUM_DECIMAL_DIGITS),
5236 STRUCT_FLD(field_type, MYSQL_TYPE_LONGLONG), STRUCT_FLD(value, 0),
5237 STRUCT_FLD(field_flags, 0), STRUCT_FLD(old_name, ""),
5238 STRUCT_FLD(open_method, 0)},
5239
5240 #define INNODB_TABLES_ROW_FORMAT 5
5241 {STRUCT_FLD(field_name, "ROW_FORMAT"), STRUCT_FLD(field_length, 12),
5242 STRUCT_FLD(field_type, MYSQL_TYPE_STRING), STRUCT_FLD(value, 0),
5243 STRUCT_FLD(field_flags, MY_I_S_MAYBE_NULL), STRUCT_FLD(old_name, ""),
5244 STRUCT_FLD(open_method, 0)},
5245
5246 #define INNODB_TABLES_ZIP_PAGE_SIZE 6
5247 {STRUCT_FLD(field_name, "ZIP_PAGE_SIZE"),
5248 STRUCT_FLD(field_length, MY_INT32_NUM_DECIMAL_DIGITS),
5249 STRUCT_FLD(field_type, MYSQL_TYPE_LONG), STRUCT_FLD(value, 0),
5250 STRUCT_FLD(field_flags, MY_I_S_UNSIGNED), STRUCT_FLD(old_name, ""),
5251 STRUCT_FLD(open_method, 0)},
5252
5253 #define INNODB_TABLES_SPACE_TYPE 7
5254 {STRUCT_FLD(field_name, "SPACE_TYPE"), STRUCT_FLD(field_length, 10),
5255 STRUCT_FLD(field_type, MYSQL_TYPE_STRING), STRUCT_FLD(value, 0),
5256 STRUCT_FLD(field_flags, MY_I_S_MAYBE_NULL), STRUCT_FLD(old_name, ""),
5257 STRUCT_FLD(open_method, 0)},
5258
5259 #define INNODB_TABLES_INSTANT_COLS 8
5260 {STRUCT_FLD(field_name, "INSTANT_COLS"),
5261 STRUCT_FLD(field_length, MY_INT32_NUM_DECIMAL_DIGITS),
5262 STRUCT_FLD(field_type, MYSQL_TYPE_LONG), STRUCT_FLD(value, 0),
5263 STRUCT_FLD(field_flags, 0), STRUCT_FLD(old_name, ""),
5264 STRUCT_FLD(open_method, 0)},
5265
5266 #define INNODB_TABLES_TOTAL_ROW_VERSIONS 9
5267 {STRUCT_FLD(field_name, "TOTAL_ROW_VERSIONS"),
5268 STRUCT_FLD(field_length, MY_INT32_NUM_DECIMAL_DIGITS),
5269 STRUCT_FLD(field_type, MYSQL_TYPE_LONG), STRUCT_FLD(value, 0),
5270 STRUCT_FLD(field_flags, 0), STRUCT_FLD(old_name, ""),
5271 STRUCT_FLD(open_method, 0)},
5272
5273 #ifdef UNIV_DEBUG
5274 #define INNODB_TABLES_INITIAL_COLUMN_COUNTS 10
5275 {STRUCT_FLD(field_name, "INITIAL_COLUMN_COUNTS"),
5276 STRUCT_FLD(field_length, MY_INT32_NUM_DECIMAL_DIGITS),
5277 STRUCT_FLD(field_type, MYSQL_TYPE_LONG), STRUCT_FLD(value, 0),
5278 STRUCT_FLD(field_flags, 0), STRUCT_FLD(old_name, ""),
5279 STRUCT_FLD(open_method, 0)},
5280
5281 #define INNODB_TABLES_CURRENT_COLUMN_COUNTS 11
5282 {STRUCT_FLD(field_name, "CURRENT_COLUMN_COUNTS"),
5283 STRUCT_FLD(field_length, MY_INT32_NUM_DECIMAL_DIGITS),
5284 STRUCT_FLD(field_type, MYSQL_TYPE_LONG), STRUCT_FLD(value, 0),
5285 STRUCT_FLD(field_flags, 0), STRUCT_FLD(old_name, ""),
5286 STRUCT_FLD(open_method, 0)},
5287
5288 #define INNODB_TABLES_TOTAL_COLUMN_COUNTS 12
5289 {STRUCT_FLD(field_name, "TOTAL_COLUMN_COUNTS"),
5290 STRUCT_FLD(field_length, MY_INT32_NUM_DECIMAL_DIGITS),
5291 STRUCT_FLD(field_type, MYSQL_TYPE_LONG), STRUCT_FLD(value, 0),
5292 STRUCT_FLD(field_flags, 0), STRUCT_FLD(old_name, ""),
5293 STRUCT_FLD(open_method, 0)},
5294 #endif
5295
5296 END_OF_ST_FIELD_INFO};
5297
5298 /** Populate information_schema.innodb_tables table with information
5299 from INNODB_TABLES.
5300 @param[in] thd thread
5301 @param[in] table table obj
5302 @param[in,out] table_to_fill fill this table
5303 @return 0 on success */
5304 static int i_s_dict_fill_innodb_tables(THD *thd, dict_table_t *table,
5305 TABLE *table_to_fill) {
5306 Field **fields;
5307 ulint compact = DICT_TF_GET_COMPACT(table->flags);
5308 ulint atomic_blobs = DICT_TF_HAS_ATOMIC_BLOBS(table->flags);
5309 const page_size_t &page_size = dict_tf_get_page_size(table->flags);
5310 const char *row_format;
5311 const char *space_type;
5312
5313 if (!compact) {
5314 row_format = "Redundant";
5315 } else if (!atomic_blobs) {
5316 row_format = "Compact";
5317 } else if (DICT_TF_GET_ZIP_SSIZE(table->flags)) {
5318 row_format = "Compressed";
5319 } else {
5320 row_format = "Dynamic";
5321 }
5322
5323 if (fsp_is_system_or_temp_tablespace(table->space)) {
5324 space_type = "System";
5325 } else if (DICT_TF_HAS_SHARED_SPACE(table->flags)) {
5326 space_type = "General";
5327 } else {
5328 space_type = "Single";
5329 }
5330
5331 DBUG_TRACE;
5332
5333 fields = table_to_fill->field;
5334
5335 OK(fields[INNODB_TABLES_ID]->store(longlong(table->id), true));
5336
5337 OK(field_store_string(fields[INNODB_TABLES_NAME], table->name.m_name));
5338
5339 OK(fields[INNODB_TABLES_FLAG]->store(table->flags));
5340
5341 OK(fields[INNODB_TABLES_NUM_COLUMN]->store(table->n_cols));
5342
5343 OK(fields[INNODB_TABLES_SPACE]->store(table->space));
5344
5345 OK(field_store_string(fields[INNODB_TABLES_ROW_FORMAT], row_format));
5346
5347 OK(fields[INNODB_TABLES_ZIP_PAGE_SIZE]->store(
5348 page_size.is_compressed() ? page_size.physical() : 0, true));
5349
5350 OK(field_store_string(fields[INNODB_TABLES_SPACE_TYPE], space_type));
5351
5352 OK(fields[INNODB_TABLES_INSTANT_COLS]->store(
5353 table->is_upgraded_instant() ? table->get_instant_cols() : 0));
5354
5355 OK(fields[INNODB_TABLES_TOTAL_ROW_VERSIONS]->store(
5356 table->current_row_version));
5357
5358 #ifdef UNIV_DEBUG
5359 OK(fields[INNODB_TABLES_INITIAL_COLUMN_COUNTS]->store(
5360 table->initial_col_count));
5361
5362 OK(fields[INNODB_TABLES_CURRENT_COLUMN_COUNTS]->store(
5363 table->current_col_count));
5364
5365 OK(fields[INNODB_TABLES_TOTAL_COLUMN_COUNTS]->store(table->total_col_count));
5366 #endif
5367
5368 OK(schema_table_store_record(thd, table_to_fill));
5369
5370 return 0;
5371 }
5372
5373 /** Function to go through each record in INNODB_TABLES table, and fill the
5374 information_schema.innodb_tables table with related table information
5375 @param[in] thd thread
5376 @param[in,out] tables tables to fill
5377 @return 0 on success */
5378 static int i_s_innodb_tables_fill_table(THD *thd, Table_ref *tables, Item *) {
5379 btr_pcur_t pcur;
5380 const rec_t *rec;
5381 mem_heap_t *heap;
5382 mtr_t mtr;
5383 MDL_ticket *mdl = nullptr;
5384 dict_table_t *dd_tables;
5385
5386 DBUG_TRACE;
5387
5388 /* deny access to user without PROCESS_ACL privilege */
5389 if (check_global_access(thd, PROCESS_ACL)) {
5390 return 0;
5391 }
5392
5393 heap = mem_heap_create(100, UT_LOCATION_HERE);
5394 dict_sys_mutex_enter();
5395 mtr_start(&mtr);
5396
5397 rec = dd_startscan_system(thd, &mdl, &pcur, &mtr, dd_tables_name.c_str(),
5398 &dd_tables);
5399
5400 while (rec) {
5401 dict_table_t *table_rec;
5402 MDL_ticket *mdl_on_tab = nullptr;
5403
5404 /* Fetch the dict_table_t structure corresponding to
5405 this INNODB_TABLES record */
5406 dd_process_dd_tables_rec_and_mtr_commit(heap, rec, &table_rec, dd_tables,
5407 &mdl_on_tab, &mtr);
5408
5409 dict_sys_mutex_exit();
5410 if (table_rec != nullptr) {
5411 i_s_dict_fill_innodb_tables(thd, table_rec, tables->table);
5412 }
5413
5414 mem_heap_empty(heap);
5415
5416 /* Get the next record */
5417 dict_sys_mutex_enter();
5418
5419 if (table_rec != nullptr) {
5420 dd_table_close(table_rec, thd, &mdl_on_tab, true);
5421 }
5422
5423 mtr_start(&mtr);
5424 rec = dd_getnext_system_rec(&pcur, &mtr);
5425 }
5426
5427 mtr_commit(&mtr);
5428 dd_table_close(dd_tables, thd, &mdl, true);
5429
5430 /* Scan mysql.partitions */
5431 mem_heap_empty(heap);
5432 mtr_start(&mtr);
5433
5434 rec = dd_startscan_system(thd, &mdl, &pcur, &mtr, dd_partitions_name.c_str(),
5435 &dd_tables);
5436
5437 while (rec) {
5438 dict_table_t *table_rec;
5439 MDL_ticket *mdl_on_tab = nullptr;
5440
5441 /* Fetch the dict_table_t structure corresponding to
5442 this INNODB_TABLES record */
5443 dd_process_dd_partitions_rec_and_mtr_commit(heap, rec, &table_rec,
5444 dd_tables, &mdl_on_tab, &mtr);
5445
5446 dict_sys_mutex_exit();
5447 if (table_rec != nullptr) {
5448 i_s_dict_fill_innodb_tables(thd, table_rec, tables->table);
5449 }
5450
5451 mem_heap_empty(heap);
5452
5453 /* Get the next record */
5454 dict_sys_mutex_enter();
5455
5456 if (table_rec != nullptr) {
5457 dd_table_close(table_rec, thd, &mdl_on_tab, true);
5458 }
5459
5460 mtr_start(&mtr);
5461 rec = dd_getnext_system_rec(&pcur, &mtr);
5462 }
5463
5464 mtr_commit(&mtr);
5465 dd_table_close(dd_tables, thd, &mdl, true);
5466 dict_sys_mutex_exit();
5467
5468 mem_heap_free(heap);
5469
5470 return 0;
5471 }
5472
5473 /** Bind the dynamic table INFORMATION_SCHEMA.innodb_tables
5474 @param[in,out] p table schema object
5475 @return 0 on success */
5476 static int innodb_tables_init(void *p) {
5477 ST_SCHEMA_TABLE *schema;
5478
5479 DBUG_TRACE;
5480
5481 schema = (ST_SCHEMA_TABLE *)p;
5482
5483 schema->fields_info = innodb_tables_fields_info;
5484 schema->fill_table = i_s_innodb_tables_fill_table;
5485
5486 return 0;
5487 }
5488
5489 struct st_mysql_plugin i_s_innodb_tables = {
5490 /* the plugin type (a MYSQL_XXX_PLUGIN value) */
5491 /* int */
5492 STRUCT_FLD(type, MYSQL_INFORMATION_SCHEMA_PLUGIN),
5493
5494 /* pointer to type-specific plugin descriptor */
5495 /* void* */
5496 STRUCT_FLD(info, &i_s_info),
5497
5498 /* plugin name */
5499 /* const char* */
5500 STRUCT_FLD(name, "INNODB_TABLES"),
5501
5502 /* plugin author (for SHOW PLUGINS) */
5503 /* const char* */
5504 STRUCT_FLD(author, plugin_author),
5505
5506 /* general descriptive text (for SHOW PLUGINS) */
5507 /* const char* */
5508 STRUCT_FLD(descr, "InnoDB INNODB_TABLES"),
5509
5510 /* the plugin license (PLUGIN_LICENSE_XXX) */
5511 /* int */
5512 STRUCT_FLD(license, PLUGIN_LICENSE_GPL),
5513
5514 /* the function to invoke when plugin is loaded */
5515 /* int (*)(void*); */
5516 STRUCT_FLD(init, innodb_tables_init),
5517
5518 /* the function to invoke when plugin is un installed */
5519 /* int (*)(void*); */
5520 STRUCT_FLD(check_uninstall, nullptr),
5521
5522 /* the function to invoke when plugin is unloaded */
5523 /* int (*)(void*); */
5524 STRUCT_FLD(deinit, i_s_common_deinit),
5525
5526 /* plugin version (for SHOW PLUGINS) */
5527 /* unsigned int */
5528 STRUCT_FLD(version, i_s_innodb_plugin_version),
5529
5530 /* SHOW_VAR* */
5531 STRUCT_FLD(status_vars, nullptr),
5532
5533 /* SYS_VAR** */
5534 STRUCT_FLD(system_vars, nullptr),
5535
5536 /* reserved for dependency checking */
5537 /* void* */
5538 STRUCT_FLD(__reserved1, nullptr),
5539
5540 /* Plugin flags */
5541 /* unsigned long */
5542 STRUCT_FLD(flags, 0UL),
5543 };
5544
5545 /** INNODB_TABLESTATS ***********************************************/
5546 /* Fields of the dynamic table INFORMATION_SCHEMA.INNODB_TABLESTATS
5547 Every time any column gets changed, added or removed, please remember
5548 to change i_s_innodb_plugin_version_postfix accordingly, so that
5549 the change can be propagated to server */
5550 static ST_FIELD_INFO innodb_tablestats_fields_info[] = {
5551 #define INNODB_TABLESTATS_ID 0
5552 {STRUCT_FLD(field_name, "TABLE_ID"),
5553 STRUCT_FLD(field_length, MY_INT64_NUM_DECIMAL_DIGITS),
5554 STRUCT_FLD(field_type, MYSQL_TYPE_LONGLONG), STRUCT_FLD(value, 0),
5555 STRUCT_FLD(field_flags, MY_I_S_UNSIGNED), STRUCT_FLD(old_name, ""),
5556 STRUCT_FLD(open_method, 0)},
5557
5558 #define INNODB_TABLESTATS_NAME 1
5559 {STRUCT_FLD(field_name, "NAME"), STRUCT_FLD(field_length, NAME_LEN + 1),
5560 STRUCT_FLD(field_type, MYSQL_TYPE_STRING), STRUCT_FLD(value, 0),
5561 STRUCT_FLD(field_flags, 0), STRUCT_FLD(old_name, ""),
5562 STRUCT_FLD(open_method, 0)},
5563
5564 #define INNODB_TABLESTATS_INIT 2
5565 {STRUCT_FLD(field_name, "STATS_INITIALIZED"),
5566 STRUCT_FLD(field_length, NAME_LEN + 1),
5567 STRUCT_FLD(field_type, MYSQL_TYPE_STRING), STRUCT_FLD(value, 0),
5568 STRUCT_FLD(field_flags, 0), STRUCT_FLD(old_name, ""),
5569 STRUCT_FLD(open_method, 0)},
5570
5571 #define INNODB_TABLESTATS_NROW 3
5572 {STRUCT_FLD(field_name, "NUM_ROWS"),
5573 STRUCT_FLD(field_length, MY_INT64_NUM_DECIMAL_DIGITS),
5574 STRUCT_FLD(field_type, MYSQL_TYPE_LONGLONG), STRUCT_FLD(value, 0),
5575 STRUCT_FLD(field_flags, MY_I_S_UNSIGNED), STRUCT_FLD(old_name, ""),
5576 STRUCT_FLD(open_method, 0)},
5577
5578 #define INNODB_TABLESTATS_CLUST_SIZE 4
5579 {STRUCT_FLD(field_name, "CLUST_INDEX_SIZE"),
5580 STRUCT_FLD(field_length, MY_INT64_NUM_DECIMAL_DIGITS),
5581 STRUCT_FLD(field_type, MYSQL_TYPE_LONGLONG), STRUCT_FLD(value, 0),
5582 STRUCT_FLD(field_flags, MY_I_S_UNSIGNED), STRUCT_FLD(old_name, ""),
5583 STRUCT_FLD(open_method, 0)},
5584
5585 #define INNODB_TABLESTATS_INDEX_SIZE 5
5586 {STRUCT_FLD(field_name, "OTHER_INDEX_SIZE"),
5587 STRUCT_FLD(field_length, MY_INT64_NUM_DECIMAL_DIGITS),
5588 STRUCT_FLD(field_type, MYSQL_TYPE_LONGLONG), STRUCT_FLD(value, 0),
5589 STRUCT_FLD(field_flags, MY_I_S_UNSIGNED), STRUCT_FLD(old_name, ""),
5590 STRUCT_FLD(open_method, 0)},
5591
5592 #define INNODB_TABLESTATS_MODIFIED 6
5593 {STRUCT_FLD(field_name, "MODIFIED_COUNTER"),
5594 STRUCT_FLD(field_length, MY_INT64_NUM_DECIMAL_DIGITS),
5595 STRUCT_FLD(field_type, MYSQL_TYPE_LONGLONG), STRUCT_FLD(value, 0),
5596 STRUCT_FLD(field_flags, MY_I_S_UNSIGNED), STRUCT_FLD(old_name, ""),
5597 STRUCT_FLD(open_method, 0)},
5598
5599 #define INNODB_TABLESTATS_AUTONINC 7
5600 {STRUCT_FLD(field_name, "AUTOINC"),
5601 STRUCT_FLD(field_length, MY_INT64_NUM_DECIMAL_DIGITS),
5602 STRUCT_FLD(field_type, MYSQL_TYPE_LONGLONG), STRUCT_FLD(value, 0),
5603 STRUCT_FLD(field_flags, MY_I_S_UNSIGNED), STRUCT_FLD(old_name, ""),
5604 STRUCT_FLD(open_method, 0)},
5605
5606 #define INNODB_TABLESTATS_TABLE_REF_COUNT 8
5607 {STRUCT_FLD(field_name, "REF_COUNT"),
5608 STRUCT_FLD(field_length, MY_INT32_NUM_DECIMAL_DIGITS),
5609 STRUCT_FLD(field_type, MYSQL_TYPE_LONG), STRUCT_FLD(value, 0),
5610 STRUCT_FLD(field_flags, 0), STRUCT_FLD(old_name, ""),
5611 STRUCT_FLD(open_method, 0)},
5612
5613 END_OF_ST_FIELD_INFO};
5614
5615 /** Populate information_schema.innodb_tablestats table with information
5616 from INNODB_TABLES.
5617 @param[in] thd thread ID
5618 @param[in,out] table table
5619 @param[in] ref_count table reference count
5620 @param[in,out] table_to_fill fill this table
5621 @return 0 on success */
5622 static int i_s_dict_fill_innodb_tablestats(THD *thd, dict_table_t *table,
5623 ulint ref_count,
5624 TABLE *table_to_fill) {
5625 Field **fields;
5626
5627 DBUG_TRACE;
5628
5629 fields = table_to_fill->field;
5630
5631 OK(fields[INNODB_TABLESTATS_ID]->store(longlong(table->id), true));
5632
5633 OK(field_store_string(fields[INNODB_TABLESTATS_NAME], table->name.m_name));
5634
5635 dict_table_stats_lock(table, RW_S_LATCH);
5636
5637 if (table->stat_initialized) {
5638 OK(field_store_string(fields[INNODB_TABLESTATS_INIT], "Initialized"));
5639
5640 OK(fields[INNODB_TABLESTATS_NROW]->store(table->stat_n_rows, true));
5641
5642 OK(fields[INNODB_TABLESTATS_CLUST_SIZE]->store(
5643 table->stat_clustered_index_size, true));
5644
5645 OK(fields[INNODB_TABLESTATS_INDEX_SIZE]->store(
5646 table->stat_sum_of_other_index_sizes, true));
5647
5648 OK(fields[INNODB_TABLESTATS_MODIFIED]->store(table->stat_modified_counter,
5649 true));
5650 } else {
5651 OK(field_store_string(fields[INNODB_TABLESTATS_INIT], "Uninitialized"));
5652
5653 OK(fields[INNODB_TABLESTATS_NROW]->store(0, true));
5654
5655 OK(fields[INNODB_TABLESTATS_CLUST_SIZE]->store(0, true));
5656
5657 OK(fields[INNODB_TABLESTATS_INDEX_SIZE]->store(0, true));
5658
5659 OK(fields[INNODB_TABLESTATS_MODIFIED]->store(0, true));
5660 }
5661
5662 dict_table_stats_unlock(table, RW_S_LATCH);
5663
5664 OK(fields[INNODB_TABLESTATS_AUTONINC]->store(table->autoinc, true));
5665
5666 OK(fields[INNODB_TABLESTATS_TABLE_REF_COUNT]->store(ref_count, true));
5667
5668 OK(schema_table_store_record(thd, table_to_fill));
5669
5670 return 0;
5671 }
5672
5673 /** Function to go through each record in INNODB_TABLES table, and fill the
5674 information_schema.innodb_tablestats table with table statistics
5675 related information
5676 @param[in] thd thread
5677 @param[in,out] tables tables to fill
5678 @return 0 on success */
5679 static int i_s_innodb_tables_fill_table_stats(THD *thd, Table_ref *tables,
5680 Item *) {
5681 btr_pcur_t pcur;
5682 const rec_t *rec;
5683 mem_heap_t *heap;
5684 mtr_t mtr;
5685 MDL_ticket *mdl = nullptr;
5686 dict_table_t *dd_tables;
5687
5688 DBUG_TRACE;
5689
5690 /* deny access to user without PROCESS_ACL privilege */
5691 if (check_global_access(thd, PROCESS_ACL)) {
5692 return 0;
5693 }
5694
5695 heap = mem_heap_create(100, UT_LOCATION_HERE);
5696
5697 /* Prevent DDL to drop tables. */
5698 dict_sys_mutex_enter();
5699 mtr_start(&mtr);
5700 rec = dd_startscan_system(thd, &mdl, &pcur, &mtr, dd_tables_name.c_str(),
5701 &dd_tables);
5702
5703 while (rec) {
5704 dict_table_t *table_rec;
5705 MDL_ticket *mdl_on_tab = nullptr;
5706 ulint ref_count = 0;
5707
5708 /* Fetch the dict_table_t structure corresponding to
5709 this INNODB_TABLES record */
5710 dd_process_dd_tables_rec_and_mtr_commit(heap, rec, &table_rec, dd_tables,
5711 &mdl_on_tab, &mtr);
5712 if (table_rec != nullptr) {
5713 ref_count = table_rec->get_ref_count();
5714 }
5715
5716 dict_sys_mutex_exit();
5717
5718 if (table_rec != nullptr) {
5719 i_s_dict_fill_innodb_tablestats(thd, table_rec, ref_count, tables->table);
5720 }
5721
5722 mem_heap_empty(heap);
5723
5724 /* Get the next record */
5725 dict_sys_mutex_enter();
5726
5727 if (table_rec != nullptr) {
5728 dd_table_close(table_rec, thd, &mdl_on_tab, true);
5729 }
5730
5731 mtr_start(&mtr);
5732 rec = dd_getnext_system_rec(&pcur, &mtr);
5733 }
5734
5735 mtr_commit(&mtr);
5736 dd_table_close(dd_tables, thd, &mdl, true);
5737 dict_sys_mutex_exit();
5738 mem_heap_free(heap);
5739
5740 return 0;
5741 }
5742
5743 /** Bind the dynamic table INFORMATION_SCHEMA.innodb_tablestats
5744 @param[in,out] p table schema object
5745 @return 0 on success */
5746 static int innodb_tablestats_init(void *p) {
5747 ST_SCHEMA_TABLE *schema;
5748
5749 DBUG_TRACE;
5750
5751 schema = (ST_SCHEMA_TABLE *)p;
5752
5753 schema->fields_info = innodb_tablestats_fields_info;
5754 schema->fill_table = i_s_innodb_tables_fill_table_stats;
5755
5756 return 0;
5757 }
5758
5759 struct st_mysql_plugin i_s_innodb_tablestats = {
5760 /* the plugin type (a MYSQL_XXX_PLUGIN value) */
5761 /* int */
5762 STRUCT_FLD(type, MYSQL_INFORMATION_SCHEMA_PLUGIN),
5763
5764 /* pointer to type-specific plugin descriptor */
5765 /* void* */
5766 STRUCT_FLD(info, &i_s_info),
5767
5768 /* plugin name */
5769 /* const char* */
5770 STRUCT_FLD(name, "INNODB_TABLESTATS"),
5771
5772 /* plugin author (for SHOW PLUGINS) */
5773 /* const char* */
5774 STRUCT_FLD(author, plugin_author),
5775
5776 /* general descriptive text (for SHOW PLUGINS) */
5777 /* const char* */
5778 STRUCT_FLD(descr, "InnoDB INNODB_TABLESTATS"),
5779
5780 /* the plugin license (PLUGIN_LICENSE_XXX) */
5781 /* int */
5782 STRUCT_FLD(license, PLUGIN_LICENSE_GPL),
5783
5784 /* the function to invoke when plugin is loaded */
5785 /* int (*)(void*); */
5786 STRUCT_FLD(init, innodb_tablestats_init),
5787
5788 /* the function to invoke when plugin is un installed */
5789 /* int (*)(void*); */
5790 STRUCT_FLD(check_uninstall, nullptr),
5791
5792 /* the function to invoke when plugin is unloaded */
5793 /* int (*)(void*); */
5794 STRUCT_FLD(deinit, i_s_common_deinit),
5795
5796 /* plugin version (for SHOW PLUGINS) */
5797 /* unsigned int */
5798 STRUCT_FLD(version, i_s_innodb_plugin_version),
5799
5800 /* SHOW_VAR* */
5801 STRUCT_FLD(status_vars, nullptr),
5802
5803 /* SYS_VAR** */
5804 STRUCT_FLD(system_vars, nullptr),
5805
5806 /* reserved for dependency checking */
5807 /* void* */
5808 STRUCT_FLD(__reserved1, nullptr),
5809
5810 /* Plugin flags */
5811 /* unsigned long */
5812 STRUCT_FLD(flags, 0UL),
5813 };
5814
5815 /** INNODB_INDEXES **************************************************/
5816 /* Fields of the dynamic table INFORMATION_SCHEMA.INNODB_INDEXES
5817 Every time any column gets changed, added or removed, please remember
5818 to change i_s_innodb_plugin_version_postfix accordingly, so that
5819 the change can be propagated to server */
5820 static ST_FIELD_INFO innodb_sysindex_fields_info[] = {
5821 #define SYS_INDEX_ID 0
5822 {STRUCT_FLD(field_name, "INDEX_ID"),
5823 STRUCT_FLD(field_length, MY_INT64_NUM_DECIMAL_DIGITS),
5824 STRUCT_FLD(field_type, MYSQL_TYPE_LONGLONG), STRUCT_FLD(value, 0),
5825 STRUCT_FLD(field_flags, MY_I_S_UNSIGNED), STRUCT_FLD(old_name, ""),
5826 STRUCT_FLD(open_method, 0)},
5827
5828 #define SYS_INDEX_NAME 1
5829 {STRUCT_FLD(field_name, "NAME"), STRUCT_FLD(field_length, NAME_LEN + 1),
5830 STRUCT_FLD(field_type, MYSQL_TYPE_STRING), STRUCT_FLD(value, 0),
5831 STRUCT_FLD(field_flags, 0), STRUCT_FLD(old_name, ""),
5832 STRUCT_FLD(open_method, 0)},
5833
5834 #define SYS_INDEX_TABLE_ID 2
5835 {STRUCT_FLD(field_name, "TABLE_ID"),
5836 STRUCT_FLD(field_length, MY_INT64_NUM_DECIMAL_DIGITS),
5837 STRUCT_FLD(field_type, MYSQL_TYPE_LONGLONG), STRUCT_FLD(value, 0),
5838 STRUCT_FLD(field_flags, MY_I_S_UNSIGNED), STRUCT_FLD(old_name, ""),
5839 STRUCT_FLD(open_method, 0)},
5840
5841 #define SYS_INDEX_TYPE 3
5842 {STRUCT_FLD(field_name, "TYPE"),
5843 STRUCT_FLD(field_length, MY_INT32_NUM_DECIMAL_DIGITS),
5844 STRUCT_FLD(field_type, MYSQL_TYPE_LONG), STRUCT_FLD(value, 0),
5845 STRUCT_FLD(field_flags, 0), STRUCT_FLD(old_name, ""),
5846 STRUCT_FLD(open_method, 0)},
5847
5848 #define SYS_INDEX_NUM_FIELDS 4
5849 {STRUCT_FLD(field_name, "N_FIELDS"),
5850 STRUCT_FLD(field_length, MY_INT32_NUM_DECIMAL_DIGITS),
5851 STRUCT_FLD(field_type, MYSQL_TYPE_LONG), STRUCT_FLD(value, 0),
5852 STRUCT_FLD(field_flags, 0), STRUCT_FLD(old_name, ""),
5853 STRUCT_FLD(open_method, 0)},
5854
5855 #define SYS_INDEX_PAGE_NO 5
5856 {STRUCT_FLD(field_name, "PAGE_NO"),
5857 STRUCT_FLD(field_length, MY_INT32_NUM_DECIMAL_DIGITS),
5858 STRUCT_FLD(field_type, MYSQL_TYPE_LONG), STRUCT_FLD(value, 0),
5859 STRUCT_FLD(field_flags, 0), STRUCT_FLD(old_name, ""),
5860 STRUCT_FLD(open_method, 0)},
5861
5862 #define SYS_INDEX_SPACE 6
5863 {STRUCT_FLD(field_name, "SPACE"),
5864 STRUCT_FLD(field_length, MY_INT32_NUM_DECIMAL_DIGITS),
5865 STRUCT_FLD(field_type, MYSQL_TYPE_LONG), STRUCT_FLD(value, 0),
5866 STRUCT_FLD(field_flags, 0), STRUCT_FLD(old_name, ""),
5867 STRUCT_FLD(open_method, 0)},
5868
5869 #define SYS_INDEX_MERGE_THRESHOLD 7
5870 {STRUCT_FLD(field_name, "MERGE_THRESHOLD"),
5871 STRUCT_FLD(field_length, MY_INT32_NUM_DECIMAL_DIGITS),
5872 STRUCT_FLD(field_type, MYSQL_TYPE_LONG), STRUCT_FLD(value, 0),
5873 STRUCT_FLD(field_flags, 0), STRUCT_FLD(old_name, ""),
5874 STRUCT_FLD(open_method, 0)},
5875
5876 END_OF_ST_FIELD_INFO};
5877
5878 /** Function to populate the information_schema.innodb_indexes table with
5879 collected index information
5880 @param[in] thd thread
5881 @param[in] index dict_index_t obj
5882 @param[in,out] table_to_fill fill this table
5883 @return 0 on success */
5884 static int i_s_dict_fill_innodb_indexes(THD *thd, const dict_index_t *index,
5885 TABLE *table_to_fill) {
5886 Field **fields;
5887
5888 DBUG_TRACE;
5889
5890 fields = table_to_fill->field;
5891
5892 OK(field_store_index_name(fields[SYS_INDEX_NAME], index->name));
5893
5894 OK(fields[SYS_INDEX_ID]->store(longlong(index->id), true));
5895
5896 OK(fields[SYS_INDEX_TABLE_ID]->store(longlong(index->table->id), true));
5897
5898 OK(fields[SYS_INDEX_TYPE]->store(index->type));
5899
5900 OK(fields[SYS_INDEX_NUM_FIELDS]->store(index->n_fields));
5901
5902 /* FIL_NULL is UINT32_UNDEFINED */
5903 if (index->page == FIL_NULL) {
5904 OK(fields[SYS_INDEX_PAGE_NO]->store(-1));
5905 } else {
5906 OK(fields[SYS_INDEX_PAGE_NO]->store(index->page));
5907 }
5908
5909 OK(fields[SYS_INDEX_SPACE]->store(index->space));
5910
5911 OK(fields[SYS_INDEX_MERGE_THRESHOLD]->store(index->merge_threshold));
5912
5913 OK(schema_table_store_record(thd, table_to_fill));
5914
5915 return 0;
5916 }
5917
5918 /** Function to go through each record in INNODB_INDEXES table, and fill the
5919 information_schema.innodb_indexes table with related index information
5920 @param[in] thd thread
5921 @param[in,out] tables tables to fill
5922 @return 0 on success */
5923 static int i_s_innodb_indexes_fill_table(THD *thd, Table_ref *tables, Item *) {
5924 btr_pcur_t pcur;
5925 const rec_t *rec;
5926 mem_heap_t *heap;
5927 mtr_t mtr;
5928 MDL_ticket *mdl = nullptr;
5929 dict_table_t *dd_indexes;
5930 bool ret;
5931
5932 DBUG_TRACE;
5933
5934 /* deny access to user without PROCESS_ACL privilege */
5935 if (check_global_access(thd, PROCESS_ACL)) {
5936 return 0;
5937 }
5938
5939 heap = mem_heap_create(100, UT_LOCATION_HERE);
5940 dict_sys_mutex_enter();
5941 mtr_start(&mtr);
5942
5943 /* Start scan the mysql.indexes */
5944 rec = dd_startscan_system(thd, &mdl, &pcur, &mtr, dd_indexes_name.c_str(),
5945 &dd_indexes);
5946
5947 /* Process each record in the table */
5948 while (rec) {
5949 const dict_index_t *index_rec;
5950 MDL_ticket *mdl_on_tab = nullptr;
5951 dict_table_t *parent = nullptr;
5952 MDL_ticket *mdl_on_parent = nullptr;
5953
5954 /* Populate a dict_index_t structure with information from
5955 a INNODB_INDEXES row */
5956 ret = dd_process_dd_indexes_rec(heap, rec, &index_rec, &mdl_on_tab, &parent,
5957 &mdl_on_parent, dd_indexes, &mtr);
5958
5959 dict_sys_mutex_exit();
5960
5961 if (ret) {
5962 i_s_dict_fill_innodb_indexes(thd, index_rec, tables->table);
5963 }
5964
5965 mem_heap_empty(heap);
5966
5967 /* Get the next record */
5968 dict_sys_mutex_enter();
5969
5970 if (index_rec != nullptr) {
5971 dd_table_close(index_rec->table, thd, &mdl_on_tab, true);
5972
5973 /* Close parent table if it's a fts aux table. */
5974 if (index_rec->table->is_fts_aux() && parent) {
5975 dd_table_close(parent, thd, &mdl_on_parent, true);
5976 }
5977 }
5978
5979 mtr_start(&mtr);
5980 rec = dd_getnext_system_rec(&pcur, &mtr);
5981 }
5982
5983 mtr_commit(&mtr);
5984 dd_table_close(dd_indexes, thd, &mdl, true);
5985 dict_sys_mutex_exit();
5986 mem_heap_free(heap);
5987
5988 return 0;
5989 }
5990
5991 /** Bind the dynamic table INFORMATION_SCHEMA.innodb_indexes
5992 @param[in,out] p table schema object
5993 @return 0 on success */
5994 static int innodb_indexes_init(void *p) {
5995 ST_SCHEMA_TABLE *schema;
5996
5997 DBUG_TRACE;
5998
5999 schema = (ST_SCHEMA_TABLE *)p;
6000
6001 schema->fields_info = innodb_sysindex_fields_info;
6002 schema->fill_table = i_s_innodb_indexes_fill_table;
6003
6004 return 0;
6005 }
6006
6007 struct st_mysql_plugin i_s_innodb_indexes = {
6008 /* the plugin type (a MYSQL_XXX_PLUGIN value) */
6009 /* int */
6010 STRUCT_FLD(type, MYSQL_INFORMATION_SCHEMA_PLUGIN),
6011
6012 /* pointer to type-specific plugin descriptor */
6013 /* void* */
6014 STRUCT_FLD(info, &i_s_info),
6015
6016 /* plugin name */
6017 /* const char* */
6018 STRUCT_FLD(name, "INNODB_INDEXES"),
6019
6020 /* plugin author (for SHOW PLUGINS) */
6021 /* const char* */
6022 STRUCT_FLD(author, plugin_author),
6023
6024 /* general descriptive text (for SHOW PLUGINS) */
6025 /* const char* */
6026 STRUCT_FLD(descr, "InnoDB INNODB_INDEXES"),
6027
6028 /* the plugin license (PLUGIN_LICENSE_XXX) */
6029 /* int */
6030 STRUCT_FLD(license, PLUGIN_LICENSE_GPL),
6031
6032 /* the function to invoke when plugin is loaded */
6033 /* int (*)(void*); */
6034 STRUCT_FLD(init, innodb_indexes_init),
6035
6036 /* the function to invoke when plugin is un installed */
6037 /* int (*)(void*); */
6038 STRUCT_FLD(check_uninstall, nullptr),
6039
6040 /* the function to invoke when plugin is unloaded */
6041 /* int (*)(void*); */
6042 STRUCT_FLD(deinit, i_s_common_deinit),
6043
6044 /* plugin version (for SHOW PLUGINS) */
6045 /* unsigned int */
6046 STRUCT_FLD(version, i_s_innodb_plugin_version),
6047
6048 /* SHOW_VAR* */
6049 STRUCT_FLD(status_vars, nullptr),
6050
6051 /* SYS_VAR** */
6052 STRUCT_FLD(system_vars, nullptr),
6053
6054 /* reserved for dependency checking */
6055 /* void* */
6056 STRUCT_FLD(__reserved1, nullptr),
6057
6058 /* Plugin flags */
6059 /* unsigned long */
6060 STRUCT_FLD(flags, 0UL),
6061 };
6062
6063 /** INNODB_COLUMNS **************************************************/
6064 /* Fields of the dynamic table INFORMATION_SCHEMA.INNODB_COLUMNS
6065 Every time any column gets changed, added or removed, please remember
6066 to change i_s_innodb_plugin_version_postfix accordingly, so that
6067 the change can be propagated to server */
6068 static ST_FIELD_INFO innodb_columns_fields_info[] = {
6069 #define SYS_COLUMN_TABLE_ID 0
6070 {STRUCT_FLD(field_name, "TABLE_ID"),
6071 STRUCT_FLD(field_length, MY_INT64_NUM_DECIMAL_DIGITS),
6072 STRUCT_FLD(field_type, MYSQL_TYPE_LONGLONG), STRUCT_FLD(value, 0),
6073 STRUCT_FLD(field_flags, MY_I_S_UNSIGNED), STRUCT_FLD(old_name, ""),
6074 STRUCT_FLD(open_method, 0)},
6075
6076 #define SYS_COLUMN_NAME 1
6077 {STRUCT_FLD(field_name, "NAME"), STRUCT_FLD(field_length, NAME_LEN + 1),
6078 STRUCT_FLD(field_type, MYSQL_TYPE_STRING), STRUCT_FLD(value, 0),
6079 STRUCT_FLD(field_flags, 0), STRUCT_FLD(old_name, ""),
6080 STRUCT_FLD(open_method, 0)},
6081
6082 #define SYS_COLUMN_POSITION 2
6083 {STRUCT_FLD(field_name, "POS"),
6084 STRUCT_FLD(field_length, MY_INT64_NUM_DECIMAL_DIGITS),
6085 STRUCT_FLD(field_type, MYSQL_TYPE_LONGLONG), STRUCT_FLD(value, 0),
6086 STRUCT_FLD(field_flags, MY_I_S_UNSIGNED), STRUCT_FLD(old_name, ""),
6087 STRUCT_FLD(open_method, 0)},
6088
6089 #define SYS_COLUMN_MTYPE 3
6090 {STRUCT_FLD(field_name, "MTYPE"),
6091 STRUCT_FLD(field_length, MY_INT32_NUM_DECIMAL_DIGITS),
6092 STRUCT_FLD(field_type, MYSQL_TYPE_LONG), STRUCT_FLD(value, 0),
6093 STRUCT_FLD(field_flags, 0), STRUCT_FLD(old_name, ""),
6094 STRUCT_FLD(open_method, 0)},
6095
6096 #define SYS_COLUMN_PRTYPE 4
6097 {STRUCT_FLD(field_name, "PRTYPE"),
6098 STRUCT_FLD(field_length, MY_INT32_NUM_DECIMAL_DIGITS),
6099 STRUCT_FLD(field_type, MYSQL_TYPE_LONG), STRUCT_FLD(value, 0),
6100 STRUCT_FLD(field_flags, 0), STRUCT_FLD(old_name, ""),
6101 STRUCT_FLD(open_method, 0)},
6102
6103 #define SYS_COLUMN_COLUMN_LEN 5
6104 {STRUCT_FLD(field_name, "LEN"),
6105 STRUCT_FLD(field_length, MY_INT32_NUM_DECIMAL_DIGITS),
6106 STRUCT_FLD(field_type, MYSQL_TYPE_LONG), STRUCT_FLD(value, 0),
6107 STRUCT_FLD(field_flags, 0), STRUCT_FLD(old_name, ""),
6108 STRUCT_FLD(open_method, 0)},
6109
6110 #define SYS_COLUMN_HAS_DEFAULT 6
6111 {STRUCT_FLD(field_name, "HAS_DEFAULT"), STRUCT_FLD(field_length, 1),
6112 STRUCT_FLD(field_type, MYSQL_TYPE_LONG), STRUCT_FLD(value, 0),
6113 STRUCT_FLD(field_flags, 0), STRUCT_FLD(old_name, ""),
6114 STRUCT_FLD(open_method, 0)},
6115
6116 #define SYS_COLUMN_DEFAULT_VALUE 7
6117 {STRUCT_FLD(field_name, "DEFAULT_VALUE"),
6118 /* The length should cover max length of varchar in utf8mb4 */
6119 STRUCT_FLD(field_length, 65536 * 4),
6120 STRUCT_FLD(field_type, MYSQL_TYPE_BLOB), STRUCT_FLD(value, 0),
6121 STRUCT_FLD(field_flags, MY_I_S_MAYBE_NULL), STRUCT_FLD(old_name, ""),
6122 STRUCT_FLD(open_method, 0)},
6123
6124 #ifdef UNIV_DEBUG
6125 #define SYS_COLUMN_VERSION_ADDED 8
6126 {STRUCT_FLD(field_name, "VERSION_ADDED"),
6127 STRUCT_FLD(field_length, MY_INT32_NUM_DECIMAL_DIGITS),
6128 STRUCT_FLD(field_type, MYSQL_TYPE_LONG), STRUCT_FLD(value, 0),
6129 STRUCT_FLD(field_flags, 0), STRUCT_FLD(old_name, ""),
6130 STRUCT_FLD(open_method, 0)},
6131
6132 #define SYS_COLUMN_VERSION_DROPPED 9
6133 {STRUCT_FLD(field_name, "VERSION_DROPPED"),
6134 STRUCT_FLD(field_length, MY_INT32_NUM_DECIMAL_DIGITS),
6135 STRUCT_FLD(field_type, MYSQL_TYPE_LONG), STRUCT_FLD(value, 0),
6136 STRUCT_FLD(field_flags, 0), STRUCT_FLD(old_name, ""),
6137 STRUCT_FLD(open_method, 0)},
6138
6139 #define SYS_COLUMN_PHYSICAL_POS 10
6140 {STRUCT_FLD(field_name, "PHYSICAL_POS"),
6141 STRUCT_FLD(field_length, MY_INT32_NUM_DECIMAL_DIGITS),
6142 STRUCT_FLD(field_type, MYSQL_TYPE_LONG), STRUCT_FLD(value, 0),
6143 STRUCT_FLD(field_flags, 0), STRUCT_FLD(old_name, ""),
6144 STRUCT_FLD(open_method, 0)},
6145 #endif
6146
6147 END_OF_ST_FIELD_INFO};
6148
6149 /** Function to fill the BLOB value for column default value
6150 @param[in,out] field field to store default value
6151 @param[in] default_val default value to fill
6152 @return 0 on success */
6153 static int field_blob_store(Field *field, dict_col_default_t *default_val) {
6154 int ret = 0;
6155
6156 if (default_val->len == UNIV_SQL_NULL) {
6157 field->set_null();
6158 } else {
6159 size_t len = 0;
6160 DD_instant_col_val_coder coder;
6161 const char *value =
6162 coder.encode(default_val->value, default_val->len, &len);
6163
6164 field->set_notnull();
6165 ret = field->store(value, len, field->charset());
6166 }
6167
6168 return (ret);
6169 }
6170
6171 /** Function to populate the information_schema.innodb_columns with
6172 related column information
6173 @param[in] thd thread
6174 @param[in] table_id table id
6175 @param[in] col_name column name
6176 @param[in] column dict_col_t obj
6177 @param[in] nth_v_col virtual column, its sequence number
6178 @param[in,out] table_to_fill fill this table
6179 @return 0 on success */
6180 static int i_s_dict_fill_innodb_columns(THD *thd, table_id_t table_id,
6181 const char *col_name,
6182 dict_col_t *column, ulint nth_v_col,
6183 TABLE *table_to_fill) {
6184 Field **fields;
6185
6186 DBUG_TRACE;
6187
6188 fields = table_to_fill->field;
6189
6190 OK(fields[SYS_COLUMN_TABLE_ID]->store((longlong)table_id, true));
6191
6192 OK(field_store_string(fields[SYS_COLUMN_NAME], col_name));
6193
6194 if (column->is_virtual()) {
6195 ulint pos = dict_create_v_col_pos(nth_v_col, column->ind);
6196 OK(fields[SYS_COLUMN_POSITION]->store(pos, true));
6197 } else {
6198 OK(fields[SYS_COLUMN_POSITION]->store(column->ind, true));
6199 }
6200
6201 OK(fields[SYS_COLUMN_MTYPE]->store(column->mtype));
6202
6203 OK(fields[SYS_COLUMN_PRTYPE]->store(column->prtype));
6204
6205 OK(fields[SYS_COLUMN_COLUMN_LEN]->store(column->len));
6206
6207 if (column->instant_default != nullptr) {
6208 OK(fields[SYS_COLUMN_HAS_DEFAULT]->store(1));
6209 OK(field_blob_store(fields[SYS_COLUMN_DEFAULT_VALUE],
6210 column->instant_default));
6211 } else {
6212 OK(fields[SYS_COLUMN_HAS_DEFAULT]->store(0));
6213 fields[SYS_COLUMN_DEFAULT_VALUE]->set_null();
6214 }
6215
6216 #ifdef UNIV_DEBUG
6217 if (column->is_instant_added()) {
6218 OK(fields[SYS_COLUMN_VERSION_ADDED]->store(column->get_version_added()));
6219 } else {
6220 OK(fields[SYS_COLUMN_VERSION_ADDED]->store(0));
6221 }
6222
6223 if (column->is_instant_dropped()) {
6224 OK(fields[SYS_COLUMN_VERSION_DROPPED]->store(
6225 column->get_version_dropped()));
6226 } else {
6227 OK(fields[SYS_COLUMN_VERSION_DROPPED]->store(0));
6228 }
6229
6230 if (column->get_phy_pos() == UINT32_UNDEFINED) {
6231 OK(fields[SYS_COLUMN_PHYSICAL_POS]->store(-1));
6232 } else {
6233 OK(fields[SYS_COLUMN_PHYSICAL_POS]->store(column->get_phy_pos()));
6234 }
6235
6236 #endif
6237
6238 OK(schema_table_store_record(thd, table_to_fill));
6239
6240 return 0;
6241 }
6242
6243 static void process_rows(THD *thd, Table_ref *tables, const rec_t *rec,
6244 dict_table_t *dd_table, btr_pcur_t &pcur, mtr_t &mtr,
6245 mem_heap_t *heap, bool is_partition) {
6246 ut_ad(dict_sys_mutex_own());
6247
6248 while (rec) {
6249 dict_table_t *table_rec = nullptr;
6250 MDL_ticket *mdl_on_tab = nullptr;
6251
6252 /* Fetch the dict_table_t structure corresponding to this table or
6253 partition record */
6254 if (!is_partition) {
6255 dd_process_dd_tables_rec_and_mtr_commit(heap, rec, &table_rec, dd_table,
6256 &mdl_on_tab, &mtr);
6257 } else {
6258 dd_process_dd_partitions_rec_and_mtr_commit(heap, rec, &table_rec,
6259 dd_table, &mdl_on_tab, &mtr);
6260 }
6261
6262 if (table_rec == nullptr) {
6263 mem_heap_empty(heap);
6264
6265 /* Get the next record */
6266 mtr_start(&mtr);
6267 rec = dd_getnext_system_rec(&pcur, &mtr);
6268 continue;
6269 }
6270
6271 dict_sys_mutex_exit();
6272
6273 /* For each column in the table, fill in innodb_columns. */
6274 dict_col_t *column = table_rec->cols;
6275 const char *name = table_rec->col_names;
6276 dict_v_col_t *v_column = nullptr;
6277 const char *v_name = nullptr;
6278
6279 bool has_virtual_cols = table_rec->n_v_cols > 0 ? true : false;
6280 if (has_virtual_cols) {
6281 v_column = table_rec->v_cols;
6282 v_name = table_rec->v_col_names;
6283 }
6284
6285 uint16_t total_s_cols = table_rec->n_cols;
6286 uint16_t total_v_cols = table_rec->n_v_cols;
6287
6288 DBUG_EXECUTE_IF("show_dropped_column",
6289 total_s_cols = table_rec->get_total_cols(););
6290
6291 for (size_t i = 0, v_i = 0; i < total_s_cols || v_i < total_v_cols;) {
6292 if (i < total_s_cols && (!has_virtual_cols || v_i == total_v_cols ||
6293 column->ind < v_column->m_col.ind)) {
6294 /* Fill up normal column */
6295 ut_ad(!column->is_virtual());
6296
6297 DBUG_EXECUTE_IF(
6298 "show_dropped_column", if (column->is_instant_dropped()) {
6299 i_s_dict_fill_innodb_columns(thd, table_rec->id, name, column,
6300 UINT32_UNDEFINED, tables->table);
6301 });
6302
6303 if (column->is_visible) {
6304 i_s_dict_fill_innodb_columns(thd, table_rec->id, name, column,
6305 UINT32_UNDEFINED, tables->table);
6306 }
6307
6308 column++;
6309 i++;
6310 name += strlen(name) + 1;
6311 } else {
6312 /* Fill up virtual column */
6313 ut_ad(v_column->m_col.is_virtual());
6314 ut_ad(v_i < total_v_cols);
6315
6316 if (v_column->m_col.is_visible) {
6317 uint64_t v_pos =
6318 dict_create_v_col_pos(v_column->v_pos, v_column->m_col.ind);
6319 uint64_t nth_v_col = dict_get_v_col_pos(v_pos);
6320
6321 i_s_dict_fill_innodb_columns(thd, table_rec->id, v_name,
6322 &v_column->m_col, nth_v_col,
6323 tables->table);
6324 }
6325
6326 v_column++;
6327 v_i++;
6328 v_name += strlen(v_name) + 1;
6329 }
6330 }
6331
6332 /* Get the next record */
6333 mem_heap_empty(heap);
6334 dict_sys_mutex_enter();
6335 dd_table_close(table_rec, thd, &mdl_on_tab, true);
6336 mtr_start(&mtr);
6337 rec = dd_getnext_system_rec(&pcur, &mtr);
6338 }
6339 }
6340
6341 /** Function to fill information_schema.innodb_columns with information
6342 collected by scanning INNODB_COLUMNS table.
6343 @param[in] thd thread
6344 @param[in,out] tables tables to fill
6345 @return 0 on success */
6346 static int i_s_innodb_columns_fill_table(THD *thd, Table_ref *tables, Item *) {
6347 btr_pcur_t pcur;
6348 const rec_t *rec;
6349 mem_heap_t *heap;
6350 mtr_t mtr;
6351 MDL_ticket *mdl = nullptr;
6352 dict_table_t *dd_tables;
6353
6354 DBUG_TRACE;
6355
6356 /* deny access to user without PROCESS_ACL privilege */
6357 if (check_global_access(thd, PROCESS_ACL)) {
6358 return 0;
6359 }
6360
6361 heap = mem_heap_create(100, UT_LOCATION_HERE);
6362 dict_sys_mutex_enter();
6363
6364 /* Scan mysql.tables table */
6365 mtr_start(&mtr);
6366 rec = dd_startscan_system(thd, &mdl, &pcur, &mtr, dd_tables_name.c_str(),
6367 &dd_tables);
6368
6369 process_rows(thd, tables, rec, dd_tables, pcur, mtr, heap, false);
6370
6371 mtr_commit(&mtr);
6372 dd_table_close(dd_tables, thd, &mdl, true);
6373
6374 /* Scan mysql.partitions table */
6375 mem_heap_empty(heap);
6376 mtr_start(&mtr);
6377 rec = dd_startscan_system(thd, &mdl, &pcur, &mtr, dd_partitions_name.c_str(),
6378 &dd_tables);
6379
6380 process_rows(thd, tables, rec, dd_tables, pcur, mtr, heap, true);
6381
6382 mtr_commit(&mtr);
6383 dd_table_close(dd_tables, thd, &mdl, true);
6384
6385 dict_sys_mutex_exit();
6386 mem_heap_free(heap);
6387
6388 return 0;
6389 }
6390
6391 /** Bind the dynamic table INFORMATION_SCHEMA.innodb_columns
6392 @param[in,out] p table schema object
6393 @return 0 on success */
6394 static int innodb_columns_init(void *p) {
6395 ST_SCHEMA_TABLE *schema;
6396
6397 DBUG_TRACE;
6398
6399 schema = (ST_SCHEMA_TABLE *)p;
6400
6401 schema->fields_info = innodb_columns_fields_info;
6402 schema->fill_table = i_s_innodb_columns_fill_table;
6403
6404 return 0;
6405 }
6406
6407 struct st_mysql_plugin i_s_innodb_columns = {
6408 /* the plugin type (a MYSQL_XXX_PLUGIN value) */
6409 /* int */
6410 STRUCT_FLD(type, MYSQL_INFORMATION_SCHEMA_PLUGIN),
6411
6412 /* pointer to type-specific plugin descriptor */
6413 /* void* */
6414 STRUCT_FLD(info, &i_s_info),
6415
6416 /* plugin name */
6417 /* const char* */
6418 STRUCT_FLD(name, "INNODB_COLUMNS"),
6419
6420 /* plugin author (for SHOW PLUGINS) */
6421 /* const char* */
6422 STRUCT_FLD(author, plugin_author),
6423
6424 /* general descriptive text (for SHOW PLUGINS) */
6425 /* const char* */
6426 STRUCT_FLD(descr, "InnoDB INNODB_COLUMNS"),
6427
6428 /* the plugin license (PLUGIN_LICENSE_XXX) */
6429 /* int */
6430 STRUCT_FLD(license, PLUGIN_LICENSE_GPL),
6431
6432 /* the function to invoke when plugin is loaded */
6433 /* int (*)(void*); */
6434 STRUCT_FLD(init, innodb_columns_init),
6435
6436 /* the function to invoke when plugin is un installed */
6437 /* int (*)(void*); */
6438 STRUCT_FLD(check_uninstall, nullptr),
6439
6440 /* the function to invoke when plugin is unloaded */
6441 /* int (*)(void*); */
6442 STRUCT_FLD(deinit, i_s_common_deinit),
6443
6444 /* plugin version (for SHOW PLUGINS) */
6445 /* unsigned int */
6446 STRUCT_FLD(version, i_s_innodb_plugin_version),
6447
6448 /* SHOW_VAR* */
6449 STRUCT_FLD(status_vars, nullptr),
6450
6451 /* SYS_VAR** */
6452 STRUCT_FLD(system_vars, nullptr),
6453
6454 /* reserved for dependency checking */
6455 /* void* */
6456 STRUCT_FLD(__reserved1, nullptr),
6457
6458 /* Plugin flags */
6459 /* unsigned long */
6460 STRUCT_FLD(flags, 0UL),
6461 };
6462
6463 /** INNODB_VIRTUAL **************************************************/
6464 /** Fields of the dynamic table INFORMATION_SCHEMA.INNODB_VIRTUAL
6465 Every time any column gets changed, added or removed, please remember
6466 to change i_s_innodb_plugin_version_postfix accordingly, so that
6467 the change can be propagated to server */
6468 static ST_FIELD_INFO innodb_virtual_fields_info[] = {
6469 #define INNODB_VIRTUAL_TABLE_ID 0
6470 {STRUCT_FLD(field_name, "TABLE_ID"),
6471 STRUCT_FLD(field_length, MY_INT64_NUM_DECIMAL_DIGITS),
6472 STRUCT_FLD(field_type, MYSQL_TYPE_LONGLONG), STRUCT_FLD(value, 0),
6473 STRUCT_FLD(field_flags, MY_I_S_UNSIGNED), STRUCT_FLD(old_name, ""),
6474 STRUCT_FLD(open_method, 0)},
6475
6476 #define INNODB_VIRTUAL_POS 1
6477 {STRUCT_FLD(field_name, "POS"),
6478 STRUCT_FLD(field_length, MY_INT32_NUM_DECIMAL_DIGITS),
6479 STRUCT_FLD(field_type, MYSQL_TYPE_LONG), STRUCT_FLD(value, 0),
6480 STRUCT_FLD(field_flags, MY_I_S_UNSIGNED), STRUCT_FLD(old_name, ""),
6481 STRUCT_FLD(open_method, 0)},
6482
6483 #define INNODB_VIRTUAL_BASE_POS 2
6484 {STRUCT_FLD(field_name, "BASE_POS"),
6485 STRUCT_FLD(field_length, MY_INT32_NUM_DECIMAL_DIGITS),
6486 STRUCT_FLD(field_type, MYSQL_TYPE_LONG), STRUCT_FLD(value, 0),
6487 STRUCT_FLD(field_flags, MY_I_S_UNSIGNED), STRUCT_FLD(old_name, ""),
6488 STRUCT_FLD(open_method, 0)},
6489
6490 END_OF_ST_FIELD_INFO};
6491
6492 /** Function to populate the information_schema.innodb_virtual with
6493 related information
6494 param[in] thd thread
6495 param[in] table_id table ID
6496 param[in] pos virtual column position
6497 param[in] base_pos base column position
6498 param[in,out] table_to_fill fill this table
6499 @return 0 on success */
6500 static int i_s_dict_fill_innodb_virtual(THD *thd, table_id_t table_id,
6501 ulint pos, ulint base_pos,
6502 TABLE *table_to_fill) {
6503 Field **fields;
6504
6505 DBUG_TRACE;
6506
6507 fields = table_to_fill->field;
6508
6509 OK(fields[INNODB_VIRTUAL_TABLE_ID]->store(table_id, true));
6510
6511 OK(fields[INNODB_VIRTUAL_POS]->store(pos, true));
6512
6513 OK(fields[INNODB_VIRTUAL_BASE_POS]->store(base_pos, true));
6514
6515 OK(schema_table_store_record(thd, table_to_fill));
6516
6517 return 0;
6518 }
6519
6520 /** Function to fill information_schema.innodb_virtual with information
6521 collected by scanning INNODB_VIRTUAL table.
6522 param[in] thd thread
6523 param[in,out] tables tables to fill
6524 param[in] item condition (not used)
6525 @return 0 on success */
6526 static int i_s_innodb_virtual_fill_table(THD *thd, Table_ref *tables, Item *) {
6527 btr_pcur_t pcur;
6528 const rec_t *rec;
6529 mem_heap_t *heap;
6530 mtr_t mtr;
6531 MDL_ticket *mdl = nullptr;
6532 dict_table_t *dd_columns;
6533 bool ret;
6534
6535 DBUG_TRACE;
6536
6537 /* deny access to user without PROCESS_ACL privilege */
6538 if (check_global_access(thd, PROCESS_ACL)) {
6539 return 0;
6540 }
6541
6542 heap = mem_heap_create(100, UT_LOCATION_HERE);
6543 dict_sys_mutex_enter();
6544 mtr_start(&mtr);
6545
6546 /* Start scan the mysql.columns */
6547 rec = dd_startscan_system(thd, &mdl, &pcur, &mtr, dd_columns_name.c_str(),
6548 &dd_columns);
6549
6550 while (rec) {
6551 table_id_t table_id;
6552 ulint *pos;
6553 ulint *base_pos;
6554 ulint n_row;
6555
6556 /* populate a dict_col_t structure with information from
6557 a row */
6558 ret = dd_process_dd_virtual_columns_rec(
6559 heap, rec, &table_id, &pos, &base_pos, &n_row, dd_columns, &mtr);
6560
6561 dict_sys_mutex_exit();
6562
6563 if (ret) {
6564 for (ulint i = 0; i < n_row; i++) {
6565 i_s_dict_fill_innodb_virtual(thd, table_id, *(pos++), *(base_pos++),
6566 tables->table);
6567 }
6568 }
6569
6570 mem_heap_empty(heap);
6571
6572 /* Get the next record */
6573 dict_sys_mutex_enter();
6574 mtr_start(&mtr);
6575 rec = dd_getnext_system_rec(&pcur, &mtr);
6576 }
6577
6578 mtr_commit(&mtr);
6579 dd_table_close(dd_columns, thd, &mdl, true);
6580 dict_sys_mutex_exit();
6581 mem_heap_free(heap);
6582
6583 return 0;
6584 }
6585
6586 /** Bind the dynamic table INFORMATION_SCHEMA.innodb_virtual
6587 param[in,out] p table schema object
6588 @return 0 on success */
6589 static int innodb_virtual_init(void *p) {
6590 ST_SCHEMA_TABLE *schema;
6591
6592 DBUG_TRACE;
6593
6594 schema = (ST_SCHEMA_TABLE *)p;
6595
6596 schema->fields_info = innodb_virtual_fields_info;
6597 schema->fill_table = i_s_innodb_virtual_fill_table;
6598
6599 return 0;
6600 }
6601
6602 struct st_mysql_plugin i_s_innodb_virtual = {
6603 /* the plugin type (a MYSQL_XXX_PLUGIN value) */
6604 /* int */
6605 STRUCT_FLD(type, MYSQL_INFORMATION_SCHEMA_PLUGIN),
6606
6607 /* pointer to type-specific plugin descriptor */
6608 /* void* */
6609 STRUCT_FLD(info, &i_s_info),
6610
6611 /* plugin name */
6612 /* const char* */
6613 STRUCT_FLD(name, "INNODB_VIRTUAL"),
6614
6615 /* plugin author (for SHOW PLUGINS) */
6616 /* const char* */
6617 STRUCT_FLD(author, plugin_author),
6618
6619 /* general descriptive text (for SHOW PLUGINS) */
6620 /* const char* */
6621 STRUCT_FLD(descr, "InnoDB INNODB_VIRTUAL"),
6622
6623 /* the plugin license (PLUGIN_LICENSE_XXX) */
6624 /* int */
6625 STRUCT_FLD(license, PLUGIN_LICENSE_GPL),
6626
6627 /* the function to invoke when plugin is loaded */
6628 /* int (*)(void*); */
6629 STRUCT_FLD(init, innodb_virtual_init),
6630
6631 /* the function to invoke when plugin is un installed */
6632 /* int (*)(void*); */
6633 STRUCT_FLD(check_uninstall, nullptr),
6634
6635 /* the function to invoke when plugin is unloaded */
6636 /* int (*)(void*); */
6637 STRUCT_FLD(deinit, i_s_common_deinit),
6638
6639 /* plugin version (for SHOW PLUGINS) */
6640 /* unsigned int */
6641 STRUCT_FLD(version, i_s_innodb_plugin_version),
6642
6643 /* SHOW_VAR* */
6644 STRUCT_FLD(status_vars, nullptr),
6645
6646 /* SYS_VAR** */
6647 STRUCT_FLD(system_vars, nullptr),
6648
6649 /* reserved for dependency checking */
6650 /* void* */
6651 STRUCT_FLD(__reserved1, nullptr),
6652
6653 /* Plugin flags */
6654 /* unsigned long */
6655 STRUCT_FLD(flags, 0UL),
6656 };
6657
6658 /** INNODB_TABLESPACES ********************************************/
6659 /* Fields of the dynamic table INFORMATION_SCHEMA.INNODB_TABLESPACES
6660 Every time any column gets changed, added or removed, please remember
6661 to change i_s_innodb_plugin_version_postfix accordingly, so that
6662 the change can be propagated to server */
6663 static ST_FIELD_INFO innodb_tablespaces_fields_info[] = {
6664 #define INNODB_TABLESPACES_SPACE 0
6665 {STRUCT_FLD(field_name, "SPACE"),
6666 STRUCT_FLD(field_length, MY_INT32_NUM_DECIMAL_DIGITS),
6667 STRUCT_FLD(field_type, MYSQL_TYPE_LONG), STRUCT_FLD(value, 0),
6668 STRUCT_FLD(field_flags, MY_I_S_UNSIGNED), STRUCT_FLD(old_name, ""),
6669 STRUCT_FLD(open_method, 0)},
6670
6671 #define INNODB_TABLESPACES_NAME 1
6672 {STRUCT_FLD(field_name, "NAME"),
6673 STRUCT_FLD(field_length, MAX_FULL_NAME_LEN + 1),
6674 STRUCT_FLD(field_type, MYSQL_TYPE_STRING), STRUCT_FLD(value, 0),
6675 STRUCT_FLD(field_flags, 0), STRUCT_FLD(old_name, ""),
6676 STRUCT_FLD(open_method, 0)},
6677
6678 #define INNODB_TABLESPACES_FLAGS 2
6679 {STRUCT_FLD(field_name, "FLAG"),
6680 STRUCT_FLD(field_length, MY_INT32_NUM_DECIMAL_DIGITS),
6681 STRUCT_FLD(field_type, MYSQL_TYPE_LONG), STRUCT_FLD(value, 0),
6682 STRUCT_FLD(field_flags, MY_I_S_UNSIGNED), STRUCT_FLD(old_name, ""),
6683 STRUCT_FLD(open_method, 0)},
6684
6685 #define INNODB_TABLESPACES_ROW_FORMAT 3
6686 {STRUCT_FLD(field_name, "ROW_FORMAT"), STRUCT_FLD(field_length, 22),
6687 STRUCT_FLD(field_type, MYSQL_TYPE_STRING), STRUCT_FLD(value, 0),
6688 STRUCT_FLD(field_flags, MY_I_S_MAYBE_NULL), STRUCT_FLD(old_name, ""),
6689 STRUCT_FLD(open_method, 0)},
6690
6691 #define INNODB_TABLESPACES_PAGE_SIZE 4
6692 {STRUCT_FLD(field_name, "PAGE_SIZE"),
6693 STRUCT_FLD(field_length, MY_INT32_NUM_DECIMAL_DIGITS),
6694 STRUCT_FLD(field_type, MYSQL_TYPE_LONG), STRUCT_FLD(value, 0),
6695 STRUCT_FLD(field_flags, MY_I_S_UNSIGNED), STRUCT_FLD(old_name, ""),
6696 STRUCT_FLD(open_method, 0)},
6697
6698 #define INNODB_TABLESPACES_ZIP_PAGE_SIZE 5
6699 {STRUCT_FLD(field_name, "ZIP_PAGE_SIZE"),
6700 STRUCT_FLD(field_length, MY_INT32_NUM_DECIMAL_DIGITS),
6701 STRUCT_FLD(field_type, MYSQL_TYPE_LONG), STRUCT_FLD(value, 0),
6702 STRUCT_FLD(field_flags, MY_I_S_UNSIGNED), STRUCT_FLD(old_name, ""),
6703 STRUCT_FLD(open_method, 0)},
6704
6705 #define INNODB_TABLESPACES_SPACE_TYPE 6
6706 {STRUCT_FLD(field_name, "SPACE_TYPE"), STRUCT_FLD(field_length, 10),
6707 STRUCT_FLD(field_type, MYSQL_TYPE_STRING), STRUCT_FLD(value, 0),
6708 STRUCT_FLD(field_flags, MY_I_S_MAYBE_NULL), STRUCT_FLD(old_name, ""),
6709 STRUCT_FLD(open_method, 0)},
6710
6711 #define INNODB_TABLESPACES_FS_BLOCK_SIZE 7
6712 {STRUCT_FLD(field_name, "FS_BLOCK_SIZE"),
6713 STRUCT_FLD(field_length, MY_INT32_NUM_DECIMAL_DIGITS),
6714 STRUCT_FLD(field_type, MYSQL_TYPE_LONG), STRUCT_FLD(value, 0),
6715 STRUCT_FLD(field_flags, MY_I_S_UNSIGNED), STRUCT_FLD(old_name, ""),
6716 STRUCT_FLD(open_method, 0)},
6717
6718 #define INNODB_TABLESPACES_FILE_SIZE 8
6719 {STRUCT_FLD(field_name, "FILE_SIZE"),
6720 STRUCT_FLD(field_length, MY_INT64_NUM_DECIMAL_DIGITS),
6721 STRUCT_FLD(field_type, MYSQL_TYPE_LONGLONG), STRUCT_FLD(value, 0),
6722 STRUCT_FLD(field_flags, MY_I_S_UNSIGNED), STRUCT_FLD(old_name, ""),
6723 STRUCT_FLD(open_method, 0)},
6724
6725 #define INNODB_TABLESPACES_ALLOC_SIZE 9
6726 {STRUCT_FLD(field_name, "ALLOCATED_SIZE"),
6727 STRUCT_FLD(field_length, MY_INT64_NUM_DECIMAL_DIGITS),
6728 STRUCT_FLD(field_type, MYSQL_TYPE_LONGLONG), STRUCT_FLD(value, 0),
6729 STRUCT_FLD(field_flags, MY_I_S_UNSIGNED), STRUCT_FLD(old_name, ""),
6730 STRUCT_FLD(open_method, 0)},
6731
6732 #define INNODB_TABLESPACES_AUTOEXTEND_SIZE 10
6733 {STRUCT_FLD(field_name, "AUTOEXTEND_SIZE"),
6734 STRUCT_FLD(field_length, MY_INT64_NUM_DECIMAL_DIGITS),
6735 STRUCT_FLD(field_type, MYSQL_TYPE_LONGLONG), STRUCT_FLD(value, 0),
6736 STRUCT_FLD(field_flags, MY_I_S_UNSIGNED), STRUCT_FLD(old_name, ""),
6737 STRUCT_FLD(open_method, 0)},
6738
6739 #define INNODB_TABLESPACES_SERVER_VERSION 11
6740 {STRUCT_FLD(field_name, "SERVER_VERSION"), STRUCT_FLD(field_length, 10),
6741 STRUCT_FLD(field_type, MYSQL_TYPE_STRING), STRUCT_FLD(value, 0),
6742 STRUCT_FLD(field_flags, MY_I_S_MAYBE_NULL), STRUCT_FLD(old_name, ""),
6743 STRUCT_FLD(open_method, 0)},
6744
6745 #define INNODB_TABLESPACES_SPACE_VERSION 12
6746 {STRUCT_FLD(field_name, "SPACE_VERSION"),
6747 STRUCT_FLD(field_length, MY_INT32_NUM_DECIMAL_DIGITS),
6748 STRUCT_FLD(field_type, MYSQL_TYPE_LONG), STRUCT_FLD(value, 0),
6749 STRUCT_FLD(field_flags, MY_I_S_UNSIGNED), STRUCT_FLD(old_name, ""),
6750 STRUCT_FLD(open_method, 0)},
6751
6752 #define INNODB_TABLESPACES_ENCRYPTION 13
6753 {STRUCT_FLD(field_name, "ENCRYPTION"), STRUCT_FLD(field_length, 1),
6754 STRUCT_FLD(field_type, MYSQL_TYPE_STRING), STRUCT_FLD(value, 0),
6755 STRUCT_FLD(field_flags, MY_I_S_MAYBE_NULL), STRUCT_FLD(old_name, ""),
6756 STRUCT_FLD(open_method, 0)},
6757
6758 #define INNODB_TABLESPACES_STATE 14
6759 {STRUCT_FLD(field_name, "STATE"), STRUCT_FLD(field_length, 10),
6760 STRUCT_FLD(field_type, MYSQL_TYPE_STRING), STRUCT_FLD(value, 0),
6761 STRUCT_FLD(field_flags, MY_I_S_MAYBE_NULL), STRUCT_FLD(old_name, ""),
6762 STRUCT_FLD(open_method, 0)},
6763
6764 END_OF_ST_FIELD_INFO
6765
6766 };
6767
6768 /** Function to fill INFORMATION_SCHEMA.INNODB_TABLESPACES with information
6769 collected by scanning INNODB_TABLESPACESS table.
6770 @param[in] thd thread
6771 @param[in] space_id space ID
6772 @param[in] name tablespace name
6773 @param[in] flags tablespace flags
6774 @param[in] server_version server version
6775 @param[in] space_version tablespace version
6776 @param[in] is_encrypted true if tablespace is encrypted
6777 @param[in] autoextend_size autoextend_size attribute value
6778 @param[in] state tablespace state
6779 @param[in,out] table_to_fill fill this table
6780 @return 0 on success */
6781 static int i_s_dict_fill_innodb_tablespaces(
6782 THD *thd, space_id_t space_id, const char *name, uint32_t flags,
6783 uint32_t server_version, uint32_t space_version, bool is_encrypted,
6784 uint64_t autoextend_size, const char *state, TABLE *table_to_fill) {
6785 Field **fields;
6786 ulint atomic_blobs = FSP_FLAGS_HAS_ATOMIC_BLOBS(flags);
6787 bool is_compressed = FSP_FLAGS_GET_ZIP_SSIZE(flags);
6788 const char *row_format;
6789 const page_size_t page_size(flags);
6790 const char *space_type;
6791 ulint major_version = server_version / 10000;
6792 ulint minor_version = (server_version - (major_version * 10000)) / 100;
6793 ulint patch_version =
6794 server_version - (major_version * 10000) - (minor_version * 100);
6795 char version_str[NAME_LEN];
6796
6797 DBUG_TRACE;
6798
6799 snprintf(version_str, NAME_LEN, ULINTPF "." ULINTPF "." ULINTPF,
6800 major_version, minor_version, patch_version);
6801
6802 if (fsp_is_undo_tablespace(space_id)) {
6803 row_format = "Undo";
6804 } else if (fsp_is_system_or_temp_tablespace(space_id)) {
6805 row_format = "Compact or Redundant";
6806 } else if (fsp_is_shared_tablespace(flags) && !is_compressed) {
6807 row_format = "Any";
6808 } else if (is_compressed) {
6809 row_format = "Compressed";
6810 } else if (atomic_blobs) {
6811 row_format = "Dynamic";
6812 } else {
6813 row_format = "Compact or Redundant";
6814 }
6815
6816 if (fsp_is_undo_tablespace(space_id)) {
6817 space_type = "Undo";
6818 } else if (fsp_is_system_or_temp_tablespace(space_id)) {
6819 space_type = "System";
6820 } else if (fsp_is_shared_tablespace(flags)) {
6821 space_type = "General";
6822 } else {
6823 space_type = "Single";
6824 }
6825
6826 fields = table_to_fill->field;
6827
6828 OK(fields[INNODB_TABLESPACES_SPACE]->store(space_id, true));
6829
6830 OK(field_store_string(fields[INNODB_TABLESPACES_NAME], name));
6831
6832 OK(fields[INNODB_TABLESPACES_FLAGS]->store(flags, true));
6833
6834 OK(field_store_string(fields[INNODB_TABLESPACES_ENCRYPTION],
6835 is_encrypted ? "Y" : "N"));
6836
6837 OK(fields[INNODB_TABLESPACES_AUTOEXTEND_SIZE]->store(autoextend_size, true));
6838
6839 OK(field_store_string(fields[INNODB_TABLESPACES_ROW_FORMAT], row_format));
6840
6841 OK(fields[INNODB_TABLESPACES_PAGE_SIZE]->store(univ_page_size.physical(),
6842 true));
6843
6844 OK(fields[INNODB_TABLESPACES_ZIP_PAGE_SIZE]->store(
6845 page_size.is_compressed() ? page_size.physical() : 0, true));
6846
6847 OK(field_store_string(fields[INNODB_TABLESPACES_SPACE_TYPE], space_type));
6848
6849 OK(field_store_string(fields[INNODB_TABLESPACES_SERVER_VERSION],
6850 version_str));
6851
6852 OK(fields[INNODB_TABLESPACES_SPACE_VERSION]->store(space_version, true));
6853
6854 dict_sys_mutex_enter();
6855 char *filepath = fil_space_get_first_path(space_id);
6856 dict_sys_mutex_exit();
6857
6858 if (filepath == nullptr) {
6859 filepath = Fil_path::make_ibd_from_table_name(name);
6860 }
6861
6862 os_file_stat_t stat;
6863 os_file_size_t file;
6864
6865 memset(&file, 0xff, sizeof(file));
6866 memset(&stat, 0x0, sizeof(stat));
6867
6868 if (filepath != nullptr) {
6869 /* Get the file system (or Volume) block size. */
6870 dberr_t err = os_file_get_status(filepath, &stat, false, false);
6871
6872 switch (err) {
6873 case DB_FAIL:
6874 ib::warn(ER_IB_MSG_603) << "File '" << filepath << "', failed to get "
6875 << "stats";
6876 break;
6877
6878 case DB_SUCCESS:
6879 file = os_file_get_size(filepath);
6880 break;
6881
6882 case DB_NOT_FOUND:
6883 break;
6884
6885 default:
6886 ib::error(ER_IB_MSG_604)
6887 << "File '" << filepath << "' " << ut_strerr(err);
6888 break;
6889 }
6890
6891 ut::free(filepath);
6892 }
6893
6894 if (file.m_total_size == static_cast<os_offset_t>(~0)) {
6895 stat.block_size = 0;
6896 file.m_total_size = 0;
6897 file.m_alloc_size = 0;
6898 }
6899
6900 OK(fields[INNODB_TABLESPACES_FS_BLOCK_SIZE]->store(stat.block_size, true));
6901
6902 OK(fields[INNODB_TABLESPACES_FILE_SIZE]->store(file.m_total_size, true));
6903
6904 OK(fields[INNODB_TABLESPACES_ALLOC_SIZE]->store(file.m_alloc_size, true));
6905
6906 OK(field_store_string(fields[INNODB_TABLESPACES_STATE], state));
6907
6908 OK(schema_table_store_record(thd, table_to_fill));
6909
6910 return 0;
6911 }
6912
6913 /** Function to populate INFORMATION_SCHEMA.INNODB_TABLESPACES table.
6914 Loop through each record in INNODB_TABLESPACES, and extract the column
6915 information and fill the INFORMATION_SCHEMA.INNODB_TABLESPACES table.
6916 @param[in] thd thread
6917 @param[in,out] tables tables to fill
6918 @return 0 on success */
6919 static int i_s_innodb_tablespaces_fill_table(THD *thd, Table_ref *tables,
6920 Item *) {
6921 btr_pcur_t pcur;
6922 const rec_t *rec;
6923 mem_heap_t *heap;
6924 mtr_t mtr;
6925 dict_table_t *dd_spaces;
6926 MDL_ticket *mdl = nullptr;
6927 bool ret;
6928
6929 DBUG_TRACE;
6930
6931 /* deny access to user without PROCESS_ACL privilege */
6932 if (check_global_access(thd, PROCESS_ACL)) {
6933 return 0;
6934 }
6935
6936 heap = mem_heap_create(100, UT_LOCATION_HERE);
6937 dict_sys_mutex_enter();
6938 mtr_start(&mtr);
6939
6940 for (rec = dd_startscan_system(thd, &mdl, &pcur, &mtr,
6941 dd_tablespaces_name.c_str(), &dd_spaces);
6942 rec != nullptr; rec = dd_getnext_system_rec(&pcur, &mtr)) {
6943 space_id_t space;
6944 char *name{nullptr};
6945 uint32_t flags;
6946 uint32_t server_version;
6947 uint32_t space_version;
6948 bool is_encrypted = false;
6949 dd::String_type state;
6950 uint64_t autoextend_size;
6951
6952 /* Extract necessary information from a INNODB_TABLESPACES
6953 row */
6954 ret = dd_process_dd_tablespaces_rec(
6955 heap, rec, &space, &name, &flags, &server_version, &space_version,
6956 &is_encrypted, &autoextend_size, &state, dd_spaces);
6957
6958 mtr_commit(&mtr);
6959 dict_sys_mutex_exit();
6960
6961 if (ret && space != 0) {
6962 i_s_dict_fill_innodb_tablespaces(
6963 thd, space, name, flags, server_version, space_version, is_encrypted,
6964 autoextend_size, state.c_str(), tables->table);
6965 }
6966
6967 mem_heap_empty(heap);
6968
6969 /* Get the next record */
6970 dict_sys_mutex_enter();
6971 mtr_start(&mtr);
6972 }
6973
6974 mtr_commit(&mtr);
6975 dd_table_close(dd_spaces, thd, &mdl, true);
6976 dict_sys_mutex_exit();
6977 mem_heap_free(heap);
6978
6979 return 0;
6980 }
6981 /** Bind the dynamic table INFORMATION_SCHEMA.INNODB_TABLESPACES
6982 @param[in,out] p table schema object
6983 @return 0 on success */
6984 static int innodb_tablespaces_init(void *p) {
6985 ST_SCHEMA_TABLE *schema;
6986
6987 DBUG_TRACE;
6988
6989 schema = (ST_SCHEMA_TABLE *)p;
6990
6991 schema->fields_info = innodb_tablespaces_fields_info;
6992 schema->fill_table = i_s_innodb_tablespaces_fill_table;
6993
6994 return 0;
6995 }
6996
6997 struct st_mysql_plugin i_s_innodb_tablespaces = {
6998 /* the plugin type (a MYSQL_XXX_PLUGIN value) */
6999 /* int */
7000 STRUCT_FLD(type, MYSQL_INFORMATION_SCHEMA_PLUGIN),
7001
7002 /* pointer to type-specific plugin descriptor */
7003 /* void* */
7004 STRUCT_FLD(info, &i_s_info),
7005
7006 /* plugin name */
7007 /* const char* */
7008 STRUCT_FLD(name, "INNODB_TABLESPACES"),
7009
7010 /* plugin author (for SHOW PLUGINS) */
7011 /* const char* */
7012 STRUCT_FLD(author, plugin_author),
7013
7014 /* general descriptive text (for SHOW PLUGINS) */
7015 /* const char* */
7016 STRUCT_FLD(descr, "InnoDB INNODB_TABLESPACES"),
7017
7018 /* the plugin license (PLUGIN_LICENSE_XXX) */
7019 /* int */
7020 STRUCT_FLD(license, PLUGIN_LICENSE_GPL),
7021
7022 /* the function to invoke when plugin is loaded */
7023 /* int (*)(void*); */
7024 STRUCT_FLD(init, innodb_tablespaces_init),
7025
7026 /* the function to invoke when plugin is un installed */
7027 /* int (*)(void*); */
7028 STRUCT_FLD(check_uninstall, nullptr),
7029
7030 /* the function to invoke when plugin is unloaded */
7031 /* int (*)(void*); */
7032 STRUCT_FLD(deinit, i_s_common_deinit),
7033
7034 /* plugin version (for SHOW PLUGINS) */
7035 /* unsigned int */
7036 STRUCT_FLD(version, i_s_innodb_plugin_version),
7037
7038 /* SHOW_VAR* */
7039 STRUCT_FLD(status_vars, nullptr),
7040
7041 /* SYS_VAR** */
7042 STRUCT_FLD(system_vars, nullptr),
7043
7044 /* reserved for dependency checking */
7045 /* void* */
7046 STRUCT_FLD(__reserved1, nullptr),
7047
7048 /* Plugin flags */
7049 /* unsigned long */
7050 STRUCT_FLD(flags, 0UL),
7051 };
7052
7053 /** INFORMATION_SCHEMA.INNODB_CACHED_INDEXES */
7054
7055 /* Fields of the dynamic table INFORMATION_SCHEMA.INNODB_CACHED_INDEXES
7056 Every time any column gets changed, added or removed, please remember
7057 to change i_s_innodb_plugin_version_postfix accordingly, so that
7058 the change can be propagated to server */
7059 static ST_FIELD_INFO innodb_cached_indexes_fields_info[] = {
7060 #define CACHED_INDEXES_SPACE_ID 0
7061 {STRUCT_FLD(field_name, "SPACE_ID"),
7062 STRUCT_FLD(field_length, MY_INT32_NUM_DECIMAL_DIGITS),
7063 STRUCT_FLD(field_type, MYSQL_TYPE_LONG), STRUCT_FLD(value, 0),
7064 STRUCT_FLD(field_flags, MY_I_S_UNSIGNED), STRUCT_FLD(old_name, ""),
7065 STRUCT_FLD(open_method, 0)},
7066
7067 #define CACHED_INDEXES_INDEX_ID 1
7068 {STRUCT_FLD(field_name, "INDEX_ID"),
7069 STRUCT_FLD(field_length, MY_INT64_NUM_DECIMAL_DIGITS),
7070 STRUCT_FLD(field_type, MYSQL_TYPE_LONGLONG), STRUCT_FLD(value, 0),
7071 STRUCT_FLD(field_flags, MY_I_S_UNSIGNED), STRUCT_FLD(old_name, ""),
7072 STRUCT_FLD(open_method, 0)},
7073
7074 #define CACHED_INDEXES_N_CACHED_PAGES 2
7075 {STRUCT_FLD(field_name, "N_CACHED_PAGES"),
7076 STRUCT_FLD(field_length, MY_INT64_NUM_DECIMAL_DIGITS),
7077 STRUCT_FLD(field_type, MYSQL_TYPE_LONGLONG), STRUCT_FLD(value, 0),
7078 STRUCT_FLD(field_flags, MY_I_S_UNSIGNED), STRUCT_FLD(old_name, ""),
7079 STRUCT_FLD(open_method, 0)},
7080
7081 END_OF_ST_FIELD_INFO};
7082
7083 /** Populate INFORMATION_SCHEMA.INNODB_CACHED_INDEXES.
7084 @param[in] thd user thread
7085 @param[in] space_id space id
7086 @param[in] index_id index id
7087 @param[in,out] table_to_fill fill this table
7088 @return 0 on success */
7089 static int i_s_fill_innodb_cached_indexes_row(THD *thd, space_id_t space_id,
7090 ulint index_id,
7091 TABLE *table_to_fill) {
7092 DBUG_TRACE;
7093
7094 const index_id_t idx_id(space_id, index_id);
7095 const uint64_t n = buf_stat_per_index->get(idx_id);
7096
7097 if (n == 0) {
7098 return 0;
7099 }
7100
7101 Field **fields = table_to_fill->field;
7102
7103 OK(fields[CACHED_INDEXES_SPACE_ID]->store(space_id, true));
7104
7105 OK(fields[CACHED_INDEXES_INDEX_ID]->store(index_id, true));
7106
7107 OK(fields[CACHED_INDEXES_N_CACHED_PAGES]->store(n, true));
7108
7109 OK(schema_table_store_record(thd, table_to_fill));
7110
7111 return 0;
7112 }
7113
7114 /** Go through each record in INNODB_INDEXES, and fill
7115 INFORMATION_SCHEMA.INNODB_CACHED_INDEXES.
7116 @param[in] thd thread
7117 @param[in,out] tables tables to fill
7118 @return 0 on success */
7119 static int i_s_innodb_cached_indexes_fill_table(THD *thd, Table_ref *tables,
7120 Item * /* not used */) {
7121 MDL_ticket *mdl = nullptr;
7122 dict_table_t *dd_indexes;
7123 space_id_t space_id;
7124 space_index_t index_id{0};
7125
7126 DBUG_TRACE;
7127
7128 /* deny access to user without PROCESS_ACL privilege */
7129 if (check_global_access(thd, PROCESS_ACL)) {
7130 return 0;
7131 }
7132
7133 mem_heap_t *heap = mem_heap_create(100, UT_LOCATION_HERE);
7134
7135 dict_sys_mutex_enter();
7136
7137 mtr_t mtr;
7138
7139 mtr_start(&mtr);
7140
7141 /* Start the scan of INNODB_INDEXES. */
7142 btr_pcur_t pcur;
7143 const rec_t *rec = dd_startscan_system(thd, &mdl, &pcur, &mtr,
7144 dd_indexes_name.c_str(), &dd_indexes);
7145
7146 /* Process each record in the table. */
7147 while (rec != nullptr) {
7148 /* Populate a dict_index_t structure with an information
7149 from a INNODB_INDEXES row. */
7150 bool ret = dd_process_dd_indexes_rec_simple(heap, rec, &index_id, &space_id,
7151 dd_indexes);
7152
7153 mtr_commit(&mtr);
7154
7155 dict_sys_mutex_exit();
7156
7157 if (ret) {
7158 i_s_fill_innodb_cached_indexes_row(thd, space_id, index_id,
7159 tables->table);
7160 }
7161
7162 mem_heap_empty(heap);
7163
7164 /* Get the next record. */
7165 dict_sys_mutex_enter();
7166
7167 mtr_start(&mtr);
7168
7169 rec = dd_getnext_system_rec(&pcur, &mtr);
7170 }
7171
7172 mtr_commit(&mtr);
7173
7174 dd_table_close(dd_indexes, thd, &mdl, true);
7175
7176 dict_sys_mutex_exit();
7177
7178 mem_heap_free(heap);
7179
7180 return 0;
7181 }
7182
7183 /** Bind the dynamic table INFORMATION_SCHEMA.INNODB_CACHED_INDEXES.
7184 @param[in,out] p table schema object
7185 @return 0 on success */
7186 static int innodb_cached_indexes_init(void *p) {
7187 ST_SCHEMA_TABLE *schema;
7188
7189 DBUG_TRACE;
7190
7191 schema = static_cast<ST_SCHEMA_TABLE *>(p);
7192
7193 schema->fields_info = innodb_cached_indexes_fields_info;
7194 schema->fill_table = i_s_innodb_cached_indexes_fill_table;
7195
7196 return 0;
7197 }
7198
7199 struct st_mysql_plugin i_s_innodb_cached_indexes = {
7200 /* the plugin type (a MYSQL_XXX_PLUGIN value) */
7201 /* int */
7202 STRUCT_FLD(type, MYSQL_INFORMATION_SCHEMA_PLUGIN),
7203
7204 /* pointer to type-specific plugin descriptor */
7205 /* void* */
7206 STRUCT_FLD(info, &i_s_info),
7207
7208 /* plugin name */
7209 /* const char* */
7210 STRUCT_FLD(name, "INNODB_CACHED_INDEXES"),
7211
7212 /* plugin author (for SHOW PLUGINS) */
7213 /* const char* */
7214 STRUCT_FLD(author, plugin_author),
7215
7216 /* general descriptive text (for SHOW PLUGINS) */
7217 /* const char* */
7218 STRUCT_FLD(descr, "InnoDB cached indexes"),
7219
7220 /* the plugin license (PLUGIN_LICENSE_XXX) */
7221 /* int */
7222 STRUCT_FLD(license, PLUGIN_LICENSE_GPL),
7223
7224 /* the function to invoke when plugin is loaded */
7225 /* int (*)(void*); */
7226 STRUCT_FLD(init, innodb_cached_indexes_init),
7227
7228 /* the function to invoke when plugin is un installed */
7229 /* int (*)(void*); */
7230 STRUCT_FLD(check_uninstall, nullptr),
7231
7232 /* the function to invoke when plugin is unloaded */
7233 /* int (*)(void*); */
7234 STRUCT_FLD(deinit, i_s_common_deinit),
7235
7236 /* plugin version (for SHOW PLUGINS) */
7237 /* unsigned int */
7238 STRUCT_FLD(version, i_s_innodb_plugin_version),
7239
7240 /* SHOW_VAR* */
7241 STRUCT_FLD(status_vars, nullptr),
7242
7243 /* SYS_VAR** */
7244 STRUCT_FLD(system_vars, nullptr),
7245
7246 /* reserved for dependency checking */
7247 /* void* */
7248 STRUCT_FLD(__reserved1, nullptr),
7249
7250 /* Plugin flags */
7251 /* unsigned long */
7252 STRUCT_FLD(flags, 0UL),
7253 };
7254
7255 /** INNODB_SESSION_TEMPORARY TABLESPACES ***********************/
7256 /* Fields of the dynamic table
7257 INFORMATION_SCHEMA.INNODB_SESSION_TEMPORARY_TABLESPACES */
7258 static ST_FIELD_INFO innodb_session_temp_tablespaces_fields_info[] = {
7259 #define INNODB_SESSION_TEMP_TABLESPACES_ID 0
7260 {STRUCT_FLD(field_name, "ID"),
7261 STRUCT_FLD(field_length, MY_INT32_NUM_DECIMAL_DIGITS),
7262 STRUCT_FLD(field_type, MYSQL_TYPE_LONG), STRUCT_FLD(value, 0),
7263 STRUCT_FLD(field_flags, MY_I_S_UNSIGNED), STRUCT_FLD(old_name, ""),
7264 STRUCT_FLD(open_method, 0)},
7265
7266 #define INNODB_SESSION_TEMP_TABLESPACES_SPACE 1
7267 {STRUCT_FLD(field_name, "SPACE"),
7268 STRUCT_FLD(field_length, MY_INT32_NUM_DECIMAL_DIGITS),
7269 STRUCT_FLD(field_type, MYSQL_TYPE_LONG), STRUCT_FLD(value, 0),
7270 STRUCT_FLD(field_flags, MY_I_S_UNSIGNED), STRUCT_FLD(old_name, ""),
7271 STRUCT_FLD(open_method, 0)},
7272
7273 #define INNODB_SESSION_TEMP_TABLESPACES_PATH 2
7274 {STRUCT_FLD(field_name, "PATH"),
7275 STRUCT_FLD(field_length, OS_FILE_MAX_PATH + 1),
7276 STRUCT_FLD(field_type, MYSQL_TYPE_STRING), STRUCT_FLD(value, 0),
7277 STRUCT_FLD(field_flags, 0), STRUCT_FLD(old_name, ""),
7278 STRUCT_FLD(open_method, 0)},
7279
7280 #define INNODB_SESSION_TEMP_TABLESPACES_SIZE 3
7281 {STRUCT_FLD(field_name, "SIZE"),
7282 STRUCT_FLD(field_length, MY_INT64_NUM_DECIMAL_DIGITS),
7283 STRUCT_FLD(field_type, MYSQL_TYPE_LONGLONG), STRUCT_FLD(value, 0),
7284 STRUCT_FLD(field_flags, MY_I_S_UNSIGNED), STRUCT_FLD(old_name, ""),
7285 STRUCT_FLD(open_method, 0)},
7286
7287 #define INNODB_SESSION_TEMP_TABLESPACES_STATE 4
7288 {STRUCT_FLD(field_name, "STATE"), STRUCT_FLD(field_length, NAME_LEN),
7289 STRUCT_FLD(field_type, MYSQL_TYPE_STRING), STRUCT_FLD(value, 0),
7290 STRUCT_FLD(field_flags, 0), STRUCT_FLD(old_name, ""),
7291 STRUCT_FLD(open_method, 0)},
7292
7293 #define INNODB_SESSION_TEMP_TABLESPACES_PURPOSE 5
7294 {STRUCT_FLD(field_name, "PURPOSE"), STRUCT_FLD(field_length, NAME_LEN),
7295 STRUCT_FLD(field_type, MYSQL_TYPE_STRING), STRUCT_FLD(value, 0),
7296 STRUCT_FLD(field_flags, 0), STRUCT_FLD(old_name, ""),
7297 STRUCT_FLD(open_method, 0)},
7298
7299 END_OF_ST_FIELD_INFO
7300
7301 };
7302
7303 /** Function to fill INFORMATION_SCHEMA.INNODB_SESSION_TEMPORARY_TABLESPACES
7304 @param[in] thd thread
7305 @param[in] ts temp tablespace object
7306 @param[in,out] table_to_fill fill this table
7307 @return 0 on success */
7308 static int i_s_innodb_session_temp_tablespaces_fill_one(
7309 THD *thd, const ibt::Tablespace *ts, TABLE *table_to_fill) {
7310 Field **fields;
7311
7312 DBUG_TRACE;
7313
7314 fields = table_to_fill->field;
7315
7316 my_thread_id id = ts->thread_id();
7317 OK(fields[INNODB_SESSION_TEMP_TABLESPACES_ID]->store(id, true));
7318
7319 space_id_t space_id = ts->space_id();
7320 OK(fields[INNODB_SESSION_TEMP_TABLESPACES_SPACE]->store(space_id, true));
7321
7322 std::string path = ts->path();
7323 Fil_path::normalize(path);
7324
7325 OK(field_store_string(fields[INNODB_SESSION_TEMP_TABLESPACES_PATH],
7326 path.c_str()));
7327
7328 fil_space_t *space = fil_space_get(space_id);
7329 size_t size = 0;
7330 if (space != nullptr) {
7331 page_size_t page_size(space->flags);
7332 size = space->size * page_size.physical();
7333 }
7334 OK(fields[INNODB_SESSION_TEMP_TABLESPACES_SIZE]->store(size, true));
7335
7336 const char *state = id == 0 ? "INACTIVE" : "ACTIVE";
7337
7338 OK(field_store_string(fields[INNODB_SESSION_TEMP_TABLESPACES_STATE], state));
7339
7340 ibt::tbsp_purpose purpose = ts->purpose();
7341
7342 const char *p =
7343 purpose == ibt::TBSP_NONE
7344 ? "NONE"
7345 : (purpose == ibt::TBSP_USER
7346 ? "USER"
7347 : (purpose == ibt::TBSP_INTRINSIC ? "INTRINSIC" : "SLAVE"));
7348
7349 OK(field_store_string(fields[INNODB_SESSION_TEMP_TABLESPACES_PURPOSE], p));
7350
7351 OK(schema_table_store_record(thd, table_to_fill));
7352
7353 return 0;
7354 }
7355
7356 /** Function to populate INFORMATION_SCHEMA.INNODB_SESSION_TEMPORARY_TABLESPACES
7357 table. Iterate over the in-memory structure and fill the table
7358 @param[in] thd thread
7359 @param[in,out] tables tables to fill
7360 @return 0 on success */
7361 static int i_s_innodb_session_temp_tablespaces_fill(THD *thd, Table_ref *tables,
7362 Item *) {
7363 DBUG_TRACE;
7364
7365 /* deny access to user without PROCESS_ACL privilege */
7366 if (check_global_access(thd, PROCESS_ACL)) {
7367 return 0;
7368 }
7369
7370 /* Allocate one session temp tablespace to avoid allocating a session
7371 temp tabelspaces during iteration of session temp tablespaces.
7372 This is because we have already acquired session pool mutex and iterating.
7373 After acquiring mutex, the I_S query tries to acquire session temp pool
7374 mutex again */
7375 check_trx_exists(thd);
7376 innodb_session_t *innodb_session = thd_to_innodb_session(thd);
7377 innodb_session->get_instrinsic_temp_tblsp();
7378 auto print = [&](const ibt::Tablespace *ts) {
7379 i_s_innodb_session_temp_tablespaces_fill_one(thd, ts, tables->table);
7380 };
7381
7382 ibt::tbsp_pool->iterate_tbsp(print);
7383
7384 return 0;
7385 }
7386
7387 /** Bind the dynamic table
7388 INFORMATION_SCHEMA.INNODB_SESSION_TEMPORARY_TABLESPACES
7389 @param[in,out] p table schema object
7390 @return 0 on success */
7391 static int innodb_session_temp_tablespaces_init(void *p) {
7392 ST_SCHEMA_TABLE *schema;
7393
7394 DBUG_TRACE;
7395
7396 schema = (ST_SCHEMA_TABLE *)p;
7397
7398 schema->fields_info = innodb_session_temp_tablespaces_fields_info;
7399 schema->fill_table = i_s_innodb_session_temp_tablespaces_fill;
7400
7401 return 0;
7402 }
7403
7404 struct st_mysql_plugin i_s_innodb_session_temp_tablespaces = {
7405 /* the plugin type (a MYSQL_XXX_PLUGIN value) */
7406 /* int */
7407 STRUCT_FLD(type, MYSQL_INFORMATION_SCHEMA_PLUGIN),
7408
7409 /* pointer to type-specific plugin descriptor */
7410 /* void* */
7411 STRUCT_FLD(info, &i_s_info),
7412
7413 /* plugin name */
7414 /* const char* */
7415 STRUCT_FLD(name, "INNODB_SESSION_TEMP_TABLESPACES"),
7416
7417 /* plugin author (for SHOW PLUGINS) */
7418 /* const char* */
7419 STRUCT_FLD(author, plugin_author),
7420
7421 /* general descriptive text (for SHOW PLUGINS) */
7422 /* const char* */
7423 STRUCT_FLD(descr, "InnoDB Session Temporary tablespaces"),
7424
7425 /* the plugin license (PLUGIN_LICENSE_XXX) */
7426 /* int */
7427 STRUCT_FLD(license, PLUGIN_LICENSE_GPL),
7428
7429 /* the function to invoke when plugin is loaded */
7430 /* int (*)(void*); */
7431 STRUCT_FLD(init, innodb_session_temp_tablespaces_init),
7432
7433 /* the function to invoke when plugin is un installed */
7434 /* int (*)(void*); */
7435 STRUCT_FLD(check_uninstall, nullptr),
7436
7437 /* the function to invoke when plugin is unloaded */
7438 /* int (*)(void*); */
7439 STRUCT_FLD(deinit, i_s_common_deinit),
7440
7441 /* plugin version (for SHOW PLUGINS) */
7442 /* unsigned int */
7443 STRUCT_FLD(version, INNODB_VERSION_SHORT),
7444
7445 /* SHOW_VAR* */
7446 STRUCT_FLD(status_vars, nullptr),
7447
7448 /* SYS_VAR** */
7449 STRUCT_FLD(system_vars, nullptr),
7450
7451 /* reserved for dependency checking */
7452 /* void* */
7453 STRUCT_FLD(__reserved1, nullptr),
7454
7455 /* Plugin flags */
7456 /* unsigned long */
7457 STRUCT_FLD(flags, 0UL),
7458 };