Class: Queris::Query::IntersectOp

Inherits:
Op
  • Object
show all
Defined in:
lib/queris/query/operations.rb

Constant Summary collapse

COMMAND =
:zinterstore
SYMBOL =
:'∩'
NAME =
:intersect
OPTIMIZATION_THRESHOLD_MULTIPLIER =
5

Instance Attribute Summary

Attributes inherited from Op

#fragile, #operands

Instance Method Summary collapse

Methods inherited from Op

#command, #initialize, #json_redis_dump, #keys, #marshal_dump, #notready!, #operand_key, #operand_key_weight, #optimized?, #prepare, #push, #query_run_stage_inspect, #query_run_stage_release, #run, #subqueries, #symbol, #target_key_weight, #temp_keys, #temp_keys?, #to_s, #weights

Constructor Details

This class inherits a constructor from Queris::Query::Op

Instance Method Details

#optimize(smallkey, smallsize, page = nil) ⇒ Object



327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
# File 'lib/queris/query/operations.rb', line 327

def optimize(smallkey, smallsize, page=nil)
  smallestkey, smallestsize, smallestop = Float::INFINITY, Float::INFINITY, nil
  m = self.class::OPTIMIZATION_THRESHOLD_MULTIPLIER
  #subquery_ops=[]
  super do |key, size, op|
    smallestkey, smallestsize, smallestop = key, size, op if size < smallestsize
    #subquery_ops << op if op.is_query?
  end
  #no need to preintersect subqueries for intersects - it's not trivial (size may not be available before query subquery is run), and it's not terribly advantageous
  if smallsize * m < smallestsize
    puts "optimization reduced intersect operand from #{smallestsize} to #{smallsize}"
    smallestop.preintersect(smallkey, smallestkey)
  elsif page && page.size * m < smallestsize
    smallestop.preintersect(page.key, smallestkey)
  end
  if smallestsize < smallsize
    #puts "found a smaller intersect key: |#{smallestkey}|=#{smallestsize}"
    return smallestkey, smallestsize
  else
    return smallkey, smallsize
  end
end