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 +4 -4
- data/CHANGELOG.md +4 -0
- data/lib/huginn/searchable/query.rb +16 -2
- data/lib/huginn/version.rb +1 -1
- metadata +1 -1
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 69da28c529c40a8b48b25dec0b0d2dbae158b9b070b4744ffd880c7600d5b915
|
|
4
|
+
data.tar.gz: 15fb1354d48685d12e1e8f0c5f61f1ec93a9bf8053292a8fff527e9287af6a07
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
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
|
|
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]
|
|
178
|
+
member_of(arel_table[primary_key], base.joins(spec).where(predicate).arel)
|
|
165
179
|
end
|
|
166
180
|
|
|
167
181
|
def fuzzy_predicate(attr)
|
data/lib/huginn/version.rb
CHANGED