Migrate from Cluster 5.7 to 8. Different results in sql

I have some querys that are acting very differently between the two systems… I did find the following that spits out the differences between the versions.

https://mysql-params.tmtms.net/mysqld/?vers=8.0.22,5.7.32&diff=true

Once Query (attached) is largely different on 8.0 vs 5.7. I can make it match on 8.0 if I set
SET GLOBAL optimizer_switch = ‘derived_merge=off’;

But this, in turn, causes other queries to act differently I think it has to do with the optimizer where the join is now actually joining on a null value where before it was not.

I do run in the following SQL mode and have for years.
sql_mode=STRICT_TRANS_TABLES,NO_ENGINE_SUBSTITUTION

Net/Net What am I missing that is causing it now to join on null values…

query.txt (2.1 KB)

1 Like

Differences in query execution do change with different versions of MySQL. You can remove the “GLOBAL” from that command and make the change apply only to that session. Or you can use optimizer hints to make the change apply to only 1 single query. Here’s an example:

SELECT /*+ NO_MERGE(dt) */ * FROM (SELECT * FROM t1) AS dt;
1 Like

Thank you for the quick reply… I do understand that it can be session or query-based but I was attempting to not have to validate every single query that the application uses which is in the tens of thousands… I was looking to try to set the server defaults to similar to the execution plans in 5.7.

1 Like

BTW the Explain statements are exactly the same which I dont get… (on 5.7 and 8.x)

1 Like

Well, that’s the job and best-practice of every DBA when upgrading to new databases right? :slight_smile: The best practice is to create an 8.0 replica of your 5.7 source and validate queries on this server before migrating production, which that sounds like what you are doing. Yes, check sql_mode defaults between 5.7 and 8.0 and check for any new optimizer features that were introduced in 8.0 and disable them.

1 Like

I’ve had similar issues (8.0.23)
A sub-select was no longer joining what it should have.
I was told they filed an internal bug and never heard from it again.
Still blocked from updating to 8.

1 Like

Happen to know what the Ticket number is? BTW I am at 8.0.22-13.1

1 Like

I found your stackoverflow post… select - mysql 8 query regression coming from 5.7 (what's wrong?) - Stack Overflow

Reading notes on 8.0.17 to see if I can go with that as I do not have a choice but to go to 8.0

1 Like

MySQL Bugs: #103346: Mysql 8 vs 5.7 Query Regression failure opened and already listed as Verified and a S2 Status

1 Like