[MDEV-607] LP:821241 - Server reports memory exhausted on statement prepare Created: 2011-08-05  Updated: 2021-07-27

Status: Open
Project: MariaDB Server
Component/s: Parser
Affects Version/s: 10.0.2, 5.5.31, 5.1.67, 5.2.14, 5.3.12, 5.5, 10.0, 10.1
Fix Version/s: 10.1

Type: Bug Priority: Minor
Reporter: Arjen Lentz (Inactive) Assignee: Unassigned
Resolution: Unresolved Votes: 1
Labels: Launchpad, upstream, verified

Attachments: XML File LPexportBug821241.xml    

 Description   

Applying this trick: http://openquery.com/blog/cache-preloading-mysqld-startup
(I realise this has been superceded by the XtraDB LRU dump/reload stuff - but since the below occurred and appears to identify a bug, it's useful to report anyway)

It's MariaDB 5.2.7

MariaDB [(none)]> SET SESSION group_concat_max_len=100*1024*1024;
Query OK, 0 rows affected (0.00 sec)
 
MariaDB [(none)]> SELECT GROUP_CONCAT(CONCAT('SELECT COUNT(`',column_name,'`) FROM `',table_schema,'`.`',table_name,'` FORCE INDEX (`',index_name,'`)') SEPARATOR ' UNION ALL ') INTO @sql FROM information_schema.statistics WHERE table_schema NOT IN ('information_schema','mysql') AND seq_in_index = 1;
Query OK, 1 row affected (0.15 sec)
 
MariaDB [(none)]> select length(@sql);
+--------------+
| length(@sql) |
+--------------+
|       869378 |
+--------------+
1 row in set (0.00 sec)

so far so good, resulting SQL query is only 800K long.

MariaDB [(none)]> PREPARE stmt FROM @sql;
ERROR 1064 (42000): memory exhausted near 'INDEX (`PRIMARY`) UNION ALL SELECT COUNT(`id`) FROM `dbname`.`colname' at line 1

It appears (thanks HarrisonF) that the parser runs out of memory? We reckon that'd be a bug.

I'm happy to pass along the entire @sql string, but a) it contains customer details (db/table/col names) so it'd have to be in private and b) the SQL wouldn't run on any other server anyway since the parser would find nonexistent dbs/tables/cols and thus never get to the bug.



 Comments   
Comment by Rasmus Johansson (Inactive) [ 2011-08-05 ]

Launchpad bug id: 821241

Comment by Elena Stepanova [ 2013-06-02 ]
  1. Also reproducible on all of MySQL 5.1 - 5.7

MTR test case

--disable_warnings
DROP DATABASE IF EXISTS db;
--enable_warnings
CREATE DATABASE db;
USE db;
 
--let $tables = 200
while ($tables) 
{
	--let $sql = CREATE TABLE t$tables (pk INT NOT NULL
	--let $indexes = PRIMARY KEY (pk)
	--let $columns = 63
	while ($columns) 
	{
		--let $sql = $sql, c$columns INT
		--let $indexes = $indexes, INDEX ind$columns (c$columns)
		--dec $columns
	}
	--let $sql = $sql, $indexes) ENGINE=MyISAM
	--eval $sql
	--dec $tables
}
 
SET SESSION group_concat_max_len=100*1024*1024;
 
SELECT GROUP_CONCAT(CONCAT('SELECT COUNT(`',column_name,'`) FROM `',table_schema,'`.`',table_name,'` FORCE INDEX (`',index_name,'`)') SEPARATOR ' UNION ALL ') INTO @sql FROM information_schema.statistics WHERE table_schema NOT IN ('information_schema','mysql') AND seq_in_index = 1;
 
select length(@sql);
 
prepare stmt from @sql;
 
DROP DATABASE db;

Comment by Dennis [ 2021-07-27 ]

Ran into this issue today attempting to execute a generated query consisting of:

insert into...
select from (
  select [constants]
  union all
  select [constants]
  union all
 ...
) left join ...
where ...

The query was a little over 3 megs long and the parser died around line 10.000 (~1.3 megs parsed). The only difference with the reported issue is that this wasn't a prepared statement, just "mysql database < filename.sql". The result however was the same "ERROR 1064 (42000) at line 1202: memory exhausted near '...' at line 10662".

Problem is reproducible on MariaDB 10.3.29. It is not reproducible on MariaDB 5.5.65 or MySQL 5.6.59.

I compared every single configuration parameter related to limits but didn't find any notable differences. All values were either the same, larger or several gigabytes.

Generated at Thu Feb 08 06:30:00 UTC 2024 using Jira 8.20.16#820016-sha1:9d11dbea5f4be3d4cc21f03a88dd11d8c8687422.