New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
High memory usage of preg_match_all() in SQLParserUtils::collectPlaceholders() #4261
Comments
Link for the lazy: dbal/lib/Doctrine/DBAL/SQLParserUtils.php Lines 106 to 126 in ce85bd8
|
Given that the query being processed is relatively small and the fact that the issue is reproducible at a certain scale, it looks like a memory leak. @sgrossberndt could you provide a script that could be used to reproduce this high memory usage? |
<?php
$connection = DriverManager::getConnection(array(/*..*/));
$parameterTypeForQueryBuilder = 'createNamedParameter';
if ($parameterTypeForQueryBuilder === 'createNamedParameter') {
for ($uid = 1; $uid < 6000; $uid++) {
$queryBuilder = $connection->createQueryBuilder();
$records = $queryBuilder
->select('x.uid', 'mm.uid_foreign')
->from('tx_my_x_y_mm', 'mm')
->join('mm', 'tx_my_y', 'x', $queryBuilder->expr()->eq('x.uid', $queryBuilder->quoteIdentifier('mm.uid_local')))
->where($queryBuilder->expr()->eq('x.uid', $queryBuilder->createNamedParameter($uid, \PDO::PARAM_INT)))
->orderBy('x.uid')
->addOrderBy('mm.uid_foreign')
->execute()
->fetchAll();
var_dump($records);
// has a Excl. MemUse of 243 MB for preg_match_all() where 238MB are calls from Doctrine\DBAL\SQLParserUtils::getUnquotedStatementFragments
}
} elseif ($parameterTypeForQueryBuilder === 'createPositionalParameter') {
for ($uid = 1; $uid < 6000; $uid++) {
$queryBuilder = $connection->createQueryBuilder();
$records = $queryBuilder
->select('x.uid', 'mm.uid_foreign')
->from('tx_my_x_y_mm', 'mm')
->join('mm', 'tx_my_y', 'x', $queryBuilder->expr()->eq('x.uid', $queryBuilder->quoteIdentifier('mm.uid_local')))
->where($queryBuilder->expr()->eq('x.uid', $queryBuilder->createPositionalParameter($uid, \PDO::PARAM_INT)))
->orderBy('x.uid')
->addOrderBy('mm.uid_foreign')
->execute()
->fetchAll();
var_dump($records);
}
// has a Excl. MemUse of 1,4 MB for preg_match_all() where 1,3 MB are calls from Doctrine\DBAL\SQLParserUtils::getUnquotedStatementFragments
} Here are the xhprof profiles of both runs: |
I'm also facing this memory leak when running a query in a long running process.. 😞 |
What DBAL version are you using? The SQL parser was completely reworked in 3.0.0 (#4397). |
I'm on 2.13 because orm blocks from upgrading to v3 |
Currently trying to release 2.10.0, which will allow it :) |
But why it was not fixed in v2? :) The rework in my opinion was not a feature but a bugfix |
I don't know 🤷♂️ , and I'm not sure we should care if I can manage to release 2.10.0 (which is harder than it sounds) |
doctrine/migrations is another blocker :) |
Feel free to work on either a fix or migration of |
Closing as irrelevant as of #4397. |
This thread has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs. |
Bug Report
When executing a lot of queries (6.000+ in my case) with one named parameter each this leads to a very high memory usage (250MB in my case in one request) due to the
preg_match_all()
statement in theSQLParserUtils::collectPlaceholders()
method. When using positional parameters for the query instead this high memory usage does not happen.Current behaviour
How to reproduce
7.2.33-1+0~20200807.47+debian9~1.gbpcb3068
8.43 2019-02-23
Execute many queries with one named parameter and profile the memory usage
Exceute many queries with one positional parameter and profile the memory usage
Compare the memory usages and you see a huge difference due to the
preg_match_all
Expected behaviour
Memory usage it much lower although named parameters are used.
The text was updated successfully, but these errors were encountered: