1 /*****************************************************************************
2 
3 Copyright (c) 2005, 2020, Oracle and/or its affiliates. All Rights Reserved.
4 
5 This program is free software; you can redistribute it and/or modify it under
6 the terms of the GNU General Public License, version 2.0, as published by the
7 Free Software Foundation.
8 
9 This program is also distributed with certain software (including but not
10 limited to OpenSSL) that is licensed under separate terms, as designated in a
11 particular file or component or in included license documentation. The authors
12 of MySQL hereby grant you an additional permission to link the program and
13 your derivative works with the separately licensed software that they have
14 included with MySQL.
15 
16 This program is distributed in the hope that it will be useful, but WITHOUT
17 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
18 FOR A PARTICULAR PURPOSE. See the GNU General Public License, version 2.0,
19 for more details.
20 
21 You should have received a copy of the GNU General Public License along with
22 this program; if not, write to the Free Software Foundation, Inc.,
23 51 Franklin St, Fifth Floor, Boston, MA 02110-1301  USA
24 
25 *****************************************************************************/
26 
27 /** @file include/handler0alter.h
28  Smart ALTER TABLE
29  *******************************************************/
30 
31 #ifndef handler0alter_h
32 #define handler0alter_h
33 
34 #define ERROR_STR_LENGTH 1024
35 
36 /** Copies an InnoDB record to table->record[0]. */
37 void innobase_rec_to_mysql(struct TABLE *table, /*!< in/out: MySQL table */
38                            const rec_t *rec,    /*!< in: record */
39                            const dict_index_t *index, /*!< in: index */
40                            const ulint *offsets);     /*!< in: rec_get_offsets(
41                                                      rec, index, ...) */
42 
43 /** Copies an InnoDB index entry to table->record[0]. */
44 void innobase_fields_to_mysql(
45     struct TABLE *table,       /*!< in/out: MySQL table */
46     const dict_index_t *index, /*!< in: InnoDB index */
47     const dfield_t *fields);   /*!< in: InnoDB index fields */
48 
49 /** Copies an InnoDB row to table->record[0]. */
50 void innobase_row_to_mysql(struct TABLE *table,      /*!< in/out: MySQL table */
51                            const dict_table_t *itab, /*!< in: InnoDB table */
52                            const dtuple_t *row);     /*!< in: InnoDB row */
53 
54 /** Resets table->record[0]. */
55 void innobase_rec_reset(struct TABLE *table); /*!< in/out: MySQL table */
56 
57 /** Generate the next autoinc based on a snapshot of the session
58 auto_increment_increment and auto_increment_offset variables.
59 Assingnment operator would be used during the inplace_alter_table()
60 phase only **/
61 struct ib_sequence_t {
62   /**
63   @param thd the session
64   @param start_value the lower bound
65   @param max_value the upper bound (inclusive) */
66   ib_sequence_t(THD *thd, ulonglong start_value, ulonglong max_value);
67 
68   /** Postfix increment
69   @return the value to insert */
70   ulonglong operator++(int) UNIV_NOTHROW;
71 
72   /** Check if the autoinc "sequence" is exhausted.
73   @return true if the sequence is exhausted */
eofib_sequence_t74   bool eof() const UNIV_NOTHROW { return (m_eof); }
75 
76   /** assignment operator to copy the sequence values
77   @param in 		sequence to copy from */
78   ib_sequence_t &operator=(const ib_sequence_t &in) {
79     ut_ad(in.m_next_value > 0);
80     ut_ad(in.m_max_value == m_max_value);
81     m_next_value = in.m_next_value;
82     m_increment = in.m_increment;
83     m_offset = in.m_offset;
84     m_eof = in.m_eof;
85     return (*this);
86   }
87   /**
88   @return the next value in the sequence */
lastib_sequence_t89   ulonglong last() const UNIV_NOTHROW {
90     ut_ad(m_next_value > 0);
91 
92     return (m_next_value);
93   }
94 
95   /** Maximum calumn value if adding an AUTOINC column else 0. Once
96   we reach the end of the sequence it will be set to ~0. */
97   const ulonglong m_max_value;
98 
99   /** Value of auto_increment_increment */
100   ulong m_increment;
101 
102   /** Value of auto_increment_offset */
103   ulong m_offset;
104 
105   /** Next value in the sequence */
106   ulonglong m_next_value;
107 
108   /** true if no more values left in the sequence */
109   bool m_eof;
110 };
111 
112 #endif /* handler0alter_h */
113