Bug 83765 - EDITING: Wrong/Random ordering on sort by column.
Summary: EDITING: Wrong/Random ordering on sort by column.
Status: RESOLVED FIXED
Alias: None
Product: LibreOffice
Classification: Unclassified
Component: Calc (show other bugs)
Version:
(earliest affected)
4.2.6.2 release
Hardware: All All
: high normal
Assignee: Eike Rathke
URL:
Whiteboard: target:4.4.0 target:4.2.8 target:4.3.5
Keywords: regression
Depends on:
Blocks:
 
Reported: 2014-09-11 12:40 UTC by Doriano Cometto
Modified: 2014-11-26 18:48 UTC (History)
3 users (show)

See Also:
Crash report or crash signature:


Attachments
Calc document to reproduce this bug in Calc 4.3.0.4 (57.55 KB, application/vnd.oasis.opendocument.spreadsheet)
2014-09-11 12:40 UTC, Doriano Cometto
Details
Simpler calc document to reproduce this bug (17.37 KB, application/vnd.oasis.opendocument.spreadsheet)
2014-09-22 06:25 UTC, Doriano Cometto
Details
Table to reproduce the sorting error (24.86 KB, application/vnd.oasis.opendocument.spreadsheet)
2014-11-07 02:11 UTC, ralf.fehlau
Details
Attempted to sort by TotalCost3Nights and it sorts by PerNight v4.2.7.2 Build ID: 420m0(Build:2) (68.84 KB, application/vnd.oasis.opendocument.spreadsheet)
2014-11-07 21:21 UTC, David Fuller
Details

Note You need to log in before you can comment on or make changes to this bug.
Description Doriano Cometto 2014-09-11 12:40:42 UTC
Created attachment 106129 [details]
Calc document to reproduce this bug in Calc 4.3.0.4

Re-executing the same sort command (with the same settings) many times, produces as a result many different ordered set of data.

Steps to reproduce:

1) Open the attached calc document in Calc.
2) Select range from F1 to AY373
3) Open the "Sort" dialog with Data--> Sort...
4) In the "Option" tab check "Left to right (sort columns)
5) In the "Sort criteria" tab set:
   - Sort key 1: Row 7 Descending
   - Sort key 2: Row 8 Ascending
6) Press OK.

You can see a wrong ordered set of data.

7) Open again the Sort dialog and Press OK again.

You can see another wrong ordered set of data.

8) Any time you press OK, you get a different wrong ordered set of data.
Comment 1 ign_christian 2014-09-15 06:14:10 UTC
Reproducible with LO 4.3.1.2 portable under Win7 x86

Still don't have a clue how to repro from scratch with a simpler case.
Comment 2 Doriano Cometto 2014-09-22 06:25:17 UTC
Created attachment 106653 [details]
Simpler calc document to reproduce this bug
Comment 3 Doriano Cometto 2014-09-22 06:30:00 UTC
I added a simpler Calc document reproducing this bug, which is depending on the fact that sorting by colums causes the forulas in row 2 to become wrong.

To reproduce:

- Select range B1-F8
- Sort by column: row 2 descending, row 1 ascending.

Result: the formulas in row2 don't change to reflect their new position.
Comment 4 ign_christian 2014-09-22 08:08:38 UTC
Thanks Doriano...it's clearer now :D

Simplified steps to repro from scratch:

1). Fill cells A1:C3 with following data:

1	1	2
3	1	1
=SUM(A1:A2)	=SUM(B1:B2)	=SUM(C1:C2)

2). Select cells A1:C3 > Data > Sort
3). Tab: Options > choose Direction 'Left to right (sort columns)'
4). Tab: Sort Criteria > Sort key 1 "Row 3" (default: Ascending) > OK

Sort result: 3  4  2 -> incorrect

Expected result: 2  3  4

*) Incorrect result also shown if we choose Descending on step 4).

Reproduced with: LO 4.3.1.2, 4.2.6.3 portable under Win7 x86 

Not reproduced with: LO 4.1.6.2 portable
Comment 5 ign_christian 2014-09-22 13:17:52 UTC
That should be fixed in latest release. Not reproduced under Ubuntu 12.04 x86 with:

- LO 4.3.2.2
- LO 4.2.7.0.0+ Time: 2014-09-11_14:25:14

@Doriano, please reopen and mark UNCONFIRMED if you can reproduce in the next release
Comment 6 Jean-Baptiste Faure 2014-10-09 20:03:10 UTC
In fact this bug report is a duplicate of bug 79441.

Best regards. JBF

*** This bug has been marked as a duplicate of bug 79441 ***
Comment 7 Eike Rathke 2014-10-31 01:20:05 UTC
This is NOT a duplicate of 79441 which is about references to *other* sheets within the document. I couldn't reproduce in 4.3.3 either. This seems to have been fixed by one of the other various sorting bugfixes.
Comment 8 Doriano Cometto 2014-10-31 08:22:12 UTC
Steps to reproduce this bug on 4.3.3.2 on Win7:

1). Fill cells A1:C3 with following data:

1	1	2
3	1	1
=SUM(A1:A2)	=SUM(B1:B2)	=SUM(C1:C2)

2). Select the WHOLE COLUMNS A:C > Data > Sort
3). Tab: Options > choose Direction 'Left to right (sort columns)'
4). Tab: Sort Criteria > Sort key 1 "Row 3" (default: Ascending) > OK

Sort result: 3  4  2 -> incorrect

Expected result: 2  3  4

This bug doesn't show anymore if you select only the cells range A1:C3 while sorting.
Comment 9 Eike Rathke 2014-10-31 22:46:28 UTC
Can reproduce with a whole column selection also in Linux 4.3.3.2, and it is reproducible in 4-3 (to-be 4.3.4) when selecting only A1:C3
Comment 10 Jean-Baptiste Faure 2014-11-01 15:50:57 UTC
(In reply to Eike Rathke from comment #9)
> Can reproduce with a whole column selection also in Linux 4.3.3.2, and it is
> reproducible in 4-3 (to-be 4.3.4) when selecting only A1:C3

For me it works in 4.3.4.0.0+ when selecting only A1:C3 if you set the hidden option UpdateReferenceOnSort to true (default value: false).

Note: the step "select entire columns" was not in the initial description and comments before comments #8. So I guess it is a distinct issue.

Tested on Version: 4.3.4.0.0+
Build ID: 9f89fbf3be626b13799b1b9c0fb8ca246148bcfb
built at home under Ubuntu 14.10 x86-64

Best regards. JBF
Comment 11 Joel Madero 2014-11-02 16:37:53 UTC
Needs to be confirmed again by QA Team. Setting to UNCONFIRMED.
Comment 12 Doriano Cometto 2014-11-04 08:43:36 UTC
Thank you to everybody for your deep involvement trying to find a solution to this issue.
Unfortunately I'm not a sw developer and I'm not able to find any hint where to set that "UpdateReferenceOnSort" to True. Any help is greatly appreciated.

Even if this options seems to me an option like:

"Do you want to use this bug? Yes/No"
Comment 13 Jean-Baptiste Faure 2014-11-06 21:20:48 UTC
(In reply to Doriano Cometto from comment #12)

> Unfortunately I'm not a sw developer and I'm not able to find any hint where
> to set that "UpdateReferenceOnSort" to True. Any help is greatly appreciated.

You will have this option in next version 4.3.4.

Best regards. JBF
Comment 14 ralf.fehlau 2014-11-07 02:09:56 UTC
I have this effect, too. My version of libreoffice is 4.2.7.2 on Ubuntu Linux. 

This effect occurs, when inserting the 98 row of data. The original file had 117 data sheets, most of then were filled by links to internet data (tables). I reduced the content as long as I could reproduce this error. The remaining data is a single table with 3 data rows.
Comment 15 ralf.fehlau 2014-11-07 02:11:13 UTC
Created attachment 109069 [details]
Table to reproduce the sorting error
Comment 16 ralf.fehlau 2014-11-07 08:55:51 UTC
First I though that my file was corrupted. Now I assume, it is libreoffice calc, which is broken. The same effect occurs with old backups of my file. 

The sort order changes every time, the sort button is pressed. The more rows in the table, the more phantasy the sort algorithm gets.
Comment 17 ralf.fehlau 2014-11-07 18:54:12 UTC
Version: 4.2.6.3 Build-ID: 420m0(Build:3) on Ubuntu works well.
Comment 18 David Fuller 2014-11-07 21:21:01 UTC
Created attachment 109119 [details]
Attempted to sort by TotalCost3Nights and it sorts by PerNight v4.2.7.2 Build ID: 420m0(Build:2)
Comment 19 Jean-Baptiste Faure 2014-11-12 08:50:28 UTC
Sorry, forgot to confirm this bug report (see comment #3), I used it for the case "Ranking_Columns" in the summary spreadsheet for the metabug bug 85490, see attachment 109016 [details].

The issue here is that it works in versions 4.0 and 4.1 but not in 4.2 and in versions 4.3.4 and future 4.4.0 it works again but only with a config option incompatible with previous versions. So the regression has its cause in earlier versions of the branch 4.2, not in the change due to bug 81309, even if this change make sorting working again on this case.

Best regards. JBF
Comment 20 Eike Rathke 2014-11-20 10:23:32 UTC
I can NOT reproduce in any released version the problem reported in comment 14 to comment 17 with attachment 109069 [details]. Even if I could that would be a different problem as sorting with the button reorders by rows, whereas this bug here is about reordering by columns. I assume that other problem is specific to Ubuntu having applied a patch that landed on the 4-2 branch with http://cgit.freedesktop.org/libreoffice/core/commit/?h=libreoffice-4-2&id=67f3ce3a9df2bc62db5602dd84975047c1137b92
I remember I've seen such a bug but I don't recall which.
@Bjoern: Do you?

Actually that was fixed on master with http://cgit.freedesktop.org/libreoffice/core/commit/?id=10fc138307afb4b39baddb0d56eb8e986e5d29ea and backported to 4-3 with https://gerrit.libreoffice.org/12113 pushed as http://cgit.freedesktop.org/libreoffice/core/commit/?h=libreoffice-4-3&id=81e4dbe1adf196ee20f1a4bfbc50b54abfc79f4b
See also bug 85215#c13
That change needs to be applied also to 4-2 and probably also for Ubuntu.
Comment 22 Commit Notification 2014-11-20 10:41:32 UTC
Eike Rathke committed a patch related to this issue.
It has been pushed to "master":

http://cgit.freedesktop.org/libreoffice/core/commit/?id=115a4b7ca36f65d93070d2e81048320d202e87a3

fdo#83765 do not update references in SortReorderByColumn() if disabled

It will be available in 4.4.0.

The patch should be included in the daily builds available at
http://dev-builds.libreoffice.org/daily/ in the next 24-48 hours. More
information about daily builds can be found at:
http://wiki.documentfoundation.org/Testing_Daily_Builds
Affected users are encouraged to test the fix and report feedback.
Comment 23 Eike Rathke 2014-11-20 11:27:45 UTC
Also attachment 109119 [details] comment 18 seems to be a victim of that other bug.
Comment 24 Eike Rathke 2014-11-20 11:48:18 UTC
Pending review
for 4-3 at https://gerrit.libreoffice.org/12986
for 4-2 at https://gerrit.libreoffice.org/12987