Minor perf improvement: create idx_tx_lookup_added after populating tx_lookup.

This commit is contained in:
Richard Newman 2016-08-09 16:55:04 -07:00
parent 2a55b138f6
commit f53869ba6f
2 changed files with 7 additions and 2 deletions

View file

@ -238,6 +238,7 @@
many? (memoize (fn [a] (ds/multival? schema a)))
<exec (partial s/execute! (:sqlite-connection db))]
(p :delete-tx-lookup-before
(<? (<exec ["DROP INDEX IF EXISTS id_tx_lookup_added"]))
(<? (<exec ["DELETE FROM tx_lookup"])))
(p :insertions
@ -303,6 +304,9 @@
(catch java.sql.SQLException e
(throw (ex-info "Transaction violates cardinality constraint" {} e))))) ;; TODO: say more about the conflicting datoms.
(p :create-tx-lookup-indices
(<? (<exec ["CREATE INDEX IF NOT EXISTS idx_tx_lookup_added ON tx_lookup (added0)"])))
(p :join
;; Fast, only one table walk: lookup by exact eav.
(p :join-eav
@ -348,6 +352,7 @@
;; The lookup table takes space on disk, so we purge it aggressively.
(p :delete-tx-lookup-after
(<? (<exec ["DROP INDEX IF EXISTS id_tx_lookup_added"]))
(<? (<exec ["DELETE FROM tx_lookup"])))
;; The transaction has been written -- read it back. (We index on tx, so the following is fast.)

View file

@ -39,8 +39,8 @@
rid INTEGER,
e INTEGER, a SMALLINT, v BLOB, tx INTEGER, value_type_tag SMALLINT)"
"CREATE INDEX idx_tx_lookup_added ON tx_lookup (added0)"
;; Note that `id_tx_lookup_added` is created and dropped
;; after insertion, which makes insertion slightly faster.
;; Prevent overlapping transactions. TODO: drop added0?
"CREATE UNIQUE INDEX idx_tx_lookup_eavt ON tx_lookup (e0, a0, v0, added0, value_type_tag0) WHERE sv IS NOT NULL"