Skip to content

Commit 82fb00f

Browse files
Oana Tanasoiuaustb
Oana Tanasoiu
authored andcommitted
(PDB-4985) Ensure an index hit for trusted facts
1 parent 469afb9 commit 82fb00f

File tree

2 files changed

+18
-2
lines changed

2 files changed

+18
-2
lines changed

src/puppetlabs/puppetdb/query_eng/engine.clj

+5-2
Original file line numberDiff line numberDiff line change
@@ -1806,7 +1806,7 @@
18061806

18071807
[[(op :guard #{"=" ">" "<" "<=" ">=" "~"}) (column :guard validate-dotted-field) value]]
18081808
;; (= :inventory (get-in (meta node) [:query-context :entity]))
1809-
(when (string/includes? column "match(")
1809+
(if (string/includes? column "match(")
18101810
(let [[head & path] (->> column
18111811
utils/parse-matchfields
18121812
su/dotted-query->path
@@ -1819,7 +1819,10 @@
18191819
(map :path_array)
18201820
(map (fn [path] (if (= (first path) "trusted") path (cons "facts" path))))
18211821
(map #(string/join "." %)))]
1822-
(into ["or"] (map #(vector op % value) fact_paths))))
1822+
(into ["or"] (map #(vector op % value) fact_paths)))
1823+
(if (re-matches #"^trusted.*" column)
1824+
[op (str "facts." column) value]
1825+
[op column value]))
18231826

18241827
[["extract" (columns :guard numeric-fact-functions?) (expr :guard no-type-restriction?)]]
18251828
(when (= :facts (get-in meta node [:query-context :entity]))

test/puppetlabs/puppetdb/query_eng_test.clj

+13
Original file line numberDiff line numberDiff line change
@@ -178,6 +178,19 @@
178178
:results-query
179179
first)))))
180180

181+
(deftest index-hit-for-trusted-facts-on-inventory
182+
(testing "facts.trusted.extensions and trusted.extensions should generate the same SQL"
183+
(is (re-find #"WHERE \(fs.stable||fs.volatile\) @> ?"
184+
(->> ["extract" [] ["=" "facts.trusted.extensions.foo" "bar"]]
185+
(compile-user-query->sql inventory-query)
186+
:results-query
187+
first)))
188+
(is (re-find #"WHERE \(fs.stable||fs.volatile\) @> ?"
189+
(->> ["extract" [] ["=" "trusted.extensions.foo" "bar"]]
190+
(compile-user-query->sql inventory-query)
191+
:results-query
192+
first)))))
193+
181194
(deftest test-valid-query-operators
182195
(is (thrown-with-msg? IllegalArgumentException
183196
#"'and' takes at least one argument, but none were supplied"

0 commit comments

Comments
 (0)