1 /*****************************************************************************
2 
3 Copyright (c) 2005, 2016, Oracle and/or its affiliates. All Rights Reserved.
4 Copyright (c) 2019, MariaDB Corporation.
5 
6 This program is free software; you can redistribute it and/or modify it under
7 the terms of the GNU General Public License as published by the Free Software
8 Foundation; version 2 of the License.
9 
10 This program is distributed in the hope that it will be useful, but WITHOUT
11 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
12 FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
13 
14 You should have received a copy of the GNU General Public License along with
15 this program; if not, write to the Free Software Foundation, Inc.,
16 51 Franklin Street, Fifth Floor, Boston, MA 02110-1335 USA
17 
18 *****************************************************************************/
19 
20 /**************************************************//**
21 @file include/handler0alter.h
22 Smart ALTER TABLE
23 *******************************************************/
24 
25 #include "rem0types.h"
26 
27 /*************************************************************//**
28 Copies an InnoDB record to table->record[0]. */
29 void
30 innobase_rec_to_mysql(
31 /*==================*/
32 	struct TABLE*		table,	/*!< in/out: MySQL table */
33 	const rec_t*		rec,	/*!< in: record */
34 	const dict_index_t*	index,	/*!< in: index */
35 	const rec_offs*		offsets)/*!< in: rec_get_offsets(
36 					rec, index, ...) */
37 	MY_ATTRIBUTE((nonnull));
38 
39 /*************************************************************//**
40 Copies an InnoDB index entry to table->record[0]. */
41 void
42 innobase_fields_to_mysql(
43 /*=====================*/
44 	struct TABLE*		table,	/*!< in/out: MySQL table */
45 	const dict_index_t*	index,	/*!< in: InnoDB index */
46 	const dfield_t*		fields)	/*!< in: InnoDB index fields */
47 	MY_ATTRIBUTE((nonnull));
48 
49 /*************************************************************//**
50 Copies an InnoDB row to table->record[0]. */
51 void
52 innobase_row_to_mysql(
53 /*==================*/
54 	struct TABLE*		table,	/*!< in/out: MySQL table */
55 	const dict_table_t*	itab,	/*!< in: InnoDB table */
56 	const dtuple_t*		row)	/*!< in: InnoDB row */
57 	MY_ATTRIBUTE((nonnull));
58 
59 /** Generate the next autoinc based on a snapshot of the session
60 auto_increment_increment and auto_increment_offset variables. */
61 struct ib_sequence_t {
62 
63 	/**
64 	@param thd the session
65 	@param start_value the lower bound
66 	@param max_value the upper bound (inclusive) */
67 	ib_sequence_t(THD* thd, ulonglong start_value, ulonglong max_value);
68 
69 	/** Postfix increment
70 	@return the value to insert */
71 	ulonglong operator++(int) UNIV_NOTHROW;
72 
73 	/** Check if the autoinc "sequence" is exhausted.
74 	@return true if the sequence is exhausted */
eofib_sequence_t75 	bool eof() const UNIV_NOTHROW
76 	{
77 		return(m_eof);
78 	}
79 
80 	/**
81 	@return the next value in the sequence */
lastib_sequence_t82 	ulonglong last() const UNIV_NOTHROW
83 	{
84 		ut_ad(m_next_value > 0);
85 
86 		return(m_next_value);
87 	}
88 
89 	/** @return maximum column value
90 	@retval	0	if not adding AUTO_INCREMENT column */
max_valueib_sequence_t91 	ulonglong max_value() const { return m_max_value; }
92 
93 private:
94 	/** Maximum value if adding an AUTO_INCREMENT column, else 0 */
95 	ulonglong	m_max_value;
96 
97 	/** Value of auto_increment_increment */
98 	ulong		m_increment;
99 
100 	/** Value of auto_increment_offset */
101 	ulong		m_offset;
102 
103 	/** Next value in the sequence */
104 	ulonglong	m_next_value;
105 
106 	/** true if no more values left in the sequence */
107 	bool		m_eof;
108 };
109