Bug 158833

Summary: IDBIndex.openCursor() matches indices on multiple object stores
Product: WebKit Reporter: David Fahlander <david.fahlander>
Component: WebCore Misc.Assignee: Brady Eidson <beidson>
Severity: Major CC: achristensen, alecflett, beidson, commit-queue, david.fahlander, jsbell, webkit-bug-importer
Priority: P2 Keywords: HTML5, InRadar
Version: Safari Technology Preview   
Hardware: Mac   
OS: OS X 10.11   
URL: https://bl.ocks.org/dfahlander/a7a0608513d527742c5a09e3c95dd343
Description Flags
Patch achristensen: review+

Description David Fahlander 2016-06-16 02:59:55 PDT
When having multiple object stores and querying an index of one store, you will also get matches for indexes on other stores. cursor.key shows values from the index of another store. cursor.value shows some duplicate values from the store you are querying.

Basically, if you have objectStores 'students' with an index 'name' and 'schools' with an index 'city', and you query the 'name' index on 'students' with no range specified (or WITH a range - it doesnt matter), you will get a cursor that iterates a mix of student names and cities. Each onsuccess callback from the cursor will have a key that sometimes is a student name and sometimes a city. The value though is always a student and some students are shown multiple times - one time with the name key and another time with a city key.

This issue was detected when running the [unit-test suite for Dexie.js](https://cdn.rawgit.com/dfahlander/Dexie.js/v1.4.0-rc.1/test/run-unit-tests.html). That suite has over 1000 assertions and all works perfectly on chrome, opera and firefox. Please use it as a compatibility test if you like. In the latest technical preview for Safari, all but 10 assertings succeed, so you're defenitely on the way to completenes :)

Comment 1 David Fahlander 2016-06-29 09:24:32 PDT
Any news on this?
Comment 2 David Fahlander 2016-08-22 08:32:07 PDT
Any news on this one? I adore the try to really support the full indexedDB spec, but as you are about to release Safari 10, please view this severe indexedDB bug!

You have the URL (https://cdn.rawgit.com/dfahlander/Dexie.js/v1.4.0-rc.1/test/run-unit-tests.html) that reproduces the error. And you have the description on what's happening (in the main description of this bug). Please contact me if you need to get more explanations about it.

Kind Regards,
David Fahlander, author of dexie.js (http://dexie.org)
Comment 3 David Fahlander 2016-09-17 14:12:07 PDT
Added another simpler repro of this bug (simple gist) that is not Dexie-dependant: https://bl.ocks.org/dfahlander/a7a0608513d527742c5a09e3c95dd343
Comment 4 David Fahlander 2016-09-17 14:14:19 PDT
Tested again with Safari 10.0 (12602.1.38.2) on browserstack.com.
Comment 5 David Fahlander 2016-09-19 14:31:22 PDT
I've nailed it down further and it seems this behaviour occurs only when the different object stores primary keys collide. In my repro, I use options {autoIncrement: true} when creating the ObjectStore, which will for sure make the primary keys on 'schools' and 'students' collide.

Please keep me in the loop when testing this out. I'll be happy to help out. Feel free to run the dexie unit tests that pass on Chrome and Firefox: https://cdn.rawgit.com/dfahlander/Dexie.js/v1.4.2/test/run-unit-tests.html
Comment 6 David Fahlander 2016-09-19 14:44:31 PDT
I've been in contact with Brady Eidson about this issue over twitter, so he is informed about it.

Please make sure this bug is taken care of and assigned to the right person.

The simple reproduction of the bug is available here: https://bl.ocks.org/dfahlander/a7a0608513d527742c5a09e3c95dd343 and it also contains text files with expected output versus Safari 10 output.
Comment 7 Florin 2016-09-22 03:41:24 PDT
Please fix this bug.
Comment 8 Radar WebKit Bug Importer 2016-09-22 14:27:36 PDT
Comment 9 Brady Eidson 2016-09-22 14:28:39 PDT
This was a problem in the query for index cursors.

Easy fix, patch coming soon.

Wish I saw this when it was filed :(
Comment 10 Brady Eidson 2016-09-22 14:46:55 PDT
With my fix, with the Dexie test suite, I see:
1122 assertions of 1122 passed, 0 failed.
Comment 11 Brady Eidson 2016-09-22 14:50:01 PDT
Created attachment 289607 [details]
Comment 12 David Fahlander 2016-09-22 15:30:02 PDT
Wow :-) This is great news!
Comment 13 Brady Eidson 2016-09-22 15:36:38 PDT