-
-
Notifications
You must be signed in to change notification settings - Fork 1.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
[BUG] FromQuery - Sort Bug Showing Duplicated Data #3101
Comments
I think this is because we use |
Hi, Laravel: 8.56.0 We see the same behaviour with randomly duplicate rows with large data. |
Same issue here. Confirmed that chunking is the issue. Issue is resolved when set chunk size > # rows. |
Hello, Versions Same issue here. |
Same issue also for me, with Laravel-Excel version 3.1.44. |
This is actually normal, if you run this same query with pagination, it will return random rows, because the order clause is not producing a unique value for each row, so mysql will return all the rows with the exact same value in whatever order it wants, you simply need to add a second order by clause on an unique column You need to Possibly we could add an orderBy key to the given query if we don't find it already, but if it's already ordering by a unique key that is not primary it might come at a performance cost on the query In laravel's chunk method you'll find /**
* Add a generic "order by" clause if the query doesn't already have one.
*
* @return void
*/
protected function enforceOrderBy()
{
if (empty($this->query->orders) && empty($this->query->unionOrders)) {
$this->orderBy($this->model->getQualifiedKeyName(), 'asc');
}
} So I'd just classify it as undesired behavior and a bug of mysql and not this lib, leave it as is and add a note in the doc about the fact the |
Versions
Laravel version: 6.2
Php version: 7.4.16
Laravel-Excel version: 3.1.27
Description:
When using FromQuery to do a custom query and using the sort function on the Eloquent object (users table), some of the rows are duplicated.
Expected behaviour:
All the relevant rows in the database should show correct data. Users in the table are unique.
Code screenshot
First line produces incorrect result
2nd line produces correct data with no duplicates.
The code is part of an UsersExport class which implements FromQuery, WithHeadings, WithMapping
The text was updated successfully, but these errors were encountered: