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