You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Dear All,
I have a legacy Database that has a table that has a primary key that is a varchar(20). Problem is that 99% of the values in that primary key column are integers and the queries regarding this table (there's a hasMany() from another model) show up in my slow log as queries not using indexes.
I have examined the issue and what is happening is, that Model A is retrieved and has a primary key of 1234. Then the hasMany is followed and a
select from B where primarykey = 1234 is built and executed.
And mysql would only use the index if data types match, so the query should be (in my case!)
select from B where primarykey = '1234'.
I tracked it down to the function
public function bindValues($statement, $bindings)
in lluminate/Database/Connection.php where only if the bound value is an int, PDO::PARAM_INT is passed down to the corresponding quoting functions:
is_int($value) ? PDO::PARAM_INT : PDO::PARAM_STR
Would it make sense to make this somehow configurable?
Sure, the db design is to blame but as I said, it's a legacy. During digging into the issue I've found some posts on stackexchange with a similar setting.
reacted with thumbs up emoji reacted with thumbs down emoji reacted with laugh emoji reacted with hooray emoji reacted with confused emoji reacted with heart emoji reacted with rocket emoji reacted with eyes emoji
Uh oh!
There was an error while loading. Please reload this page.
-
Dear All,
I have a legacy Database that has a table that has a primary key that is a varchar(20). Problem is that 99% of the values in that primary key column are integers and the queries regarding this table (there's a hasMany() from another model) show up in my slow log as queries not using indexes.
I have examined the issue and what is happening is, that Model A is retrieved and has a primary key of 1234. Then the hasMany is followed and a
select from B where primarykey = 1234 is built and executed.
And mysql would only use the index if data types match, so the query should be (in my case!)
select from B where primarykey = '1234'.
I tracked it down to the function
public function bindValues($statement, $bindings)
in lluminate/Database/Connection.php where only if the bound value is an int, PDO::PARAM_INT is passed down to the corresponding quoting functions:
is_int($value) ? PDO::PARAM_INT : PDO::PARAM_STR
Would it make sense to make this somehow configurable?
Sure, the db design is to blame but as I said, it's a legacy. During digging into the issue I've found some posts on stackexchange with a similar setting.
Or is there already some sort of workaround?
Tia, RS
Beta Was this translation helpful? Give feedback.
All reactions