File: dictionary.h

package info (click to toggle)
mysql-8.0 8.0.43-3
  • links: PTS, VCS
  • area: main
  • in suites: sid
  • size: 1,273,924 kB
  • sloc: cpp: 4,684,605; ansic: 412,450; pascal: 108,398; java: 83,641; perl: 30,221; cs: 27,067; sql: 26,594; sh: 24,181; python: 21,816; yacc: 17,169; php: 11,522; xml: 7,388; javascript: 7,076; makefile: 2,194; lex: 1,075; awk: 670; asm: 520; objc: 183; ruby: 97; lisp: 86
file content (463 lines) | stat: -rw-r--r-- 17,101 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
/* Copyright (c) 2014, 2025, Oracle and/or its affiliates.

   This program is free software; you can redistribute it and/or modify
   it under the terms of the GNU General Public License, version 2.0,
   as published by the Free Software Foundation.

   This program is designed to work with certain software (including
   but not limited to OpenSSL) that is licensed under separate terms,
   as designated in a particular file or component or in included license
   documentation.  The authors of MySQL hereby grant you an additional
   permission to link the program and your derivative works with the
   separately licensed software that they have either included with
   the program or referenced in the documentation.

   This program is distributed in the hope that it will be useful,
   but WITHOUT ANY WARRANTY; without even the implied warranty of
   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
   GNU General Public License, version 2.0, for more details.

   You should have received a copy of the GNU General Public License
   along with this program; if not, write to the Free Software
   Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301  USA */

#ifndef DD__DICTIONARY_INCLUDED
#define DD__DICTIONARY_INCLUDED

#include "sql/dd/string_type.h"  // dd::String_type
#include "sql/dd/types/tablespace.h"

class THD;
class MDL_ticket;
class Plugin_table;
// class Tablespace;

namespace dd {

///////////////////////////////////////////////////////////////////////////

class Collation;
class Object_table;
class Schema;
class Tablespace;

namespace cache {
class Dictionary_client;
}

///////////////////////////////////////////////////////////////////////////

/// Main interface class enabling users to operate on data dictionary.
class Dictionary {
 public:
  /**
    Get dictionary object for a given dictionary table name.
    If the given schema_name and table_name is not a dictionary
    table name, then the function returns NULL.

    @returns Pointer to dictionary object for the given
             dictionary table name, else NULL.
  */
  virtual const Object_table *get_dd_table(
      const String_type &schema_name, const String_type &table_name) const = 0;

 public:
  /////////////////////////////////////////////////////////////////////////
  // Auxiliary operations.
  /////////////////////////////////////////////////////////////////////////

  /**
    Check if the given schema name is 'mysql', which where
    the DD tables are stored.

    @param schema_name    Schema name to check.

    @returns true - If schema_name is 'mysql'
    @returns false - If schema_name is not 'mysql'
  */
  virtual bool is_dd_schema_name(const String_type &schema_name) const = 0;

  /**
    Check if given table name is a dictionary table name.

    @param schema_name    Schema name to check.
    @param table_name     Table name to check.

    @returns true -  If given table name is a dictionary table.
    @returns false - If table name is not a dictionary table.
  */
  virtual bool is_dd_table_name(const String_type &schema_name,
                                const String_type &table_name) const = 0;

  /**
    Check if given table name is a system table name.

    @param schema_name    Schema name to check.
    @param table_name     Table name to check.

    @returns true -  If given table name is a system table.
    @returns false - If table name is not a system table.
  */
  virtual bool is_system_table_name(const String_type &schema_name,
                                    const String_type &table_name) const = 0;

  /**
    Get the error code representing the type name string for a dictionary
    or system table.

    Necessary to support localization of error messages.

    @param schema_name    Schema name to check.
    @param table_name     Table name to check.

    @returns The error code representing the type name associated with the
    table, for being used in error messages.
  */
  virtual int table_type_error_code(const String_type &schema_name,
                                    const String_type &table_name) const = 0;

  /**
    Check if given table name can be accessed by the given thread type.

    @param is_dd_internal_thread    'true' if this is a DD internal
                                    thread.
    @param is_ddl_statement         'true' if this is a DDL statement.
    @param schema_name              Schema name to check.
    @param schema_length            Length of schema name to check.
    @param table_name               Table name to check.

    @returns true -  If given table name is accessible by the thread type.
    @returns false - If table name is not accessible.
  */
  virtual bool is_dd_table_access_allowed(bool is_dd_internal_thread,
                                          bool is_ddl_statement,
                                          const char *schema_name,
                                          size_t schema_length,
                                          const char *table_name) const = 0;

  /**
    Check if given table name is a system view name.

    @param schema_name              Schema name to check.
    @param table_name               Table name to check.
    @param[out] hidden              Pointer to boolean flag indicating
                                    if the object is hidden.

    @returns true -  If given table name is a system view.
    @returns false - If table name is not a system view.
  */
  virtual bool is_system_view_name(const char *schema_name,
                                   const char *table_name,
                                   bool *hidden) const = 0;

  /**
    Check if given table name is a system view name.

    @param schema_name              Schema name to check.
    @param table_name               Table name to check.

    @returns true -  If given table name is a system view.
    @returns false - If table name is not a system view.
  */
  virtual bool is_system_view_name(const char *schema_name,
                                   const char *table_name) const = 0;

 public:
  // Destructor to cleanup data dictionary instance upon server shutdown.
  virtual ~Dictionary() = default;
};

///////////////////////////////////////////////////////////////////////////

//
// MDL wrapper functions
//

/**
  @brief
    Acquire shared metadata lock on the given table name with
    explicit duration.

  @param thd - THD to which lock belongs to.
  @param schema_name    - Schema name
  @param table_name     - Table name
  @param no_wait        - Use try_acquire_lock() if no_wait is true.
                          else use acquire_lock() with
                          thd->variables.lock_wait_timeout timeout value.
  @param out_mdl_ticket - This is a OUT parameter, a pointer to MDL_ticket
                          upon successful lock attempt.

*/
[[nodiscard]] bool acquire_shared_table_mdl(THD *thd, const char *schema_name,
                                            const char *table_name,
                                            bool no_wait,
                                            MDL_ticket **out_mdl_ticket);

/**
  Predicate to check if we have a shared meta data lock on the
  submitted schema qualified table name.

  @param    thd            Thread context.
  @param    schema_name    Schema name.
  @param    table_name     Table name.

  @retval   true           The thread context has a lock.
  @retval   false          The thread context does not have a lock.
*/

bool has_shared_table_mdl(THD *thd, const char *schema_name,
                          const char *table_name);

/**
  Predicate to check if we have an exclusive meta data lock on the
  submitted schema qualified table name.

  @param    thd            Thread context.
  @param    schema_name    Schema name.
  @param    table_name     Table name.

  @retval   true           The thread context has a lock.
  @retval   false          The thread context does not have a lock.
*/

bool has_exclusive_table_mdl(THD *thd, const char *schema_name,
                             const char *table_name);

/**
  Acquire an exclusive metadata lock on the given tablespace name with
  transaction duration.

  @param       thd           THD to which lock belongs.
  @param       tablespace_name  Tablespace name
  @param       no_wait        Use try_acquire_lock() if no_wait is true,
                              else use acquire_lock() with
                              thd->variables.lock_wait_timeout timeout value.
  @param       ticket         ticket for request (optional out parameter)
  @param       for_trx        true if MDL duration is MDL_TRANSACTION
                              false if MDL duration is MDL_EXPLICIT

  @retval      true           Failure, e.g. a lock wait timeout.
  @retval      false          Successful lock acquisition.
*/

[[nodiscard]] bool acquire_exclusive_tablespace_mdl(
    THD *thd, const char *tablespace_name, bool no_wait,
    MDL_ticket **ticket = nullptr, bool for_trx = true);

/**
  Acquire a shared metadata lock on the given tablespace name with
  transaction duration.

  @param       thd           THD to which lock belongs.
  @param       tablespace_name  Tablespace name
  @param       no_wait        Use try_acquire_lock() if no_wait is true,
                              else use acquire_lock() with
                              thd->variables.lock_wait_timeout timeout value.
  @param       ticket         ticket for request (optional out parameter)
  @param       for_trx        true if MDL duration is MDL_TRANSACTION
                              false if MDL duration is MDL_EXPLICIT

  @retval      true           Failure, e.g. a lock wait timeout.
  @retval      false          Successful lock acquisition.
*/
[[nodiscard]] bool acquire_shared_tablespace_mdl(THD *thd,
                                                 const char *tablespace_name,
                                                 bool no_wait,
                                                 MDL_ticket **ticket = nullptr,
                                                 bool for_trx = true);

/**
  Predicate to check if we have a shared meta data lock on the
  submitted tablespace name.

  @param    thd              Thread context.
  @param    tablespace_name  Tablespace name.

  @retval   true             The thread context has a lock.
  @retval   false            The thread context does not have a lock.
*/

bool has_shared_tablespace_mdl(THD *thd, const char *tablespace_name);

/**
  Predicate to check if we have an exclusive meta data lock on the
  submitted tablespace name.

  @param    thd              Thread context.
  @param    tablespace_name  Tablespace name.

  @retval   true             The thread context has a lock.
  @retval   false            The thread context does not have a lock.
*/

bool has_exclusive_tablespace_mdl(THD *thd, const char *tablespace_name);

/**
  Acquire exclusive metadata lock on the given table name with
  TRANSACTIONAL duration.

  @param[in]  thd              THD to which lock belongs to.
  @param[in]  schema_name      Schema name
  @param[in]  table_name       Table name
  @param[in]  no_wait          Use try_acquire_lock() if no_wait is true.
                               else use acquire_lock() with
                               thd->variables.lock_wait_timeout timeout value.
  @param[out] out_mdl_ticket   A pointer to MDL_ticket upon successful lock
                               attempt.
*/

[[nodiscard]] bool acquire_exclusive_table_mdl(THD *thd,
                                               const char *schema_name,
                                               const char *table_name,
                                               bool no_wait,
                                               MDL_ticket **out_mdl_ticket);

/**
  Acquire exclusive metadata lock on the given table name with
  TRANSACTIONAL duration.

  @param[in]  thd               THD to which lock belongs to.
  @param[in]  schema_name       Schema name
  @param[in]  table_name        Table name
  @param[in]  lock_wait_timeout Time to wait.
  @param[out] out_mdl_ticket    A pointer to MDL_ticket upon successful lock
                                attempt.
*/

[[nodiscard]] bool acquire_exclusive_table_mdl(
    THD *thd, const char *schema_name, const char *table_name,
    unsigned long int lock_wait_timeout, MDL_ticket **out_mdl_ticket);

/**
  Acquire exclusive metadata lock on the given schema name with
  explicit duration.

  @param[in]  thd              THD to which lock belongs to.
  @param[in]  schema_name      Schema name
  @param[in]  no_wait          Use try_acquire_lock() if no_wait is true.
                               else use acquire_lock() with
                               thd->variables.lock_wait_timeout timeout value.
  @param[out] out_mdl_ticket   A pointer to MDL_ticket upon successful lock
                               attempt.
*/

[[nodiscard]] bool acquire_exclusive_schema_mdl(THD *thd,
                                                const char *schema_name,
                                                bool no_wait,
                                                MDL_ticket **out_mdl_ticket);

/**
  @brief
    Release MDL_EXPLICIT lock held by a ticket

  @param thd - THD to which lock belongs to.
  @param mdl_ticket - Lock ticket.

*/
void release_mdl(THD *thd, MDL_ticket *mdl_ticket);

/** Get Dictionary_client from THD object (the latter is opaque * in SEs). */
cache::Dictionary_client *get_dd_client(THD *thd);

/**
  Create plugin native table. The API would only write metadata to DD
  and skip calling handler::create().

  @param[in]  thd              THD to which lock belongs to.
  @param[in]  pt               Plugin_table* contain metadata of table to
                               be created.

  @returns false on success, otherwise true.
*/

bool create_native_table(THD *thd, const Plugin_table *pt);

/**
  Remove plugin native table from DD. The API would only update
  metadata to DD and skip calling handler::drop().

  @param[in]  thd              THD to which lock belongs to.
  @param[in]  schema_name      schema name which the table belongs to.
  @param[in]  table_name       table name to be dropped.

  @returns false on success, otherwise true.
*/

bool drop_native_table(THD *thd, const char *schema_name,
                       const char *table_name);

/**
  Reset the tables and tablespace partitions in the DD cache,
  and invalidate the entries in the DDSE cache.

  @note This is a temporary workaround to support proper recovery
        after ha_recover().

  @returns false on success, otherwise true.
*/
bool reset_tables_and_tablespaces();

/**
  Update a tablespace change, commit and release transactional MDL.

  @param[in,out]  thd    Current thread context.
  @param[in,out]  space  Tablespace to update and commit.
  @param[in]      error  true for failure: Do rollback.
                         false for success: Do commit.
  @param[in]      release_mdl_on_commit_only release MDLs only on commit

  @retval true    If error is true, or if failure in update or in commit.
  @retval false   Otherwise.
*/

bool commit_or_rollback_tablespace_change(
    THD *thd, dd::Tablespace *space, bool error,
    bool release_mdl_on_commit_only = false);

/**
  Get the Object_table instance storing the given entity object type.

  We can return this as a reference since all relevant types for which
  this template is used will indeed have a corresponding object table.

  @tparam Entity_object_type   Type for which to get the object table.

  @returns reference to Object_table instance.
*/
template <typename Entity_object_type>
const Object_table &get_dd_table();

/**
  Implicit tablespaces are renamed inside SE. But it is necessary to inform the
  server layer about the rename, specifically which MDLs have been taken, so
  that it can perform the necessary adjustment of MDLs when running in LOCK
  TABLES mode.

  @param thd thread context
  @param src ticket for old name
  @param dst ticket for new name
*/
void rename_tablespace_mdl_hook(THD *thd, MDL_ticket *src, MDL_ticket *dst);

/**
  Execute an ALTER TABLESPACE ... ENCRYPTION statement.

  During recovery of a storage engine, an ALTER TABLESPACE ... ENCRYPTION
  statement may be resumed. This is initiated from the SE, which will first
  set the state as appropriate in the SE, then invoke this method to start
  executing the statement. When the SE is involved during execution of the
  statement, the internal state in the SE will indicate that this is a
  statement that has been initiated and partially executed already.

  @param    thd              Thread context.
  @param    tablespace_name  Name of tablespace to encrypt/decrypt.
  @param    encryption       True to turn on encryption, false to turn off.

  @retval   false if no errors, otherwise true.
*/
bool alter_tablespace_encryption(THD *thd, const char *tablespace_name,
                                 bool encryption);

}  // namespace dd

#endif  // DD__DICTIONARY_INCLUDED