MySQL 9.5.0
Source Code Documentation
ddl0ddl.h
Go to the documentation of this file.
1/*****************************************************************************
2
3Copyright (c) 2005, 2025, Oracle and/or its affiliates.
4
5This program is free software; you can redistribute it and/or modify it under
6the terms of the GNU General Public License, version 2.0, as published by the
7Free Software Foundation.
8
9This program is designed to work with certain software (including
10but not limited to OpenSSL) that is licensed under separate terms,
11as designated in a particular file or component or in included license
12documentation. The authors of MySQL hereby grant you an additional
13permission to link the program and your derivative works with the
14separately licensed software that they have either included with
15the program or referenced in the documentation.
16
17This program is distributed in the hope that it will be useful, but WITHOUT
18ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
19FOR A PARTICULAR PURPOSE. See the GNU General Public License, version 2.0,
20for more details.
21
22You should have received a copy of the GNU General Public License along with
23this program; if not, write to the Free Software Foundation, Inc.,
2451 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
25
26*****************************************************************************/
27
28/** @file include/ddl0ddl.h
29 DDL context */
30
31#ifndef ddl0ddl_h
32#define ddl0ddl_h
33
34#include "fts0fts.h"
35#include "lock0types.h"
36#include "os0file.h"
37#include "ut0class_life_cycle.h"
38
39// Forward declaration
40class Flush_observer;
41class Alter_stage;
42
43namespace ddl {
44// Forward declaration
45struct Dup;
46struct Row;
47struct FTS;
48class Loader;
49struct Cursor;
50struct Context;
51struct Builder;
52struct Sequence;
53struct Merge_file_sort;
54struct Load_cursor;
55struct Btree_cursor;
56struct Parallel_cursor;
57
58/** Innodb B-tree index fill factor for bulk load. */
59extern long fill_factor;
60
61/** Variable specifying the number of FTS parser threads to use. */
62extern ulong fts_parser_threads;
63
64/** Minimum IO buffer size. */
65constexpr size_t IO_BLOCK_SIZE = 4 * 1024;
66
67/** @brief Secondary buffer for I/O operations of merge records.
68
69This buffer is used for writing or reading a record that spans two
70Aligned_buffer. Thus, it must be able to hold one merge record,
71whose maximum size is the same as the minimum size of Aligned_buffer. */
73
74/** @brief Merge record in Aligned_buffer.
75
76The format is the same as a record in ROW_FORMAT=COMPACT with the
77exception that the REC_N_NEW_EXTRA_BYTES are omitted. */
78using mrec_t = byte;
79
80/** Index field definition */
82 /** Column offset */
83 size_t m_col_no{};
84
85 /** Column prefix length, or 0 if indexing the whole column */
86 size_t m_prefix_len{};
87
88 /** Whether this is a virtual column */
89 bool m_is_v_col{};
90
91 /** Whether it has multi-value */
93
94 /** true=ASC, false=DESC */
96};
97
98/** Definition of an index being created */
99struct Index_defn {
100 /** Index name */
101 const char *m_name{};
102
103 /** Whether the table is rebuilt */
104 bool m_rebuild{};
105
106 /** 0, DICT_UNIQUE, or DICT_CLUSTERED */
107 size_t m_ind_type{};
108
109 /** MySQL key number, or ULINT_UNDEFINED if none */
111
112 /** Number of fields in index */
113 size_t m_n_fields{};
114
115 /** Field definitions */
117
118 /** Fulltext parser plugin */
120
121 /** true if it's ngram parser */
123
124 /** true if we want to check SRID while inserting to index */
126
127 /** SRID obtained from dd column */
128 uint32_t m_srid{};
129};
130
131/** Structure for reporting duplicate records. */
132struct Dup {
133 Dup() = default;
134
135 /** Constructor.
136 @param[in] index the index being sorted.
137 @param[in] table MySQL table, for reporting duplicate key
138 value, if applicable
139 @param[in] col_map Mapping of old column numbers to new
140 ones, or nullptr if old_table == new_table
141 @param[in] n_dup number of duplicates. */
142 Dup(dict_index_t *index, TABLE *table, const ulint *col_map, size_t n_dup)
143 : m_index(index),
144 m_table(table),
145 m_col_map(col_map),
146 m_n_dup(n_dup),
147 m_entry(nullptr) {}
148
149 /** Report a duplicate key. This function will report the duplicate key
150 to the m_table->record[0]. Care needs to be taken when multiple threads
151 call this function, which could result in corruption of the record in
152 m_table->record[0].
153 @param[in] entry the duplicate key. */
154 void report(const dfield_t *entry) noexcept;
155
156 /** Report a duplicate key, saved in m_entry member. This function
157 will report the duplicate key to the m_table->record[0]. Care needs to
158 be taken when multiple threads call this function, which could result
159 in corruption of the record in m_table->record[0]. */
160 void report() noexcept;
161
162 /** Report a duplicate key. This function will report the duplicate key
163 to the m_table->record[0]. Care needs to be taken when multiple threads
164 call this function, which could result in corruption of the record in
165 m_table->record[0].
166 @param[in] entry the duplicate key.
167 @param[in] offsets Row offsets */
168 void report(const mrec_t *entry, const ulint *offsets) noexcept;
169
170 /** @return true if no duplicates reported yet. */
171 [[nodiscard]] bool empty() const noexcept { return m_n_dup == 0; }
172
173 /** Save the duplicate tuple information.
174 @param[in] entry duplicate tuple of index m_index */
176 m_n_dup++;
177 m_entry = entry;
178 }
179
180 /** Index being sorted */
182
183 /** MySQL table object */
185
186 /** Mapping of column numbers in table to the rebuilt table
187 (index->table), or NULL if not rebuilding table */
188 const ulint *m_col_map{};
189
190 /** Number of duplicates */
191 size_t m_n_dup{};
192
193 private:
194 /** The duplicate tuple of index m_index. */
195 const dfield_t *m_entry{nullptr};
196};
197
198/** Captures ownership and manages lifetime of an already opened OS file
199descriptor. Closes the file on object destruction. */
201 public:
202 /** Default constructor, does not hold any file, does not close any on
203 destruction. */
205 /** Main constructor capturing an already opened OS file descriptor. */
207
209
211
212 /** Returns the managed OS file descriptor for use with OS functions that
213 operate on file. Do not close this file. */
214 os_fd_t get() const {
215 ut_a(is_open());
216 return m_fd;
217 }
218 bool is_open() const { return m_fd != OS_FD_CLOSED; }
219
221 close();
222 swap(other);
223 return *this;
224 }
225
226 /** Swaps the underlying managed file descriptors between two instances of
227 Unique_os_file_descriptor. No files are closed. */
229
230 /** Closes the managed file. Leaves the instance in the same state as default
231 constructed instance. */
232 void close() {
233#ifdef UNIV_PFS_IO
234 struct PSI_file_locker *locker = nullptr;
236 locker = PSI_FILE_CALL(get_thread_file_descriptor_locker)(&state, m_fd,
238 if (locker != nullptr) {
239 PSI_FILE_CALL(start_file_wait)
240 (locker, 0, __FILE__, __LINE__);
241 }
242#endif /* UNIV_PFS_IO */
243 if (m_fd != OS_FD_CLOSED) {
244 ::close(m_fd);
246 }
247#ifdef UNIV_PFS_IO
248 if (locker != nullptr) {
249 PSI_FILE_CALL(end_file_wait)(locker, 0);
250 }
251#endif /* UNIV_PFS_IO */
252 }
253
254 private:
256};
257
258/** Sets an exclusive lock on a table, for the duration of creating indexes.
259@param[in,out] trx Transaction
260@param[in] table Table to lock.
261@param[in] mode Lock mode LOCK_X or LOCK_S
262@return error code or DB_SUCCESS */
263[[nodiscard]] dberr_t lock_table(trx_t *trx, dict_table_t *table,
264 lock_mode mode) noexcept;
265
266/** Drop those indexes which were created before an error occurred.
267The data dictionary must have been locked exclusively by the caller,
268because the transaction will not be committed.
269@param[in,out] trx Transaction
270@param[in] table Table to lock.
271@param[in] locked true=table locked, false=may need to do a lazy
272 drop */
273void drop_indexes(trx_t *trx, dict_table_t *table, bool locked) noexcept;
274
275/**Create temporary merge files in the given parameter path, and if
276UNIV_PFS_IO defined, register the file descriptor with Performance Schema.
277@param[in] path Location for creating temporary merge files.
278@return File descriptor */
279[[nodiscard]] Unique_os_file_descriptor file_create_low(
280 const char *path) noexcept;
281
282/** Create the index and load in to the dictionary.
283@param[in,out] trx Trx (sets error_state)
284@param[in,out] table The index is on this table
285@param[in] index_def The index definition
286@param[in] add_v New virtual columns added along with add
287 index call
288@return index, or nullptr on error */
289[[nodiscard]] dict_index_t *create_index(
290 trx_t *trx, dict_table_t *table, const Index_defn *index_def,
291 const dict_add_v_col_t *add_v) noexcept;
292
293/** Drop a table. The caller must have ensured that the background stats
294thread is not processing the table. This can be done by calling
295dict_stats_wait_bg_to_stop_using_table() after locking the dictionary and
296before calling this function.
297@param[in,out] trx Transaction
298@param[in,out] table Table to drop.
299@return DB_SUCCESS or error code */
300dberr_t drop_table(trx_t *trx, dict_table_t *table) noexcept;
301
302/** Generate the next autoinc based on a snapshot of the session
303auto_increment_increment and auto_increment_offset variables.
304Assignment operator would be used during the inplace_alter_table()
305phase only **/
306struct Sequence {
307 /** Constructor.
308 @param[in,out] thd The session
309 @param[in] start_value The lower bound
310 @param[in] max_value The upper bound (inclusive) */
311 Sequence(THD *thd, ulonglong start_value, ulonglong max_value) noexcept;
312
313 /** Destructor. */
314 ~Sequence() = default;
315
316 /** Postfix increment
317 @return the value to insert */
318 ulonglong operator++(int) noexcept;
319
320 /** Check if the autoinc "sequence" is exhausted.
321 @return true if the sequence is exhausted */
322 bool eof() const noexcept { return m_eof; }
323
324 /** Assignment operator to copy the sequence values
325 @param[in] rhs Sequence to copy from */
326 ddl::Sequence &operator=(const ddl::Sequence &rhs) noexcept {
327 ut_ad(rhs.m_next_value > 0);
328 ut_ad(rhs.m_max_value == m_max_value);
329 m_next_value = rhs.m_next_value;
330 m_increment = rhs.m_increment;
331 m_offset = rhs.m_offset;
332 m_eof = rhs.m_eof;
333 return *this;
334 }
335
336 /** @return the next value in the sequence */
337 ulonglong last() const noexcept {
338 ut_ad(m_next_value > 0);
339 return m_next_value;
340 }
341
342 /** Maximum column value if adding an AUTOINC column else 0. Once
343 we reach the end of the sequence it will be set to ~0. */
345
346 /** Value of auto_increment_increment */
347 ulong m_increment{};
348
349 /** Value of auto_increment_offset */
350 ulong m_offset{};
351
352 /** Next value in the sequence */
354
355 /** true if no more values left in the sequence */
356 bool m_eof{};
357};
358
359/** DDL context/configuration. */
360struct Context {
361 /** Full text search context information and state. */
362 struct FTS {
363 /** Document ID sequence */
364 struct Sequence {
365 /** Destructor. */
366 virtual ~Sequence() noexcept;
367
368 /** Get the next document ID.
369 @param[in] dtuple Row from which to fetch ID.
370 @return the next document ID. */
371 virtual doc_id_t fetch(const dtuple_t *dtuple = nullptr) noexcept = 0;
372
373 /** Get the current document ID.
374 @return the current document ID. */
375 virtual doc_id_t current() noexcept = 0;
376
377 /** @return the number of document IDs generated. */
378 virtual doc_id_t generated_count() const noexcept = 0;
379
380 /** @return the maximum document ID seen so far. */
381 virtual doc_id_t max_doc_id() const noexcept = 0;
382
383 /** @return true if the document ID is generated, instead of fetched
384 from a column from the row. */
385 virtual bool is_generated() const noexcept = 0;
386
387 /** Advance the document ID. */
388 virtual void increment() noexcept = 0;
389
390 /** Current document ID. */
392 };
393
394 /** Constructor.
395 @param[in] n_parser_threads Number of FTS parser threads. */
396 explicit FTS(size_t n_parser_threads) noexcept
397 : m_n_parser_threads(n_parser_threads) {}
398
399 /** Destructor. */
400 ~FTS() noexcept { ut::delete_(m_doc_id); }
401
402 /** FTS index. */
404
405 /** Maximum number of FTS parser and sort threads to use. */
406 const size_t m_n_parser_threads{};
407
408 /** Document ID sequence generator. */
410
411 /** FTS instance. */
413 };
414
415 /** Scan sort and IO buffer size. */
416 using Scan_buffer_size = std::pair<size_t, size_t>;
417
418 /** Build indexes on a table by reading a clustered index, creating a
419 temporary file containing index entries, merge sorting these index entries and
420 inserting sorted index entries to indexes.
421 @param[in] trx Transaction.
422 @param[in] old_table Table where rows are read from
423 @param[in] new_table Table where indexes are created; identical to
424 old_table unless creating a PRIMARY KEY
425 @param[in] online True if creating indexes online
426 @param[in] indexes Indexes to be created
427 @param[in] key_numbers MySQL key numbers
428 @param[in] n_indexes Size of indexes[]
429 @param[in,out] table MySQL table, for reporting erroneous key
430 value if applicable
431 @param[in] add_cols Default values of added columns, or NULL
432 @param[in] col_map Mapping of old column numbers to new
433 ones, or nullptr if old_table == new_table
434 @param[in] add_autoinc Number of added AUTO_INCREMENT columns, or
435 ULINT_UNDEFINED if none is added
436 @param[in,out] sequence Autoinc sequence
437 @param[in] skip_pk_sort Whether the new PRIMARY KEY will follow
438 existing order
439 @param[in,out] stage Performance schema accounting object,
440 used by ALTER TABLE.
441 stage->begin_phase_read_pk() will be called
442 at the beginning of this function and it will
443 be passed to other functions for further
444 accounting.
445 @param[in] add_v New virtual columns added along with indexes
446 @param[in] eval_table MySQL table used to evaluate virtual column
447 value, see innobase_get_computed_value().
448 @param[in] max_buffer_size Memory use upper limit.
449 @param[in] max_threads true if DDL should use multiple threads. */
451 bool online, dict_index_t **indexes, const ulint *key_numbers,
452 size_t n_indexes, TABLE *table, const dtuple_t *add_cols,
453 const ulint *col_map, size_t add_autoinc, ddl::Sequence &sequence,
454 bool skip_pk_sort, Alter_stage *stage, const dict_add_v_col_t *add_v,
455 TABLE *eval_table, size_t max_buffer_size,
456 size_t max_threads) noexcept;
457
458 /** Destructor. */
459 ~Context() noexcept;
460
461 /** @return the DDL error status. */
462 dberr_t get_error() const noexcept { return m_err.load(); }
463
464 /** Set the error code, when it's not specific to an index.
465 @param[in] err Error code. */
466 void set_error(dberr_t err) noexcept {
468
469 /* This should only be settable by the the thread that encounters the
470 first error, therefore try only once. */
471
472 dberr_t expected{DB_SUCCESS};
473 m_err.compare_exchange_strong(expected, err);
474 }
475
476 /** Set the error code and index number where the error occurred.
477 @param[in] err Error code.
478 @param[in] id Index ordinal value where error occurred.
479 @return true iff this thread successfully set the error code.*/
480 bool set_error(dberr_t err, size_t id) noexcept {
481 /* This should only be settable by the the thread that encounters the
482 first error, therefore try only once. */
483
484 ut_a(err != DB_SUCCESS);
485
486 dberr_t expected{DB_SUCCESS};
487
488 if (m_err.compare_exchange_strong(expected, err)) {
491 return true;
492 }
493
494 return false;
495 }
496
497 /** Build the indexes.
498 @return DB_SUCCESS or error code. */
499 [[nodiscard]] dberr_t build() noexcept;
500
501 /** @return the flush observer to use for flushing. */
502 [[nodiscard]] Flush_observer *flush_observer() noexcept;
503
504 /** @return the old table. */
505 [[nodiscard]] dict_table_t *old_table() noexcept { return m_old_table; }
506
507 /** @return the new table. */
508 [[nodiscard]] dict_table_t *new_table() noexcept { return m_new_table; }
509
510 /** Calculate the sort and buffer size per thread.
511 @param[in] n_threads Total number of threads used for scanning.
512 @return the sort and IO buffer size per thread. */
514 size_t n_threads) const noexcept;
515
516 /** Calculate the io buffer size per file for the sort phase.
517 @param[in] n_buffers Total number of buffers to use for the merge.
518 @return the sort buffer size for one instance. */
519 [[nodiscard]] size_t merge_io_buffer_size(size_t n_buffers) const noexcept;
520
521 /** Calculate the io buffer size per file for the load phase.
522 @param[in] n_buffers Total number of buffers to use for the loading.
523 @return the per thread io buffer size. */
524 [[nodiscard]] size_t load_io_buffer_size(size_t n_buffers) const noexcept;
525
526 /** Request number of bytes for a buffer.
527 @param[in] n Number of bytes requested.
528 @return the number of bytes available. */
529 [[nodiscard]] size_t allocate(size_t n) const;
530
531 /** @return the server session/connection context. */
532 [[nodiscard]] THD *thd() noexcept;
533
534 /** Copy the added columns dtuples so that we don't use the same
535 column data buffer for the added column across multiple threads.
536 @return new instance or nullptr if out of memory. */
537 [[nodiscard]] dtuple_t *create_add_cols() noexcept;
538
539 private:
540 /** @return the cluster index read cursor. */
541 [[nodiscard]] Cursor *cursor() noexcept { return m_cursor; }
542
543 /** @return the original table cluster index. */
544 [[nodiscard]] const dict_index_t *index() const noexcept;
545
546 /** Initialize the context for a cluster index scan.
547 @param[in,out] cursor Cursor used for the cluster index read. */
548 [[nodiscard]] dberr_t read_init(Cursor *cursor) noexcept;
549
550 /** Initialize the FTS build infrastructure.
551 @param[in,out] index Index prototype to build.
552 @return DB_SUCCESS or error code. */
554
555 /** Setup the FTS index build data structures.
556 @return DB_SUCCESS or error code. */
557 [[nodiscard]] dberr_t setup_fts_build() noexcept;
558
559 /** Get the next Doc ID and increment the current value.
560 @return a document ID. */
561 [[nodiscard]] doc_id_t next_doc_id() noexcept;
562
563 /** Update the FTS document ID. */
564 void update_fts_doc_id() noexcept;
565
566 /** Check the state of the online build log for the index.
567 @return DB_SUCCESS or error code. */
568 [[nodiscard]] dberr_t check_state_of_online_build_log() noexcept;
569
570 /** Track the highest TxID that modified this index when the scan
571 was completed. We prevent older readers from accessing this index, to
572 ensure read consistency.
573 @param[in,out] index Index to track. */
574 void note_max_trx_id(dict_index_t *index) noexcept;
575
576 /** Setup the primary key sort.
577 @param[in,out] cursor Setup the primary key data structures.
578 @return DB_SUCCESS or error code. */
579 [[nodiscard]] dberr_t setup_pk_sort(Cursor *cursor) noexcept;
580
581 /** Init the non-null column constraints checks (if required). */
582 void setup_nonnull() noexcept;
583
584 /** Check if the nonnull columns satisfy the constraint.
585 @param[in] row Row to check.
586 @return true on success. */
587 [[nodiscard]] bool check_null_constraints(const dtuple_t *row) const noexcept;
588
589 /** Clean up the data structures at the end of the DDL.
590 @param[in] err Status of the DDL.
591 @return DB_SUCCESS or error code. */
592 [[nodiscard]] dberr_t cleanup(dberr_t err) noexcept;
593
594 /** Handle auto increment.
595 @param[in] row Row with autoinc column.
596 @param[in] heap Heap to use for allocation of autoinc column.
597 @return DB_SUCCESS or error code. */
598 [[nodiscard]] dberr_t handle_autoinc(const dtuple_t *row,
599 mem_heap_t *heap) noexcept;
600
601 /** @return true if any virtual columns are involved. */
602 [[nodiscard]] bool has_virtual_columns() const noexcept;
603
604 /** @return true if any FTS indexes are involved. */
605 [[nodiscard]] bool has_fts_indexes() const noexcept;
606
607 /** @return true if the DDL was interrupted. */
608 [[nodiscard]] bool is_interrupted() noexcept;
609
610 private:
611 using Key_numbers = std::vector<size_t, ut::allocator<size_t>>;
612 using Indexes = std::vector<dict_index_t *, ut::allocator<dict_index_t *>>;
613
614 /** Common error code for all index builders running in parallel. */
616
617 /** Index where the error occurred. */
619
620 /** Transaction covering the index build. */
622
623 /** The FTS builder. There is one FTS per table. */
625
626 /** Source table, read rows from this table. */
628
629 /** Table where indexes are created; identical to old_table unless creating
630 a PRIMARY KEY. */
632
633 /** True if creating index online. Non-online implies that we have an
634 S latch on the table, therefore there can't be concurrent updates to
635 the table while we are executing the DDL. We don't log the changes to
636 the row log. */
637 bool m_online{};
638
639 /** Indexes to be created. */
641
642 /** MySQL key numbers. */
644
645 /** MySQL table for reporting errors/warnings. */
647
648 /** Default value for added columns or null. */
650
651 /** Mapping of old column numbers to new ones, or nullptr if none
652 were added. */
653 const ulint *m_col_map{};
654
655 /** Number of added AUTO_INCREMENT columns, or ULINT_UNDEFINED if
656 none added. */
658
659 /** Autoinc sequence. */
661
662 /** Performance schema accounting object, used by ALTER TABLE.
663 stage->begin_phase_read_pk() will be called at the beginning of
664 this function and it will be passed to other functions for further
665 accounting. */
667
668 /** New virtual columns added along with indexes */
670
671 /** MySQL table used to evaluate virtual column value, see
672 innobase_get_computed_value(). */
674
675 /** Skip the sorting phase if true. */
677
678 /** Non null columns. */
679 std::vector<size_t, ut::allocator<size_t>> m_nonnull{};
680
681 /** Number of unique columns in the key. */
682 size_t m_n_uniq{};
683
684 /** true if need flush observer. */
686
687 /** Cursor for reading the cluster index. */
689
690 /** Number of bytes used. */
692
693 /** Maximum number of bytes to use. */
694 const size_t m_max_buffer_size{};
695
696 /** Maximum number of threads to use. We don't do a parallel scan of the
697 clustered index when FTS and/or virtual columns are involved. The build
698 phase is parallel though. */
699 const size_t m_max_threads{};
700
701 /** For parallel access to the autoincrement generator. */
702 ib_mutex_t m_autoinc_mutex;
703
704 /** Heap for copies of m_add_cols. */
706
707 friend struct Row;
708 friend class Loader;
709 friend struct Cursor;
710 friend struct Builder;
711 friend struct ddl::FTS;
712 friend struct Load_cursor;
713 friend struct Btree_cursor;
714 friend struct Merge_file_sort;
715 friend struct Parallel_cursor;
716};
717
718} // namespace ddl
719
720#endif /* ddl0ddl_h */
Kerberos Client Authentication nullptr
Definition: auth_kerberos_client_plugin.cc:247
Class used to report ALTER TABLE progress via performance_schema.
Definition: ut0stage.h:81
We use Flush_observer to track flushing of non-redo logged pages in bulk create index(btr0load....
Definition: buf0flu.h:258
Definition: conf_to_src.cc:76
A row of result or a row of metadata A row is a collection of Column values or Column metadata.
Definition: protocol_local_v2.h:92
For each client connection we create a separate thread with THD serving as a thread/connection descri...
Definition: sql_lexer_thd.h:36
Build indexes on a table by reading a clustered index, creating a temporary file containing index ent...
Definition: ddl0impl-loader.h:44
Captures ownership and manages lifetime of an already opened OS file descriptor.
Definition: ddl0ddl.h:200
Unique_os_file_descriptor(os_fd_t fd)
Main constructor capturing an already opened OS file descriptor.
Definition: ddl0ddl.h:206
os_fd_t get() const
Returns the managed OS file descriptor for use with OS functions that operate on file.
Definition: ddl0ddl.h:214
os_fd_t m_fd
Definition: ddl0ddl.h:255
void swap(Unique_os_file_descriptor &other)
Swaps the underlying managed file descriptors between two instances of Unique_os_file_descriptor.
Definition: ddl0ddl.h:228
Unique_os_file_descriptor(Unique_os_file_descriptor &&other)
Definition: ddl0ddl.h:208
bool is_open() const
Definition: ddl0ddl.h:218
Unique_os_file_descriptor()=default
Default constructor, does not hold any file, does not close any on destruction.
Unique_os_file_descriptor & operator=(Unique_os_file_descriptor &&other)
Definition: ddl0ddl.h:220
void close()
Closes the managed file.
Definition: ddl0ddl.h:232
~Unique_os_file_descriptor()
Definition: ddl0ddl.h:210
A utility class which, if inherited from, prevents the descendant class from being copied,...
Definition: ut0class_life_cycle.h:41
struct _entry entry
#define PSI_FILE_CALL(M)
Definition: psi_file.h:36
dberr_t
Definition: db0err.h:39
@ DB_SUCCESS
Definition: db0err.h:43
@ DB_END_OF_INDEX
Definition: db0err.h:221
Full text search header file.
uint64_t doc_id_t
Document id type.
Definition: fts0fts.h:76
struct PSI_file_locker PSI_file_locker
Definition: psi_file_bits.h:62
@ PSI_FILE_CLOSE
File close, as in close().
Definition: psi_file_bits.h:75
unsigned char byte
Blob class.
Definition: common.h:151
The transaction lock system global types.
lock_mode
Definition: lock0types.h:54
unsigned long long int ulonglong
Definition: my_inttypes.h:56
static char * path
Definition: mysqldump.cc:150
static PFS_engine_table_share_proxy table
Definition: pfs.cc:61
The general architecture is that the work is done in two phases, roughly the read and write phase.
Definition: btr0load.cc:42
ulong fts_parser_threads
Variable specifying the number of FTS parser threads to use.
Definition: ddl0fts.cc:49
void drop_indexes(trx_t *trx, dict_table_t *table, bool locked) noexcept
Drop those indexes which were created before an error occurred.
Definition: ddl0ddl.cc:474
dberr_t lock_table(trx_t *trx, dict_table_t *table, enum lock_mode mode) noexcept
Sets an exclusive lock on a table, for the duration of creating indexes.
Definition: ddl0ddl.cc:306
dberr_t drop_table(trx_t *trx, dict_table_t *table) noexcept
Drop a table.
Definition: ddl0ddl.cc:297
byte mrec_t
Merge record in Aligned_buffer.
Definition: ddl0ddl.h:78
long fill_factor
Innodb B-tree index fill factor for bulk load.
Definition: btr0load.cc:44
constexpr size_t IO_BLOCK_SIZE
Minimum IO buffer size.
Definition: ddl0ddl.h:65
Unique_os_file_descriptor file_create_low(const char *path) noexcept
Create temporary merge files in the given parameter path, and if UNIV_PFS_IO defined,...
Definition: ddl0ddl.cc:135
dict_index_t * create_index(trx_t *trx, dict_table_t *table, const Index_defn *index_def, const dict_add_v_col_t *add_v) noexcept
Create the index and load in to the dictionary.
Definition: ddl0ddl.cc:190
byte[UNIV_PAGE_SIZE_MAX] mrec_buf_t
Secondary buffer for I/O operations of merge records.
Definition: ddl0ddl.h:72
bool index(const std::string &value, const String &search_for, uint32_t *idx)
Definition: contains.h:76
static Value err()
Create a Value object that represents an error condition.
Definition: json_binary.cc:924
ValueType max(X &&first)
Definition: gtid.h:103
Definition: gcs_xcom_synode.h:64
mode
Definition: file_handle.h:61
This file contains a set of libraries providing overloads for regular dynamic allocation routines whi...
Definition: aligned_alloc.h:48
std::vector< T, ut::allocator< T > > vector
Specialization of vector which uses allocator.
Definition: ut0new.h:2880
void delete_(T *ptr) noexcept
Releases storage which has been dynamically allocated through any of the ut::new*() variants.
Definition: ut0new.h:811
The interface to the operating system file io.
static constexpr os_fd_t OS_FD_CLOSED
Definition: os0file.h:117
int os_fd_t
Raw file handle.
Definition: os0file.h:115
static void swap(String &a, String &b) noexcept
Definition: sql_string.h:650
State data storage for get_thread_file_name_locker_v1_t.
Definition: psi_file_bits.h:146
Definition: table.h:1435
Definition: completion_hash.h:35
For loading indexes.
Definition: ddl0impl-builder.h:48
Document ID sequence.
Definition: ddl0ddl.h:364
virtual doc_id_t generated_count() const noexcept=0
virtual ~Sequence() noexcept
Destructor.
Definition: ddl0ctx.cc:134
virtual void increment() noexcept=0
Advance the document ID.
virtual bool is_generated() const noexcept=0
virtual doc_id_t fetch(const dtuple_t *dtuple=nullptr) noexcept=0
Get the next document ID.
virtual doc_id_t current() noexcept=0
Get the current document ID.
doc_id_t m_doc_id
Current document ID.
Definition: ddl0ddl.h:391
virtual doc_id_t max_doc_id() const noexcept=0
Full text search context information and state.
Definition: ddl0ddl.h:362
~FTS() noexcept
Destructor.
Definition: ddl0ddl.h:400
ddl::FTS * m_ptr
FTS instance.
Definition: ddl0ddl.h:412
FTS(size_t n_parser_threads) noexcept
Constructor.
Definition: ddl0ddl.h:396
const size_t m_n_parser_threads
Maximum number of FTS parser and sort threads to use.
Definition: ddl0ddl.h:406
Sequence * m_doc_id
Document ID sequence generator.
Definition: ddl0ddl.h:409
dict_index_t * m_index
FTS index.
Definition: ddl0ddl.h:403
DDL context/configuration.
Definition: ddl0ddl.h:360
size_t m_err_key_number
Index where the error occurred.
Definition: ddl0ddl.h:618
~Context() noexcept
Destructor.
Definition: ddl0ctx.cc:126
const dict_index_t * index() const noexcept
Definition: ddl0ctx.cc:145
bool m_need_observer
true if need flush observer.
Definition: ddl0ddl.h:685
void set_error(dberr_t err) noexcept
Set the error code, when it's not specific to an index.
Definition: ddl0ddl.h:466
const dtuple_t * m_add_cols
Default value for added columns or null.
Definition: ddl0ddl.h:649
dict_table_t * old_table() noexcept
Definition: ddl0ddl.h:505
bool is_interrupted() noexcept
Definition: ddl0ctx.cc:528
size_t allocate(size_t n) const
Request number of bytes for a buffer.
const ulint * m_col_map
Mapping of old column numbers to new ones, or nullptr if none were added.
Definition: ddl0ddl.h:653
dberr_t cleanup(dberr_t err) noexcept
Clean up the data structures at the end of the DDL.
Definition: ddl0ctx.cc:305
Context(trx_t *trx, dict_table_t *old_table, dict_table_t *new_table, bool online, dict_index_t **indexes, const ulint *key_numbers, size_t n_indexes, TABLE *table, const dtuple_t *add_cols, const ulint *col_map, size_t add_autoinc, ddl::Sequence &sequence, bool skip_pk_sort, Alter_stage *stage, const dict_add_v_col_t *add_v, TABLE *eval_table, size_t max_buffer_size, size_t max_threads) noexcept
Build indexes on a table by reading a clustered index, creating a temporary file containing index ent...
Definition: ddl0ctx.cc:46
mem_heap_t * m_dtuple_heap
Heap for copies of m_add_cols.
Definition: ddl0ddl.h:705
bool set_error(dberr_t err, size_t id) noexcept
Set the error code and index number where the error occurred.
Definition: ddl0ddl.h:480
dtuple_t * create_add_cols() noexcept
Copy the added columns dtuples so that we don't use the same column data buffer for the added column ...
Definition: ddl0ctx.cc:530
bool m_skip_pk_sort
Skip the sorting phase if true.
Definition: ddl0ddl.h:676
size_t merge_io_buffer_size(size_t n_buffers) const noexcept
Calculate the io buffer size per file for the sort phase.
Definition: ddl0ctx.cc:201
Scan_buffer_size scan_buffer_size(size_t n_threads) const noexcept
Calculate the sort and buffer size per thread.
Definition: ddl0ctx.cc:149
void note_max_trx_id(dict_index_t *index) noexcept
Track the highest TxID that modified this index when the scan was completed.
Definition: ddl0ctx.cc:479
std::vector< size_t, ut::allocator< size_t > > m_nonnull
Non null columns.
Definition: ddl0ddl.h:679
TABLE * m_table
MySQL table for reporting errors/warnings.
Definition: ddl0ddl.h:646
dict_table_t * m_old_table
Source table, read rows from this table.
Definition: ddl0ddl.h:627
std::vector< size_t, ut::allocator< size_t > > Key_numbers
Definition: ddl0ddl.h:611
dict_table_t * new_table() noexcept
Definition: ddl0ddl.h:508
void setup_nonnull() noexcept
Init the non-null column constraints checks (if required).
Definition: ddl0ctx.cc:392
const dict_add_v_col_t * m_add_v
New virtual columns added along with indexes.
Definition: ddl0ddl.h:669
const size_t m_max_buffer_size
Maximum number of bytes to use.
Definition: ddl0ddl.h:694
dict_table_t * m_new_table
Table where indexes are created; identical to old_table unless creating a PRIMARY KEY.
Definition: ddl0ddl.h:631
void update_fts_doc_id() noexcept
Update the FTS document ID.
trx_t * m_trx
Transaction covering the index build.
Definition: ddl0ddl.h:621
size_t m_n_allocated
Number of bytes used.
Definition: ddl0ddl.h:691
std::atomic< dberr_t > m_err
Common error code for all index builders running in parallel.
Definition: ddl0ddl.h:615
Cursor * cursor() noexcept
Definition: ddl0ddl.h:541
size_t m_n_uniq
Number of unique columns in the key.
Definition: ddl0ddl.h:682
ib_mutex_t m_autoinc_mutex
For parallel access to the autoincrement generator.
Definition: ddl0ddl.h:702
bool has_virtual_columns() const noexcept
Definition: ddl0ctx.cc:224
bool has_fts_indexes() const noexcept
Definition: ddl0ctx.cc:436
dberr_t check_state_of_online_build_log() noexcept
Check the state of the online build log for the index.
Definition: ddl0ctx.cc:466
dberr_t setup_fts_build() noexcept
Setup the FTS index build data structures.
Definition: ddl0ctx.cc:449
FTS m_fts
The FTS builder.
Definition: ddl0ddl.h:624
dberr_t setup_pk_sort(Cursor *cursor) noexcept
Setup the primary key sort.
Definition: ddl0ctx.cc:499
dberr_t handle_autoinc(const dtuple_t *row, mem_heap_t *heap) noexcept
Handle auto increment.
Definition: ddl0ctx.cc:239
std::pair< size_t, size_t > Scan_buffer_size
Scan sort and IO buffer size.
Definition: ddl0ddl.h:416
Key_numbers m_key_numbers
MySQL key numbers.
Definition: ddl0ddl.h:643
size_t m_add_autoinc
Number of added AUTO_INCREMENT columns, or ULINT_UNDEFINED if none added.
Definition: ddl0ddl.h:657
Flush_observer * flush_observer() noexcept
Definition: ddl0ctx.cc:136
bool m_online
True if creating index online.
Definition: ddl0ddl.h:637
Indexes m_indexes
Indexes to be created.
Definition: ddl0ddl.h:640
size_t load_io_buffer_size(size_t n_buffers) const noexcept
Calculate the io buffer size per file for the load phase.
Definition: ddl0ctx.cc:216
dberr_t get_error() const noexcept
Definition: ddl0ddl.h:462
std::vector< dict_index_t *, ut::allocator< dict_index_t * > > Indexes
Definition: ddl0ddl.h:612
dberr_t read_init(Cursor *cursor) noexcept
Initialize the context for a cluster index scan.
Definition: ddl0ctx.cc:507
ddl::Sequence & m_sequence
Autoinc sequence.
Definition: ddl0ddl.h:660
friend struct Btree_cursor
Definition: ddl0ddl.h:713
Cursor * m_cursor
Cursor for reading the cluster index.
Definition: ddl0ddl.h:688
Alter_stage * m_stage
Performance schema accounting object, used by ALTER TABLE.
Definition: ddl0ddl.h:666
const size_t m_max_threads
Maximum number of threads to use.
Definition: ddl0ddl.h:699
dberr_t build() noexcept
Build the indexes.
Definition: ddl0ctx.cc:516
bool check_null_constraints(const dtuple_t *row) const noexcept
Check if the nonnull columns satisfy the constraint.
Definition: ddl0ctx.cc:422
dberr_t fts_create(dict_index_t *index) noexcept
Initialize the FTS build infrastructure.
Definition: ddl0ctx.cc:291
TABLE * m_eval_table
MySQL table used to evaluate virtual column value, see innobase_get_computed_value().
Definition: ddl0ddl.h:673
THD * thd() noexcept
Definition: ddl0ctx.cc:140
doc_id_t next_doc_id() noexcept
Get the next Doc ID and increment the current value.
Cursor for reading the data.
Definition: ddl0impl-cursor.h:41
Structure for reporting duplicate records.
Definition: ddl0ddl.h:132
dict_index_t * m_index
Index being sorted.
Definition: ddl0ddl.h:181
size_t m_n_dup
Number of duplicates.
Definition: ddl0ddl.h:191
void save_duplicate(const dfield_t *entry)
Save the duplicate tuple information.
Definition: ddl0ddl.h:175
Dup(dict_index_t *index, TABLE *table, const ulint *col_map, size_t n_dup)
Constructor.
Definition: ddl0ddl.h:142
const dfield_t * m_entry
The duplicate tuple of index m_index.
Definition: ddl0ddl.h:195
const ulint * m_col_map
Mapping of column numbers in table to the rebuilt table (index->table), or NULL if not rebuilding tab...
Definition: ddl0ddl.h:188
TABLE * m_table
MySQL table object.
Definition: ddl0ddl.h:184
Dup()=default
bool empty() const noexcept
Definition: ddl0ddl.h:171
void report() noexcept
Report a duplicate key, saved in m_entry member.
Definition: ddl0ddl.cc:92
Full text search index builder.
Definition: ddl0fts.h:67
Definition of an index being created.
Definition: ddl0ddl.h:99
const char * m_name
Index name.
Definition: ddl0ddl.h:101
bool m_srid_is_valid
true if we want to check SRID while inserting to index
Definition: ddl0ddl.h:125
bool m_is_ngram
true if it's ngram parser
Definition: ddl0ddl.h:122
size_t m_ind_type
0, DICT_UNIQUE, or DICT_CLUSTERED
Definition: ddl0ddl.h:107
size_t m_key_number
MySQL key number, or ULINT_UNDEFINED if none.
Definition: ddl0ddl.h:110
Index_field * m_fields
Field definitions.
Definition: ddl0ddl.h:116
uint32_t m_srid
SRID obtained from dd column.
Definition: ddl0ddl.h:128
size_t m_n_fields
Number of fields in index.
Definition: ddl0ddl.h:113
st_mysql_ftparser * m_parser
Fulltext parser plugin.
Definition: ddl0ddl.h:119
bool m_rebuild
Whether the table is rebuilt.
Definition: ddl0ddl.h:104
Index field definition.
Definition: ddl0ddl.h:81
bool m_is_ascending
true=ASC, false=DESC
Definition: ddl0ddl.h:95
size_t m_col_no
Column offset.
Definition: ddl0ddl.h:83
size_t m_prefix_len
Column prefix length, or 0 if indexing the whole column.
Definition: ddl0ddl.h:86
bool m_is_v_col
Whether this is a virtual column.
Definition: ddl0ddl.h:89
bool m_is_multi_value
Whether it has multi-value.
Definition: ddl0ddl.h:92
Definition: ddl0impl-builder.h:458
Merge the blocks in the file.
Definition: ddl0impl-merge.h:45
Cursor used for parallel reads.
Definition: ddl0par-scan.cc:45
Physical row context.
Definition: ddl0impl.h:121
Generate the next autoinc based on a snapshot of the session auto_increment_increment and auto_increm...
Definition: ddl0ddl.h:306
ulonglong last() const noexcept
Definition: ddl0ddl.h:337
bool m_eof
true if no more values left in the sequence
Definition: ddl0ddl.h:356
ulong m_increment
Value of auto_increment_increment.
Definition: ddl0ddl.h:347
const ulonglong m_max_value
Maximum column value if adding an AUTOINC column else 0.
Definition: ddl0ddl.h:344
ddl::Sequence & operator=(const ddl::Sequence &rhs) noexcept
Assignment operator to copy the sequence values.
Definition: ddl0ddl.h:326
ulong m_offset
Value of auto_increment_offset.
Definition: ddl0ddl.h:350
ulonglong operator++(int) noexcept
Postfix increment.
Definition: ddl0ctx.cc:565
Sequence(THD *thd, ulonglong start_value, ulonglong max_value) noexcept
Constructor.
Definition: ddl0ctx.cc:543
ulonglong m_next_value
Next value in the sequence.
Definition: ddl0ddl.h:353
~Sequence()=default
Destructor.
bool eof() const noexcept
Check if the autoinc "sequence" is exhausted.
Definition: ddl0ddl.h:322
Structure for an SQL data field.
Definition: data0data.h:617
Data structure for newly added virtual column in a table.
Definition: dict0mem.h:830
Data structure for an index.
Definition: dict0mem.h:1041
Data structure for a database table.
Definition: dict0mem.h:1922
Structure for an SQL data tuple of fields (logical record)
Definition: data0data.h:696
The info structure stored at the beginning of a heap block.
Definition: mem0mem.h:302
Definition: plugin_ftparser.h:216
Definition: trx0trx.h:675
long long sequence(UDF_INIT *initid, UDF_ARGS *args, unsigned char *, unsigned char *)
Definition: udf_example.cc:568
unsigned long int ulint
Definition: univ.i:406
constexpr size_t UNIV_PAGE_SIZE_MAX
Maximum page size InnoDB currently supports.
Definition: univ.i:323
constexpr ulint ULINT_UNDEFINED
The 'undefined' value for a ulint.
Definition: univ.i:420
Utilities related to class lifecycle.
#define ut_ad(EXPR)
Debug assertion.
Definition: ut0dbg.h:105
#define ut_a(EXPR)
Abort execution if EXPR does not evaluate to nonzero.
Definition: ut0dbg.h:93
unsigned long id[MAX_DEAD]
Definition: xcom_base.cc:510
int n
Definition: xcom_base.cc:509