question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

MySqlException on bool filter with inner join

See original GitHub issue

Hi 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:closed
  • Created a year ago
  • Comments:10

github_iconTop GitHub Comments

1reaction
Raiquencommented, Apr 26, 2022

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!

0reactions
mguinnesscommented, Apr 25, 2022

Just to reiterate, I think the issue lies with Aurora. Have you tried against a local MySQL?

Read more comments on GitHub >

github_iconTop Results From Across the Web

MySQL filter based on inner join
Try moving the status condition to the queries WHERE part like. SELECT po.id FROM product_order as po INNER JOIN ...
Read more >
How can I join two tables while filtering the results with a" ...
try: SELECT b.id,sum(bm.totalvotes) FROM bills b inner join favoritebills fb ...
Read more >
Incorrect filter group OR behavior, LEFT JOIN changed to ...
I have a view, in code, which uses two groups of ANDed filters, with group behaviour OR. Since updating to views 3.5 (from...
Read more >
Incorrect queries generated by Pomelo after migrating from ...
The error appears to show LEFT JOIN LATERAL as the issue, so they should double check server is a MySQL 8.0.18 instance.
Read more >
Help with multiple INNER JOIN's : r/SQL
Help with multiple INNER JOIN's. Hello,. I'm a student taking my second SQL class but in the first I was working with very...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found