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