mysql_handler/sys.rs
1// Copyright (C) 2026 ren-yamanashi
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 this program 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 for more details.
19//
20// You should have received a copy of the GNU General Public License
21// along with this program; if not, see <https://www.gnu.org/licenses/>.
22
23//! Raw FFI bindings: MySQL handler constants and opaque C++ types
24
25#[allow(non_upper_case_globals, non_camel_case_types, non_snake_case)]
26#[allow(missing_docs, unreachable_pub, missing_debug_implementations)]
27#[allow(clippy::all, clippy::pedantic)]
28mod generated {
29 include!("sys_bindings.rs");
30}
31
32pub use generated::*;
33
34// Hand-written as `u64` because `Table_flags` is `unsigned long long` upstream
35// but bindgen's default macro type would render these as `i64`.
36
37/// `HA_BINLOG_ROW_CAPABLE` from `sql/handler.h`
38pub const HA_BINLOG_ROW_CAPABLE: u64 = 1 << 34;
39
40/// `HA_BINLOG_STMT_CAPABLE` from `sql/handler.h`
41pub const HA_BINLOG_STMT_CAPABLE: u64 = 1 << 35;
42
43/// `HTON_CAN_RECREATE` from `sql/handler.h`: the engine implements `TRUNCATE`
44/// by recreating the table. This is the flag the zero-config handlerton sets,
45/// so it backs [`HtonFlags::CAN_RECREATE`]. Hand-written as `u32` because
46/// `sql/handler.h` is not a bindgen input; `shim/binding.cc` static-asserts
47/// the value to catch upstream drift.
48///
49/// [`HtonFlags::CAN_RECREATE`]: crate::hton::HtonFlags::CAN_RECREATE
50pub const HTON_CAN_RECREATE: u32 = 1 << 2;
51
52/// `HA_READ_NEXT` from `sql/handler.h`: index supports forward
53/// `index_next`.
54pub const HA_READ_NEXT: u32 = 1;
55
56/// `HA_READ_PREV` from `sql/handler.h`: index supports backward
57/// `index_prev`.
58pub const HA_READ_PREV: u32 = 2;
59
60/// `HA_READ_ORDER` from `sql/handler.h`: index reads return rows in key
61/// order (the optimizer skips a server-side sort).
62pub const HA_READ_ORDER: u32 = 4;
63
64/// `HA_READ_RANGE` from `sql/handler.h`: index supports `read_range_first`
65/// / `read_range_next`.
66pub const HA_READ_RANGE: u32 = 8;
67
68/// Opaque C++ `RustHandlerBase` from `shim/binding.hpp`
69#[repr(C)]
70#[derive(Debug)]
71pub struct RustHandlerBase([u8; 0]);
72
73/// Opaque MySQL `TABLE`
74#[repr(C)]
75#[derive(Debug)]
76pub struct TABLE([u8; 0]);
77
78/// Opaque MySQL `TABLE_SHARE`
79#[repr(C)]
80#[derive(Debug)]
81pub struct TABLE_SHARE([u8; 0]);
82
83/// Opaque MySQL `THD` (thread handle)
84#[repr(C)]
85#[derive(Debug)]
86pub struct THD([u8; 0]);
87
88/// Opaque MySQL `XID` (X/Open distributed-transaction identifier)
89#[repr(C)]
90#[derive(Debug)]
91pub struct XID([u8; 0]);
92
93/// Opaque MySQL data-dictionary `dd::Table`
94#[repr(C)]
95#[derive(Debug)]
96pub struct DdTable([u8; 0]);
97
98/// Opaque MySQL data-dictionary `dd::Column`
99#[repr(C)]
100#[derive(Debug)]
101pub struct DdColumn([u8; 0]);
102
103/// Opaque MySQL data-dictionary `dd::Index`
104#[repr(C)]
105#[derive(Debug)]
106pub struct DdIndex([u8; 0]);
107
108/// Opaque MySQL data-dictionary `dd::Index_element` (key part)
109#[repr(C)]
110#[derive(Debug)]
111pub struct DdIndexElement([u8; 0]);
112
113/// Opaque MySQL `HA_CREATE_INFO`
114#[allow(non_camel_case_types)]
115#[repr(C)]
116#[derive(Debug)]
117pub struct HA_CREATE_INFO([u8; 0]);
118
119/// Opaque MySQL `KEY` (index descriptor)
120#[allow(non_camel_case_types)]
121#[repr(C)]
122#[derive(Debug)]
123pub struct KEY([u8; 0]);
124
125/// Opaque MySQL `List<Create_field>` (C++ template instantiation)
126#[repr(C)]
127#[derive(Debug)]
128pub struct ListCreateField([u8; 0]);
129
130/// Opaque MySQL `Rows_mysql` (bulk-load row batch)
131#[repr(C)]
132#[derive(Debug)]
133pub struct RowsMysql([u8; 0]);
134
135/// Opaque MySQL `Bulk_load::Stat_callbacks` (bulk-load progress callbacks)
136#[repr(C)]
137#[derive(Debug)]
138pub struct BulkLoadStatCallbacks([u8; 0]);
139
140/// Opaque MySQL `String` (a full-text query string, among other uses)
141#[repr(C)]
142#[derive(Debug)]
143pub struct MysqlString([u8; 0]);
144
145/// Opaque MySQL `Ft_hints` (full-text search hints)
146#[repr(C)]
147#[derive(Debug)]
148pub struct FtHints([u8; 0]);
149
150/// Opaque MySQL `RANGE_SEQ_IF` (multi-range read range-sequence interface)
151#[repr(C)]
152#[derive(Debug)]
153pub struct RangeSeqIf([u8; 0]);
154
155/// Opaque MySQL `Cost_estimate` (optimizer cost accumulator)
156#[repr(C)]
157#[derive(Debug)]
158pub struct CostEstimate([u8; 0]);
159
160/// Opaque MySQL `HANDLER_BUFFER` (caller-owned multi-range read scratch buffer)
161#[repr(C)]
162#[derive(Debug)]
163pub struct HandlerBuffer([u8; 0]);
164
165/// Opaque MySQL `Field` (one table column's metadata and value accessors)
166#[repr(C)]
167#[derive(Debug)]
168pub struct Field([u8; 0]);
169
170/// Opaque MySQL `Alter_inplace_info` (in-place `ALTER TABLE` change descriptor)
171#[repr(C)]
172#[derive(Debug)]
173pub struct AlterInplaceInfo([u8; 0]);
174
175/// Opaque MySQL `HA_CHECK_OPT` (options for `CHECK` / `REPAIR` / `ANALYZE` etc.)
176#[repr(C)]
177#[derive(Debug)]
178pub struct HaCheckOpt([u8; 0]);
179
180/// Opaque MySQL `MDL_key` (metadata-lock key identifying a database object)
181#[repr(C)]
182#[derive(Debug)]
183pub struct MdlKey([u8; 0]);
184
185/// Opaque MySQL `dd::Tablespace` (data-dictionary tablespace object)
186#[repr(C)]
187#[derive(Debug)]
188pub struct DdTablespace([u8; 0]);
189
190/// Opaque MySQL `st_alter_tablespace` (legacy ALTER TABLESPACE descriptor)
191#[repr(C)]
192#[derive(Debug)]
193pub struct StAlterTablespace([u8; 0]);
194
195/// Opaque MySQL `sdi_key_t` (SDI key identifying a dictionary object)
196#[repr(C)]
197#[derive(Debug)]
198pub struct SdiKey([u8; 0]);
199
200/// Opaque MySQL `sdi_vector_t` (collection of SDI keys filled by `sdi_get_keys`)
201#[repr(C)]
202#[derive(Debug)]
203pub struct SdiVector([u8; 0]);
204
205/// Opaque MySQL `Json_dom` (JSON DOM node for log-info collection)
206#[repr(C)]
207#[derive(Debug)]
208pub struct JsonDom([u8; 0]);
209
210/// Opaque MySQL `Ha_fk_column_type` (foreign-key column type descriptor)
211#[repr(C)]
212#[derive(Debug)]
213pub struct HaFkColumnType([u8; 0]);
214
215/// Opaque MySQL `LEX` (parsed-statement descriptor used by the optimizer)
216#[repr(C)]
217#[derive(Debug)]
218pub struct Lex([u8; 0]);
219
220/// Opaque MySQL `JOIN` (join-plan descriptor handed to cost-comparison hooks)
221#[repr(C)]
222#[derive(Debug)]
223pub struct Join([u8; 0]);
224
225/// Opaque MySQL `JoinHypergraph` (hypergraph used by the new join optimizer)
226#[repr(C)]
227#[derive(Debug)]
228pub struct JoinHypergraph([u8; 0]);
229
230/// Opaque MySQL `AccessPath` (an execution-plan node from the join optimizer)
231#[repr(C)]
232#[derive(Debug)]
233pub struct AccessPath([u8; 0]);
234
235/// Opaque MySQL `Ha_clone_cbk` (data-transfer callback object used by clone)
236#[repr(C)]
237#[derive(Debug)]
238pub struct HaCloneCbk([u8; 0]);
239
240#[cfg(test)]
241mod tests {
242 use super::*;
243
244 #[test]
245 fn ha_err_end_of_file_is_137() {
246 assert_eq!(HA_ERR_END_OF_FILE, 137);
247 }
248
249 #[test]
250 fn ha_binlog_stmt_capable_bit() {
251 assert_eq!(HA_BINLOG_STMT_CAPABLE, 1u64 << 35);
252 }
253
254 #[test]
255 fn hton_can_recreate_bit() {
256 assert_eq!(HTON_CAN_RECREATE, 1u32 << 2);
257 }
258}