MySQL 9.6.0
Source Code Documentation
sql_foreign_key_constraint.h
Go to the documentation of this file.
1/* Copyright (c) 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#pragma once
24
25class THD;
26struct TABLE;
27
28enum class enum_fk_dml_type {
32 // REPLACE executes as DELETE (of the conflicting row) + INSERT (the new row)
33 // For the DELETE, FK checks must use the before-image (record[1]) to build
34 // the FK search key; FK_DELETE_REPLACE signals this path (not record[0],
35 // the after-image).
37};
38
39/**
40 * @brief Check if TABLE instance for foreign key is already opened.
41 *
42 * @param thd Thread handle.
43 * @param db_name DB name.
44 * @param table_name Table name.
45 * @param fk_name Foreign key name.
46 *
47 * @return true If table for foreign key is already opened.
48 * @return false If table is not opened.
49 */
50bool is_foreign_key_table_opened(THD *thd, const char *db_name,
51 const char *table_name, const char *fk_name);
52
53/**
54 * @brief Check all foreign key constraints on parent tables for DML operation
55 * on a child table.
56 *
57 * @param thd Thread handle.
58 * @param table_c TABLE instance of a child table.
59 * @param dml_type DML operation type.
60 *
61 * @return true On error.
62 * @return false On Success.
63 */
64bool check_all_parent_fk_ref(THD *thd, const TABLE *table_c,
65 enum_fk_dml_type dml_type);
66
67/**
68 * @brief Check all foreign key constraints on child tables for DML operation
69 * on a parent table.
70 *
71 * @param thd Thread handle.
72 * @param table_p TABLE instance of a parent table.
73 * @param dml_type DML operation type.
74 *
75 * @return true On error.
76 * @return false On Success.
77 */
78bool check_all_child_fk_ref(THD *thd, const TABLE *table_p,
79 enum_fk_dml_type dml_type);
For each client connection we create a separate thread with THD serving as a thread/connection descri...
Definition: sql_lexer_thd.h:36
const char * table_name
Definition: rules_table_service.cc:56
const char * db_name
Definition: rules_table_service.cc:55
bool is_foreign_key_table_opened(THD *thd, const char *db_name, const char *table_name, const char *fk_name)
Check if TABLE instance for foreign key is already opened.
Definition: sql_foreign_key_constraint.cc:1669
enum_fk_dml_type
Definition: sql_foreign_key_constraint.h:28
bool check_all_parent_fk_ref(THD *thd, const TABLE *table_c, enum_fk_dml_type dml_type)
Check all foreign key constraints on parent tables for DML operation on a child table.
Definition: sql_foreign_key_constraint.cc:1583
bool check_all_child_fk_ref(THD *thd, const TABLE *table_p, enum_fk_dml_type dml_type)
Check all foreign key constraints on child tables for DML operation on a parent table.
Definition: sql_foreign_key_constraint.cc:1662
Definition: table.h:1450