This is a read-only copy of the MariaDB Knowledgebase generated on 2024-12-23. For the latest, interactive version please visit https://mariadb.com/kb/.

Connect Memory Usage

When creating a connection, a THD object is created for that connection. This contains all connection information and also caches to speed up queries and avoid frequent malloc() calls.

When creating a new connection, the following malloc() calls are done for the THD:

The following information is the state in MariaDB 10.6.1 when compiled without debugging.

Local Thread Memory

This is part of select memory_used from information_schema.processlist .

Amount allocatedWhere allocated Description
26646THD::THDAllocation of THD object
256Statement_map::Statement_map(), my_hash_init(key_memory_prepared_statement_map, &st_hashPrepared statements
256my_hash_init(key_memory_prepared_statement_map, &names_hashNames of used prepared statements
128wsrep_wfc(), Opt_trace_context(), dynamic_array()
1024Diagnostics_area::init(),init_sql_alloc(PSI_INSTRUMENT_ME, &m_warn_root
120Session_sysvars_tracker, global_system_variables.session_track_system_variablesTracking of changed session variables
280THD::THD,my_hash_init(key_memory_user_var_entry,&user_vars
280THD::THD,my_hash_init(PSI_INSTRUMENT_ME, &sequencesCache of used sequences
1048THD::THD, m_token_array= my_malloc(PSI_INSTRUMENT_ME, max_digest_length
16416CONNECT::create_thd(), my_net_init(), net_allocate_new_packet()This is for reading data from the connected user
16416check_connection(), thd->packet.alloc()This is for sending data to connected user

Objects Stored in THD->memroot During Connect

Amount allocatedWhere allocatedDescription
72send_server_handshake_packet, mpvio->cached_server_packet.pkt=
64parse_client_handshake_packet, thd->copy_with_error(...db,db_len)
32parse_client_handshake_packet, sctx->user=
368ACL_USER::copy(), root=Allocation of ACL_USER object
56ACL_USER::copy(), dst->user= safe_lexcstrdup_root(root, user)
56ACL_USER::copy()Allocation of other connect attributes
56ACL_USER::copy()
64ACL_USER::copy()
64ACL_USER::copy()
32mysql_change_db()Store current db in THD
48dbname_cache->insert(db_name)Store db name in db name cache
40mysql_change_db(), my_register_filename(db.opt)Store filename db.opt
8216load_db_opt(), init_io_cache()Disk cache for reading db.opt
1112load_db_opts(), put_dbopts()Cache default database parameters

State at First Call to mysql_execute_command

(gdb) p thd->status_var.local_memory_used
$24 = 75496
(gdb) p thd->status_var.global_memory_used
$25 = 17544
(gdb) p thd->variables.query_prealloc_size
$30 = 24576
(gdb) p thd->variables.trans_prealloc_size
$37 = 4096
Content reproduced on this site is the property of its respective owners, and this content is not reviewed in advance by MariaDB. The views, information and opinions expressed by this content do not necessarily represent those of MariaDB or any other party.