MySQL 9.3.0
Source Code Documentation
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages Concepts
ha_mock.h
Go to the documentation of this file.
1/* Copyright (c) 2018, 2025, Oracle and/or its affiliates.
2
3 This program is free software; you can redistribute it and/or modify
4 it under the terms of the GNU General Public License, version 2.0,
5 as published by the Free Software Foundation.
6
7 This program is designed to work with certain software (including
8 but not limited to OpenSSL) that is licensed under separate terms,
9 as designated in a particular file or component or in included license
10 documentation. The authors of MySQL hereby grant you an additional
11 permission to link the program and your derivative works with the
12 separately licensed software that they have either included with
13 the program or referenced in the documentation.
14
15 This program is distributed in the hope that it will be useful,
16 but WITHOUT ANY WARRANTY; without even the implied warranty of
17 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 GNU General Public License, version 2.0, for more details.
19
20 You should have received a copy of the GNU General Public License
21 along with this program; if not, write to the Free Software
22 Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA */
23
24#ifndef PLUGIN_SECONDARY_ENGINE_MOCK_HA_MOCK_H_
25#define PLUGIN_SECONDARY_ENGINE_MOCK_HA_MOCK_H_
26
27#include "my_base.h"
28#include "sql/handler.h"
30#include "thr_lock.h"
31
32class THD;
33struct TABLE;
34struct TABLE_SHARE;
35
36namespace dd {
37class Table;
38}
39
40namespace mock {
41
42/**
43 * The MOCK storage engine does not actually implement partitioning,
44 * but we support the Partition_handler interface in order to be able
45 * to access tables that are partitioned in the primary engine.
46 */
48 public:
49 explicit FakePartitionHandler(const handler *engine) : m_engine(engine) {}
50
52 ha_checksum *check_sum,
53 uint part_id) override {
54 auto *primary_part_handler =
56
57 return primary_part_handler->get_dynamic_partition_info(stat_info,
58 check_sum, part_id);
59 }
60
61 void set_part_info(partition_info *, bool) override {}
62
63 enum row_type get_partition_row_type(const dd::Table *, uint) override {
64 return ROW_TYPE_NOT_USED;
65 }
66
67 private:
69};
70
71/**
72 * The MOCK storage engine is used for testing MySQL server functionality
73 * related to secondary storage engines.
74 *
75 * There are currently no secondary storage engines mature enough to be merged
76 * into mysql-trunk. Therefore, this bare-minimum storage engine, with no
77 * actual functionality and implementing only the absolutely necessary handler
78 * interfaces to allow setting it as a secondary engine of a table, was created
79 * to facilitate pushing MySQL server code changes to mysql-trunk with test
80 * coverage without depending on ongoing work of other storage engines.
81 *
82 * @note This mock storage engine does not support being set as a primary
83 * storage engine.
84 */
85class ha_mock : public handler {
86 public:
88
89 /**
90 * Partition_handler
91 */
93 return &m_part_handler;
94 }
95
96 private:
97 int create(const char *, TABLE *, HA_CREATE_INFO *, dd::Table *) override {
99 }
100
101 int open(const char *name, int mode, unsigned int test_if_locked,
102 const dd::Table *table_def) override;
103
104 int close() override { return 0; }
105
106 int rnd_init(bool) override { return 0; }
107
108 int rnd_next(unsigned char *) override { return HA_ERR_END_OF_FILE; }
109
110 int rnd_pos(unsigned char *, unsigned char *) override {
112 }
113
114 int info(unsigned int) override;
115
116 ha_rows records_in_range(unsigned int index, key_range *min_key,
117 key_range *max_key) override;
118
119 void position(const unsigned char *) override {}
120
121 unsigned long index_flags(unsigned int, unsigned int, bool) const override;
122
124 thr_lock_type lock_type) override;
125
126 Table_flags table_flags() const override;
127
128 const char *table_type() const override { return "MOCK"; }
129
130 /**
131 * Load table into the secondary engine.
132 *
133 * @param[in] table - table to be loaded
134 * @param[out] skip_metadata_update - should the DD metadata be updated for
135 * the load of this table
136 * @return 0 if success
137 */
138 int load_table(const TABLE &table, bool *skip_metadata_update) override;
139
140 /**
141 * Unload the table from secondary engine
142 *
143 * @param[in] db_name database name
144 * @param[in] table_name table name
145 * @param[in] error_if_not_loaded - whether to report an error if the table is
146 * already not present in the secondary engine.
147 * @return 0 if success
148 */
149 int unload_table(const char *db_name, const char *table_name,
150 bool error_if_not_loaded) override;
151
154};
155
156} // namespace mock
157
158#endif // PLUGIN_SECONDARY_ENGINE_MOCK_HA_MOCK_H_
Class for partitioning specific operations.
Definition: partition_handler.h:194
virtual void get_dynamic_partition_info(ha_statistics *stat_info, ha_checksum *check_sum, uint part_id)=0
Get dynamic table information from partition.
For each client connection we create a separate thread with THD serving as a thread/connection descri...
Definition: sql_lexer_thd.h:36
Definition: table.h:47
Definition: handler.h:4076
The handler class is the interface for dynamically loadable storage engines.
Definition: handler.h:4618
TABLE_SHARE * table_share
Definition: handler.h:4626
virtual Partition_handler * get_partition_handler()
Definition: handler.h:7236
ulonglong Table_flags
Definition: handler.h:4622
handler * ha_get_primary_handler() const
Get a pointer to a handler for the table in the primary storage engine, if this handler is for a tabl...
Definition: handler.h:7266
TABLE * table
Definition: handler.h:4627
The MOCK storage engine does not actually implement partitioning, but we support the Partition_handle...
Definition: ha_mock.h:47
const handler * m_engine
Definition: ha_mock.h:68
FakePartitionHandler(const handler *engine)
Definition: ha_mock.h:49
void set_part_info(partition_info *, bool) override
Set the partition info object to be used by the handler.
Definition: ha_mock.h:61
void get_dynamic_partition_info(ha_statistics *stat_info, ha_checksum *check_sum, uint part_id) override
Get dynamic table information from partition.
Definition: ha_mock.h:51
enum row_type get_partition_row_type(const dd::Table *, uint) override
Get partition row type from SE.
Definition: ha_mock.h:63
The MOCK storage engine is used for testing MySQL server functionality related to secondary storage e...
Definition: ha_mock.h:85
int rnd_init(bool) override
rnd_init() can be called two times without rnd_end() in between (it only makes sense if scan=1).
Definition: ha_mock.h:106
const char * table_type() const override
The following can be called without an open handler.
Definition: ha_mock.h:128
int create(const char *, TABLE *, HA_CREATE_INFO *, dd::Table *) override
Create table (implementation).
Definition: ha_mock.h:97
int unload_table(const char *db_name, const char *table_name, bool error_if_not_loaded) override
Unload the table from secondary engine.
Definition: ha_mock.cc:222
THR_LOCK_DATA m_lock
Definition: ha_mock.h:152
int close() override
Definition: ha_mock.h:104
void position(const unsigned char *) override
Definition: ha_mock.h:119
int info(unsigned int) override
Definition: ha_mock.cc:161
int load_table(const TABLE &table, bool *skip_metadata_update) override
Load table into the secondary engine.
Definition: ha_mock.cc:209
int rnd_pos(unsigned char *, unsigned char *) override
Definition: ha_mock.h:110
ha_rows records_in_range(unsigned int index, key_range *min_key, key_range *max_key) override
Definition: ha_mock.cc:195
unsigned long index_flags(unsigned int, unsigned int, bool) const override
Definition: ha_mock.cc:177
Table_flags table_flags() const override
Definition: ha_mock.cc:171
ha_mock(handlerton *hton, TABLE_SHARE *table_share)
Definition: ha_mock.cc:146
int rnd_next(unsigned char *) override
Definition: ha_mock.h:108
THR_LOCK_DATA ** store_lock(THD *thd, THR_LOCK_DATA **to, thr_lock_type lock_type) override
Is not invoked for non-transactional temporary tables.
Definition: ha_mock.cc:201
int open(const char *name, int mode, unsigned int test_if_locked, const dd::Table *table_def) override
Definition: ha_mock.cc:149
FakePartitionHandler m_part_handler
Definition: ha_mock.h:153
Partition_handler * get_partition_handler() override
Partition_handler.
Definition: ha_mock.h:92
Definition: partition_info.h:209
A table definition from the master.
Definition: rpl_utility.h:249
This file includes constants used by all storage engines.
my_off_t ha_rows
Definition: my_base.h:1141
#define HA_ERR_WRONG_COMMAND
Command not supported.
Definition: my_base.h:841
#define HA_ERR_END_OF_FILE
end in next/prev/first/last
Definition: my_base.h:853
std::uint32_t ha_checksum
Definition: my_checksum.h:106
The version of the current data dictionary table definitions.
Definition: dictionary_client.h:43
bool index(const std::string &value, const String &search_for, uint32_t *idx)
Definition: contains.h:75
Definition: ha_mock.cc:144
entry::Table Table
Definition: select.h:51
const char * table_name
Definition: rules_table_service.cc:56
const char * db_name
Definition: rules_table_service.cc:55
mode
Definition: file_handle.h:61
row_type
Definition: handler.h:686
@ ROW_TYPE_NOT_USED
Definition: handler.h:687
Struct to hold information about the table that should be created.
Definition: handler.h:3238
This structure is shared between different table objects.
Definition: table.h:708
Definition: table.h:1425
Definition: thr_lock.h:124
handlerton is a singleton structure - one instance per storage engine - to provide access to storage ...
Definition: handler.h:2765
Definition: my_base.h:1125
thr_lock_type
Definition: thr_lock.h:51