Indexes on vectors return surprising results
まだ誰も着手していません。
評価
調査の方向性
まず、2つの再現用スニペットを実行し、インデックス付きの :path 属性に対する d/datoms :avet ルックアップを追跡します。追加の :children datom がある場合とない場合で、ベクター、リスト、シーケンスの入力を比較します;完了の条件は、ルックアップが一貫して動作し、意図したインデックス付きの値にのみ一致することです。
索引モデルが issue の本文から書いたものです。
説明
I'm seeing some odd behavior with indexed vectors. I thought this might have been introduced in 1.6.4, but it was also happening in 1.6.3. Given
(let [db (-> (d/empty-db {:path {:db/index true}})
(d/db-with [{:path [1 2]}
{:path [1 2 3]}]))]
(for [v [;; variations on 1, 2
[1 2]
(list 1 2)
(butlast [1 2 3])
;; variations on 1, 2, 3
[1 2 3]
(list 1 2 3)
(butlast [1 2 3 4])]]
[v
(->> (d/datoms db :avet :path v)
(mapv :e))]))
I'd expect this to only find entity ids for the first and fourth values of v, i.e. for the vectors, not the lists or sequences. However, this is what is returned.
;; => ([[1 2] [1]]
;; [(1 2) [1]]
;; [(1 2) []]
;; [[1 2 3] [2]]
;; [(1 2 3) []]
;; [(1 2 3) [2]])
It's particularly odd that first list, (list 1 2) returns an entity id but (list 1 2 3) doesn't. And contrarily that the first sequence (butlast [1 2 3]) doesn't return an entity id but (butlast [1 2 3 4]) does.
As I was playing with this I also ran across another odd variation. The presence of other datoms seems to affect the result.
(let [db (-> (d/empty-db {:path {:db/index true}
;; this attribute is new
:children {:db/valueType :db.type/ref
:db/cardinality :db.cardinality/many}})
(d/db-with [{:db/id "a"
:path [1 2]}
{:db/id "b"
:path [1 2 3]}
;; this datom is new
[:db/add "a" :children "b"]]))]
(for [v [;; variations on 1, 2
[1 2]
(list 1 2)
(butlast [1 2 3])
;; variations on 1, 2, 3
[1 2 3]
(list 1 2 3)
(butlast [1 2 3 4])]]
[v
(->> (d/datoms db :avet :path v)
(mapv :e))]))
;; => ([[1 2] [1]]
;; [(1 2) [1]]
;; this result has changed
;; [(1 2) [1 2]]
;; [[1 2 3] [2]]
;; [(1 2 3) []]
;; [(1 2 3) [2]])
Here the result is almost the same, except that whereas before when v was (list 1 2), d/datoms returned nothing. Now, with the other datom, it returns both entity ids. Very odd!
The easiest fix is, on the calling side, to be careful to pass vectors not sequences. That's what we'll do in our project, but I wanted to report the issue anyway.
- 主要言語
- Clojure
- スター
- 5.8k
- フォーク
- 318
- PR マージ指標
- 30日以内にマージされた PR はありません
コントリビューションガイド
このリポジトリのコントリビューションガイドは索引されていません
はじめの一歩
- issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
- 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
- リポジトリをフォークし、ブランチを切って変更します。
- issue 番号を参照したプルリクエストを送ります。
tonsky/datascript のほかの issue
-
難易度 4/5 3〜5日 初心者へのやさしさ 42/100
tonsky/datascript#498 · コメント 1 件 ·
-
難易度 5/5 1週間以上 初心者へのやさしさ 10/100
tonsky/datascript#489 ·
-
Stack overflow when transacting :db.type/tupleAttrs with a :db.type/ref attr through :db.fn/call オープン
難易度 4/5 3〜5日 初心者へのやさしさ 35/100
tonsky/datascript#483 · コメント 2 件 ·
-
難易度 4/5 3〜5日 初心者へのやさしさ 35/100
tonsky/datascript#441 · コメント 1 件 · リアクション 3 件 ·
-
難易度 4/5 3〜5日 初心者へのやさしさ 25/100
tonsky/datascript#434 · コメント 2 件 ·
tonsky/datascript の issue をすべて見る
似ている issue
-
難易度 1/5 1時間未満 初心者へのやさしさ 90/100
-
難易度 1/5 1時間未満 初心者へのやさしさ 88/100
-
.Team/Metabot Priority:P3
難易度 2/5 1〜3時間 初心者へのやさしさ 72/100
-
needs triage
難易度 1/5 1時間未満 初心者へのやさしさ 90/100
-
難易度 2/5 1〜3時間 初心者へのやさしさ 78/100
scalar-labs/scalar-jepsen#222 · コメント 1 件 ·