MySQL 26.10.0
Source Code Documentation
mrs_component_table_access.h
Go to the documentation of this file.
1/*
2 Copyright (c) 2026, Oracle and/or its affiliates.
3
4 This program is free software; you can redistribute it and/or modify
5 it under the terms of the GNU General Public License, version 2.0,
6 as published by the Free Software Foundation.
7
8 This program is designed to work with certain software (including
9 but not limited to OpenSSL) that is licensed under separate terms,
10 as designated in a particular file or component or in included license
11 documentation. The authors of MySQL hereby grant you an additional
12 permission to link the program and your derivative works with the
13 separately licensed software that they have either included with
14 the program or referenced in the documentation.
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 for more details.
20
21 You should have received a copy of the GNU General Public License
22 along with this program; if not, write to the Free Software
23 Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
24*/
25
26#ifndef MRS_COMPONENT_TABLE_ACCESS_H
27#define MRS_COMPONENT_TABLE_ACCESS_H
28
29#include <cstdint>
30#include <functional>
31#include <string>
32#include <vector>
33
35
36namespace mrs_component {
37
38/**
39 RAII wrapper around MySQL Table Access services.
40 Handles:
41 - session creation/destruction
42 - table registration/open
43 - simple row scanning
44 - VARCHAR field getter
45*/
47 public:
48 struct Ticket {
49 size_t id{SIZE_MAX}; // Ticket ID assigned by table_access
50 TA_table tbl{nullptr}; // Filled after begin()
51 };
52
53 // Factory: create Table_accessor bound to current THD
54 static Table_accessor make_with_current_ctx(size_t max_tables = 4);
55
57
58 Table_accessor() = delete;
59 Table_accessor(const Table_accessor &) = delete;
63
64 [[nodiscard]] bool valid() const { return ta_ != nullptr; }
65
66 Ticket add_table_read(const char *schema, const char *table);
67 Ticket add_table_write(const char *schema, const char *table);
68
69 bool begin();
70 bool materialize_tables(std::vector<Ticket> &tickets);
71 bool materialize_table(Ticket &ticket);
72
73 // Full table scan, calls on_row(table) for each row. Return false to stop it
74 bool scan(TA_table t, const std::function<bool(TA_table)> &on_row);
75
76 // VARCHAR getter
77 bool get_varchar(TA_table t, int col, std::string &out) const;
78
79 private:
80 Table_access ta_{nullptr};
81 MYSQL_THD thd_{nullptr};
82
83 Table_accessor(MYSQL_THD thd, size_t max_tables);
84 Ticket add_table(const char *schema, const char *table, TA_lock_type mode);
85};
86
87} // namespace mrs_component
88
89#endif // MRS_COMPONENT_TABLE_ACCESS_H
#define MYSQL_THD
Definition: backup_page_tracker.h:38
RAII wrapper around MySQL Table Access services.
Definition: mrs_component_table_access.h:46
Table_access ta_
Definition: mrs_component_table_access.h:80
bool valid() const
Definition: mrs_component_table_access.h:64
Ticket add_table_write(const char *schema, const char *table)
Definition: mrs_component_table_access.cc:57
bool materialize_tables(std::vector< Ticket > &tickets)
Definition: mrs_component_table_access.cc:68
static Table_accessor make_with_current_ctx(size_t max_tables=4)
Definition: mrs_component_table_access.cc:43
bool begin()
Definition: mrs_component_table_access.cc:62
Ticket add_table_read(const char *schema, const char *table)
Definition: mrs_component_table_access.cc:52
Ticket add_table(const char *schema, const char *table, TA_lock_type mode)
Definition: mrs_component_table_access.cc:141
bool materialize_table(Ticket &ticket)
Definition: mrs_component_table_access.cc:82
Table_accessor & operator=(const Table_accessor &)=delete
Table_accessor & operator=(Table_accessor &&)=delete
bool get_varchar(TA_table t, int col, std::string &out) const
Definition: mrs_component_table_access.cc:107
bool scan(TA_table t, const std::function< bool(TA_table)> &on_row)
Definition: mrs_component_table_access.cc:89
Table_accessor(const Table_accessor &)=delete
~Table_accessor()
Definition: mrs_component_table_access.cc:36
MYSQL_THD thd_
Definition: mrs_component_table_access.h:81
Table_accessor(Table_accessor &&)=delete
TA_lock_type
Table lock type.
Definition: table_access_bits.h:46
struct Table_access_imp * Table_access
Table_access.
Definition: table_access_bits.h:99
struct TA_table_imp * TA_table
An opened table.
Definition: table_access_bits.h:104
static PFS_engine_table_share_proxy table
Definition: pfs.cc:61
Definition: mrs_component.cc:137
mode
Definition: file_handle.h:61
Definition: mrs_component_table_access.h:48
TA_table tbl
Definition: mrs_component_table_access.h:50
Generic table access interface.