diff --git a/src/datomish/db.cljc b/src/datomish/db.cljc index 854e8558..6608a972 100644 --- a/src/datomish/db.cljc +++ b/src/datomish/db.cljc @@ -260,12 +260,20 @@ chunk))]) (partition-all (quot max-sql-vars 11) ops)))) +(def initial-many-searchid 2000) ; Just to make it more obvious in the DB. +(def initial-one-searchid 5000) + ;;; An FTS insertion happens in two parts. +;;; ;;; Firstly, we ensure that the fulltext value is present in the store. ;;; This is effectively an INSERT OR IGNORE… but FTS tables don't support ;;; uniqueness constraints. So we do it through a trigger on a view. +;;; ;;; When we insert the value, we pass with it a searchid. We'll use this -;;; later when inserting the datom. +;;; later when inserting the datom, then we'll throw it away. The FTS table +;;; only contains searchids for the duration of the transaction that uses +;;; them. +;;; ;;; Secondly, we insert a row just like for non-FTS. The only difference ;;; is that the value is the rowid into the fulltext_values table. (defn- fts-many->queries [ops tx ->SQLite indexing? ref? unique?] @@ -293,7 +301,7 @@ (unique? a) ; unique_value tag]])) ops - (range 2000 999999999)) + (range initial-many-searchid 999999999)) ["UPDATE fulltext_values SET searchid = NULL WHERE searchid IS NOT NULL"])) (defn fts-one->queries [ops tx ->SQLite indexing? ref? unique?] @@ -322,7 +330,7 @@ "(?, ?, (SELECT rowid FROM fulltext_values WHERE searchid = ?), ?, 0, ?)") e a searchid tx tag]])) ops - (range 3000 999999999)) + (range initial-one-searchid 999999999)) ["UPDATE fulltext_values SET searchid = NULL WHERE searchid IS NOT NULL"])) (defn- -run-queries [conn queries exception-message] diff --git a/src/datomish/query/cc.cljc b/src/datomish/query/cc.cljc index 22698f68..3f211783 100644 --- a/src/datomish/query/cc.cljc +++ b/src/datomish/query/cc.cljc @@ -53,7 +53,7 @@ ;; ;; `from` is a list of [source alias] pairs, suitable for passing to honeysql. ;; `bindings` is a map from var to qualified columns. -;; `known-types` is a map from var to type keyword. +;; `known-types` is a map from var to type keyword (e.g., :db.type/ref) ;; `extracted-types` is a mapping, similar to `bindings`, but used to pull ;; type tags out of the store at runtime. ;; `wheres` is a list of fragments that can be joined by `:and`. diff --git a/test/datomish/test/query.cljc b/test/datomish/test/query.cljc index 88f14a17..6482c421 100644 --- a/test/datomish/test/query.cljc +++ b/test/datomish/test/query.cljc @@ -181,12 +181,12 @@ {:select [1], :from [[:all_datoms 'all_datoms1]], :where (list :and - [:= :all_datoms1.e 15] + [:= :all_datoms1.e 999] [:= :datoms0.v :all_datoms1.v])}]])} (expand '[:find ?e ?v :in $ :where [?e :foo/int ?v] - (not [15 ?a ?v])] + (not [999 ?a ?v])] conn)))) (testing "Type collisions inside :not." @@ -195,7 +195,7 @@ (expand '[:find ?e ?v :in $ :where [?e :foo/int ?v] - (not [15 :foo/str ?v])] + (not [999 :foo/str ?v])] conn)))) (testing "Type collisions inside :or" @@ -205,8 +205,8 @@ '[:find ?e ?v :in $ :where [?e :foo/int ?v] (or - [15 :foo/str ?v] - [10 :foo/int ?v])] + [999 :foo/str ?v] + [666 :foo/int ?v])] conn)))))) (deftest-db test-type-collision conn