-
-
Notifications
You must be signed in to change notification settings - Fork 6.9k
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
MSSQL Server supports a maximum of 2100 parameters #10371
Comments
This problem related not the MSSQL only. See #10305 |
Usually it's not a huge issue. If there are more than 100 ids in a query per page, there's probably an issue in software logic. |
Not a bug, just use joinWith() instead. |
this should make no difference since |
If I have AR relation defined that in runtime resolves to more than 2100 records that needs to be looked up in the database, the application will fail. |
It seems that this error message text is misleading and the error is thrown by Microsoft SQL Server PHP driver and not by MS SQL Server itself . MSSQL by itself has no problems with the size of parameter arrays passed to it. Correction: MSSQL has a hard limit in a number of parameters you can pass to stored procedure. And it looks like Yii2 uses stored procedures to prepare SQL statement. The query composed is fine - when I copy it from the error log and run in MSSQL Management Studio it runs fine. |
Makes sense to use non-prepared statements in this case. |
I have a work around that fixes this issue for active relations that use via(), may also be faster for relations with lots of records. At least in my case using MSSQL. Basically this just uses the subquery in the where in condition instead of using filterByModels() https://gist.github.com/kevm256/cb4557ec5f60d8723d45b4e845d60712 I haven't done extensive testing, so not sure if there are other unintended side effects. |
@kevm256 that's a good workaround but not a permanent solution. That would likely break relationships between multiple database types that work perfectly fine now. |
@samdark yeah, I don't think it will work across databases. I did try adding a buildValues() override in the mssql InConditionBuilder class to put int values directly into the condition instead of binding them: protected function buildValues(ConditionInterface $condition, $values, &$params)
{
if(count($values) > 2000){
$intValues = [];
foreach ($values as $i => $value)
{
if(is_int($value)){
$intValues[] = strval($value);
unset($values[$i]);
}
}
$sqlValues = parent::buildValues($condition, $values,$params);
return array_merge( $sqlValues, $intValues);
}
return parent::buildValues($condition, $values,$params);
} However this still doesn't solve for the general case, and adding or binding 2000+ params to the where in condition uses a lot of memory and in my case was way too slow. I think I will just use joinWith to replace the relation. |
It's not Yii bug. It's bug of MS SQL driver. |
Usage another MS SQL driver With PDO_SQLSRV - failed (Tried to bind parameter number 2101. SQL Server supports a maximum of 2100 parameters.) |
In some cases there is a problem how Yii2 handles the
[id] IN (1,2,3..)
statement.The text was updated successfully, but these errors were encountered: