nobrainer 0.41.1 → 0.42.0

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: 5864cbae71a2eaa5c5f7efeb27d46c3a05f083618904641d793bef097b0b66d5
4
- data.tar.gz: 1a905f02f1623ade41cc4fe2913dbfbdbcbb539a494a1df37d457b0b695d15df
3
+ metadata.gz: 69052877b8fd9f2684f63a0bc7a917812fd771f793d55e7f5182149fc1346643
4
+ data.tar.gz: 33dbe632e862a31bb4ac95ab8015834947bd1207df3bbdfb921b742274d06517
5
5
  SHA512:
6
- metadata.gz: 8f3effc2a43c6f71f1eb0a42cd19d4ba6652599839998e746f9978a96aa8e3f9bc0b779e0524ac3315bc918cc06cd21399c8006d0f28f88c58d8a62008ab83c0
7
- data.tar.gz: 2801dbe94a1268d752dd9844ecd79c56a34e5029797cf5414cabc9ec85189d8703ee1e3ab40d7645ffa260f6f09ba5cc58542d3fa769def2cfb25424312a3b6b
6
+ metadata.gz: 102682b8e844b1fd574b3d29f386923bb4dfaee33e88e7da6c5615b4901d20023267cbd4e698bec34a94b77718ca04f251f8aebdfd8f74ef5837c637931dd206
7
+ data.tar.gz: 3cb7abcc47fd15d71abac788e7c5844229d30f532c01000d177d7c5b718848b48d2150cda32a1725ed7d0b68adbb775f4461805d9c2f4768104ba1320eb95d52
data/CHANGELOG.md CHANGED
@@ -7,6 +7,10 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
7
7
  ## [Unreleased]
8
8
 
9
9
 
10
+ ## [0.42.0] - 2022-06-15
11
+ ### Added
12
+ - Add support for partial compound index queries
13
+
10
14
  ## [0.41.1] - 2022-03-21
11
15
  ### Fixed
12
16
  - Removing table_config duplicates after a runtime exception (caspiano)
@@ -120,7 +124,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
120
124
  - Locks: bug fix: allow small timeouts in lock()
121
125
  - Fix reentrant lock counter on steals
122
126
 
123
- [Unreleased]: https://github.com/nobrainerorm/nobrainer/compare/v0.41.1...HEAD
127
+ [Unreleased]: https://github.com/nobrainerorm/nobrainer/compare/v0.42.0...HEAD
128
+ [0.41.1]: https://github.com/nobrainerorm/nobrainer/compare/v0.41.1...v0.42.0
124
129
  [0.41.1]: https://github.com/nobrainerorm/nobrainer/compare/v0.41.0...v0.41.1
125
130
  [0.41.0]: https://github.com/nobrainerorm/nobrainer/compare/v0.40.0...v0.41.0
126
131
  [0.40.0]: https://github.com/nobrainerorm/nobrainer/compare/v0.36.0...v0.40.0
@@ -399,12 +399,45 @@ module NoBrainer::Criteria::Where
399
399
  get_usable_indexes(:kind => :compound, :geo => false, :multi => false).each do |index|
400
400
  indexed_clauses = index.what.map { |field| clauses[[field]] }
401
401
  next unless indexed_clauses.all? { |c| c.try(:compatible_with_index?, index) }
402
-
403
402
  return IndexStrategy.new(self, ast, indexed_clauses, index, :get_all, [indexed_clauses.map(&:value)])
404
403
  end
405
404
  return nil
406
405
  end
407
406
 
407
+ def find_strategy_compound_partial
408
+ clauses = get_candidate_clauses(:eq, :between).map { |c| [c.key_path, c] }.to_h
409
+ return nil unless clauses.present?
410
+
411
+ get_usable_indexes(:kind => :compound, :geo => false, :multi => false).each do |index|
412
+ indexed_clauses = index.what.map { |field| clauses[[field]] }
413
+ partial_clauses = indexed_clauses.compact
414
+ pad = indexed_clauses.length - partial_clauses.length
415
+ if partial_clauses.any? && partial_clauses.all? { |c| c.try(:compatible_with_index?, index) }
416
+ # can only use partial compound index if:
417
+ # * index contains all clause fields
418
+ next unless (clauses.values & partial_clauses) == clauses.values
419
+ # * all clause fields come first in the indexed clauses (unused indexed fields are at the end)
420
+ next unless indexed_clauses.last(pad).all?(&:nil?)
421
+ # * all clause fields are :eq, except the last (which may be :between)
422
+ next unless partial_clauses[0..-2].all? { |c| c.op == :eq }
423
+
424
+ # use range query to cover unused index fields
425
+ left_bound = partial_clauses.map(&:value)
426
+ right_bound = partial_clauses.map(&:value)
427
+ if (clause = partial_clauses[-1]).op == :between
428
+ left_bound[-1] = clause.value.min
429
+ right_bound[-1] = clause.value.max
430
+ end
431
+ if pad > 0
432
+ left_bound.append *Array.new(pad, RethinkDB::RQL.new.minval)
433
+ right_bound.append *Array.new(pad, RethinkDB::RQL.new.maxval)
434
+ end
435
+ return IndexStrategy.new(self, ast, partial_clauses, index, :between, [left_bound, right_bound], :left_bound => :closed, :right_bound => :closed)
436
+ end
437
+ end
438
+ nil
439
+ end
440
+
408
441
  def find_strategy_hidden_between
409
442
  clauses = get_candidate_clauses(:gt, :ge, :lt, :le).group_by(&:key_path)
410
443
  return nil unless clauses.present?
@@ -454,7 +487,7 @@ module NoBrainer::Criteria::Where
454
487
  def find_strategy
455
488
  return nil unless ast.try(:clauses).present? && !criteria.without_index?
456
489
  case ast.op
457
- when :and then find_strategy_compound || find_strategy_canonical || find_strategy_hidden_between
490
+ when :and then find_strategy_compound || find_strategy_compound_partial || find_strategy_canonical || find_strategy_hidden_between
458
491
  when :or then find_strategy_union
459
492
  end
460
493
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: nobrainer
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.41.1
4
+ version: 0.42.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Nicolas Viennot
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2022-03-21 00:00:00.000000000 Z
11
+ date: 2022-06-15 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activemodel
@@ -242,7 +242,11 @@ files:
242
242
  homepage: http://nobrainer.io
243
243
  licenses:
244
244
  - LGPL-3.0-only
245
- metadata: {}
245
+ metadata:
246
+ allowed_push_host: https://rubygems.org
247
+ homepage_uri: http://nobrainer.io
248
+ source_code_uri: https://github.com/NoBrainerORM/nobrainer
249
+ changelog_uri: https://github.com/NoBrainerORM/nobrainer/blob/master/CHANGELOG.md
246
250
  post_install_message:
247
251
  rdoc_options: []
248
252
  require_paths: