summaryrefslogtreecommitdiff
path: root/sql/sql_class.h
diff options
context:
space:
mode:
authorunknown <konstantin@mysql.com>2006-04-07 23:37:06 +0400
committerunknown <konstantin@mysql.com>2006-04-07 23:37:06 +0400
commit5b5530daa5c0f5fb20121ab9ce5a159fce900101 (patch)
tree8f4f2952727fffa7429bb8deb43a9a72dc7bf4e0 /sql/sql_class.h
parent5aa14b983277d45ca55bea8f5fcdf5229f054bec (diff)
downloadmariadb-git-5b5530daa5c0f5fb20121ab9ce5a159fce900101.tar.gz
A fix and a test case for Bug#16365 "Prepared Statements: DoS with
too many open statements". The patch adds a new global variable @@max_prepared_stmt_count. This variable limits the total number of prepared statements in the server. The default value of @@max_prepared_stmt_count is 16382. 16382 small statements (a select against 3 tables with GROUP, ORDER and LIMIT) consume 100MB of RAM. Once this limit has been reached, the server will refuse to prepare a new statement and return ER_UNKNOWN_ERROR (unfortunately, we can't add new errors to 4.1 without breaking 5.0). The limit is changeable after startup and can accept any value from 0 to 1 million. In case the new value of the limit is less than the current statement count, no new statements can be added, while the old still can be used. Additionally, the current count of prepared statements is now available through a global read-only variable @@prepared_stmt_count. mysql-test/r/ps.result: Test results fixed (a test case for Bug#16365) mysql-test/t/ps.test: A test case for Bug#16365 "Prepared Statements: DoS with too many open statements". Also fix statement leaks in other tests. sql/mysql_priv.h: Add declarations for new global variables. sql/mysqld.cc: Add definitions of max_prepared_stmt_count, prepared_stmt_count. sql/set_var.cc: Implement support for @@prepared_stmt_count and @@max_prepared_stmt_count. Currently these variables are queried without acquiring LOCK_prepared_stmt_count due to limitations of the set_var/sys_var class design. Updates are, however, protected with a lock. sql/set_var.h: New declarations to add support for @@max_prepared_stmt_count. Implement a new class, where the lock to be used when updating a variable is a parameter. sql/sql_class.cc: Add accounting of the total number of prepared statements in the server to the methods of Statement_map. sql/sql_class.h: Add accounting of the total number of prepared statements in the server to the methods of Statement_map. sql/sql_prepare.cc: Statement_map::insert will now send a message in case of an error.
Diffstat (limited to 'sql/sql_class.h')
-rw-r--r--sql/sql_class.h28
1 files changed, 5 insertions, 23 deletions
diff --git a/sql/sql_class.h b/sql/sql_class.h
index 41170192892..8fe1e7990e9 100644
--- a/sql/sql_class.h
+++ b/sql/sql_class.h
@@ -620,7 +620,7 @@ class Statement_map
public:
Statement_map();
- int insert(Statement *statement);
+ int insert(THD *thd, Statement *statement);
Statement *find_by_name(LEX_STRING *name)
{
@@ -642,29 +642,10 @@ public:
}
return last_found_statement;
}
- void erase(Statement *statement)
- {
- if (statement == last_found_statement)
- last_found_statement= 0;
- if (statement->name.str)
- {
- hash_delete(&names_hash, (byte *) statement);
- }
- hash_delete(&st_hash, (byte *) statement);
- }
+ void erase(Statement *statement);
/* Erase all statements (calls Statement destructor) */
- void reset()
- {
- my_hash_reset(&names_hash);
- my_hash_reset(&st_hash);
- last_found_statement= 0;
- }
-
- ~Statement_map()
- {
- hash_free(&names_hash);
- hash_free(&st_hash);
- }
+ void reset();
+ ~Statement_map();
private:
HASH st_hash;
HASH names_hash;
@@ -932,6 +913,7 @@ public:
{
my_bool my_bool_value;
long long_value;
+ ulong ulong_value;
} sys_var_tmp;
THD();