【问题标题】:Datomic hides parts of its history when query is about all attributes当查询关于所有属性时,Datomic 会隐藏部分历史记录
【发布时间】:2021-05-13 06:44:53
【问题描述】:

我有一个原子查询:

(pprint (d/q '[:find ?tx ?attr ?val ?op :in $ ?e :where [?e ?attr ?val ?tx ?op]] (d/history (d/db db/conn)) 17592186766274))

产生:

#{[13194140264981 354 6 true] 
  [13194140265425 352 "OK" true] 
  [13194140255168 348 17592186593957 true] 
  [13194140265425 353 true true] 
  [13194140255168 311 #uuid "6086bec6-7a11-4238-9ce3-67e6427d7b07" true] 
  [13194140255168 346 17592186491729 true] 
  [13194140265424 351 #uuid "60871d86-cdc2-4ddf-b091-98117c3948af" true] 
  [13194140265425 349 #inst "2021-04-26T20:29:34.566-00:00" true] 
  [13194140255168 347 "{:driver \"6144c7bd-8e71-49c3-8eef-2e9d157f3e11\", :order \"c89d32d2-92da-4cde-827d-da6406877c28\"}\n" true] 
  [13194140265424 350 #inst "2021-04-26T20:29:34.472-00:00" true] 
  [13194140255168 356 #inst "2021-04-26T18:23:18.140-00:00" true]}

请注意,属性 354 仅在历史记录中更改过一次(更改为值 6)。 那么,如果我们要求这个特定的属性......

(pprint (d/q '[:find ?tx ?val ?op :in $ ?e :where [?e 354 ?val ?tx ?op]] (d/history (d/db db/conn)) 17592186766274))

...我们突然发现它被修改了多次:

#{[13194140264479 1 false] 
  [13194140264516 2 false] 
  [13194140264585 4 true] 
  [13194140264981 6 true] 
  [13194140264721 4 false] 
  [13194140264461 1 true] 
  [13194140264479 2 true] 
  [13194140264721 5 true] 
  [13194140264516 3 true] 
  [13194140264585 3 false] 
  [13194140264981 5 false]}

此外,如果我们针对当前数据库而不是历史记录询问原始问题,我们会得到相同的结果!

(pprint (d/q '[:find ?tx ?attr ?val ?op :in $ ?e :where [?e ?attr ?val ?tx ?op]] (d/db db/conn) 17592186766274))

给予:

#{[13194140264981 354 6 true] 
  [13194140265425 352 "OK" true] 
  [13194140255168 348 17592186593957 true] 
  [13194140265425 353 true true] 
  [13194140255168 311 #uuid "6086bec6-7a11-4238-9ce3-67e6427d7b07" true] 
  [13194140255168 346 17592186491729 true] 
  [13194140265424 351 #uuid "60871d86-cdc2-4ddf-b091-98117c3948af" true] 
  [13194140265425 349 #inst "2021-04-26T20:29:34.566-00:00" true] 
  [13194140255168 347 "{:driver \"6144c7bd-8e71-49c3-8eef-2e9d157f3e11\", :order \"c89d32d2-92da-4cde-827d-da6406877c28\"}\n" true] 
  [13194140265424 350 #inst "2021-04-26T20:29:34.472-00:00" true] 
  [13194140255168 356 #inst "2021-04-26T18:23:18.140-00:00" true]}

看起来好像关于实体的所有属性更改的问题过于笼统,但没有返回错误并且给出了错误的答案。为什么?

【问题讨论】:

    标签: clojure datomic


    【解决方案1】:

    好的,我知道发生了什么。该实体的所有属性都将 :db/noHistory 设置为 true。为什么当我们查询特定属性时仍然显示更改仍然很神秘。

    【讨论】:

    • 虽然设置:db/noHistory 应该减少存储在历史记录中的总量,但不能保证保留多少历史记录,即使:db/noHistory 设置为true 的属性也可能会看到一些历史记录。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-10-06
    • 2018-10-10
    • 2013-02-13
    • 1970-01-01
    • 1970-01-01
    • 2020-05-25
    相关资源
    最近更新 更多