Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions server/src/instant/db/datalog.clj
Original file line number Diff line number Diff line change
Expand Up @@ -1963,10 +1963,11 @@
(contains? (flags/flag :always-materialize-attr-ids)
(first (uspec/tagged-unwrap (:a named-p))))))

(defn enable-row-hints? [query-hash]
(defn enable-row-hints? [app-id query-hash]
(and (or (flags/toggled? :enable-row-hints-globally true)
(coll/exists? (fn [h] (= query-hash h))
(flags/flag :enable-row-hints-query-hashes)))
(not (contains? (flags/flag :disable-row-hints-apps) app-id))
(not (coll/exists? (fn [h] (= query-hash h))
(flags/flag :disable-row-hints-query-hashes)))))

Expand Down Expand Up @@ -2875,7 +2876,7 @@

:pg-hints (if (flags/toggled? :disable-pg-hints)
[]
(if (enable-row-hints? (:query-hash ctx))
(if (enable-row-hints? app-id (:query-hash ctx))
pg-hints
(filterv (fn [hint]
(not= :'Rows (first hint)))
Expand Down
1 change: 1 addition & 0 deletions server/src/instant/flags.clj
Original file line number Diff line number Diff line change
Expand Up @@ -237,6 +237,7 @@
(update :use-reactive-cache-for-verify-token-apps parse-uuids-flag)
(update :backup-skip-app-ids parse-uuids-flag)
(update :pkey-null-padding-apps parse-uuids-flag)
(update :disable-row-hints-apps parse-uuids-flag)
(update :query-circuit-breaker parse-query-circuit-breaker-flag))
handle-receive-timeout (reduce (fn [acc {:strs [appId timeoutMs]}]
(assoc acc (parse-uuid appId) timeoutMs))
Expand Down
49 changes: 49 additions & 0 deletions server/test/instant/db/row_hints_flag_test.clj
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
(ns instant.db.row-hints-flag-test
(:require [clojure.test :refer [deftest is testing]]
[instant.db.attr-sketch :as cms]
[instant.db.datalog :as d]
[instant.db.instaql :as iq]
[instant.db.model.attr :as attr-model]
[instant.flags :as flags]
[instant.util.instaql :as instaql-util]))

(def app-id #uuid "5a0c1d2e-7b3f-4c6a-9e8d-1f2a3b4c5d6e")

(def attrs
(attr-model/wrap-attrs
(mapv (fn [n field]
(cond-> {:id (java.util.UUID. 0 n)
:forward-identity [(java.util.UUID. 1 n) "prices" field]
:value-type :blob :cardinality :one
:index? (= field "modified") :unique? (= field "id")}
(= field "modified") (assoc :checked-data-type :number)))
[1 2 3] ["id" "modified" "value"])))

(def query
{:prices {:$ {:where {:and [{:modified {:$gt 100}} {:modified {:$lte 200}}]}
:order {:modified "asc"} :first 50}}})

(defn row-hints [app-id]
(let [normalized (instaql-util/normalized-forms query)
ctx {:app-id app-id :attrs attrs
:query-normalized normalized
:query-hash (hash normalized)
:sketches (into {} (map (fn [a]
[{:app-id app-id :attr-id (:id a)}
{:sketch (assoc (cms/make-sketch) :total 240000)}])
attrs))}
patterns (:patterns (iq/instaql-query->patterns ctx query))
named (d/annotate-with-hints-impl ctx {} (d/nested->named-patterns patterns))]
(binding [d/*enable-pg-hints* true]
(->> (d/nested-match-query ctx :m- app-id named)
:query
:pg-hints
(filter #(= :'Rows (first %)))))))

(deftest row-hints-can-be-disabled-per-app
(is (seq (row-hints app-id)))
(binding [flags/*flag-overrides* {:disable-row-hints-apps #{app-id}}]
(testing "the listed app loses only its row hints"
(is (empty? (row-hints app-id))))
(testing "other apps keep theirs"
(is (seq (row-hints (random-uuid)))))))
Loading