mysql_handler/engine/bulk_access.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//! Engine decision returned from the `start_bulk_*` callbacks.
24
25/// Whether the engine batches the rows of a multi-row UPDATE or DELETE itself,
26/// or lets MySQL drive the statement one row at a time.
27///
28/// MySQL's `start_bulk_update` / `start_bulk_delete` encode this as an inverted
29/// bool (`true` means "bulk not used"); this enum exists so engine code never
30/// has to reason about that inversion.
31#[derive(Debug, Clone, Copy, PartialEq, Eq)]
32#[non_exhaustive]
33pub enum BulkAccess {
34 /// Engine batches the rows; MySQL routes them through the bulk path
35 /// (`bulk_update_row` + `exec_bulk_update` for updates, `end_bulk_delete`
36 /// for deletes). Maps to C++ `false`.
37 Batched,
38 /// Engine declines batching; MySQL performs the statement row by row via
39 /// `update_row` / `delete_row`. Maps to C++ `true`, the handler-base default.
40 PerRow,
41}
42
43impl BulkAccess {
44 /// The MySQL bool expected by `start_bulk_update` / `start_bulk_delete`:
45 /// `true` when the engine declines batching (normal per-row operation),
46 /// matching the inverted handler-base contract.
47 #[must_use]
48 pub fn to_mysql_bool(self) -> bool {
49 match self {
50 Self::Batched => false,
51 Self::PerRow => true,
52 }
53 }
54}
55
56#[cfg(test)]
57mod tests {
58 use super::*;
59
60 #[test]
61 fn per_row_declines_batching() {
62 assert!(BulkAccess::PerRow.to_mysql_bool());
63 }
64
65 #[test]
66 fn batched_accepts_the_bulk_path() {
67 assert!(!BulkAccess::Batched.to_mysql_bool());
68 }
69}