<?xml version="1.0" encoding="UTF-8" standalone="yes" ?>
<!DOCTYPE bugzilla SYSTEM "https://www.w3.org/Bugs/Public/page.cgi?id=bugzilla.dtd">

<bugzilla version="5.0.4"
          urlbase="https://www.w3.org/Bugs/Public/"
          
          maintainer="sysbot+bugzilla@w3.org"
>

    <bug>
          <bug_id>21836</bug_id>
          
          <creation_ts>2013-04-26 00:53:18 +0000</creation_ts>
          <short_desc>Remove NotSupportedError on creating index for multiEntry index with array keyPath</short_desc>
          <delta_ts>2015-08-10 20:53:04 +0000</delta_ts>
          <reporter_accessible>1</reporter_accessible>
          <cclist_accessible>1</cclist_accessible>
          <classification_id>1</classification_id>
          <classification>Unclassified</classification>
          <product>WebAppsWG</product>
          <component>Indexed Database API</component>
          <version>unspecified</version>
          <rep_platform>PC</rep_platform>
          <op_sys>All</op_sys>
          <bug_status>RESOLVED</bug_status>
          <resolution>MOVED</resolution>
          
          
          <bug_file_loc></bug_file_loc>
          <status_whiteboard></status_whiteboard>
          <keywords></keywords>
          <priority>P2</priority>
          <bug_severity>normal</bug_severity>
          <target_milestone>---</target_milestone>
          
          
          <everconfirmed>1</everconfirmed>
          <reporter name="Kyaw Tun">kyawtun</reporter>
          <assigned_to name="This bug has no owner yet - up for the taking">dave.null</assigned_to>
          <cc>jonas</cc>
    
    <cc>jsbell</cc>
    
    <cc>mike</cc>
    
    <cc>public-webapps</cc>
    
    <cc>timm</cc>
          
          <qa_contact>public-webapps-bugzilla</qa_contact>

      

      

      

          <comment_sort_order>oldest_to_newest</comment_sort_order>  
          <long_desc isprivate="0" >
    <commentid>86833</commentid>
    <comment_count>0</comment_count>
    <who name="Kyaw Tun">kyawtun</who>
    <bug_when>2013-04-26 00:53:18 +0000</bug_when>
    <thetext>In creating index, the specification state that:

&quot;If keyPath is and Array and the multiEntry
property in the optionalParameters is true, then a DOMException of type
NotSupportedError must be thrown.&quot;

However it is unnecessary. multiEntry is no different than
non-multiEntry index value, except the reference value is repeated. This
specification limit generalizes usage of composite index for key joining
algorithm.

Composite index with multiEntry is very useful, like modelling graph data
and many-to-many relationship. Currently query on such model are limited to
single index. It is also very unlikely that web developer will use excessive indexing.

Discussion on: http://lists.w3.org/Archives/Public/public-webapps/2013AprJun/0379.html</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>86877</commentid>
    <comment_count>1</comment_count>
    <who name="Joshua Bell">jsbell</who>
    <bug_when>2013-04-26 16:47:55 +0000</bug_when>
    <thetext>Thanks. Adding this to the &quot;possible for V2&quot; list by marking Resolved/Later.</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>86942</commentid>
    <comment_count>2</comment_count>
    <who name="Jonas Sicking (Not reading bugmail)">jonas</who>
    <bug_when>2013-04-29 11:17:31 +0000</bug_when>
    <thetext>There are several ways that you could interpret an array keyPath on a multiEntry index.

Consider a multiEntry index with keyPath [&quot;a&quot;, &quot;b&quot;]

It&apos;s pretty intuitive that storing a value like:

{
  id: 1,
  a: &quot;apple&quot;,
  b: &quot;orange&quot;
}

would add the following entries to the index:

&quot;apple&quot; -&gt; 1
&quot;orange&quot; -&gt; 1


But what would storing the following value result in?

{
  id: 1,
  a: [&quot;apple&quot;, &quot;x&quot;],
  b: [&quot;orange&quot;, &quot;y&quot;]
}

Would this result in the following entries

A)
[&quot;apple&quot;, &quot;x&quot;] -&gt; 1
[&quot;orange&quot;, &quot;y&quot;] -&gt; 1

or

B)
&quot;apple&quot; -&gt; 1
&quot;x&quot; -&gt; 1
&quot;orange&quot; -&gt; 1
&quot;y&quot; -&gt; 1

or

C)
[&quot;apple&quot;, &quot;orange&quot;] -&gt; 1
[&quot;x&quot;, &quot;y&quot;] -&gt; 1


Normally when an Array is used as a KeyPath the resulting key consists of an Array where each entry in the Array is the result of evaluating that KeyPath. So in this example the result would be

[[&quot;apple&quot;, &quot;x&quot;], [&quot;orange&quot;, &quot;y&quot;]]

Applying normal multiEntry processing to that key would mean that behavior A) above is the correct answer.


However a common use-case for multiEntry+Array-KeyPath is likely things like creating a &quot;name&quot; index which indexes on both first names and last names. In that case you&apos;d likely want the union of all values from each element in the Array. I.e. you&apos;d want behavior B) above.


Another way to look at it is that just like adding multiEntry to an index on &quot;a&quot; lets you store an Array in the &quot;a&quot; property to add one entry for each value in that array, so could adding multiEntry to an index on [&quot;a&quot;, &quot;b&quot;] let you store Arrays in the &quot;a&quot; and &quot;b&quot; properties to add one entry for each value in those two arrays. This interpretation says that C) above is the correct behavior.


So I&apos;m somewhat inclined to solve the use cases here using bug 10000. Or to use some other flag here than &quot;multiEntry&quot; which more clearly indicates which of the behaviors above should be used.</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>86948</commentid>
    <comment_count>3</comment_count>
    <who name="Kyaw Tun">kyawtun</who>
    <bug_when>2013-04-29 13:48:07 +0000</bug_when>
    <thetext>Thank Jonas, for very clear explanation. Both use case B) and C) must be able to specify.

Previously, I was not understand the specification correctly. I was talking from developer point of view. In fact, array keyPath with multiEntry does not make sense and the specification is correct. What I refer turn out to be composite index (array keyPath) of multiEntry index. Composite index, itself, is not multiEntry.   

Bug 10000 sounds nice, but its implication is ugly.

Indexing specification is the most beautiful part of IndexedDB API. It could go father, following google database store interpretation.


Could we specify such that

1. multiEntry effect writing index. 
2. element of array keyPath is evaluated as index value first and then keyPath of record value (current specification). If element of array keyPath is the name of index, its value is respective index value. If the name of index does not exist, it is evaluated as usual. 

In this way both use case B) and C) can be specified intuitively.</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>86950</commentid>
    <comment_count>4</comment_count>
    <who name="Jonas Sicking (Not reading bugmail)">jonas</who>
    <bug_when>2013-04-29 18:32:09 +0000</bug_when>
    <thetext>Sorry, I don&apos;t really understand what you are proposing. Could you provide some example code?</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>86984</commentid>
    <comment_count>5</comment_count>
    <who name="Kyaw Tun">kyawtun</who>
    <bug_when>2013-04-30 02:07:41 +0000</bug_when>
    <thetext>Suppose we have a record value of:

var human = {
  taxon: 9606,
  classification: [&apos;Animalia&apos;, &apos;Mammalia&apos;, &apos;Primates&apos;],
  name: {
    genus: &apos;Homo&apos;,
    species: &apos;sapiens&apos;
  },
  habitat: [&apos;asia&apos;, &apos;americas&apos;, &apos;africa&apos;, &apos;europe&apos;, &apos;oceania&apos;] 
}


store = db.createObjectStore(&apos;specie&apos;, {keyPath: &apos;taxon&apos;});
store.createIndex(&apos;clade&apos;, &apos;classification&apos;, {multiEntry: true});
store.createIndex(&apos;habitat&apos;, &apos;habitat&apos;, {multiEntry: true});
store.createIndex(&apos;binomen&apos;, [&apos;name.genus&apos;, &apos;name.species&apos;]);

The following composite index is used to list specie table. This is use case A.

store.createIndex(&apos;specie&apos;, [&apos;classification&apos;, &apos;.binomen&apos;], {unique: true});

It should create a index value of

[[&apos;Animalia&apos;, &apos;Mammalia&apos;, &apos;Primates&apos;], [&apos;Homo&apos;, &apos;sapiens&apos;]]

The following composite index is used to query specific clad order by name. This is use case B.

store.createIndex(&apos;clad-name&apos;, [&apos;.clade&apos;, &apos;.binomen&apos;]);

It should crate index values of

[&apos;Animalia&apos;, [&apos;Homo&apos;, &apos;sapiens&apos;]]
[&apos;Mammalia&apos;, [&apos;Homo&apos;, &apos;sapiens&apos;]] 
[&apos;Primates&apos;, [&apos;Homo&apos;, &apos;sapiens&apos;]] 

The following composite index is used to query habitant and clad.

store.createIndex(&apos;clad-habitat&apos;, [&apos;.clade&apos;, &apos;.habitat&apos;, &apos;.binomen&apos;);

It should crate index values of

[&apos;Animalia&apos;, &apos;africa&apos;, [&apos;Homo&apos;, &apos;sapiens&apos;]]
[&apos;Animalia&apos;, &apos;asia&apos;, [&apos;Homo&apos;, &apos;sapiens&apos;]]
[&apos;Animalia&apos;, &apos;americas&apos;, [&apos;Homo&apos;, &apos;sapiens&apos;]]
[&apos;Animalia&apos;, &apos;europe&apos;, [&apos;Homo&apos;, &apos;sapiens&apos;]]
[&apos;Animalia&apos;, &apos;oceania&apos;, [&apos;Homo&apos;, &apos;sapiens&apos;]]
[&apos;Mammalia&apos;, &apos;africa&apos;, [&apos;Homo&apos;, &apos;sapiens&apos;]]
[&apos;Mammalia&apos;, &apos;asia&apos;, [&apos;Homo&apos;, &apos;sapiens&apos;]]
[&apos;Mammalia&apos;, &apos;americas&apos;, [&apos;Homo&apos;, &apos;sapiens&apos;]]
[&apos;Mammalia&apos;, &apos;europe&apos;, [&apos;Homo&apos;, &apos;sapiens&apos;]]
[&apos;Mammalia&apos;, &apos;oceania&apos;, [&apos;Homo&apos;, &apos;sapiens&apos;]]
[&apos;Mammalia&apos;, &apos;africa&apos;, [&apos;Homo&apos;, &apos;sapiens&apos;]] 
[&apos;Primates&apos;, &apos;africa&apos;, [&apos;Homo&apos;, &apos;sapiens&apos;]]
[&apos;Primates&apos;, &apos;asia&apos;, [&apos;Homo&apos;, &apos;sapiens&apos;]]
[&apos;Primates&apos;, &apos;americas&apos;, [&apos;Homo&apos;, &apos;sapiens&apos;]]
[&apos;Primates&apos;, &apos;europe&apos;, [&apos;Homo&apos;, &apos;sapiens&apos;]]
[&apos;Primates&apos;, &apos;oceania&apos;, [&apos;Homo&apos;, &apos;sapiens&apos;]]


Notice that the last two composite index is created using array keyPath consisting of keyPath or index, in which it is argumented by a dot. 

Sorry, previously I was referring only use case for A and B. Use case C is interesting, but will not be common need.</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>122549</commentid>
    <comment_count>6</comment_count>
    <who name="Joshua Bell">jsbell</who>
    <bug_when>2015-08-10 20:53:04 +0000</bug_when>
    <thetext>Moved to https://github.com/w3c/IndexedDB/issues/36</thetext>
  </long_desc>
      
      

    </bug>

</bugzilla>