MySQL 8.4.2
Source Code Documentation
ddl0ddl.h
Go to the documentation of this file.
1/*****************************************************************************
2
3Copyright (c) 2005, 2024, 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 /** Report a duplicate key.
134 @param[in] entry For reporting duplicate key. */
135 void report(const dfield_t *entry) noexcept;
136
137 /** Report a duplicate key.
138 @param[in] entry For reporting duplicate key.
139 @param[in] offsets Row offsets */
140 void report(const mrec_t *entry, const ulint *offsets) noexcept;
141
142 /** @return true if no duplicates reported yet. */
143 [[nodiscard]] bool empty() const noexcept { return m_n_dup == 0; }
144
145 /** Index being sorted */
147
148 /** MySQL table object */
150
151 /** Mapping of column numbers in table to the rebuilt table
152 (index->table), or NULL if not rebuilding table */
153 const ulint *m_col_map{};
154
155 /** Number of duplicates */
156 size_t m_n_dup{};
157};
158
159/** Captures ownership and manages lifetime of an already opened OS file
160descriptor. Closes the file on object destruction. */
162 public:
163 /** Default constructor, does not hold any file, does not close any on
164 destruction. */
166 /** Main constructor capturing an already opened OS file descriptor. */
168
170
172
173 /** Returns the managed OS file descriptor for use with OS functions that
174 operate on file. Do not close this file. */
175 os_fd_t get() const {
176 ut_a(is_open());
177 return m_fd;
178 }
179 bool is_open() const { return m_fd != OS_FD_CLOSED; }
180
182 close();
183 swap(other);
184 return *this;
185 }
186
187 /** Swaps the underlying managed file descriptors between two instances of
188 Unique_os_file_descriptor. No files are closed. */
190
191 /** Closes the managed file. Leaves the instance in the same state as default
192 constructed instance. */
193 void close() {
194#ifdef UNIV_PFS_IO
195 struct PSI_file_locker *locker = nullptr;
197 locker = PSI_FILE_CALL(get_thread_file_descriptor_locker)(&state, m_fd,
199 if (locker != nullptr) {
200 PSI_FILE_CALL(start_file_wait)
201 (locker, 0, __FILE__, __LINE__);
202 }
203#endif /* UNIV_PFS_IO */
204 if (m_fd != OS_FD_CLOSED) {
205 ::close(m_fd);
207 }
208#ifdef UNIV_PFS_IO
209 if (locker != nullptr) {
210 PSI_FILE_CALL(end_file_wait)(locker, 0);
211 }
212#endif /* UNIV_PFS_IO */
213 }
214
215 private:
217};
218
219/** Sets an exclusive lock on a table, for the duration of creating indexes.
220@param[in,out] trx Transaction
221@param[in] table Table to lock.
222@param[in] mode Lock mode LOCK_X or LOCK_S
223@return error code or DB_SUCCESS */
224[[nodiscard]] dberr_t lock_table(trx_t *trx, dict_table_t *table,
225 lock_mode mode) noexcept;
226
227/** Drop those indexes which were created before an error occurred.
228The data dictionary must have been locked exclusively by the caller,
229because the transaction will not be committed.
230@param[in,out] trx Transaction
231@param[in] table Table to lock.
232@param[in] locked true=table locked, false=may need to do a lazy
233 drop */
234void drop_indexes(trx_t *trx, dict_table_t *table, bool locked) noexcept;
235
236/**Create temporary merge files in the given parameter path, and if
237UNIV_PFS_IO defined, register the file descriptor with Performance Schema.
238@param[in] path Location for creating temporary merge files.
239@return File descriptor */
240[[nodiscard]] Unique_os_file_descriptor file_create_low(
241 const char *path) noexcept;
242
243/** Create the index and load in to the dictionary.
244@param[in,out] trx Trx (sets error_state)
245@param[in,out] table The index is on this table
246@param[in] index_def The index definition
247@param[in] add_v New virtual columns added along with add
248 index call
249@return index, or nullptr on error */
250[[nodiscard]] dict_index_t *create_index(
251 trx_t *trx, dict_table_t *table, const Index_defn *index_def,
252 const dict_add_v_col_t *add_v) noexcept;
253
254/** Drop a table. The caller must have ensured that the background stats
255thread is not processing the table. This can be done by calling
256dict_stats_wait_bg_to_stop_using_table() after locking the dictionary and
257before calling this function.
258@param[in,out] trx Transaction
259@param[in,out] table Table to drop.
260@return DB_SUCCESS or error code */
261dberr_t drop_table(trx_t *trx, dict_table_t *table) noexcept;
262
263/** Generate the next autoinc based on a snapshot of the session
264auto_increment_increment and auto_increment_offset variables.
265Assignment operator would be used during the inplace_alter_table()
266phase only **/
267struct Sequence {
268 /** Constructor.
269 @param[in,out] thd The session
270 @param[in] start_value The lower bound
271 @param[in] max_value The upper bound (inclusive) */
272 Sequence(THD *thd, ulonglong start_value, ulonglong max_value) noexcept;
273
274 /** Destructor. */
275 ~Sequence() = default;
276
277 /** Postfix increment
278 @return the value to insert */
279 ulonglong operator++(int) noexcept;
280
281 /** Check if the autoinc "sequence" is exhausted.
282 @return true if the sequence is exhausted */
283 bool eof() const noexcept { return m_eof; }
284
285 /** Assignment operator to copy the sequence values
286 @param[in] rhs Sequence to copy from */
287 ddl::Sequence &operator=(const ddl::Sequence &rhs) noexcept {
288 ut_ad(rhs.m_next_value > 0);
289 ut_ad(rhs.m_max_value == m_max_value);
290 m_next_value = rhs.m_next_value;
291 m_increment = rhs.m_increment;
292 m_offset = rhs.m_offset;
293 m_eof = rhs.m_eof;
294 return *this;
295 }
296
297 /** @return the next value in the sequence */
298 ulonglong last() const noexcept {
299 ut_ad(m_next_value > 0);
300 return m_next_value;
301 }
302
303 /** Maximum column value if adding an AUTOINC column else 0. Once
304 we reach the end of the sequence it will be set to ~0. */
306
307 /** Value of auto_increment_increment */
308 ulong m_increment{};
309
310 /** Value of auto_increment_offset */
311 ulong m_offset{};
312
313 /** Next value in the sequence */
315
316 /** true if no more values left in the sequence */
317 bool m_eof{};
318};
319
320/** DDL context/configuration. */
321struct Context {
322 /** Full text search context information and state. */
323 struct FTS {
324 /** Document ID sequence */
325 struct Sequence {
326 /** Destructor. */
327 virtual ~Sequence() noexcept;
328
329 /** Get the next document ID.
330 @param[in] dtuple Row from which to fetch ID.
331 @return the next document ID. */
332 virtual doc_id_t fetch(const dtuple_t *dtuple = nullptr) noexcept = 0;
333
334 /** Get the current document ID.
335 @return the current document ID. */
336 virtual doc_id_t current() noexcept = 0;
337
338 /** @return the number of document IDs generated. */
339 virtual doc_id_t generated_count() const noexcept = 0;
340
341 /** @return the maximum document ID seen so far. */
342 virtual doc_id_t max_doc_id() const noexcept = 0;
343
344 /** @return true if the document ID is generated, instead of fetched
345 from a column from the row. */
346 virtual bool is_generated() const noexcept = 0;
347
348 /** Advance the document ID. */
349 virtual void increment() noexcept = 0;
350
351 /** Current document ID. */
353 };
354
355 /** Constructor.
356 @param[in] n_parser_threads Number of FTS parser threads. */
357 explicit FTS(size_t n_parser_threads) noexcept
358 : m_n_parser_threads(n_parser_threads) {}
359
360 /** Destructor. */
361 ~FTS() noexcept { ut::delete_(m_doc_id); }
362
363 /** FTS index. */
365
366 /** Maximum number of FTS parser and sort threads to use. */
367 const size_t m_n_parser_threads{};
368
369 /** Document ID sequence generator. */
371
372 /** FTS instance. */
374 };
375
376 /** Scan sort and IO buffer size. */
377 using Scan_buffer_size = std::pair<size_t, size_t>;
378
379 /** Build indexes on a table by reading a clustered index, creating a
380 temporary file containing index entries, merge sorting these index entries and
381 inserting sorted index entries to indexes.
382 @param[in] trx Transaction.
383 @param[in] old_table Table where rows are read from
384 @param[in] new_table Table where indexes are created; identical to
385 old_table unless creating a PRIMARY KEY
386 @param[in] online True if creating indexes online
387 @param[in] indexes Indexes to be created
388 @param[in] key_numbers MySQL key numbers
389 @param[in] n_indexes Size of indexes[]
390 @param[in,out] table MySQL table, for reporting erroneous key
391 value if applicable
392 @param[in] add_cols Default values of added columns, or NULL
393 @param[in] col_map Mapping of old column numbers to new
394 ones, or nullptr if old_table == new_table
395 @param[in] add_autoinc Number of added AUTO_INCREMENT columns, or
396 ULINT_UNDEFINED if none is added
397 @param[in,out] sequence Autoinc sequence
398 @param[in] skip_pk_sort Whether the new PRIMARY KEY will follow
399 existing order
400 @param[in,out] stage Performance schema accounting object,
401 used by ALTER TABLE.
402 stage->begin_phase_read_pk() will be called
403 at the beginning of this function and it will
404 be passed to other functions for further
405 accounting.
406 @param[in] add_v New virtual columns added along with indexes
407 @param[in] eval_table MySQL table used to evaluate virtual column
408 value, see innobase_get_computed_value().
409 @param[in] max_buffer_size Memory use upper limit.
410 @param[in] max_threads true if DDL should use multiple threads. */
412 bool online, dict_index_t **indexes, const ulint *key_numbers,
413 size_t n_indexes, TABLE *table, const dtuple_t *add_cols,
414 const ulint *col_map, size_t add_autoinc, ddl::Sequence &sequence,
415 bool skip_pk_sort, Alter_stage *stage, const dict_add_v_col_t *add_v,
416 TABLE *eval_table, size_t max_buffer_size,
417 size_t max_threads) noexcept;
418
419 /** Destructor. */
420 ~Context() noexcept;
421
422 /** @return the DDL error status. */
423 dberr_t get_error() const noexcept { return m_err; }
424
425 /** Set the error code, when it's not specific to an index.
426 @param[in] err Error code. */
427 void set_error(dberr_t err) noexcept {
429
430 /* This should only be settable by the the thread that encounters the
431 first error, therefore try only once. */
432
433 dberr_t expected{DB_SUCCESS};
434 m_err.compare_exchange_strong(expected, err);
435 }
436
437 /** Set the error code and index number where the error occurred.
438 @param[in] err Error code.
439 @param[in] id Index ordinal value where error occurred. */
440 void set_error(dberr_t err, size_t id) noexcept {
441 /* This should only be settable by the the thread that encounters the
442 first error, therefore try only once. */
443
444 ut_a(err != DB_SUCCESS);
445
446 dberr_t expected{DB_SUCCESS};
447
448 if (m_err.compare_exchange_strong(expected, err)) {
449 ut_ad(m_err_key_number == std::numeric_limits<size_t>::max());
451 }
452 }
453
454 /** Build the indexes.
455 @return DB_SUCCESS or error code. */
456 [[nodiscard]] dberr_t build() noexcept;
457
458 /** @return the flush observer to use for flushing. */
459 [[nodiscard]] Flush_observer *flush_observer() noexcept;
460
461 /** @return the old table. */
462 [[nodiscard]] dict_table_t *old_table() noexcept { return m_old_table; }
463
464 /** @return the new table. */
465 [[nodiscard]] dict_table_t *new_table() noexcept { return m_new_table; }
466
467 /** Calculate the sort and buffer size per thread.
468 @param[in] n_threads Total number of threads used for scanning.
469 @return the sort and IO buffer size per thread. */
471 size_t n_threads) const noexcept;
472
473 /** Calculate the io buffer size per file for the sort phase.
474 @param[in] n_buffers Total number of buffers to use for the merge.
475 @return the sort buffer size for one instance. */
476 [[nodiscard]] size_t merge_io_buffer_size(size_t n_buffers) const noexcept;
477
478 /** Calculate the io buffer size per file for the load phase.
479 @param[in] n_buffers Total number of buffers to use for the loading.
480 @return the per thread io buffer size. */
481 [[nodiscard]] size_t load_io_buffer_size(size_t n_buffers) const noexcept;
482
483 /** Request number of bytes for a buffer.
484 @param[in] n Number of bytes requested.
485 @return the number of bytes available. */
486 [[nodiscard]] size_t allocate(size_t n) const;
487
488 /** @return the server session/connection context. */
489 [[nodiscard]] THD *thd() noexcept;
490
491 /** Copy the added columns dtuples so that we don't use the same
492 column data buffer for the added column across multiple threads.
493 @return new instance or nullptr if out of memory. */
494 [[nodiscard]] dtuple_t *create_add_cols() noexcept;
495
496 private:
497 /** @return the cluster index read cursor. */
498 [[nodiscard]] Cursor *cursor() noexcept { return m_cursor; }
499
500 /** @return the original table cluster index. */
501 [[nodiscard]] const dict_index_t *index() const noexcept;
502
503 /** Initialize the context for a cluster index scan.
504 @param[in,out] cursor Cursor used for the cluster index read. */
505 [[nodiscard]] dberr_t read_init(Cursor *cursor) noexcept;
506
507 /** Initialize the FTS build infrastructure.
508 @param[in,out] index Index prototype to build.
509 @return DB_SUCCESS or error code. */
511
512 /** Setup the FTS index build data structures.
513 @return DB_SUCCESS or error code. */
514 [[nodiscard]] dberr_t setup_fts_build() noexcept;
515
516 /** Get the next Doc ID and increment the current value.
517 @return a document ID. */
518 [[nodiscard]] doc_id_t next_doc_id() noexcept;
519
520 /** Update the FTS document ID. */
521 void update_fts_doc_id() noexcept;
522
523 /** Check the state of the online build log for the index.
524 @return DB_SUCCESS or error code. */
525 [[nodiscard]] dberr_t check_state_of_online_build_log() noexcept;
526
527 /** Track the highest TxID that modified this index when the scan
528 was completed. We prevent older readers from accessing this index, to
529 ensure read consistency.
530 @param[in,out] index Index to track. */
531 void note_max_trx_id(dict_index_t *index) noexcept;
532
533 /** Setup the primary key sort.
534 @param[in,out] cursor Setup the primary key data structures.
535 @return DB_SUCCESS or error code. */
536 [[nodiscard]] dberr_t setup_pk_sort(Cursor *cursor) noexcept;
537
538 /** Init the non-null column constraints checks (if required). */
539 void setup_nonnull() noexcept;
540
541 /** Check if the nonnull columns satisfy the constraint.
542 @param[in] row Row to check.
543 @return true on success. */
544 [[nodiscard]] bool check_null_constraints(const dtuple_t *row) const noexcept;
545
546 /** Clean up the data structures at the end of the DDL.
547 @param[in] err Status of the DDL.
548 @return DB_SUCCESS or error code. */
549 [[nodiscard]] dberr_t cleanup(dberr_t err) noexcept;
550
551 /** Handle auto increment.
552 @param[in] row Row with autoinc column.
553 @return DB_SUCCESS or error code. */
554 [[nodiscard]] dberr_t handle_autoinc(const dtuple_t *row) noexcept;
555
556 /** @return true if any virtual columns are involved. */
557 [[nodiscard]] bool has_virtual_columns() const noexcept;
558
559 /** @return true if any FTS indexes are involved. */
560 [[nodiscard]] bool has_fts_indexes() const noexcept;
561
562 /** @return true if the DDL was interrupted. */
563 [[nodiscard]] bool is_interrupted() noexcept;
564
565 private:
566 using Key_numbers = std::vector<size_t, ut::allocator<size_t>>;
567 using Indexes = std::vector<dict_index_t *, ut::allocator<dict_index_t *>>;
568
569 /** Common error code for all index builders running in parallel. */
571
572 /** Index where the error occurred. */
573 size_t m_err_key_number{std::numeric_limits<size_t>::max()};
574
575 /** Transaction covering the index build. */
577
578 /** The FTS builder. There is one FTS per table. */
580
581 /** Source table, read rows from this table. */
583
584 /** Table where indexes are created; identical to old_table unless creating
585 a PRIMARY KEY. */
587
588 /** True if creating index online. Non-online implies that we have an
589 S latch on the table, therefore there can't be concurrent updates to
590 the table while we are executing the DDL. We don't log the changes to
591 the row log. */
592 bool m_online{};
593
594 /** Indexes to be created. */
596
597 /** MySQL key numbers. */
599
600 /** MySQL table for reporting errors/warnings. */
602
603 /** Default value for added columns or null. */
605
606 /** Mapping of old column numbers to new ones, or nullptr if none
607 were added. */
608 const ulint *m_col_map{};
609
610 /** Number of added AUTO_INCREMENT columns, or ULINT_UNDEFINED if
611 none added. */
613
614 /** Autoinc sequence. */
616
617 /** Performance schema accounting object, used by ALTER TABLE.
618 stage->begin_phase_read_pk() will be called at the beginning of
619 this function and it will be passed to other functions for further
620 accounting. */
622
623 /** New virtual columns added along with indexes */
625
626 /** MySQL table used to evaluate virtual column value, see
627 innobase_get_computed_value(). */
629
630 /** Skip the sorting phase if true. */
632
633 /** Non null columns. */
634 std::vector<size_t, ut::allocator<size_t>> m_nonnull{};
635
636 /** Number of unique columns in the key. */
637 size_t m_n_uniq{};
638
639 /** true if need flush observer. */
641
642 /** Cursor for reading the cluster index. */
644
645 /** Number of bytes used. */
647
648 /** Maximum number of bytes to use. */
649 const size_t m_max_buffer_size{};
650
651 /** Maximum number of threads to use. We don't do a parallel scan of the
652 clustered index when FTS and/or virtual columns are involved. The build
653 phase is parallel though. */
654 const size_t m_max_threads{};
655
656 /** For parallel access to the autoincrement generator. */
657 ib_mutex_t m_autoinc_mutex;
658
659 /** Heap for copies of m_add_cols. */
661
662 friend struct Row;
663 friend class Loader;
664 friend struct Cursor;
665 friend struct Builder;
666 friend struct ddl::FTS;
667 friend struct Load_cursor;
668 friend struct Btree_cursor;
669 friend struct Merge_file_sort;
670 friend struct Parallel_cursor;
671};
672
673} // namespace ddl
674
675#endif /* ddl0ddl_h */
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:270
Definition: conf_to_src.cc:75
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:161
Unique_os_file_descriptor(os_fd_t fd)
Main constructor capturing an already opened OS file descriptor.
Definition: ddl0ddl.h:167
os_fd_t get() const
Returns the managed OS file descriptor for use with OS functions that operate on file.
Definition: ddl0ddl.h:175
os_fd_t m_fd
Definition: ddl0ddl.h:216
void swap(Unique_os_file_descriptor &other)
Swaps the underlying managed file descriptors between two instances of Unique_os_file_descriptor.
Definition: ddl0ddl.h:189
Unique_os_file_descriptor(Unique_os_file_descriptor &&other)
Definition: ddl0ddl.h:169
bool is_open() const
Definition: ddl0ddl.h:179
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:181
void close()
Closes the managed file.
Definition: ddl0ddl.h:193
~Unique_os_file_descriptor()
Definition: ddl0ddl.h:171
A utility class which, if inherited from, prevents the descendant class from being copied,...
Definition: ut0class_life_cycle.h:41
#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:219
Full text search header file.
uint64_t doc_id_t
Document id type.
Definition: fts0fts.h:79
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:52
unsigned long long int ulonglong
Definition: my_inttypes.h:56
static char * path
Definition: mysqldump.cc:149
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:468
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:300
dberr_t drop_table(trx_t *trx, dict_table_t *table) noexcept
Drop a table.
Definition: ddl0ddl.cc:291
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:129
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:184
byte[UNIV_PAGE_SIZE_MAX] mrec_buf_t
Secondary buffer for I/O operations of merge records.
Definition: ddl0ddl.h:72
static Value err()
Create a Value object that represents an error condition.
Definition: json_binary.cc:927
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:2874
void delete_(T *ptr) noexcept
Releases storage which has been dynamically allocated through any of the ut::new*() variants.
Definition: ut0new.h:809
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:663
State data storage for get_thread_file_name_locker_v1_t.
Definition: psi_file_bits.h:146
Definition: table.h:1406
Definition: completion_hash.h:35
For loading indexes.
Definition: ddl0impl-builder.h:48
Document ID sequence.
Definition: ddl0ddl.h:325
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:352
virtual doc_id_t max_doc_id() const noexcept=0
Full text search context information and state.
Definition: ddl0ddl.h:323
~FTS() noexcept
Destructor.
Definition: ddl0ddl.h:361
ddl::FTS * m_ptr
FTS instance.
Definition: ddl0ddl.h:373
FTS(size_t n_parser_threads) noexcept
Constructor.
Definition: ddl0ddl.h:357
const size_t m_n_parser_threads
Maximum number of FTS parser and sort threads to use.
Definition: ddl0ddl.h:367
Sequence * m_doc_id
Document ID sequence generator.
Definition: ddl0ddl.h:370
dict_index_t * m_index
FTS index.
Definition: ddl0ddl.h:364
DDL context/configuration.
Definition: ddl0ddl.h:321
size_t m_err_key_number
Index where the error occurred.
Definition: ddl0ddl.h:573
~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:640
void set_error(dberr_t err) noexcept
Set the error code, when it's not specific to an index.
Definition: ddl0ddl.h:427
const dtuple_t * m_add_cols
Default value for added columns or null.
Definition: ddl0ddl.h:604
dict_table_t * old_table() noexcept
Definition: ddl0ddl.h:462
bool is_interrupted() noexcept
Definition: ddl0ctx.cc:523
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:608
dberr_t cleanup(dberr_t err) noexcept
Clean up the data structures at the end of the DDL.
Definition: ddl0ctx.cc:300
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:660
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:525
bool m_skip_pk_sort
Skip the sorting phase if true.
Definition: ddl0ddl.h:631
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:474
std::vector< size_t, ut::allocator< size_t > > m_nonnull
Non null columns.
Definition: ddl0ddl.h:634
TABLE * m_table
MySQL table for reporting errors/warnings.
Definition: ddl0ddl.h:601
dict_table_t * m_old_table
Source table, read rows from this table.
Definition: ddl0ddl.h:582
std::vector< size_t, ut::allocator< size_t > > Key_numbers
Definition: ddl0ddl.h:566
dict_table_t * new_table() noexcept
Definition: ddl0ddl.h:465
void setup_nonnull() noexcept
Init the non-null column constraints checks (if required).
Definition: ddl0ctx.cc:387
const dict_add_v_col_t * m_add_v
New virtual columns added along with indexes.
Definition: ddl0ddl.h:624
const size_t m_max_buffer_size
Maximum number of bytes to use.
Definition: ddl0ddl.h:649
dict_table_t * m_new_table
Table where indexes are created; identical to old_table unless creating a PRIMARY KEY.
Definition: ddl0ddl.h:586
void update_fts_doc_id() noexcept
Update the FTS document ID.
trx_t * m_trx
Transaction covering the index build.
Definition: ddl0ddl.h:576
size_t m_n_allocated
Number of bytes used.
Definition: ddl0ddl.h:646
std::atomic< dberr_t > m_err
Common error code for all index builders running in parallel.
Definition: ddl0ddl.h:570
Cursor * cursor() noexcept
Definition: ddl0ddl.h:498
size_t m_n_uniq
Number of unique columns in the key.
Definition: ddl0ddl.h:637
ib_mutex_t m_autoinc_mutex
For parallel access to the autoincrement generator.
Definition: ddl0ddl.h:657
bool has_virtual_columns() const noexcept
Definition: ddl0ctx.cc:224
bool has_fts_indexes() const noexcept
Definition: ddl0ctx.cc:431
dberr_t check_state_of_online_build_log() noexcept
Check the state of the online build log for the index.
Definition: ddl0ctx.cc:461
dberr_t setup_fts_build() noexcept
Setup the FTS index build data structures.
Definition: ddl0ctx.cc:444
FTS m_fts
The FTS builder.
Definition: ddl0ddl.h:579
dberr_t setup_pk_sort(Cursor *cursor) noexcept
Setup the primary key sort.
Definition: ddl0ctx.cc:494
std::pair< size_t, size_t > Scan_buffer_size
Scan sort and IO buffer size.
Definition: ddl0ddl.h:377
Key_numbers m_key_numbers
MySQL key numbers.
Definition: ddl0ddl.h:598
size_t m_add_autoinc
Number of added AUTO_INCREMENT columns, or ULINT_UNDEFINED if none added.
Definition: ddl0ddl.h:612
dberr_t handle_autoinc(const dtuple_t *row) noexcept
Handle auto increment.
Definition: ddl0ctx.cc:239
Flush_observer * flush_observer() noexcept
Definition: ddl0ctx.cc:136
bool m_online
True if creating index online.
Definition: ddl0ddl.h:592
Indexes m_indexes
Indexes to be created.
Definition: ddl0ddl.h:595
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:423
void set_error(dberr_t err, size_t id) noexcept
Set the error code and index number where the error occurred.
Definition: ddl0ddl.h:440
std::vector< dict_index_t *, ut::allocator< dict_index_t * > > Indexes
Definition: ddl0ddl.h:567
dberr_t read_init(Cursor *cursor) noexcept
Initialize the context for a cluster index scan.
Definition: ddl0ctx.cc:502
ddl::Sequence & m_sequence
Autoinc sequence.
Definition: ddl0ddl.h:615
friend struct Btree_cursor
Definition: ddl0ddl.h:668
Cursor * m_cursor
Cursor for reading the cluster index.
Definition: ddl0ddl.h:643
Alter_stage * m_stage
Performance schema accounting object, used by ALTER TABLE.
Definition: ddl0ddl.h:621
const size_t m_max_threads
Maximum number of threads to use.
Definition: ddl0ddl.h:654
dberr_t build() noexcept
Build the indexes.
Definition: ddl0ctx.cc:511
bool check_null_constraints(const dtuple_t *row) const noexcept
Check if the nonnull columns satisfy the constraint.
Definition: ddl0ctx.cc:417
dberr_t fts_create(dict_index_t *index) noexcept
Initialize the FTS build infrastructure.
Definition: ddl0ctx.cc:286
TABLE * m_eval_table
MySQL table used to evaluate virtual column value, see innobase_get_computed_value().
Definition: ddl0ddl.h:628
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:146
size_t m_n_dup
Number of duplicates.
Definition: ddl0ddl.h:156
void report(const dfield_t *entry) noexcept
Report a duplicate key.
Definition: ddl0ddl.cc:83
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:153
TABLE * m_table
MySQL table object.
Definition: ddl0ddl.h:149
bool empty() const noexcept
Definition: ddl0ddl.h:143
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:457
Merge the blocks in the file.
Definition: ddl0impl-merge.h:43
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:267
ulonglong last() const noexcept
Definition: ddl0ddl.h:298
bool m_eof
true if no more values left in the sequence
Definition: ddl0ddl.h:317
ulong m_increment
Value of auto_increment_increment.
Definition: ddl0ddl.h:308
const ulonglong m_max_value
Maximum column value if adding an AUTOINC column else 0.
Definition: ddl0ddl.h:305
ddl::Sequence & operator=(const ddl::Sequence &rhs) noexcept
Assignment operator to copy the sequence values.
Definition: ddl0ddl.h:287
ulong m_offset
Value of auto_increment_offset.
Definition: ddl0ddl.h:311
ulonglong operator++(int) noexcept
Postfix increment.
Definition: ddl0ctx.cc:560
Sequence(THD *thd, ulonglong start_value, ulonglong max_value) noexcept
Constructor.
Definition: ddl0ctx.cc:538
ulonglong m_next_value
Next value in the sequence.
Definition: ddl0ddl.h:314
~Sequence()=default
Destructor.
bool eof() const noexcept
Check if the autoinc "sequence" is exhausted.
Definition: ddl0ddl.h:283
Structure for an SQL data field.
Definition: data0data.h:605
Data structure for newly added virtual column in a table.
Definition: dict0mem.h:835
Data structure for an index.
Definition: dict0mem.h:1046
Data structure for a database table.
Definition: dict0mem.h:1909
Structure for an SQL data tuple of fields (logical record)
Definition: data0data.h:682
The info structure stored at the beginning of a heap block.
Definition: mem0mem.h:302
Definition: plugin_ftparser.h:216
Definition: trx0trx.h:684
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