From 283d9d50386e14534885c826b4037889b42f8b30 Mon Sep 17 00:00:00 2001 From: jdenquin Date: Wed, 9 Oct 2024 01:21:57 +0200 Subject: [PATCH] add notes --- lib/core_extensions/active_record/relation.rb | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/lib/core_extensions/active_record/relation.rb b/lib/core_extensions/active_record/relation.rb index 9327f547..9b047805 100644 --- a/lib/core_extensions/active_record/relation.rb +++ b/lib/core_extensions/active_record/relation.rb @@ -81,10 +81,19 @@ def window!(name, **opts) self end + # The LIMIT BY clause permit to improve deduplication based on a unique key, it has better performances than + # the GROUP BY clause + # + # users = User.limit_by(1, id) + # # SELECT users.* FROM users LIMIT 1 BY id + # + # An ActiveRecord::ActiveRecordError will be reaised if database is not Clickhouse. + # @param [Array] opts def limit_by(*opts) spawn.limit_by!(*opts) end + # @param [Array] opts def limit_by!(*opts) @values[:limit_by] = *opts self