MySQL 8.4.0
Source Code Documentation
cell.h
Go to the documentation of this file.
1/* Copyright (c) 2016, 2024, Oracle and/or its affiliates.
2
3This program is free software; you can redistribute it and/or modify it under
4the terms of the GNU General Public License, version 2.0, as published by the
5Free Software Foundation.
6
7This program is designed to work with certain software (including
8but not limited to OpenSSL) that is licensed under separate terms,
9as designated in a particular file or component or in included license
10documentation. The authors of MySQL hereby grant you an additional
11permission to link the program and your derivative works with the
12separately licensed software that they have either included with
13the program or referenced in the documentation.
14
15This program is distributed in the hope that it will be useful, but WITHOUT
16ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
17FOR A PARTICULAR PURPOSE. See the GNU General Public License, version 2.0,
18for more details.
19
20You should have received a copy of the GNU General Public License along with
21this program; if not, write to the Free Software Foundation, Inc.,
2251 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA */
23
24/** @file storage/temptable/include/temptable/cell.h
25TempTable Cell declaration. */
26
27#ifndef TEMPTABLE_CELL_H
28#define TEMPTABLE_CELL_H
29
30#include <cstdint>
31
32namespace temptable {
33
34/** A cell is the intersection of a row and a column. In the handler interface
35row format (what is provided to the write_row() handler method) a cell may
36occupy too much space - in the case of a VARCHAR(N) column it will occupy N
37bytes, even if a shorter string is stored in this particular cell. So, our
38cell is derived from the above, but does not occupy unnecessary space.
39
40This class is just an interpreter - it does not store the actual data, which
41is stored in the `Row` class, allocated at once for all the cells of a row. */
42class Cell {
43 public:
44 /** Constructor. */
45 Cell(
46 /** [in] Designate whether this cell is NULL. */
47 bool is_null,
48 /** [in] Length of the user data in bytes (no metadata or any leading
49 * bytes to designate the length. Just the user data. */
50 uint32_t data_length,
51 /** [in] Pointer to the user data. It is not copied inside this newly
52 * created Cell object, so it must remain valid for the lifetime of this
53 * object. */
54 const unsigned char *data);
55
56 /** Check if this cell is NULL.
57 * @return true if NULL */
58 bool is_null() const;
59
60 /** Get the length of the user data.
61 * @return length in bytes */
62 uint32_t data_length() const;
63
64 /** Get a pointer to the user data inside the row.
65 * @return a pointer */
66 const unsigned char *data() const;
67
68 private:
69 /** Designate whether the cell is NULL. */
70 const bool m_is_null;
71
72 /** Length of the user data pointed by `m_data` in bytes. */
73 const uint32_t m_data_length;
74
75 /** User data. */
76 const unsigned char *const m_data;
77};
78
79/* Implementation of inlined methods. */
80
81inline Cell::Cell(bool is_null, uint32_t data_length, const unsigned char *data)
82 : m_is_null(is_null), m_data_length(data_length), m_data(data) {}
83
84inline bool Cell::is_null() const { return m_is_null; }
85
86inline uint32_t Cell::data_length() const { return m_data_length; }
87
88inline const unsigned char *Cell::data() const { return m_data; }
89
90} /* namespace temptable */
91
92#endif /* TEMPTABLE_CELL_H */
A cell is the intersection of a row and a column.
Definition: cell.h:42
Cell(bool is_null, uint32_t data_length, const unsigned char *data)
Constructor.
Definition: cell.h:81
const bool m_is_null
Designate whether the cell is NULL.
Definition: cell.h:70
const unsigned char * data() const
Get a pointer to the user data inside the row.
Definition: cell.h:88
bool is_null() const
Check if this cell is NULL.
Definition: cell.h:84
const uint32_t m_data_length
Length of the user data pointed by m_data in bytes.
Definition: cell.h:73
uint32_t data_length() const
Get the length of the user data.
Definition: cell.h:86
const unsigned char *const m_data
User data.
Definition: cell.h:76
Definition: allocator.h:45