Skip to content

Commit a890d40

Browse files
committed
Use ntuples to populate row_count instead of count for Postgres
PG::Result#ntuples uses a libpq function for getting the number of rows returned from a query, whereas #count is provided by Enumerable and thus iterates through the entire result set.
1 parent 82e9029 commit a890d40

File tree

2 files changed

+5
-1
lines changed

2 files changed

+5
-1
lines changed

activerecord/CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
* Use ntuples to populate row_count instead of count for Postgres
2+
3+
*Jonathan Calvert*
4+
15
* Fix checking whether an unpersisted record is `include?`d in a strictly
26
loaded `has_and_belongs_to_many` association.
37

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -165,7 +165,7 @@ def perform_query(raw_connection, sql, binds, type_casted_binds, prepare:, notif
165165
verified!
166166

167167
notification_payload[:affected_rows] = result.cmd_tuples
168-
notification_payload[:row_count] = result.count
168+
notification_payload[:row_count] = result.ntuples
169169
result
170170
end
171171

0 commit comments

Comments
 (0)