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