MySqlException on bool filter with inner join
See original GitHub issueHi everyone, we are facing a problem when sending a query that includes a filter in the where clause with a boolean. The error surfaces when it’s in combination with an inner join and another table.
We got 3 tables, AAfiliado
(280k rows), AAfiliadoGrupoFamiliar
(130k rows) and GEmpresa
(65k rows)
AAfiliado
has FK to AAfiliadoGrupoFamiliar
. GEmpresa
has an Unique index CUIT.
CUIT and CuitEmpleador are long type, not null, (bigint(11) on db). Activo is boolean, not null, tinyint(1)
The code: (‘estado’ is boolean type)
This is the linq query:
(from item in _context.AAfiliado where item.Activo == estado
join empresa in _context.GEmpresa on item.AGrupoFamiliar.CuitEmpleador equals empresa.Cuit into empresas
from empresa in empresas.DefaultIfEmpty() select item).Count();
This outputs the following query:
SELECT COUNT(*) FROM a_afiliado AS a
INNER JOIN a_grupo_familiar AS a0 ON a.a_grupo_familiarId = a0.id
LEFT JOIN g_empresa AS g ON a0.cuit_empleador = g.CUIT
WHERE (a.activo = @__estado_0)
This throws an exception:
Exception: MySqlConnector.MySqlException (0x80004005): Internal error: oscar hash join failed
at MySqlConnector.Core.ResultSet.g_ScanRowAsyncAwaited|9_0(ResultSet resultSet, Task`1 payloadTask, Row row, CancellationToken token) in //src/MySqlConnector/Core/ResultSet.cs:line 240
at MySqlConnector.Core.ResultSet.ReadAsync(IOBehavior ioBehavior, CancellationToken cancellationToken) in //src/MySqlConnector/Core/ResultSet.cs:line 211
at MySqlConnector.Core.ResultSet.Read() in //src/MySqlConnector/Core/ResultSet.cs:line 187
at Microsoft.EntityFrameworkCore.Query.Internal.SingleQueryingEnumerable`1.Enumerator.MoveNext()
at System.Linq.Enumerable.TryGetSingle[TSource](IEnumerable`1 source, Boolean& found)
at lambda_method31667.lambda_method31667(Closure , QueryContext )
What’s really strange is that if we put a hardcoded value in the linq query:
(from item in _context.AAfiliado where (item.Activo == true && estado == true) || (item.Activo == false && estado == false)
join empresa in _context.GEmpresa on item.AGrupoFamiliar.CuitEmpleador equals empresa.Cuit into empresas
from empresa in empresas.DefaultIfEmpty() select item).Count();
This outputs the following query:
SELECT COUNT(*) FROM a_afiliado AS a
INNER JOIN a_grupo_familiar AS a0 ON a.a_grupo_familiarId = a0.id
LEFT JOIN g_empresa AS g ON a0.cuit_empleador = g.CUIT
WHERE a.activo
That work fine. What could be the cause of this?
Update:
MySQL version: 5.7.12 (Aurora 2.10.2) Pomelo.EntityFrameworkCore.MySql version: 6.0.0 Microsoft.AspNetCore.App version: net6.0
Issue Analytics
- State:
- Created a year ago
- Comments:10
Updated MySql to 8, with Aurora, these queries and Pomelo 6.0.1 work fines, without Pipelining = False.
Let’s take some time to update our system.
Thanks for the help!
Just to reiterate, I think the issue lies with Aurora. Have you tried against a local MySQL?