MySQL 8.4.2
Source Code Documentation
sql_connect.h
Go to the documentation of this file.
1/* Copyright (c) 2006, 2024, 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 SQL_CONNECT_INCLUDED
25#define SQL_CONNECT_INCLUDED
26
27#include <stddef.h>
28#include <sys/types.h>
29
30#include "my_inttypes.h"
31
32class THD;
33
34struct LEX_USER;
35
36/*
37 This structure specifies the maximum amount of resources which
38 can be consumed by each account. Zero value of a member means
39 there is no limit.
40*/
41typedef struct user_resources {
42 /* Maximum number of queries/statements per hour. */
44 /*
45 Maximum number of updating statements per hour (which statements are
46 updating is defined by sql_command_flags array).
47 */
48 uint updates;
49 /* Maximum number of connections established per hour. */
51 /* Maximum number of concurrent connections. */
53 /*
54 Values of this enum and specified_limits member are used by the
55 parser to store which user limits were specified in GRANT statement.
56 */
57 enum {
62 };
65
66/*
67 This structure is used for counting resources consumed and for checking
68 them against specified user limits.
69*/
70typedef struct user_conn {
71 /*
72 Pointer to user+host key (pair separated by '\0') defining the entity
73 for which resources are counted (By default it is user account thus
74 priv_user/priv_host pair is used).
75 */
76 char *user;
77 /* Pointer to host part of the key. */
78 char *host;
79 /**
80 The moment of time when per hour counters were reset last time
81 (i.e. start of "hour" for conn_per_hour, updates, questions counters).
82 */
84 /* Total length of the key. */
85 size_t len;
86 /* Current amount of concurrent connections for this account. */
88 /*
89 Current number of connections per hour, number of updating statements
90 per hour and total number of statements per hour for this account.
91 */
93 /* Maximum amount of resources which account is allowed to consume. */
96
97void init_max_user_conn(void);
98void free_max_user_conn(void);
99void reset_mqh(THD *thd, LEX_USER *lu, bool get_them);
100bool check_mqh(THD *thd, uint check_command);
103bool thd_init_client_charset(THD *thd, uint cs_number);
104bool thd_prepare_connection(THD *thd);
105void close_connection(THD *thd, uint sql_errno = 0,
106 bool server_shutdown = false, bool generate_event = true);
107bool thd_connection_alive(THD *thd);
108void end_connection(THD *thd);
109int get_or_create_user_conn(THD *thd, const char *user, const char *host,
110 const USER_RESOURCES *mqh);
111int check_for_max_user_connections(THD *thd, const USER_CONN *uc);
112
113#endif /* SQL_CONNECT_INCLUDED */
For each client connection we create a separate thread with THD serving as a thread/connection descri...
Definition: sql_lexer_thd.h:36
Some integer typedefs for easier portability.
unsigned long long int ulonglong
Definition: my_inttypes.h:56
char * user
Definition: mysqladmin.cc:66
const char * host
Definition: mysqladmin.cc:65
bool thd_prepare_connection(THD *thd)
Definition: sql_connect.cc:893
void init_max_user_conn(void)
Definition: sql_connect.cc:331
void decrease_user_connections(USER_CONN *uc)
Definition: sql_connect.cc:252
void close_connection(THD *thd, uint sql_errno=0, bool server_shutdown=false, bool generate_event=true)
Close a connection.
Definition: sql_connect.cc:918
int get_or_create_user_conn(THD *thd, const char *user, const char *host, const USER_RESOURCES *mqh)
Definition: sql_connect.cc:123
void reset_mqh(THD *thd, LEX_USER *lu, bool get_them)
Definition: sql_connect.cc:342
bool thd_connection_alive(THD *thd)
Definition: sql_connect.cc:936
void end_connection(THD *thd)
Definition: sql_connect.cc:733
void release_user_connection(THD *thd)
Definition: sql_connect.cc:271
bool thd_init_client_charset(THD *thd, uint cs_number)
Set thread character set variables from the given ID.
Definition: sql_connect.cc:390
int check_for_max_user_connections(THD *thd, const USER_CONN *uc)
Definition: sql_connect.cc:182
struct user_resources USER_RESOURCES
struct user_conn USER_CONN
void free_max_user_conn(void)
Definition: sql_connect.cc:337
bool check_mqh(THD *thd, uint check_command)
Definition: sql_connect.cc:293
Definition: table.h:2731
Definition: sql_connect.h:70
uint updates
Definition: sql_connect.h:92
char * user
Definition: sql_connect.h:76
char * host
Definition: sql_connect.h:78
uint conn_per_hour
Definition: sql_connect.h:92
USER_RESOURCES user_resources
Definition: sql_connect.h:94
ulonglong reset_utime
The moment of time when per hour counters were reset last time (i.e.
Definition: sql_connect.h:83
uint connections
Definition: sql_connect.h:87
uint questions
Definition: sql_connect.h:92
size_t len
Definition: sql_connect.h:85
Definition: sql_connect.h:41
uint conn_per_hour
Definition: sql_connect.h:50
uint user_conn
Definition: sql_connect.h:52
uint updates
Definition: sql_connect.h:48
uint questions
Definition: sql_connect.h:43
@ USER_CONNECTIONS
Definition: sql_connect.h:61
@ UPDATES_PER_HOUR
Definition: sql_connect.h:59
@ CONNECTIONS_PER_HOUR
Definition: sql_connect.h:60
@ QUERIES_PER_HOUR
Definition: sql_connect.h:58
uint specified_limits
Definition: sql_connect.h:63