Don't optimize count for UNION queries

Fixes #18890
This commit is contained in:
Maurício Meneghini Fauth 2024-01-29 22:08:17 -03:00 committed by GitHub
commit fa62af8cd7
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 9 additions and 0 deletions

View File

@ -752,6 +752,7 @@ class Sql
if (
$analyzedSqlResults['is_group'] === false
&& $analyzedSqlResults['distinct'] === false
&& $analyzedSqlResults['union'] === false
&& count($statement->expr) === 1
) {
$statement->expr[0] = new Expression();

View File

@ -571,6 +571,14 @@ class SqlTest extends AbstractTestCase
false,
'SELECT COUNT(*) FROM (SELECT DISTINCT country_id FROM city ) as cnt',
],
[
'SELECT * FROM t1 UNION SELECT * FROM t2;',
['max_rows' => -1, 'pos' => 0],
25,
109,
false,
'SELECT COUNT(*) FROM (SELECT * FROM t1 UNION SELECT * FROM t2 ) as cnt',
],
];
}