Replies: 1 comment 2 replies
-
Have you tried setting $keyType = 'string' in your model to see how it behaves? |
Beta Was this translation helpful? Give feedback.
2 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
Laravel Version
11.37.0
PHP Version
8.4.2
Database Driver & Version
MySQL 8.0.39 AWS RDS (db.m7g.8xlarge)
Description
Description
When using
MorphTo
relationships with a{name}_id
defined as a string data type queries perform significantly slower when the model that is morphing has an integer primary key.(Because i want to support both integers and uuid values in the morph relation)
This issue arises because MySQL does not utilize indexes effectively when there's a type mismatch between the query parameter and the column data type. The table that has this issue has 142M rows inside of it. Now as a workaround we use the DB Facade to run the query raw but having a method inside the framework to just cast for morph relations the type to string would be very beneficial.
Requested behaviour
The behaviour as it is now is expected behaviour since our primary key of the product table is indeed an integer. Is there a way we can force this integer to be a string? In mysql the issue lies in the fact that indexes are not been used when the data types don't match.
Steps To Reproduce
Steps to reproduce
Performance: Runs very fast (16 milliseconds).
Performance: Takes approximately 8 seconds.
If the above query would be
Performance: Runs very fast (16 milliseconds).
Beta Was this translation helpful? Give feedback.
All reactions