Indexes on vectors return surprising results
Chưa có ai nhận issue này.
Đánh giá
- Độ khó
- 4/5
- Thời gian dự kiến
- 3-5 ngày
- Mức phù hợp với người mới
- 35/100
Hướng nghiên cứu
Bắt đầu bằng cách chạy hai đoạn mã tái hiện và theo dõi lượt tra cứu d/datoms :avet cho thuộc tính :path được lập chỉ mục. So sánh các đầu vào dạng vector, list và sequence khi có và không có datom :children bổ sung; hoàn tất khi lượt tra cứu hoạt động nhất quán và chỉ khớp với các giá trị được lập chỉ mục mong muốn.
Do mô hình lập chỉ mục viết ra từ nội dung của issue.
Mô tả
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.
- Ngôn ngữ chính
- Clojure
- Star
- 5.8k
- Fork
- 318
- Chỉ số merge pull request
- Không có pull request nào được merge trong 30 ngày
Hướng dẫn đóng góp
Chưa lập chỉ mục được hướng dẫn đóng góp cho kho mã nguồn này
Bắt đầu từ đâu
- Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
- Bình luận trên issue rằng bạn sẽ nhận — tránh hai người làm cùng một việc.
- Fork repository và làm thay đổi trên một nhánh.
- Mở pull request có tham chiếu số hiệu của issue.
Issue khác của tonsky/datascript
-
Độ khó 4/5 3-5 ngày Mức phù hợp với người mới 42/100
tonsky/datascript#498 · 1 bình luận ·
-
Datascript MCP Server Đang mở
Độ khó 5/5 Hơn một tuần Mức phù hợp với người mới 10/100
tonsky/datascript#489 ·
-
Stack overflow when transacting :db.type/tupleAttrs with a :db.type/ref attr through :db.fn/call Đang mở
Độ khó 4/5 3-5 ngày Mức phù hợp với người mới 35/100
tonsky/datascript#483 · 2 bình luận ·
-
Độ khó 4/5 3-5 ngày Mức phù hợp với người mới 35/100
tonsky/datascript#441 · 1 bình luận · 3 reaction ·
-
Độ khó 4/5 3-5 ngày Mức phù hợp với người mới 25/100
tonsky/datascript#434 · 2 bình luận ·
Tất cả issue của tonsky/datascript
Issue tương tự
-
Độ khó 1/5 Dưới một giờ Mức phù hợp với người mới 90/100
-
Độ khó 1/5 Dưới một giờ Mức phù hợp với người mới 88/100
-
.Team/Metabot Priority:P3
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 72/100
-
needs triage
Độ khó 1/5 Dưới một giờ Mức phù hợp với người mới 90/100
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 78/100
scalar-labs/scalar-jepsen#222 · 1 bình luận ·