MySQL 8.0.30
Source Code Documentation
sql_connect.h
Go to the documentation of this file.
1/* Copyright (c) 2006, 2022, 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 also distributed 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 included with MySQL.
13
14 This program is distributed in the hope that it will be useful,
15 but WITHOUT ANY WARRANTY; without even the implied warranty of
16 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 GNU General Public License, version 2.0, for more details.
18
19 You should have received a copy of the GNU General Public License
20 along with this program; if not, write to the Free Software
21 Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA */
22
23#ifndef SQL_CONNECT_INCLUDED
24#define SQL_CONNECT_INCLUDED
25
26#include <stddef.h>
27#include <sys/types.h>
28
29#include "my_inttypes.h"
30
31class THD;
32
33struct LEX_USER;
34
35/*
36 This structure specifies the maximum amount of resources which
37 can be consumed by each account. Zero value of a member means
38 there is no limit.
39*/
40typedef struct user_resources {
41 /* Maximum number of queries/statements per hour. */
43 /*
44 Maximum number of updating statements per hour (which statements are
45 updating is defined by sql_command_flags array).
46 */
48 /* Maximum number of connections established per hour. */
50 /* Maximum number of concurrent connections. */
52 /*
53 Values of this enum and specified_limits member are used by the
54 parser to store which user limits were specified in GRANT statement.
55 */
56 enum {
61 };
64
65/*
66 This structure is used for counting resources consumed and for checking
67 them against specified user limits.
68*/
69typedef struct user_conn {
70 /*
71 Pointer to user+host key (pair separated by '\0') defining the entity
72 for which resources are counted (By default it is user account thus
73 priv_user/priv_host pair is used. If --old-style-user-limits option
74 is enabled, resources are counted for each user+host separately).
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_class.h:922
Some integer typedefs for easier portability.
unsigned long long int ulonglong
Definition: my_inttypes.h:55
char * user
Definition: mysqladmin.cc:59
const char * host
Definition: mysqladmin.cc:58
bool thd_prepare_connection(THD *thd)
Definition: sql_connect.cc:882
void init_max_user_conn(void)
Definition: sql_connect.cc:329
void decrease_user_connections(USER_CONN *uc)
Definition: sql_connect.cc:250
void close_connection(THD *thd, uint sql_errno=0, bool server_shutdown=false, bool generate_event=true)
Close a connection.
Definition: sql_connect.cc:907
int get_or_create_user_conn(THD *thd, const char *user, const char *host, const USER_RESOURCES *mqh)
Definition: sql_connect.cc:121
void reset_mqh(THD *thd, LEX_USER *lu, bool get_them)
Definition: sql_connect.cc:340
bool thd_connection_alive(THD *thd)
Definition: sql_connect.cc:925
void end_connection(THD *thd)
Definition: sql_connect.cc:730
void release_user_connection(THD *thd)
Definition: sql_connect.cc:269
bool thd_init_client_charset(THD *thd, uint cs_number)
Set thread character set variables from the given ID.
Definition: sql_connect.cc:388
int check_for_max_user_connections(THD *thd, const USER_CONN *uc)
Definition: sql_connect.cc:180
struct user_resources USER_RESOURCES
struct user_conn USER_CONN
void free_max_user_conn(void)
Definition: sql_connect.cc:335
bool check_mqh(THD *thd, uint check_command)
Definition: sql_connect.cc:291
Definition: table.h:2551
Definition: sql_connect.h:69
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:40
uint conn_per_hour
Definition: sql_connect.h:49
uint user_conn
Definition: sql_connect.h:51
@ USER_CONNECTIONS
Definition: sql_connect.h:60
@ UPDATES_PER_HOUR
Definition: sql_connect.h:58
@ CONNECTIONS_PER_HOUR
Definition: sql_connect.h:59
@ QUERIES_PER_HOUR
Definition: sql_connect.h:57
uint updates
Definition: sql_connect.h:47
uint questions
Definition: sql_connect.h:42
uint specified_limits
Definition: sql_connect.h:62
unsigned int uint
Definition: uca-dump.cc:29