huginn_datatable 0.4.1 → 0.4.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 93c77acb3179b06e77712420af3deb4c8f595a715c45e3c4f00c03a5f4e8a73c
4
- data.tar.gz: a0dba33d0fffd18d0df9303d9253ec9652ab5620d6e77fbc0b017a3c8000b335
3
+ metadata.gz: 69da28c529c40a8b48b25dec0b0d2dbae158b9b070b4744ffd880c7600d5b915
4
+ data.tar.gz: 15fb1354d48685d12e1e8f0c5f61f1ec93a9bf8053292a8fff527e9287af6a07
5
5
  SHA512:
6
- metadata.gz: 56699ffb963d5c809dc3664fbbc7456f39a634cd6952ad9472b8eb0f9f891016291baa859203a32d3024e7b496adc003c2f55ace6a384ce691c54b6adb37c715
7
- data.tar.gz: 2437df93a69e3328ae63b6be1fbb623c7a5784e0232d0bb1fa757a74698f9bad211da135459f27b5a879d9f0cbca02388372fa169f0acb7e6c947ed0693b9805
6
+ metadata.gz: 7cb1bfff379be1ee47ab9fd593a6fe974a90bb7a1bef70c0bae7d9b9b39583f96ac16ddbf0c43c27ddf7e10462eb541d6bd4aca35741c01ffd1132403dfcf5b3
7
+ data.tar.gz: 16b019669e29974017f5c8a77d33036d5f8bee2d20449024d061bb695316cc9747631ec44e1921a13ad97044109cbcbe4182368d5f0df255ae94b2ca9620ded8
data/CHANGELOG.md CHANGED
@@ -2,6 +2,10 @@
2
2
 
3
3
  ### Unreleased
4
4
 
5
+ #### 0.4.2
6
+
7
+ - **Performance (PostgreSQL):** association matches in `search` are written as `fk = ANY(ARRAY(SELECT DISTINCT ...))` instead of `fk IN (SELECT DISTINCT ...)`. The `IN` form was planned as a hashed SubPlan, which can't take part in a BitmapOr: a single association column (e.g. `searchable_columns :title, company: [:name]`) made the whole OR fall back to filtering every row, ignoring the GIN trigram/tsvector indexes. `ANY(ARRAY(...))` runs once as an InitPlan and keeps the index plan (measured on 20k-30k rows: ~500 ms → ~1 ms for a selective term). Results are unchanged; other adapters keep `IN`.
8
+
5
9
  #### 0.4.1
6
10
 
7
11
  - **Fix:** the specs no longer use the Ruby 3.1+ shorthand hash syntax (`f(allowed_paths:)`), so the suite loads again on Ruby 3.0 (the gem's minimum). No library code changed from 0.4.0.
@@ -108,6 +108,7 @@ module Huginn
108
108
  # belongs_to -> base[fk] IN (SELECT DISTINCT t1[join_pk] FROM t1 ...)
109
109
  # has_many -> base[pk] IN (SELECT DISTINCT t1[fk] FROM t1 ...)
110
110
  #
111
+ # On PostgreSQL the membership is written as `= ANY(ARRAY(...))` (see #member_of).
111
112
  # Walks the chain from the first target table outwards so the base table
112
113
  # is never scanned inside the subquery.
113
114
  def anchored_predicate(path, attrs)
@@ -139,7 +140,20 @@ module Huginn
139
140
  manager.project(projection)
140
141
  manager.distinct
141
142
 
142
- outer.in(manager)
143
+ member_of(outer, manager)
144
+ end
145
+
146
+ # `column IN (subquery)` becomes a hashed SubPlan on PostgreSQL, which can't
147
+ # take part in a BitmapOr: one association arm then forces the whole search
148
+ # (every column OR'ed together) into a filter over every row of the table,
149
+ # ignoring the GIN indexes. `column = ANY(ARRAY(subquery))` is evaluated
150
+ # once as an InitPlan and the column's index is used, so the OR stays a
151
+ # BitmapOr. Other adapters keep the plain IN.
152
+ def member_of(column, subquery)
153
+ return column.in(subquery) unless postgresql?
154
+
155
+ array = Arel::Nodes::NamedFunction.new("ARRAY", [subquery.ast])
156
+ Arel::Nodes::Equality.new(column, Arel::Nodes::NamedFunction.new("ANY", [array]))
143
157
  end
144
158
 
145
159
  # Whether the first hop goes through a join model; the FK anchoring is
@@ -161,7 +175,7 @@ module Huginn
161
175
  .distinct
162
176
 
163
177
  predicate = fuzzy_predicates(attrs).reduce(&:or)
164
- arel_table[primary_key].in(base.joins(spec).where(predicate).arel)
178
+ member_of(arel_table[primary_key], base.joins(spec).where(predicate).arel)
165
179
  end
166
180
 
167
181
  def fuzzy_predicate(attr)
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Huginn
4
- VERSION = "0.4.1"
4
+ VERSION = "0.4.2"
5
5
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: huginn_datatable
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.4.1
4
+ version: 0.4.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Kayky Marcelo