Skip to content
This repository has been archived by the owner on Jul 16, 2021. It is now read-only.

Use optimized whereIn() on eager loading for all integer keys #1561

Closed
rimace opened this issue Mar 14, 2019 · 1 comment
Closed

Use optimized whereIn() on eager loading for all integer keys #1561

rimace opened this issue Mar 14, 2019 · 1 comment

Comments

@rimace
Copy link

rimace commented Mar 14, 2019

With version 5.7.14 there where some performance optimizations for the whereIn method for relations (noted as "Improved eager loading performance" in the release notes).
This brought a breakage for existing users and this breakage was fixed by workarounds with #26622 and further with #26688.

Currently this workaround uses the optimization and stays compatible with existing apps, by doing the following checking (in Illuminate\Database\Eloquent\Relations\Relation line 320):

protected function whereInMethod(Model $model, $key)
{
    return $model->getKeyName() === last(explode('.', $key))
                && $model->getIncrementing()
                && in_array($model->getKeyType(), ['int', 'integer'])
                    ? 'whereIntegerInRaw' // <- the method name optimized for integers
                    : 'whereIn';
}

My proposal is to remove the check to $model->getIncrementing() and use the optimization also for integer keys that are not marked for auto incrementation.
As this is a breaking change it should be done for the next big release (5.9 or 6.0) and thus also needs to be documented in the upgrade guide.

@driesvints
Copy link
Member

Merged

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants