-
-
Notifications
You must be signed in to change notification settings - Fork 437
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
cast to string in loadByIncrementId, fix big regression for numeric incrementIds #381
Conversation
can you try out the queries with |
forget my last comment. https://dev.mysql.com/doc/refman/5.7/en/mysql-indexes.html also a related bug report in MySql which was declined So we should really fix this. |
Given the fact that increment_id is a text column, I'm 100% on board with casting the parameter to a string as a first step. I agree with @flyingmama that a deeper solution using the DDL cache is better and we should look towards that as well. |
@Flyingmana I had a look at the DDL, thanks for pointing me that direction. I traced the DDL to There, a method array(14) {
["SCHEMA_NAME"] => NULL
["TABLE_NAME"] => string(16) "sales_flat_order"
["COLUMN_NAME"] => string(12) "increment_id"
["COLUMN_POSITION"] => int(105)
["DATA_TYPE"] => string(7) "varchar"
["DEFAULT"] => NULL
["NULLABLE"] => bool(true)
["LENGTH"] => string(2) "50"
["SCALE"] => NULL
["PRECISION"] => NULL
["UNSIGNED"] => NULL
["PRIMARY"] => bool(false)
["PRIMARY_POSITION"] => NULL
["IDENTITY"] => bool(false)
} So it is retrieving the right data type. I did some searching for a method quote() which I suspected last time I posted already. /**
* Quote a raw string.
*
* @param string $value Raw string
* @return string Quoted string
*/
protected function _quote($value)
{
if (is_int($value)) {
return $value;
} elseif (is_float($value)) {
return sprintf('%F', $value);
}
return "'" . addcslashes($value, "\000\n\r\\'\"\032") . "'";
} Little test: is_int(201966402) = TRUE // just returns unquoted
is_int('201966402') = FALSE //
"'" . addcslashes(201966402, "\000\n\r\\'\"\032") . "'" = '201966402'
echo "'" . addcslashes('201966402', "\000\n\r\\'\"\032") . "'" = '201966402' I can't be bothered to trace it back to where quote() gets called the first time right now, maybe later :) |
…e clauses Use describeTable and then use prepareColumnValue to actually prepare the value being used in the where section of select statements. refs OpenMage#381
…e clauses Use describeTable and then use prepareColumnValue to actually prepare the value being used in the where section of select statements. refs OpenMage#381
…e clauses Use describeTable and then use prepareColumnValue to actually prepare the value being used in the where section of select statements. refs OpenMage#381
…e clauses Use describeTable and then use prepareColumnValue to actually prepare the value being used in the where section of select statements. refs OpenMage#381
…e clauses Use describeTable and then use prepareColumnValue to actually prepare the value being used in the where section of select statements. refs OpenMage#381
…e clauses Use describeTable and then use prepareColumnValue to actually prepare the value being used in the where section of select statements. refs OpenMage#381
…e clauses Use describeTable and then use prepareColumnValue to actually prepare the value being used in the where section of select statements. refs OpenMage#381
…e clauses Use describeTable and then use prepareColumnValue to actually prepare the value being used in the where section of select statements. refs OpenMage#381
So, we have a client who does not use a character prefix on their incrementId.
Zend auto quotes the value when generating it's queries, but because there's only numbers in their incrementId it does not quote the value.
This is very unfortunate because the difference in speed is quite massive.
Here's the query without quotes around the id. You are seeing that right, that's 30 seconds! There's 2.2 million orders in the system.
The EXPLAIN:
Now here's the same query with added quotes:
The EXPLAIN:
As you can see the database is not using the index because of the mismatch in type.
Percona wrote about this problem in 2006.
Now I've been experimenting a bit and casting to string before calling the method seems to solve the problem already. So I propose to just cast incrementId to string in loadByIncrementId, unless you know of other places this could be changed. We generally notice it with select * queries, which is generally what would roll out of that method.
We are running 10.1.20-MariaDB-1~xenial mariadb.org binary distribution