MySQL  8.0.17
Source Code Documentation
sql_connect.h
Go to the documentation of this file.
1 /* Copyright (c) 2006, 2017, Oracle and/or its affiliates. All rights reserved.
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 
31 class THD;
32 
33 struct 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 */
40 typedef 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 */
69 typedef 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. */
95 } USER_CONN;
96 
97 void init_max_user_conn(void);
98 void free_max_user_conn(void);
99 void reset_mqh(THD *thd, LEX_USER *lu, bool get_them);
100 bool check_mqh(THD *thd, uint check_command);
102 void release_user_connection(THD *thd);
103 bool thd_init_client_charset(THD *thd, uint cs_number);
104 bool thd_prepare_connection(THD *thd);
105 void close_connection(THD *thd, uint sql_errno = 0,
106  bool server_shutdown = false, bool generate_event = true);
107 bool thd_connection_alive(THD *thd);
108 void end_connection(THD *thd);
109 int get_or_create_user_conn(THD *thd, const char *user, const char *host,
110  const USER_RESOURCES *mqh);
111 int check_for_max_user_connections(THD *thd, const USER_CONN *uc);
112 
113 #endif /* SQL_CONNECT_INCLUDED */
unsigned long long int ulonglong
Definition: my_inttypes.h:74
bool check_mqh(THD *thd, uint check_command)
Definition: sql_connect.cc:299
char * user
Definition: mysqladmin.cc:58
uint connections
Definition: sql_connect.h:87
void decrease_user_connections(USER_CONN *uc)
Definition: sql_connect.cc:255
Some integer typedefs for easier portability.
uint user_conn
Definition: sql_connect.h:51
size_t len
Definition: sql_connect.h:85
const char * host
Definition: mysqladmin.cc:57
ulonglong reset_utime
The moment of time when per hour counters were reset last time (i.e.
Definition: sql_connect.h:83
uint conn_per_hour
Definition: sql_connect.h:92
struct user_conn USER_CONN
void end_connection(THD *thd)
Definition: sql_connect.cc:730
bool thd_prepare_connection(THD *thd)
Definition: sql_connect.cc:847
void reset_mqh(THD *thd, LEX_USER *lu, bool get_them)
Definition: sql_connect.cc:348
uint updates
Definition: sql_connect.h:47
int get_or_create_user_conn(THD *thd, const char *user, const char *host, const USER_RESOURCES *mqh)
Definition: sql_connect.cc:126
char * user
Definition: sql_connect.h:76
Definition: table.h:2342
Definition: sql_connect.h:58
bool thd_connection_alive(THD *thd)
Definition: sql_connect.cc:889
char * host
Definition: sql_connect.h:78
USER_RESOURCES user_resources
Definition: sql_connect.h:94
void close_connection(THD *thd, uint sql_errno=0, bool server_shutdown=false, bool generate_event=true)
Close a connection.
Definition: sql_connect.cc:870
Definition: sql_connect.h:57
struct user_resources USER_RESOURCES
void release_user_connection(THD *thd)
Definition: sql_connect.cc:275
Definition: sql_connect.h:60
unsigned int uint
Definition: uca-dump.cc:29
uint questions
Definition: sql_connect.h:42
Definition: sql_connect.h:59
uint conn_per_hour
Definition: sql_connect.h:49
Definition: sql_connect.h:40
Definition: sql_connect.h:69
int check_for_max_user_connections(THD *thd, const USER_CONN *uc)
Definition: sql_connect.cc:185
void free_max_user_conn(void)
Definition: sql_connect.cc:343
uint updates
Definition: sql_connect.h:92
uint questions
Definition: sql_connect.h:92
void init_max_user_conn(void)
Definition: sql_connect.cc:337
uint specified_limits
Definition: sql_connect.h:62
bool thd_init_client_charset(THD *thd, uint cs_number)
Set thread character set variables from the given ID.
Definition: sql_connect.cc:396
For each client connection we create a separate thread with THD serving as a thread/connection descri...
Definition: sql_class.h:777