Skip to content

Conversation

Copy link

Copilot AI commented Dec 18, 2025

MySQL 8.0.40+ now evaluates certain queries server-side that were previously client-evaluated or failed, causing test failures. This PR fixes two types of issues:

  1. Tests expecting empty SQL logs now fail with "Assert.Empty() Failure: Collection was not empty"
  2. Tests expecting query failures now pass successfully, requiring updated baselines

Changes

Updated 6 test methods across 2 test files:

In NorthwindMiscellaneousQueryMySqlTest.cs (5 tests):

  • SelectMany_correlated_subquery_hard - LATERAL joins with nested subqueries and DISTINCT
  • Select_subquery_recursive_trivial - Recursive LATERAL join across employees table
  • Select_correlated_subquery_ordered - Paginated LATERAL join with ORDER BY
  • DefaultIfEmpty_in_subquery_nested_filter_order_comparison - Complex CROSS JOIN with nested LEFT JOIN and LATERAL
  • SelectMany_correlated_with_Select_value_type_and_DefaultIfEmpty_in_selector - COALESCE with LATERAL join

In ComplexNavigationsQueryMySqlTest.cs (1 test):

  • Nested_SelectMany_correlated_with_join_table_correctly_translated_to_apply - Query now works correctly (no exception thrown). Updated SQL baseline to reflect new query structure with JOIN LATERAL and additional nested subqueries for DefaultIfEmpty handling.

Example SQL

Example of generated SQL now being validated:

SELECT `c1`.`City` AS `c1`, `e0`.`City`, `e0`.`c1`
FROM (
    SELECT DISTINCT `c0`.`City`
    FROM (
        SELECT `c`.`City`
        FROM `Customers` AS `c`
        LIMIT @p
    ) AS `c0`
) AS `c1`
JOIN LATERAL (
    SELECT `e`.`City`, `c1`.`City` AS `c1`
    FROM `Employees` AS `e`
    WHERE (`c1`.`City` = `e`.`City`) OR (`c1`.`City` IS NULL AND (`e`.`City` IS NULL))
    LIMIT 9
) AS `e0` ON TRUE

Compatibility

MariaDB continues to work as these queries remain client-evaluated there.

Original prompt

This section details on the original issue you should resolve

<issue_title>Assert.Empty() Failure: Collection was not empty</issue_title>
<issue_description>MySQL 8.0.40+ fails with this error, but works in all mariadb verisons

 Failed Pomelo.EntityFrameworkCore.MySql.FunctionalTests.Query.NorthwindMiscellaneousQueryMySqlTest.SelectMany_correlated_subquery_hard(async: False) [562 ms]
  Error Message:
   Assert.Empty() Failure: Collection was not empty
Collection: ["@p='91'\n\nSELECT `c1`.`City` AS `c1`, `e0`.`City`"···]
  Stack Trace:
     at Microsoft.EntityFrameworkCore.TestUtilities.TestSqlLoggerFactory.AssertBaseline(String[] expected, Boolean assertOrder, Boolean forUpdate)
   at Pomelo.EntityFrameworkCore.MySql.FunctionalTests.Query.NorthwindMiscellaneousQueryMySqlTest.AssertSql(String[] expected) in /home/runner/work/Pomelo.EntityFrameworkCore.MySql/Pomelo.EntityFrameworkCore.MySql/test/EFCore.MySql.FunctionalTests/Query/NorthwindMiscellaneousQueryMySqlTest.cs:line 7310
   at Pomelo.EntityFrameworkCore.MySql.FunctionalTests.Query.NorthwindMiscellaneousQueryMySqlTest.SelectMany_correlated_subquery_hard(Boolean async) in /home/runner/work/Pomelo.EntityFrameworkCore.MySql/Pomelo.EntityFrameworkCore.MySql/test/EFCore.MySql.FunctionalTests/Query/NorthwindMiscellaneousQueryMySqlTest.cs:line 2777
--- End of stack trace from previous location ---

Error: Assert.Empty() Failure: Collection was not empty
Collection: ["@p='91'\n\nSELECT `c1`.`City` AS `c1`, `e0`.`City`"···]

 Failed Pomelo.EntityFrameworkCore.MySql.FunctionalTests.Query.NorthwindMiscellaneousQueryMySqlTest.SelectMany_correlated_subquery_hard(async: True) [527 ms]
 Error Message:
  Assert.Empty() Failure: Collection was not empty
Collection: ["@p='91'\n\nSELECT `c1`.`City` AS `c1`, `e0`.`City`"···]
 Stack Trace:
    at Microsoft.EntityFrameworkCore.TestUtilities.TestSqlLoggerFactory.AssertBaseline(String[] expected, Boolean assertOrder, Boolean forUpdate)
  at Pomelo.EntityFrameworkCore.MySql.FunctionalTests.Query.NorthwindMiscellaneousQueryMySqlTest.AssertSql(String[] expected) in /home/runner/work/Pomelo.EntityFrameworkCore.MySql/Pomelo.EntityFrameworkCore.MySql/test/EFCore.MySql.FunctionalTests/Query/NorthwindMiscellaneousQueryMySqlTest.cs:line 7310
  at Pomelo.EntityFrameworkCore.MySql.FunctionalTests.Query.NorthwindMiscellaneousQueryMySqlTest.SelectMany_correlated_subquery_hard(Boolean async) in /home/runner/work/Pomelo.EntityFrameworkCore.MySql/Pomelo.EntityFrameworkCore.MySql/test/EFCore.MySql.FunctionalTests/Query/NorthwindMiscellaneousQueryMySqlTest.cs:line 2777
--- End of stack trace from previous location ---
Failed Pomelo.EntityFrameworkCore.MySql.FunctionalTests.Query.NorthwindMiscellaneousQueryMySqlTest.Select_subquery_recursive_trivial(async: False) [1 s]
 Error Message:
  Assert.Empty() Failure: Collection was not empty
Collection: ["SELECT `e`.`EmployeeID`, `s`.`EmployeeID`, `s`.`Em"···]
 Stack Trace:
    at Microsoft.EntityFrameworkCore.TestUtilities.TestSqlLoggerFactory.AssertBaseline(String[] expected, Boolean assertOrder, Boolean forUpdate)
  at Pomelo.EntityFrameworkCore.MySql.FunctionalTests.Query.NorthwindMiscellaneousQueryMySqlTest.AssertSql(String[] expected) in /home/runner/work/Pomelo.EntityFrameworkCore.MySql/Pomelo.EntityFrameworkCore.MySql/test/EFCore.MySql.FunctionalTests/Query/NorthwindMiscellaneousQueryMySqlTest.cs:line 7310
  at Pomelo.EntityFrameworkCore.MySql.FunctionalTests.Query.NorthwindMiscellaneousQueryMySqlTest.Select_subquery_recursive_trivial(Boolean async) in /home/runner/work/Pomelo.EntityFrameworkCore.MySql/Pomelo.EntityFrameworkCore.MySql/test/EFCore.MySql.FunctionalTests/Query/NorthwindMiscellaneousQueryMySqlTest.cs:line 2207
--- End of stack trace from previous location ---
  Failed Pomelo.EntityFrameworkCore.MySql.FunctionalTests.Query.NorthwindMiscellaneousQueryMySqlTest.Select_correlated_subquery_ordered(async: True) [213 ms]
  Error Message:
   Assert.Empty() Failure: Collection was not empty
Collection: ["@p='3'\n\nSELECT `c0`.`CustomerID`, `o0`.`OrderID`"···]
  Stack Trace:
     at Microsoft.EntityFrameworkCore.TestUtilities.TestSqlLoggerFactory.AssertBaseline(String[] expected, Boolean assertOrder, Boolean forUpdate)
   at Pomelo.EntityFrameworkCore.MySql.FunctionalTests.Query.NorthwindMiscellaneousQueryMySqlTest.AssertSql(String[] expected) in /home/runner/work/Pomelo.EntityFrameworkCore.MySql/Pomelo.EntityFrameworkCore.MySql/test/EFCore.MySql.FunctionalTests/Query/NorthwindMiscellaneousQueryMySqlTest.cs:line 7310
   at Pomelo.EntityFrameworkCore.MySql.FunctionalTests.Query.NorthwindMiscellaneousQueryMySqlTest.Select_correlated_subquery_ordered(Boolean async) in /home/runner/work/Pomelo.EntityFrameworkCore.MySql/Pomelo.EntityFrameworkCore.MySql/test/EFCore.MySql.FunctionalTests/Query/NorthwindMiscellaneousQueryMySqlTest.cs:line 2168
--- End of stack trace from previous location ---
```</issue_description>

<agent_instructions>r...

</details>



<!-- START COPILOT CODING AGENT SUFFIX -->

- Fixes microting/Pomelo.EntityFrameworkCore.MySql#231

<!-- START COPILOT CODING AGENT TIPS -->
---

💬 We'd love your input! Share your thoughts on Copilot coding agent in our [2 minute survey](https://gh.io/copilot-coding-agent-survey).

Copilot AI and others added 2 commits December 18, 2025 18:22
MySQL 8.0.40+ now generates SQL for queries that previously were
client-evaluated. Updated three test methods with correct SQL baselines:
- SelectMany_correlated_subquery_hard
- Select_subquery_recursive_trivial
- Select_correlated_subquery_ordered

Co-authored-by: renemadsen <[email protected]>
Fixed additional tests that now generate SQL in MySQL 8.0.40+:
- DefaultIfEmpty_in_subquery_nested_filter_order_comparison
- SelectMany_correlated_with_Select_value_type_and_DefaultIfEmpty_in_selector

All 934 NorthwindMiscellaneousQueryMySqlTest tests now pass.

Co-authored-by: renemadsen <[email protected]>
Copilot AI changed the title [WIP] Fix Assert.Empty() failure in MySQL tests Add SQL baselines for MySQL 8.0.40+ server-side query evaluation Dec 18, 2025
Copilot AI requested a review from renemadsen December 18, 2025 18:36
@renemadsen
Copy link
Member

@copilot We have this error for mysql version >= 8.0.40:
Failed Pomelo.EntityFrameworkCore.MySql.FunctionalTests.Query.ComplexNavigationsQueryMySqlTest.Nested_SelectMany_correlated_with_join_table_correctly_translated_to_apply(async: True) [198 ms]
Error Message:
Assert.Throws() Failure: No exception was thrown
Expected: typeof(Xunit.Sdk.EqualException)
Stack Trace:
at Pomelo.EntityFrameworkCore.MySql.FunctionalTests.Query.ComplexNavigationsQueryMySqlTest.Nested_SelectMany_correlated_with_join_table_correctly_translated_to_apply(Boolean async) in /home/runner/work/Pomelo.EntityFrameworkCore.MySql/Pomelo.EntityFrameworkCore.MySql/test/EFCore.MySql.FunctionalTests/Query/ComplexNavigationsQueryMySqlTest.cs:line 79
--- End of stack trace from previous location ---

…_to_apply for MySQL 8.0.40+

In MySQL 8.0.40+, the query now executes correctly (no exception thrown) and uses a different SQL structure with JOIN LATERAL at the top level and additional nested subqueries for DefaultIfEmpty handling.

Updated SQL baseline to match the new query structure.

Co-authored-by: renemadsen <[email protected]>
Copy link
Author

Copilot AI commented Dec 19, 2025

@copilot We have this error for mysql version >= 8.0.40:
Failed Pomelo.EntityFrameworkCore.MySql.FunctionalTests.Query.ComplexNavigationsQueryMySqlTest.Nested_SelectMany_correlated_with_join_table_co...

Fixed in commit 3108617. The query now works correctly in MySQL 8.0.40+ (no exception thrown) and the SQL baseline has been updated to match the new query structure that uses JOIN LATERAL with additional nested subqueries for DefaultIfEmpty handling.

Copilot AI changed the title Add SQL baselines for MySQL 8.0.40+ server-side query evaluation Fix MySQL 8.0.40+ query evaluation and test baseline updates Dec 19, 2025
@renemadsen renemadsen marked this pull request as ready for review December 19, 2025 04:30
@renemadsen renemadsen merged commit 9ccfb88 into master Dec 19, 2025
25 of 37 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants