MySQL 8.0.39
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 */
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. If --old-style-user-limits option
75 is enabled, resources are counted for each user+host separately).
76 */
77 char *user;
78 /* Pointer to host part of the key. */
79 char *host;
80 /**
81 The moment of time when per hour counters were reset last time
82 (i.e. start of "hour" for conn_per_hour, updates, questions counters).
83 */
85 /* Total length of the key. */
86 size_t len;
87 /* Current amount of concurrent connections for this account. */
89 /*
90 Current number of connections per hour, number of updating statements
91 per hour and total number of statements per hour for this account.
92 */
94 /* Maximum amount of resources which account is allowed to consume. */
97
98void init_max_user_conn(void);
99void free_max_user_conn(void);
100void reset_mqh(THD *thd, LEX_USER *lu, bool get_them);
101bool check_mqh(THD *thd, uint check_command);
104bool thd_init_client_charset(THD *thd, uint cs_number);
105bool thd_prepare_connection(THD *thd);
106void close_connection(THD *thd, uint sql_errno = 0,
107 bool server_shutdown = false, bool generate_event = true);
108bool thd_connection_alive(THD *thd);
109void end_connection(THD *thd);
110int get_or_create_user_conn(THD *thd, const char *user, const char *host,
111 const USER_RESOURCES *mqh);
112int check_for_max_user_connections(THD *thd, const USER_CONN *uc);
113
114#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:34
Some integer typedefs for easier portability.
unsigned long long int ulonglong
Definition: my_inttypes.h:56
char * user
Definition: mysqladmin.cc:60
const char * host
Definition: mysqladmin.cc:59
bool thd_prepare_connection(THD *thd)
Definition: sql_connect.cc:888
void init_max_user_conn(void)
Definition: sql_connect.cc:330
void decrease_user_connections(USER_CONN *uc)
Definition: sql_connect.cc:251
void close_connection(THD *thd, uint sql_errno=0, bool server_shutdown=false, bool generate_event=true)
Close a connection.
Definition: sql_connect.cc:913
int get_or_create_user_conn(THD *thd, const char *user, const char *host, const USER_RESOURCES *mqh)
Definition: sql_connect.cc:122
void reset_mqh(THD *thd, LEX_USER *lu, bool get_them)
Definition: sql_connect.cc:341
bool thd_connection_alive(THD *thd)
Definition: sql_connect.cc:931
void end_connection(THD *thd)
Definition: sql_connect.cc:731
void release_user_connection(THD *thd)
Definition: sql_connect.cc:270
bool thd_init_client_charset(THD *thd, uint cs_number)
Set thread character set variables from the given ID.
Definition: sql_connect.cc:389
int check_for_max_user_connections(THD *thd, const USER_CONN *uc)
Definition: sql_connect.cc:181
struct user_resources USER_RESOURCES
struct user_conn USER_CONN
void free_max_user_conn(void)
Definition: sql_connect.cc:336
bool check_mqh(THD *thd, uint check_command)
Definition: sql_connect.cc:292
Definition: table.h:2658
Definition: sql_connect.h:70
uint updates
Definition: sql_connect.h:93
char * user
Definition: sql_connect.h:77
char * host
Definition: sql_connect.h:79
uint conn_per_hour
Definition: sql_connect.h:93
USER_RESOURCES user_resources
Definition: sql_connect.h:95
ulonglong reset_utime
The moment of time when per hour counters were reset last time (i.e.
Definition: sql_connect.h:84
uint connections
Definition: sql_connect.h:88
uint questions
Definition: sql_connect.h:93
size_t len
Definition: sql_connect.h:86
Definition: sql_connect.h:41
uint conn_per_hour
Definition: sql_connect.h:50
uint user_conn
Definition: sql_connect.h:52
@ 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 updates
Definition: sql_connect.h:48
uint questions
Definition: sql_connect.h:43
uint specified_limits
Definition: sql_connect.h:63
unsigned int uint
Definition: uca9-dump.cc:75