Skip to content

Commit 86f0259

Browse files
committed
Always discard Trilogy multi-statement results
Previously we were trying to clear the extra results in a with_raw_connection block, which caused some issues. We never want to connect or reconnect here, we just need to drop any results from a multi-statement query and that only makes sense to do on the same connection we'd already used for the query. Previously when a query was run which hit the query cache on a fresh, non-sticky connection, the connection would perform its `verfiy!` before calling next_result, resulting in a network round trip.
1 parent cdaa1a3 commit 86f0259

File tree

1 file changed

+3
-9
lines changed

1 file changed

+3
-9
lines changed

activerecord/lib/active_record/connection_adapters/trilogy/database_statements.rb

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -4,14 +4,6 @@ module ActiveRecord
44
module ConnectionAdapters
55
module Trilogy
66
module DatabaseStatements
7-
def select_all(*, **) # :nodoc:
8-
result = super
9-
with_raw_connection do |conn|
10-
conn.next_result while conn.more_results_exist?
11-
end
12-
result
13-
end
14-
157
def internal_exec_query(sql, name = "SQL", binds = [], prepare: false, async: false, allow_retry: false) # :nodoc:
168
sql = transform_query(sql)
179
check_if_write_query(sql)
@@ -47,6 +39,9 @@ def raw_execute(sql, name, async: false, allow_retry: false, materialize_transac
4739
with_raw_connection(allow_retry: allow_retry, materialize_transactions: materialize_transactions) do |conn|
4840
sync_timezone_changes(conn)
4941
result = conn.query(sql)
42+
while conn.more_results_exist?
43+
conn.next_result
44+
end
5045
verified!
5146
handle_warnings(sql)
5247
notification_payload[:row_count] = result.count
@@ -77,7 +72,6 @@ def execute_batch(statements, name = nil)
7772
combine_multi_statements(statements).each do |statement|
7873
with_raw_connection do |conn|
7974
raw_execute(statement, name)
80-
conn.next_result while conn.more_results_exist?
8175
end
8276
end
8377
end

0 commit comments

Comments
 (0)