Skip to content

The easy-to-use open source Business Intelligence and Embedded Analytics tool that lets everyone work with data :bar_chart:

Reduce memory usage of fingerprinting postgres (#72133)

Nathan Voxlande6c13bd0e006
diff --git a/src/metabase/driver/common/table_rows_sample.clj b/src/metabase/driver/common/table_rows_sample.clj
index 9bc9127da80..a4b2623adea 100644
--- a/src/metabase/driver/common/table_rows_sample.clj
+++ b/src/metabase/driver/common/table_rows_sample.clj
@@ -74,6 +74,7 @@
(as-> $query (reduce lib/order-by $query order-by)))
(assoc :middleware {:format-rows? false
:skip-results-metadata? true})
+ (assoc-in [:info :context] :table-rows-sample)
schema.metadata-queries/add-required-filters-if-needed)))
;;; TODO (Cam 9/30/25) -- at some point we should update this stuff to use Lib-style metadata instead of Toucan
diff --git a/src/metabase/driver/sql_jdbc/execute.clj b/src/metabase/driver/sql_jdbc/execute.clj
index c4233dd9ebb..ae97a46c20a 100644
--- a/src/metabase/driver/sql_jdbc/execute.clj
+++ b/src/metabase/driver/sql_jdbc/execute.clj
@@ -65,6 +65,8 @@
;; whether this Connection should NOT be read-only, e.g. for DDL stuff or inserting data or whatever.
[:write? {:optional true} [:maybe :boolean]]
[:download? {:optional true} [:maybe :boolean]]
+ ;; true if called from table-rows-sample-query
+ [:sample? {:optional true} [:maybe :boolean]]
;; don't autoclose the connection
[:keep-open? {:optional true} [:maybe :boolean]]]])
@@ -411,7 +413,7 @@
;; todo (dan 7/11/25): fixing straightforward postgres oom on downloads in #60733, but seems like write? is
;; not set here. Note this is explicitly silent when `write?`. Lots of tests fail with autocommit false
;; there.
- (and (-> options :download?) (isa? driver/hierarchy driver :postgres))
+ (and (or (-> options :download?) (-> options :sample?)) (isa? driver/hierarchy driver :postgres))
(try
(log/trace (pr-str '(.setAutoCommit conn false)))
(.setAutoCommit conn false)
@@ -785,7 +787,8 @@
driver
(driver-api/database (driver-api/metadata-provider))
{:session-timezone (driver-api/report-timezone-id-if-supported driver (driver-api/database (driver-api/metadata-provider)))
- :download? (download? (-> outer-query :info :context))}
+ :download? (download? (-> outer-query :info :context))
+ :sample? (= :table-rows-sample (-> outer-query :info :context))}
(fn [^Connection conn]
(with-open [stmt (statement-or-prepared-statement driver conn sql params (driver-api/canceled-chan))
^ResultSet rs (try
diff --git a/src/metabase/lib/schema/info.cljc b/src/metabase/lib/schema/info.cljc
index fb73ba45876..b7341eb83f8 100644
--- a/src/metabase/lib/schema/info.cljc
+++ b/src/metabase/lib/schema/info.cljc
@@ -37,6 +37,7 @@
:embedded-xlsx-download
:embedded-json-download
:table-grid
+ :table-rows-sample
:transform-inspector
:slackbot])