Bug 149205 - IndexedDB openKeyCursor() returns primaryKeys in wrong order
Summary: IndexedDB openKeyCursor() returns primaryKeys in wrong order
Status: RESOLVED FIXED
Alias: None
Product: WebKit
Classification: Unclassified
Component: JavaScriptCore (show other bugs)
Version: WebKit Nightly Build
Hardware: Unspecified Unspecified
: P2 Normal
Assignee: Nobody
URL:
Keywords:
Depends on:
Blocks: 149117
  Show dependency treegraph
 
Reported: 2015-09-15 20:47 PDT by Nolan Lawson
Modified: 2016-03-30 10:23 PDT (History)
2 users (show)

See Also:


Attachments
Reproducible test case (2.54 KB, text/html)
2015-09-15 20:47 PDT, Nolan Lawson
no flags Details

Note You need to log in before you can comment on or make changes to this bug.
Description Nolan Lawson 2015-09-15 20:47:32 PDT
Created attachment 261291 [details]
Reproducible test case

Let's say you create an objectStore with a primary key and a secondary key, and you insert:

{primaryKey: 'a', secondaryKey: 0}
{primaryKey: 'b', secondaryKey: 0}
{primaryKey: 'c', secondaryKey: 0}

If you then call openKeyCursor() on the secondary index, then the cursor's primaryKeys should be returned in order (since the secondary indexes are all the same).

However, in WebKit nightly 10600.8.9, r189569 I am able to get the cursor to return the primaryKeys in the wrong order, although only after a refresh. It seems like the order of the keys is being determined by the length instead of lexicographic order, but I'm not sure.

I have a reproducible test to demonstrate (also attached to this bug): http://bl.ocks.org/nolanlawson/32daf56e98904562b52d

This bug cannot be reproduced in IE 10, Firefox 40, or Chrome 45. There is a note in the IndexedDB spec explaining this behavior:

> records is always sorted in ascending key order.
> In the case of source being an index, records is secondarily sorted 
> in ascending value order (where the value in an index is the key of 
> the record in the referenced object store). 

Source: http://w3c.github.io/IndexedDB/#h-cursor-iteration-operation
Comment 1 Brady Eidson 2016-03-22 09:42:27 PDT
This test case works in ToT - Please try in the latest WebKit nightly.
Comment 2 Nolan Lawson 2016-03-30 10:23:33 PDT
Confirmed fixed in WebKit Nightly. Thank you!