问题一:
Q1.1
IndexedDB(Javascript 版本)做 select 或 insert 的复杂度是多少?索引是否被“索引”?它是排序的还是散列的?例如,当我们使用 IDBKeyRange.only 时,它花费的时间是 O(1)、O(log(n)) 还是 O(n)?
Q1.2
IDBKeyRange.bound 怎么样?是先排序索引再做select吗?
Q1.3
IDBObjectStore.add() 的性能如何?
Q1.4
对于index.openCursor(),索引是否提前排序?
问题2:
我们正在使用 IDBObjectStore.createIndex() 创建索引。 如果问题 1 中的答案是肯定的(这意味着索引被索引),如何创建带有索引或不索引选项的索引?换句话说,我选择一些索引进行排序或散列,而另一些则不。我们有这个选择吗?
最佳答案
规范不强制要求性能特征。假设使用 B-tree 实现是合理的,因此操作 O(log n),但您需要在浏览器中测试实现。如果特定浏览器在常见操作上表现不佳,可能值得将其作为问题报告。
Q1.1 What is the complexity of IndexedDB (Javascript version) doing select or insert? Whether the indexes are "indexed"? Is it sorted or hashed?
索引是有序的。 https://w3c.github.io/IndexedDB/#index-construct
Q1.2 How about the IDBKeyRange.bound? Is it sorting the index first and then doing the select?
查找是针对排序的索引。
Q1.3 What is the performance of IDBObjectStore.add()?
假设一个 B 树,O(log n)
Q1.4 For index.openCursor(), is the index sorted in advance?
是的。
尽管从技术上讲,实现可以延迟创建索引——规范不要求特定的性能或实现,只是结果无法区分。
Question 2:... how to create index with options indexed or not indexed? In other words, I choose some indexes to be sorted or hashed, while others not. Do we have this choice?
否 - API 不提供此类选项。
关于javascript - 索引 : Select and Insert 的 IndexedDB 性能,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51548770/