MySQL 8.3.0
Source Code Documentation
sql_connect.h
Go to the documentation of this file.
1/* Copyright (c) 2006, 2023, 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 */
47 uint updates;
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).
74 */
75 char *user;
76 /* Pointer to host part of the key. */
77 char *host;
78 /**
79 The moment of time when per hour counters were reset last time
80 (i.e. start of "hour" for conn_per_hour, updates, questions counters).
81 */
83 /* Total length of the key. */
84 size_t len;
85 /* Current amount of concurrent connections for this account. */
87 /*
88 Current number of connections per hour, number of updating statements
89 per hour and total number of statements per hour for this account.
90 */
92 /* Maximum amount of resources which account is allowed to consume. */
95
96void init_max_user_conn(void);
97void free_max_user_conn(void);
98void reset_mqh(THD *thd, LEX_USER *lu, bool get_them);
99bool check_mqh(THD *thd, uint check_command);
102bool thd_init_client_charset(THD *thd, uint cs_number);
103bool thd_prepare_connection(THD *thd);
104void close_connection(THD *thd, uint sql_errno = 0,
105 bool server_shutdown = false, bool generate_event = true);
106bool thd_connection_alive(THD *thd);
107void end_connection(THD *thd);
108int get_or_create_user_conn(THD *thd, const char *user, const char *host,
109 const USER_RESOURCES *mqh);
110int check_for_max_user_connections(THD *thd, const USER_CONN *uc);
111
112#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:35
Some integer typedefs for easier portability.
unsigned long long int ulonglong
Definition: my_inttypes.h:55
char * user
Definition: mysqladmin.cc:64
const char * host
Definition: mysqladmin.cc:63
bool thd_prepare_connection(THD *thd)
Definition: sql_connect.cc:892
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:917
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:935
void end_connection(THD *thd)
Definition: sql_connect.cc:732
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:2720
Definition: sql_connect.h:69
uint updates
Definition: sql_connect.h:91
char * user
Definition: sql_connect.h:75
char * host
Definition: sql_connect.h:77
uint conn_per_hour
Definition: sql_connect.h:91
USER_RESOURCES user_resources
Definition: sql_connect.h:93
ulonglong reset_utime
The moment of time when per hour counters were reset last time (i.e.
Definition: sql_connect.h:82
uint connections
Definition: sql_connect.h:86
uint questions
Definition: sql_connect.h:91
size_t len
Definition: sql_connect.h:84
Definition: sql_connect.h:40
uint conn_per_hour
Definition: sql_connect.h:49
uint user_conn
Definition: sql_connect.h:51
uint updates
Definition: sql_connect.h:47
uint questions
Definition: sql_connect.h:42
uint specified_limits
Definition: sql_connect.h:62
@ 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