Debian Codegraph @

storage/innobase/include/dict0dict.ic

raw
1 /*****************************************************************************
2
3 Copyright (c) 1996, 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 include/dict0dict.ic
29 Data dictionary system
30
31 Created 1/8/1996 Heikki Tuuri
32 ***********************************************************************/
33
34 #include "data0type.h"
35 #include "dict0load.h"
36 #include "fsp0fsp.h"
37 #include "fsp0sysspace.h"
38 #include "rem0types.h"
39 #include "srv0srv.h"
40 #include "sync0rw.h"
41
42 /** Gets the column number.
43 @return col->ind, table column position (starting from 0) */
44 static inline ulint dict_col_get_no(const dict_col_t *col) /*!< in: column */
45 {
46 ut_ad(col);
47
48 return col->ind;
49 }
50
51 static inline ulint dict_col_get_clust_pos(const dict_col_t *col,
52 const dict_index_t *clust_index) {
53 ulint i;
54
55 ut_ad(col);
56 ut_ad(clust_index);
57 ut_ad(clust_index->is_clustered());
58
59 for (i = 0; i < clust_index->n_def; i++) {
60 const dict_field_t *field = &clust_index->fields[i];
61
62 if (!field->prefix_len && field->col == col) {
63 return (i);
64 }
65 }
66
67 return (ULINT_UNDEFINED);
68 }
69
70 /** Gets the column position in the given index.
71 @param[in] col table column
72 @param[in] index index to be searched for column
73 @return position of column in the given index. */
74 static inline ulint dict_col_get_index_pos(const dict_col_t *col,
75 const dict_index_t *index) {
76 ulint i;
77
78 for (i = 0; i < index->n_def; i++) {
79 const dict_field_t *field = &index->fields[i];
80
81 if (!field->prefix_len && field->col == col) {
82 return (i);
83 }
84 }
85
86 return (ULINT_UNDEFINED);
87 }
88
89 /** Check whether the index consists of descending columns only.
90 @param[in] index index tree
91 @retval true if index has any descending column
92 @retval false if index has only ascending columns */
93 static inline bool dict_index_has_desc(const dict_index_t *index) {
94 ut_ad(index->magic_n == DICT_INDEX_MAGIC_N);
95
96 for (ulint i = 0; i < index->n_def; i++) {
97 const dict_field_t *field = &index->fields[i];
98
99 if (!field->is_ascending) {
100 return (true);
101 }
102 }
103
104 return (false);
105 }
106
107 /** Check if index is auto-generated clustered index.
108 @param[in] index index
109
110 @return true if index is auto-generated clustered index. */
111 static inline bool dict_index_is_auto_gen_clust(const dict_index_t *index) {
112 return (index->type == DICT_CLUSTERED);
113 }
114
115 /** Check whether the index is unique.
116 @return nonzero for unique index, zero for other indexes */
117 static inline ulint dict_index_is_unique(
118 const dict_index_t *index) /*!< in: index */
119 {
120 ut_ad(index);
121 ut_ad(index->magic_n == DICT_INDEX_MAGIC_N);
122
123 return (index->type & DICT_UNIQUE);
124 }
125
126 /** Check whether the index is a Spatial Index.
127 @return nonzero for Spatial Index, zero for other indexes */
128 static inline ulint dict_index_is_spatial(
129 const dict_index_t *index) /*!< in: index */
130 {
131 ut_ad(index);
132 ut_ad(index->magic_n == DICT_INDEX_MAGIC_N);
133
134 return (index->type & DICT_SPATIAL);
135 }
136
137 /** Check whether the index contains a virtual column
138 @param[in] index index
139 @return nonzero for the index has virtual column, zero for other indexes */
140 static inline ulint dict_index_has_virtual(const dict_index_t *index) {
141 ut_ad(index);
142 ut_ad(index->magic_n == DICT_INDEX_MAGIC_N);
143
144 return (index->type & DICT_VIRTUAL);
145 }
146
147 /** Check whether the index is the insert buffer tree.
148 @return nonzero for insert buffer, zero for other indexes */
149 static inline ulint dict_index_is_ibuf(
150 const dict_index_t *index) /*!< in: index */
151 {
152 ut_ad(index);
153 ut_ad(index->magic_n == DICT_INDEX_MAGIC_N);
154
155 return (index->type & DICT_IBUF);
156 }
157
158 /** Check whether the index is a secondary index or the insert buffer tree.
159 @return nonzero for insert buffer, zero for other indexes */
160 static inline ulint dict_index_is_sec_or_ibuf(
161 const dict_index_t *index) /*!< in: index */
162 {
163 ulint type;
164
165 ut_ad(index);
166 ut_ad(index->magic_n == DICT_INDEX_MAGIC_N);
167
168 type = index->type;
169
170 return (!(type & DICT_CLUSTERED) || (type & DICT_IBUF));
171 }
172
173 /** Gets the number of user-defined virtual and non-virtual columns in a table
174 in the dictionary cache.
175 @param[in] table table
176 @return number of user-defined (e.g., not ROW_ID) columns of a table */
177 static inline ulint dict_table_get_n_tot_u_cols(const dict_table_t *table) {
178 ut_ad(table);
179 ut_ad(table->magic_n == DICT_TABLE_MAGIC_N);
180
181 return (table->get_n_user_cols() + dict_table_get_n_v_cols(table));
182 }
183
184 /** Gets the number of virtual columns in a table in the dictionary cache.
185 @param[in] table the table to check
186 @return number of virtual columns of a table */
187 static inline ulint dict_table_get_n_v_cols(const dict_table_t *table) {
188 ut_ad(table);
189 ut_ad(table->magic_n == DICT_TABLE_MAGIC_N);
190
191 return (table->n_v_cols);
192 }
193
194 /** Check if a table has indexed virtual columns
195 @param[in] table the table to check
196 @return true is the table has indexed virtual columns */
197 static inline bool dict_table_has_indexed_v_cols(const dict_table_t *table) {
198 for (ulint i = 0; i < table->n_v_cols; i++) {
199 const dict_v_col_t *col = dict_table_get_nth_v_col(table, i);
200 if (col->m_col.ord_part) {
201 return (true);
202 }
203 }
204
205 return (false);
206 }
207
208 #ifndef UNIV_HOTBACKUP
209 /** Gets the approximately estimated number of rows in the table.
210 @return estimated number of rows */
211 static inline uint64_t dict_table_get_n_rows(
212 const dict_table_t *table) /*!< in: table */
213 {
214 ut_ad(table->stat_initialized);
215
216 return (table->stat_n_rows);
217 }
218
219 /** Increment the number of rows in the table by one.
220 Notice that this operation is not protected by any latch, the number is
221 approximate. */
222 static inline void dict_table_n_rows_inc(
223 dict_table_t *table) /*!< in/out: table */
224 {
225 if (table->stat_initialized) {
226 uint64_t n_rows = table->stat_n_rows;
227 if (n_rows < 0xFFFFFFFFFFFFFFFFULL) {
228 table->stat_n_rows = n_rows + 1;
229 }
230 }
231 }
232
233 /** Decrement the number of rows in the table by one.
234 Notice that this operation is not protected by any latch, the number is
235 approximate. */
236 static inline void dict_table_n_rows_dec(
237 dict_table_t *table) /*!< in/out: table */
238 {
239 if (table->stat_initialized) {
240 uint64_t n_rows = table->stat_n_rows;
241 if (n_rows > 0) {
242 table->stat_n_rows = n_rows - 1;
243 }
244 }
245 }
246 #endif /* !UNIV_HOTBACKUP */
247
248 #ifdef UNIV_DEBUG
249 /** Gets the nth virtual column of a table.
250 @param[in] table table
251 @param[in] pos position of virtual column
252 @return pointer to virtual column object */
253 static inline dict_v_col_t *dict_table_get_nth_v_col(const dict_table_t *table,
254 ulint pos) {
255 ut_ad(table);
256 ut_ad(pos < table->n_v_def);
257 ut_ad(table->magic_n == DICT_TABLE_MAGIC_N);
258
259 return (static_cast<dict_v_col_t *>(table->v_cols) + pos);
260 }
261 #endif /* UNIV_DEBUG */
262
263 static inline ulint dict_table_get_sys_col_no(const dict_table_t *table,
264 ulint sys) {
265 ut_ad(table);
266 ut_ad(sys < table->get_n_sys_cols());
267 ut_ad(table->magic_n == DICT_TABLE_MAGIC_N);
268
269 return (table->n_cols - table->get_n_sys_cols() + sys);
270 }
271
272 /** Check whether the table uses the compact page format.
273 @return true if table uses the compact page format */
274 static inline bool dict_table_is_comp(
275 const dict_table_t *table) /*!< in: table */
276 {
277 ut_ad(table);
278
279 static_assert(DICT_TF_COMPACT == 1, "DICT_TF_COMPACT must be 1");
280
281 return (table->flags & DICT_TF_COMPACT);
282 }
283
284 #ifndef UNIV_HOTBACKUP
285 /************************************************************************
286 Check if the table has an FTS index. */
287 static inline bool dict_table_has_fts_index(
288 /* out: true if table has an FTS index */
289 dict_table_t *table) /* in: table */
290 {
291 ut_ad(table);
292
293 return (DICT_TF2_FLAG_IS_SET(table, DICT_TF2_FTS));
294 }
295
296 /** Validate the table flags.
297 @param[in] flags Table flags
298 @return true if valid. */
299 static inline bool dict_tf_is_valid(uint32_t flags) {
300 bool compact = DICT_TF_GET_COMPACT(flags);
301 uint32_t zip_ssize = DICT_TF_GET_ZIP_SSIZE(flags);
302 bool atomic_blobs = DICT_TF_HAS_ATOMIC_BLOBS(flags);
303 bool data_dir = DICT_TF_HAS_DATA_DIR(flags);
304 bool shared_space = DICT_TF_HAS_SHARED_SPACE(flags);
305 uint32_t unused = DICT_TF_GET_UNUSED(flags);
306
307 /* Make sure there are no bits that we do not know about. */
308 if (unused != 0) {
309 return (false);
310 }
311
312 if (atomic_blobs) {
313 /* ROW_FORMAT=COMPRESSED and ROW_FORMAT=DYNAMIC both use
314 atomic_blobs, which build on the page structure introduced
315 for the COMPACT row format by allowing keys in secondary
316 indexes to be made from data stored off-page in the
317 clustered index. */
318
319 if (!compact) {
320 return (false);
321 }
322
323 } else if (zip_ssize) {
324 /* Antelope does not support COMPRESSED row format. */
325 return (false);
326 }
327
328 if (zip_ssize) {
329 /* COMPRESSED row format must have compact and atomic_blobs
330 bits set and validate the number is within allowed range. */
331
332 if (!compact || !atomic_blobs || zip_ssize > PAGE_ZIP_SSIZE_MAX) {
333 return (false);
334 }
335 }
336
337 /* HAS_DATA_DIR and SHARED_SPACE are mutually exclusive. */
338 if (data_dir && shared_space) {
339 return (false);
340 }
341
342 return (true);
343 }
344
345 /** Validate both table flags and table flags2 and make sure they
346 are compatible.
347 @param[in] flags Table flags
348 @param[in] flags2 Table flags2
349 @return true if valid. */
350 static inline bool dict_tf2_is_valid(uint32_t flags, uint32_t flags2) {
351 if (!dict_tf_is_valid(flags)) {
352 return (false);
353 }
354
355 if ((flags2 & DICT_TF2_UNUSED_BIT_MASK) != 0) {
356 return (false);
357 }
358
359 bool file_per_table = ((flags2 & DICT_TF2_USE_FILE_PER_TABLE) != 0);
360 bool shared_space = DICT_TF_HAS_SHARED_SPACE(flags);
361 if (file_per_table && shared_space) {
362 return (false);
363 }
364
365 return (true);
366 }
367
368 /** Validate a SYS_TABLES TYPE field and return it.
369 @return Same as input after validating it as a SYS_TABLES TYPE field.
370 If there is an error, return ULINT_UNDEFINED. */
371 static inline uint32_t dict_sys_tables_type_validate(
372 uint32_t type, /*!< in: SYS_TABLES.TYPE */
373 uint32_t n_cols) /*!< in: SYS_TABLES.N_COLS */
374 {
375 uint32_t low_order_bit = DICT_TF_GET_COMPACT(type);
376 uint32_t redundant = !(n_cols & DICT_N_COLS_COMPACT);
377 uint32_t zip_ssize = DICT_TF_GET_ZIP_SSIZE(type);
378 uint32_t atomic_blobs = DICT_TF_HAS_ATOMIC_BLOBS(type);
379 uint32_t unused = DICT_TF_GET_UNUSED(type);
380
381 /* The low order bit of SYS_TABLES.TYPE is always set to 1.
382 If !atomic_blobs, this field is the same
383 as dict_table_t::flags. Zero is not allowed here. */
384 if (!low_order_bit) {
385 return (UINT32_UNDEFINED);
386 }
387
388 if (redundant) {
389 if (zip_ssize || atomic_blobs) {
390 return (UINT32_UNDEFINED);
391 }
392 }
393
394 /* Make sure there are no bits that we do not know about. */
395 if (unused) {
396 return (UINT32_UNDEFINED);
397 }
398
399 if (atomic_blobs) {
400 /* ROW_FORMAT=COMPRESSED and ROW_FORMAT=DYNAMIC build on
401 the page structure introduced for the COMPACT row format
402 by allowing keys in secondary indexes to be made from
403 data stored off-page in the clustered index.
404
405 The DICT_N_COLS_COMPACT flag should be in N_COLS,
406 but we already know that. */
407
408 } else if (zip_ssize) {
409 /* Antelope does not support COMPRESSED format. */
410 return (UINT32_UNDEFINED);
411 }
412
413 if (zip_ssize) {
414 /* COMPRESSED row format must have low_order_bit and
415 atomic_blobs bits set and the DICT_N_COLS_COMPACT flag
416 should be in N_COLS, but we already know about the
417 low_order_bit and DICT_N_COLS_COMPACT flags. */
418 if (!atomic_blobs) {
419 return (UINT32_UNDEFINED);
420 }
421
422 /* Validate that the number is within allowed range. */
423 if (zip_ssize > PAGE_ZIP_SSIZE_MAX) {
424 return (UINT32_UNDEFINED);
425 }
426 }
427
428 /* There is nothing to validate for the data_dir field.
429 CREATE TABLE ... DATA DIRECTORY is supported for any row
430 format, so the DATA_DIR flag is compatible with any other
431 table flags. However, it is not used with TEMPORARY tables. */
432
433 /* Return the validated SYS_TABLES.TYPE. */
434 return (type);
435 }
436
437 /** Determine the page format from dict_table_t::flags
438 The low order bit will be zero for REDUNDANT and 1 for COMPACT. For any
439 other row_format, flags is nonzero and DICT_TF_COMPACT will also be set.
440 @return file format version */
441 static inline rec_format_t dict_tf_get_rec_format(
442 uint32_t flags) /*!< in: dict_table_t::flags */
443 {
444 ut_a(dict_tf_is_valid(flags));
445
446 if (!DICT_TF_GET_COMPACT(flags)) {
447 return (REC_FORMAT_REDUNDANT);
448 }
449
450 if (!DICT_TF_HAS_ATOMIC_BLOBS(flags)) {
451 return (REC_FORMAT_COMPACT);
452 }
453
454 if (DICT_TF_GET_ZIP_SSIZE(flags)) {
455 return (REC_FORMAT_COMPRESSED);
456 }
457
458 return (REC_FORMAT_DYNAMIC);
459 }
460 #endif /* !UNIV_HOTBACKUP */
461
462 /** Determine if a table uses atomic BLOBs (no locally stored prefix).
463 @param[in] table InnoDB table
464 @return whether BLOBs are atomic */
465 static inline bool dict_table_has_atomic_blobs(const dict_table_t *table) {
466 return (DICT_TF_HAS_ATOMIC_BLOBS(table->flags));
467 }
468
469 #ifndef UNIV_HOTBACKUP
470 /** Set the various values in a dict_table_t::flags pointer.
471 @param[in,out] flags Pointer to a 4 byte Table Flags
472 @param[in] format File Format
473 @param[in] zip_ssize Zip Shift Size
474 @param[in] use_data_dir Table uses DATA DIRECTORY
475 @param[in] shared_space Table uses a General Shared Tablespace */
476 static inline void dict_tf_set(uint32_t *flags, rec_format_t format,
477 uint32_t zip_ssize, bool use_data_dir,
478 bool shared_space) {
479 switch (format) {
480 case REC_FORMAT_REDUNDANT:
481 *flags = 0;
482 ut_ad(zip_ssize == 0);
483 break;
484 case REC_FORMAT_COMPACT:
485 *flags = DICT_TF_COMPACT;
486 ut_ad(zip_ssize == 0);
487 break;
488 case REC_FORMAT_COMPRESSED:
489 *flags = DICT_TF_COMPACT | (1 << DICT_TF_POS_ATOMIC_BLOBS) |
490 (zip_ssize << DICT_TF_POS_ZIP_SSIZE);
491 break;
492 case REC_FORMAT_DYNAMIC:
493 *flags = DICT_TF_COMPACT | (1 << DICT_TF_POS_ATOMIC_BLOBS);
494 ut_ad(zip_ssize == 0);
495 break;
496 }
497
498 if (use_data_dir) {
499 *flags |= (1 << DICT_TF_POS_DATA_DIR);
500 }
501
502 if (shared_space) {
503 *flags |= (1 << DICT_TF_POS_SHARED_SPACE);
504 }
505 }
506
507 /** Initialize a dict_table_t::flags pointer.
508 @param[in] compact Table uses Compact or greater
509 @param[in] zip_ssize Zip Shift Size (log 2 minus 9)
510 @param[in] atomic_blobs Table uses Compressed or Dynamic
511 @param[in] data_dir Table uses DATA DIRECTORY
512 @param[in] shared_space Table uses a General Shared Tablespace */
513 static inline uint32_t dict_tf_init(bool compact, ulint zip_ssize,
514 bool atomic_blobs, bool data_dir,
515 bool shared_space) {
516 uint32_t flags = 0;
517
518 if (compact) {
519 flags |= DICT_TF_COMPACT;
520 }
521
522 if (zip_ssize) {
523 flags |= (zip_ssize << DICT_TF_POS_ZIP_SSIZE);
524 }
525
526 if (atomic_blobs) {
527 flags |= (1 << DICT_TF_POS_ATOMIC_BLOBS);
528 }
529
530 if (data_dir) {
531 flags |= (1 << DICT_TF_POS_DATA_DIR);
532 }
533
534 if (shared_space) {
535 flags |= (1 << DICT_TF_POS_SHARED_SPACE);
536 }
537
538 ut_ad(dict_tf_is_valid(flags));
539
540 return (flags);
541 }
542
543 /** Convert a 32 bit integer from SYS_TABLES.TYPE to dict_table_t::flags
544 The following chart shows the translation of the low order bit.
545 Other bits are the same.
546 ========================= Low order bit ==========================
547 | REDUNDANT | COMPACT | COMPRESSED and DYNAMIC
548 SYS_TABLES.TYPE | 1 | 1 | 1
549 dict_table_t::flags | 0 | 1 | 1
550 ==================================================================
551 @return ulint containing SYS_TABLES.TYPE */
552 static inline uint32_t dict_sys_tables_type_to_tf(
553 uint32_t type, /*!< in: SYS_TABLES.TYPE field */
554 uint32_t n_cols) /*!< in: SYS_TABLES.N_COLS field */
555 {
556 uint32_t flags;
557 uint32_t redundant = !(n_cols & DICT_N_COLS_COMPACT);
558
559 /* Adjust bit zero. */
560 flags = redundant ? 0 : 1;
561
562 /* ZIP_SSIZE, ATOMIC_BLOBS & DATA_DIR are the same. */
563 flags |= type & (DICT_TF_MASK_ZIP_SSIZE | DICT_TF_MASK_ATOMIC_BLOBS |
564 DICT_TF_MASK_DATA_DIR | DICT_TF_MASK_SHARED_SPACE);
565
566 ut_ad(!DICT_TF_GET_ZIP_SSIZE(flags) || DICT_TF_HAS_ATOMIC_BLOBS(flags));
567
568 return (flags);
569 }
570
571 /** Convert a 32 bit integer table flags to the 32bit integer that is written
572 to a SYS_TABLES.TYPE field. The following chart shows the translation of
573 the low order bit. Other bits are the same.
574 ========================= Low order bit ==========================
575 | REDUNDANT | COMPACT | COMPRESSED and DYNAMIC
576 dict_table_t::flags | 0 | 1 | 1
577 SYS_TABLES.TYPE | 1 | 1 | 1
578 ==================================================================
579 @return ulint containing SYS_TABLES.TYPE */
580 static inline ulint dict_tf_to_sys_tables_type(
581 uint32_t flags) /*!< in: dict_table_t::flags */
582 {
583 ulint type;
584
585 ut_a(dict_tf_is_valid(flags));
586
587 /* Adjust bit zero. It is always 1 in SYS_TABLES.TYPE */
588 type = 1;
589
590 /* ZIP_SSIZE, ATOMIC_BLOBS & DATA_DIR are the same. */
591 type |= flags & (DICT_TF_MASK_ZIP_SSIZE | DICT_TF_MASK_ATOMIC_BLOBS |
592 DICT_TF_MASK_DATA_DIR | DICT_TF_MASK_SHARED_SPACE);
593
594 return (type);
595 }
596 #endif /* !UNIV_HOTBACKUP */
597
598 /** Extract the page size info from table flags.
599 @param[in] flags flags
600 @return a structure containing the compressed and uncompressed
601 page sizes and a boolean indicating if the page is compressed. */
602 static inline const page_size_t dict_tf_get_page_size(uint32_t flags) {
603 const uint32_t zip_ssize = DICT_TF_GET_ZIP_SSIZE(flags);
604
605 if (zip_ssize == 0) {
606 return (univ_page_size);
607 }
608
609 const uint32_t zip_size = (UNIV_ZIP_SIZE_MIN >> 1) << zip_ssize;
610
611 ut_ad(zip_size <= UNIV_ZIP_SIZE_MAX);
612
613 return (page_size_t(zip_size, univ_page_size.logical(), true));
614 }
615
616 /** Get the table page size.
617 @param[in] table table
618 @return a structure containing the compressed and uncompressed
619 page sizes and a boolean indicating if the page is compressed */
620 static inline const page_size_t dict_table_page_size(
621 const dict_table_t *table) {
622 ut_ad(table != nullptr);
623
624 return (dict_tf_get_page_size(table->flags));
625 }
626
627 #ifndef UNIV_HOTBACKUP
628 /** Obtain exclusive locks on all index trees of the table. This is to prevent
629 accessing index trees while InnoDB is updating internal metadata for
630 operations such as FLUSH TABLES. */
631 static inline void dict_table_x_lock_indexes(
632 dict_table_t *table) /*!< in: table */
633 {
634 dict_index_t *index;
635
636 ut_a(table);
637 ut_ad(dict_sys_mutex_own());
638 ut_d(dict_validate_no_purge_rollback_threads());
639
640 /* Loop through each index of the table and lock them */
641 auto clustered_index = table->first_index();
642 for (index = clustered_index->next(); index != nullptr;
643 index = index->next()) {
644 rw_lock_x_lock(dict_index_get_lock(index), UT_LOCATION_HERE);
645 }
646 rw_lock_x_lock(dict_index_get_lock(clustered_index), UT_LOCATION_HERE);
647 }
648
649 /** Release the exclusive locks on all index tree. */
650 static inline void dict_table_x_unlock_indexes(
651 dict_table_t *table) /*!< in: table */
652 {
653 dict_index_t *index;
654
655 ut_a(table);
656 ut_ad(dict_sys_mutex_own());
657
658 for (index = table->first_index(); index != nullptr; index = index->next()) {
659 rw_lock_x_unlock(dict_index_get_lock(index));
660 }
661 }
662 #endif /* !UNIV_HOTBACKUP */
663
664 /** Gets the number of fields in the internal representation of an index,
665 including fields added by the dictionary system.
666 @return number of fields */
667 inline uint16_t dict_index_get_n_fields(
668 const dict_index_t *index) /*!< in: an internal
669 representation of index (in
670 the dictionary cache) */
671 {
672 ut_ad(index);
673 ut_ad(index->magic_n == DICT_INDEX_MAGIC_N);
674
675 if (index->has_row_versions()) {
676 return index->n_total_fields;
677 }
678
679 return index->n_fields;
680 }
681
682 /** Gets the number of fields in the internal representation of an index
683 that uniquely determine the position of an index entry in the index, if
684 we do not take multiversioning into account: in the B-tree use the value
685 returned by dict_index_get_n_unique_in_tree.
686 @return number of fields */
687 inline uint16_t dict_index_get_n_unique(
688 const dict_index_t *index) /*!< in: an internal representation
689 of index (in the dictionary cache) */
690 {
691 ut_ad(index);
692 ut_ad(index->magic_n == DICT_INDEX_MAGIC_N);
693 ut_ad(index->cached);
694
695 return index->n_uniq;
696 }
697
698 /** Gets the number of fields in the internal representation of an index
699 which uniquely determine the position of an index entry in the index, if
700 we also take multiversioning into account.
701 @return number of fields */
702 inline uint16_t dict_index_get_n_unique_in_tree(
703 const dict_index_t *index) /*!< in: an internal representation
704 of index (in the dictionary cache) */
705 {
706 ut_ad(index);
707 ut_ad(index->magic_n == DICT_INDEX_MAGIC_N);
708 ut_ad(index->cached);
709
710 if (index->is_clustered()) {
711 return dict_index_get_n_unique(index);
712 }
713
714 return dict_index_get_n_fields(index);
715 }
716
717 /**
718 Gets the number of fields on nonleaf page level in the internal representation
719 of an index which uniquely determine the position of an index entry in the
720 index, if we also take multiversioning into account. Note, it doesn't
721 include page no field.
722 @param[in] index index
723 @return number of fields */
724 inline uint16_t dict_index_get_n_unique_in_tree_nonleaf(
725 const dict_index_t *index) {
726 ut_ad(index != nullptr);
727 ut_ad(index->magic_n == DICT_INDEX_MAGIC_N);
728 ut_ad(index->cached);
729
730 if (dict_index_is_spatial(index)) {
731 /* For spatial index, on non-leaf page, we have only
732 2 fields(mbr+page_no). So, except page no field,
733 there's one field there. */
734 return DICT_INDEX_SPATIAL_NODEPTR_SIZE;
735 }
736
737 return dict_index_get_n_unique_in_tree(index);
738 }
739
740 /** Gets the number of user-defined ordering fields in the index. In the
741 internal representation of clustered indexes we add the row id to the ordering
742 fields to make a clustered index unique, but this function returns the number
743 of fields the user defined in the index as ordering fields.
744 @return number of fields */
745 inline ulint dict_index_get_n_ordering_defined_by_user(
746 const dict_index_t *index) /*!< in: an internal representation
747 of index (in the dictionary cache) */
748 {
749 return (index->n_user_defined_cols);
750 }
751
752 #ifdef UNIV_DEBUG
753 /** Check if a table is a temporary table with compressed row format,
754 we should always expect false.
755 @param[in] table table
756 @return true if it's a compressed temporary table, false otherwise */
757 inline bool dict_table_is_compressed_temporary(const dict_table_t *table) {
758 if (table->is_temporary()) {
759 ut_ad(fsp_is_system_temporary(table->space));
760
761 return (dict_table_page_size(table).is_compressed());
762 }
763
764 return (false);
765 }
766 #endif /* UNIV_DEBUG */
767
768 /** Gets the space id of the root of the index tree.
769 @return space id */
770 static inline space_id_t dict_index_get_space(
771 const dict_index_t *index) /*!< in: index */
772 {
773 ut_ad(index);
774 ut_ad(index->magic_n == DICT_INDEX_MAGIC_N);
775
776 return (index->space);
777 }
778
779 /** Sets the space id of the root of the index tree. */
780 static inline void dict_index_set_space(
781 dict_index_t *index, /*!< in/out: index */
782 space_id_t space) /*!< in: space id */
783 {
784 ut_ad(index);
785 ut_ad(index->magic_n == DICT_INDEX_MAGIC_N);
786
787 index->space = space;
788 }
789
790 /** Gets the page number of the root of the index tree.
791 @return page number */
792 static inline page_no_t dict_index_get_page(
793 const dict_index_t *index) /*!< in: index */
794 {
795 ut_ad(index);
796 ut_ad(index->magic_n == DICT_INDEX_MAGIC_N);
797
798 return (index->page);
799 }
800
801 /** Gets the read-write lock of the index tree.
802 @return read-write lock */
803 static inline rw_lock_t *dict_index_get_lock(
804 dict_index_t *index) /*!< in: index */
805 {
806 ut_ad(index);
807 ut_ad(index->magic_n == DICT_INDEX_MAGIC_N);
808
809 return (&(index->lock));
810 }
811
812 /** Returns free space reserved for future updates of records. This is
813 relevant only in the case of many consecutive inserts, as updates
814 which make the records bigger might fragment the index.
815 @return number of free bytes on page, reserved for updates */
816 static inline ulint dict_index_get_space_reserve(void) {
817 return (UNIV_PAGE_SIZE / 16);
818 }
819
820 /** Gets the status of online index creation.
821 @return the status */
822 static inline enum online_index_status dict_index_get_online_status(
823 const dict_index_t *index) /*!< in: secondary index */
824 {
825 enum online_index_status status;
826
827 status = (enum online_index_status)index->online_status;
828
829 /* Without the index->lock protection, the online
830 status can change from ONLINE_INDEX_CREATION to
831 ONLINE_INDEX_COMPLETE (or ONLINE_INDEX_ABORTED) in
832 row_log_apply() once log application is done. So to make
833 sure the status is ONLINE_INDEX_CREATION or ONLINE_INDEX_COMPLETE
834 you should always do the recheck after acquiring index->lock */
835
836 #ifdef UNIV_DEBUG
837 switch (status) {
838 case ONLINE_INDEX_COMPLETE:
839 case ONLINE_INDEX_CREATION:
840 case ONLINE_INDEX_ABORTED:
841 case ONLINE_INDEX_ABORTED_DROPPED:
842 return (status);
843 }
844 ut_error;
845 #else /* UNIV_DEBUG */
846 return (status);
847 #endif
848 }
849
850 /** Sets the status of online index creation. */
851 static inline void dict_index_set_online_status(
852 dict_index_t *index, /*!< in/out: index */
853 enum online_index_status status) /*!< in: status */
854 {
855 ut_ad(!(index->type & DICT_FTS));
856 ut_ad(rw_lock_own(dict_index_get_lock(index), RW_LOCK_X));
857
858 #ifdef UNIV_DEBUG
859 switch (dict_index_get_online_status(index)) {
860 case ONLINE_INDEX_COMPLETE:
861 case ONLINE_INDEX_CREATION:
862 break;
863 case ONLINE_INDEX_ABORTED:
864 ut_ad(status == ONLINE_INDEX_ABORTED_DROPPED);
865 break;
866 case ONLINE_INDEX_ABORTED_DROPPED:
867 ut_error;
868 }
869 #endif /* UNIV_DEBUG */
870
871 index->online_status = status;
872 ut_ad(dict_index_get_online_status(index) == status);
873 }
874
875 /** Determines if a secondary index is being or has been created online,
876 or if the table is being rebuilt online, allowing concurrent modifications
877 to the table.
878 @retval true if the index is being or has been built online, or
879 if this is a clustered index and the table is being or has been rebuilt online
880 @retval false if the index has been created or the table has been
881 rebuilt completely */
882 static inline bool dict_index_is_online_ddl(
883 const dict_index_t *index) /*!< in: index */
884 {
885 #ifdef UNIV_DEBUG
886 if (index->is_clustered()) {
887 switch (dict_index_get_online_status(index)) {
888 case ONLINE_INDEX_CREATION:
889 return (true);
890 case ONLINE_INDEX_COMPLETE:
891 return (false);
892 case ONLINE_INDEX_ABORTED:
893 case ONLINE_INDEX_ABORTED_DROPPED:
894 break;
895 }
896 ut_d(ut_error);
897 ut_o(return (false));
898 }
899 #endif /* UNIV_DEBUG */
900
901 return (UNIV_UNLIKELY(dict_index_get_online_status(index) !=
902 ONLINE_INDEX_COMPLETE));
903 }
904
905 static inline ulint dict_table_is_fts_column(ib_vector_t *indexes, ulint col_no,
906 bool is_virtual)
907
908 {
909 ulint i;
910
911 for (i = 0; i < ib_vector_size(indexes); ++i) {
912 dict_index_t *index;
913
914 index = (dict_index_t *)ib_vector_getp(indexes, i);
915
916 if (dict_index_contains_col_or_prefix(index, col_no, is_virtual)) {
917 return (i);
918 }
919 }
920
921 return (ULINT_UNDEFINED);
922 }
923
924 static inline ulint dict_max_field_len_store_undo(dict_table_t *table,
925 const dict_col_t *col) {
926 if (!dict_table_has_atomic_blobs(table)) {
927 return (0);
928 }
929
930 if (col->max_prefix != 0) {
931 return (col->max_prefix);
932 }
933
934 return (REC_VERSION_56_MAX_INDEX_COL_LEN);
935 }
936
937 /** Determine maximum bytes of a virtual column need to be stored
938 in the undo log.
939 @param[in] table dict_table_t for the table
940 @param[in] col_no virtual column number
941 @return maximum bytes of virtual column to be stored in the undo log */
942 static inline ulint dict_max_v_field_len_store_undo(dict_table_t *table,
943 ulint col_no) {
944 const dict_col_t *col = &dict_table_get_nth_v_col(table, col_no)->m_col;
945 ulint max_log_len;
946
947 /* This calculation conforms to the non-virtual column
948 maximum log length calculation:
949 1) if No atomic BLOB, up to REC_ANTELOPE_MAX_INDEX_COL_LEN
950 2) if atomic BLOB, up to col->max_prefix or
951 REC_VERSION_56_MAX_INDEX_COL_LEN, whichever is less */
952 if (dict_table_has_atomic_blobs(table)) {
953 if (DATA_BIG_COL(col) && col->max_prefix > 0) {
954 max_log_len = col->max_prefix;
955 } else {
956 max_log_len = DICT_MAX_FIELD_LEN_BY_FORMAT(table);
957 }
958 } else {
959 max_log_len = REC_ANTELOPE_MAX_INDEX_COL_LEN;
960 }
961
962 return (max_log_len);
963 }
964
965 #ifndef UNIV_HOTBACKUP
966 /** Prevent table eviction by moving a table to the non-LRU list from the
967 LRU list if it is not already there. */
968 static inline void dict_table_prevent_eviction(
969 dict_table_t *table) /*!< in: table to prevent eviction */
970 {
971 ut_ad(dict_sys_mutex_own());
972 if (table->can_be_evicted) {
973 dict_table_move_from_lru_to_non_lru(table);
974 }
975 table->explicitly_non_lru = true;
976 }
977
978 /** Allow the table to be evicted by moving a table to the LRU list from
979 the non-LRU list if it is not already there.
980 @param[in] table InnoDB table object can be evicted */
981 static inline void dict_table_allow_eviction(dict_table_t *table) {
982 ut_ad(dict_sys_mutex_own());
983 if (!table->can_be_evicted) {
984 dict_table_move_from_non_lru_to_lru(table);
985 }
986 table->explicitly_non_lru = false;
987 }
988
989 /** Move this table to non-LRU list for DDL operations if it's
990 currently not there. This also prevents later opening table via DD objects,
991 when the table name in InnoDB doesn't match with DD object.
992 @param[in,out] table Table to put in non-LRU list */
993 static inline void dict_table_ddl_acquire(dict_table_t *table) {
994 ut_ad(dict_sys_mutex_own());
995 if (table->can_be_evicted) {
996 ut_ad(!table->ddl_not_evictable);
997 dict_table_prevent_eviction(table);
998 table->ddl_not_evictable = true;
999 }
1000 }
1001
1002 /** Move this table to LRU list after DDL operations if it was moved
1003 to non-LRU list
1004 @param[in,out] table Table to put in LRU list */
1005 static inline void dict_table_ddl_release(dict_table_t *table) {
1006 ut_ad(dict_sys_mutex_own());
1007 if (table->ddl_not_evictable) {
1008 ut_ad(!table->can_be_evicted);
1009 dict_table_allow_eviction(table);
1010 table->ddl_not_evictable = false;
1011 }
1012 }
1013 #endif /* !UNIV_HOTBACKUP */
1014
1015 /** Check if the tablespace for the table has been discarded.
1016 @return true if the tablespace has been discarded. */
1017 static inline bool dict_table_is_discarded(
1018 const dict_table_t *table) /*!< in: table to check */
1019 {
1020 return (DICT_TF2_FLAG_IS_SET(table, DICT_TF2_DISCARDED));
1021 }
1022
1023 #ifndef UNIV_HOTBACKUP
1024 /** Check whether the table is DDTableBuffer. See class DDTableBuffer
1025 @param[in] table table to check
1026 @return true if this is a DDTableBuffer table. */
1027 static inline bool dict_table_is_table_buffer(const dict_table_t *table) {
1028 return (table == dict_sys->dynamic_metadata);
1029 }
1030 #endif /* !UNIV_HOTBACKUP */
1031
1032 /** Check if the table is in a shared tablespace (System or General).
1033 @param[in] table table to check
1034 @return true if table is in shared tablespace, false if not. */
1035 static inline bool dict_table_in_shared_tablespace(const dict_table_t *table) {
1036 return (fsp_is_system_or_temp_tablespace(table->space) ||
1037 DICT_TF_HAS_SHARED_SPACE(table->flags));
1038 }
1039
1040 #ifndef UNIV_HOTBACKUP
1041 /** Check whether locking is disabled for this table.
1042 Currently this is done for intrinsic table as their visibility is limited
1043 to the connection and the DDTableBuffer as it's protected by
1044 dict_persist->mutex.
1045
1046 @param[in] table table to check
1047 @return true if locking is disabled. */
1048 static inline bool dict_table_is_locking_disabled(const dict_table_t *table) {
1049 return (table->is_intrinsic() || dict_table_is_table_buffer(table));
1050 }
1051 #endif /* !UNIV_HOTBACKUP */
1052
1053 /** Turn-off redo-logging if temporary table. */
1054 static inline void dict_disable_redo_if_temporary(
1055 const dict_table_t *table, /*!< in: table to check */
1056 mtr_t *mtr) /*!< out: mini-transaction */
1057 {
1058 if (table->is_temporary()) {
1059 mtr_set_log_mode(mtr, MTR_LOG_NO_REDO);
1060 }
1061 }
1062
1063 /** Check if the table is found is a file_per_table tablespace.
1064 This test does not use table flags2 since some REDUNDANT tables in the
1065 system tablespace may have garbage in the MIX_LEN field where flags2 is
1066 stored. These garbage MIX_LEN fields were written before v3.23.52.
1067 A patch was added to v3.23.52 which initializes the MIX_LEN field to 0.
1068 Since file-per-table tablespaces were added in 4.1, any SYS_TABLES
1069 record with a non-zero space ID will have a reliable MIX_LEN field.
1070 However, this test does not use flags2 from SYS_TABLES.MIX_LEN. Instead,
1071 assume that if the tablespace is not a predefined system tablespace and it
1072 is not a general shared tablespace, then it must be file-per-table.
1073 Also, during ALTER TABLE, the DICT_TF2_USE_FILE_PER_TABLE flag may not be
1074 set on one of the file-per-table tablespaces.
1075 This test cannot be done on a table in the process of being created
1076 because the space_id will be zero until the tablespace is created.
1077 @param[in] table An existing open table to check
1078 @return true if this table was created as a file-per-table tablespace. */
1079 static inline bool dict_table_is_file_per_table(
1080 const dict_table_t *table) /*!< in: table to check */
1081 {
1082 bool is_file_per_table = !fsp_is_system_or_temp_tablespace(table->space) &&
1083 !DICT_TF_HAS_SHARED_SPACE(table->flags);
1084
1085 /* If the table is file-per-table and it is not redundant, then
1086 it should have the flags2 bit for DICT_TF2_USE_FILE_PER_TABLE. */
1087 /* flags2 is also not set for tables before 5.5 */
1088 ut_ad(!is_file_per_table || !DICT_TF_GET_COMPACT(table->flags) ||
1089 (table->flags2 == 0 ||
1090 DICT_TF2_FLAG_IS_SET(table, DICT_TF2_USE_FILE_PER_TABLE)));
1091
1092 return (is_file_per_table);
1093 }
1094
1095 /** Get index by first field of the index
1096 @return index which is having first field matches
1097 with the field present in field_index position of table */
1098 static inline dict_index_t *dict_table_get_index_on_first_col(
1099 dict_table_t *table, /*!< in: table */
1100 ulint col_index) /*!< in: position of column
1101 in table */
1102 {
1103 ut_a(col_index < table->n_t_cols);
1104
1105 ulint non_v_col_index = col_index;
1106 dict_col_t *column = nullptr;
1107
1108 /** Decrement the col_index if the virtual column encountered
1109 before the col_index of the table. */
1110 for (ulint i = 0; i < table->n_v_cols; i++) {
1111 column = reinterpret_cast<dict_col_t *>(dict_table_get_nth_v_col(table, i));
1112
1113 if (column->ind >= col_index) {
1114 break;
1115 }
1116
1117 non_v_col_index--;
1118 }
1119
1120 column = table->get_col(non_v_col_index);
1121
1122 for (dict_index_t *index = table->first_index(); index != nullptr;
1123 index = index->next()) {
1124 if (index->fields[0].col == column) {
1125 return (index);
1126 }
1127 }
1128 ut_error;
1129 }
1130
1131 /** Get table session row-id and increment the row-id counter for next use.
1132 @param[in,out] table table handler
1133 @return next table session row-id. */
1134 static inline row_id_t dict_table_get_next_table_sess_row_id(
1135 dict_table_t *table) {
1136 return (++table->sess_row_id);
1137 }
1138
1139 /** Get table session trx-id and increment the trx-id counter for next use.
1140 @param[in,out] table table handler
1141 @return next table session trx-id. */
1142 static inline trx_id_t dict_table_get_next_table_sess_trx_id(
1143 dict_table_t *table) {
1144 return (++table->sess_trx_id);
1145 }
1146
1147 /** Get current session trx-id.
1148 @param[in] table table handler
1149 @return table session trx-id. */
1150 static inline trx_id_t dict_table_get_curr_table_sess_trx_id(
1151 const dict_table_t *table) {
1152 return (table->sess_trx_id);
1153 }
1154
1155 /** Get reference count.
1156 @return current value of n_ref_count */
1157 inline uint64_t dict_table_t::get_ref_count() const { return (n_ref_count); }
1158
1159 /** Acquire the table handle. */
1160 inline void dict_table_t::acquire() {
1161 ut_ad(dict_sys_mutex_own() || is_intrinsic());
1162 MONITOR_INC(MONITOR_TABLE_REFERENCE);
1163 ++n_ref_count;
1164 }
1165
1166 inline void dict_table_t::acquire_with_lock() {
1167 ut_ad(dict_sys_mutex_own());
1168 ut_ad(!is_intrinsic());
1169
1170 /* Acquiring the lock first, to prevent race between n_ref_count and
1171 stat_initialized in dict_table_close(). This lock makes sure the close
1172 code path either destroys the stats information before increasing
1173 n_ref_count, or finds the n_ref_count is not 0, so not to destroy the stats
1174 information. */
1175 lock();
1176 MONITOR_INC(MONITOR_TABLE_REFERENCE);
1177 ++n_ref_count;
1178 unlock();
1179 }
1180
1181 /** Release the table handle. */
1182 inline void dict_table_t::release() {
1183 ut_ad(n_ref_count > 0);
1184 MONITOR_DEC(MONITOR_TABLE_REFERENCE);
1185 --n_ref_count;
1186 }
1187
1188 #ifndef UNIV_HOTBACKUP
1189 /** Allocate the mutex of the given table.
1190 This function must not be called concurrently on the same table object.
1191 @param[in] table_void table whose mutex to create */
1192 inline void dict_table_mutex_alloc(void *table_void) {
1193 dict_table_t *table = static_cast<dict_table_t *>(table_void);
1194
1195 table->mutex = ut::new_withkey<ib_mutex_t>(UT_NEW_THIS_FILE_PSI_KEY);
1196 ut_ad(table->mutex != nullptr);
1197 mutex_create(LATCH_ID_DICT_TABLE, table->mutex);
1198 }
1199 #endif /* !UNIV_HOTBACKUP */
1200
1201 /** Lock the table handle. */
1202 inline void dict_table_t::lock() {
1203 #ifndef UNIV_HOTBACKUP
1204 os_once::do_or_wait_for_done(&mutex_created, dict_table_mutex_alloc, this);
1205
1206 mutex_enter(mutex);
1207 #endif /* !UNIV_HOTBACKUP */
1208 }
1209
1210 /** Unlock the table handle. */
1211 inline void dict_table_t::unlock() {
1212 #ifndef UNIV_HOTBACKUP
1213 mutex_exit(mutex);
1214 #endif /* !UNIV_HOTBACKUP */
1215 }
1216
1217 /** Check if tablespace name is "innodb_general".
1218 @param[in] tablespace_name tablespace name
1219 @retval true if name is "innodb_general"
1220 @retval false if name is not "innodb_general" */
1221 inline bool dict_table_has_temp_general_tablespace_name(
1222 const char *tablespace_name) {
1223 return (tablespace_name != nullptr &&
1224 strncmp(tablespace_name, general_space_name,
1225 strlen(general_space_name)) == 0);
1226 }
1227
1228 /** Update the persisted autoinc counter to specified one, we should hold
1229 autoinc_persisted_mutex.
1230 @param[in,out] table table
1231 @param[in] autoinc set autoinc_persisted to this value */
1232 static inline void dict_table_autoinc_persisted_update(dict_table_t *table,
1233 uint64_t autoinc) {
1234 #ifndef UNIV_HOTBACKUP
1235 ut_ad(dict_table_has_autoinc_col(table));
1236 ut_ad(mutex_own(table->autoinc_persisted_mutex));
1237 #endif /* !UNIV_HOTBACKUP */
1238
1239 table->autoinc_persisted = autoinc;
1240 }
1241
1242 /** Check if a table has an autoinc counter column.
1243 @param[in] table table
1244 @return true if there is an autoinc column in the table, otherwise false. */
1245 static inline bool dict_table_has_autoinc_col(const dict_table_t *table) {
1246 return (table->autoinc_field_no != ULINT_UNDEFINED);
1247 }
1248
1249 /** Set the column position of autoinc column in clustered index for a table.
1250 @param[in] table table
1251 @param[in] pos column position in table definition */
1252 static inline void dict_table_autoinc_set_col_pos(dict_table_t *table,
1253 ulint pos) {
1254 ulint innodb_pos = dict_table_mysql_pos_to_innodb(table, pos);
1255
1256 ulint idx = dict_table_get_nth_col_pos(table, innodb_pos);
1257
1258 table->autoinc_field_no = idx;
1259 }
1260
1261 /** Encode the number of columns and number of virtual columns in a
1262 4 bytes value. We could do this because the number of columns in
1263 InnoDB is limited to 1017
1264 @param[in] n_col number of non-virtual column
1265 @param[in] n_v_col number of virtual column
1266 @return encoded value */
1267 static inline ulint dict_table_encode_n_col(ulint n_col, ulint n_v_col) {
1268 return (n_col + (n_v_col << 16));
1269 }
1270
1271 /** decode number of virtual and non-virtual columns in one 4 bytes value.
1272 @param[in] encoded encoded value
1273 @param[in,out] n_col number of non-virtual column
1274 @param[in,out] n_v_col number of virtual column */
1275 static inline void dict_table_decode_n_col(uint32_t encoded, uint32_t *n_col,
1276 uint32_t *n_v_col) {
1277 uint32_t num = encoded & ~DICT_N_COLS_COMPACT;
1278 *n_v_col = num >> 16;
1279 *n_col = num & 0xFFFF;
1280 }
1281
1282 /** Free the virtual column template
1283 @param[in,out] vc_templ virtual column template */
1284 static inline void dict_free_vc_templ(dict_vcol_templ_t *vc_templ) {
1285 if (vc_templ->vtempl != nullptr) {
1286 ut_ad(vc_templ->n_v_col > 0);
1287 for (ulint i = 0; i < vc_templ->n_col + vc_templ->n_v_col; i++) {
1288 if (vc_templ->vtempl[i] != nullptr) {
1289 ut::free(vc_templ->vtempl[i]);
1290 }
1291 }
1292 ut::free(vc_templ->default_rec);
1293 ut::free(vc_templ->vtempl);
1294 vc_templ->vtempl = nullptr;
1295 }
1296 }
1297
1298 /** Check whether the table have virtual index.
1299 @param[in] table InnoDB table
1300 @return true if the table have virtual index, false otherwise. */
1301 static inline bool dict_table_have_virtual_index(dict_table_t *table) {
1302 for (ulint col_no = 0; col_no < dict_table_get_n_v_cols(table); col_no++) {
1303 const dict_v_col_t *col = dict_table_get_nth_v_col(table, col_no);
1304
1305 if (col->m_col.ord_part) {
1306 return (true);
1307 }
1308 }
1309
1310 return (false);
1311 }
1312 /** Allocate memory for intrinsic cache elements in the index
1313 @param[in] index index object */
1314 static inline void dict_allocate_mem_intrinsic_cache(dict_index_t *index) {
1315 index->last_ins_cur = static_cast<last_ops_cur_t *>(
1316 mem_heap_alloc(index->heap, sizeof(last_ops_cur_t)));
1317
1318 new (index->last_ins_cur) last_ops_cur_t();
1319
1320 index->last_sel_cur = static_cast<last_ops_cur_t *>(
1321 mem_heap_alloc(index->heap, sizeof(last_ops_cur_t)));
1322
1323 new (index->last_sel_cur) last_ops_cur_t();
1324 }
1325
1326 /** Generate a table_id from space id for SDI Index.
1327 @param[in] space_id InnoDB tablespace id
1328 @return table_id */
1329 static inline uint64_t dict_sdi_get_table_id(space_id_t space_id) {
1330 return ((~0ULL << 32) | space_id);
1331 }
1332
1333 /** Extract space_id from table_id for SDI Index.
1334 @param[in] table_id InnoDB table id
1335 @return space_id */
1336 static inline space_id_t dict_sdi_get_space_id(table_id_t table_id) {
1337 return (static_cast<space_id_t>(table_id));
1338 }
1339
1340 /** Check if the index is SDI index
1341 @param[in] index in-memory index structure
1342 @return true if index is SDI index else false */
1343 static inline bool dict_index_is_sdi(const dict_index_t *index) {
1344 return (index->type & DICT_SDI);
1345 }
1346
1347 /** Check if an table id belongs SDI table
1348 @param[in] table_id dict_table_t id
1349 @return true if table_id is SDI table_id else false */
1350 static inline bool dict_table_is_sdi(table_id_t table_id) {
1351 /* The lowest possible SDI table_id is for space 0.
1352 So any table id greater than system tablespace
1353 table id is SDI table id. */
1354 return (table_id >= dict_sdi_get_table_id(SYSTEM_TABLE_SPACE));
1355 }
1356
1357 /** Return a SDI Index id for given SDI copy
1358 @return index_id for SDI copy */
1359 static inline space_index_t dict_sdi_get_index_id() {
1360 return (std::numeric_limits<uint64_t>::max());
1361 }
1362
1363 /* GAP locks are skipped for DD tables and SDI tables
1364 @return true if table is DD table or SDI table, else false */
1365 inline bool dict_table_t::skip_gap_locks() const {
1366 return (is_dd_table || dict_table_is_sdi(id));
1367 }
1368
1369 /** Determine if the table can support instant ADD/DROP COLUMN */
1370 inline bool dict_table_t::support_instant_add_drop() const {
1371 return (
1372 !DICT_TF_GET_ZIP_SSIZE(flags) && space != dict_sys_t::s_dict_space_id &&
1373 !DICT_TF2_FLAG_IS_SET(this, DICT_TF2_FTS_HAS_DOC_ID) && !is_temporary() &&
1374 !DICT_TF2_FLAG_IS_SET(this, DICT_TF2_FTS) && !is_system_table);
1375 }
1376
1377 /** Check whether the dict_table_t is a partition.
1378 A partitioned table on the SQL level is composed of InnoDB tables,
1379 where each InnoDB table is a [sub]partition including its secondary indexes
1380 which belongs to the partition.
1381 @param[in] table Table to check.
1382 @return true if the dict_table_t is a partition else false. */
1383 static inline bool dict_table_is_partition(const dict_table_t *table) {
1384 return (dict_name::is_partition(table->name.m_name));
1385 }