[MDEV-9954] Prevent MEMORY tables from consuming all RAM Created: 2016-04-19  Updated: 2020-11-06

Status: Confirmed
Project: MariaDB Server
Component/s: Storage Engine - Memory
Fix Version/s: None

Type: Task Priority: Major
Reporter: Hartmut Holzgraefe Assignee: Unassigned
Resolution: Unresolved Votes: 1
Labels: None

Issue Links:
Relates
relates to MDEV-18257 Make memory usage safer for temp tables Open

 Description   

While the size of a single MEMORY/HEAP table is limited by max_heap_table_size there is no limit for the number of tables (max_tmp_table variable exists, but has no function and is deprecated) or for the total amount of RAM available for MEMORY tables.

Memory usage of implicit memory tables is more or less limited by MIN(tmp_table_size, max_heap_table_size)*max_connections (when not taking subqueries and stored function calls into account), but so far nothing prevents a single user session from explicitly creating MEMORY tables until the mysqld process runs into an out-of-memory (OOM) situation ... which could e.g. be used for denial-of-service attacks ...



 Comments   
Comment by Sergei Golubchik [ 2016-04-21 ]

That's not much different from creating many on-disk tables and consuming all disk space. If the user was granted the privilege to create tables, he can create a lot of them, there is no currently no way to prevent that.

Might be useful to implement some limits there, indeed...

Comment by Hartmut Holzgraefe [ 2016-04-21 ]

The big difference is that "disk full" situations are handled more or less gracefully ("Table full" errors etc.) while running out of RAM due to too much data in MEMORY tables leads to mysqld process termination, usually even without leaving traces in the mysqld error log about the actual cause of termination ...

We already have max_heap_table_size for MEMORY tables to limit their size and memory consumption on a per-table basis, something we don't have for disk based tables either. So we're treating MEMORY tables different to on-disk tables already. With disk tables you can fill up all disk with a single table, too, there is not even a need to create multiple ones.

This is a feature request to extend what we already do to single MEMORY tables – putting an upper limit on their memory resource usage – to the MEMORY engine as a whole, to be more consistent.

Following your argument we should just get rid of max_heap_table_size, too, as it makes things different from on-disk tables ...

Generated at Thu Feb 08 07:38:34 UTC 2024 using Jira 8.20.16#820016-sha1:9d11dbea5f4be3d4cc21f03a88dd11d8c8687422.