[Groonga-commit] groonga/groonga at b92176a [master] mrb: support estimating size for index search in expression

Back to archive index

Kouhei Sutou null+****@clear*****
Thu Feb 19 13:57:44 JST 2015


Kouhei Sutou	2015-02-19 13:57:44 +0900 (Thu, 19 Feb 2015)

  New Revision: b92176a83eb5c308779b3b632a413525a4d6fc1f
  https://github.com/groonga/groonga/commit/b92176a83eb5c308779b3b632a413525a4d6fc1f

  Message:
    mrb: support estimating size for index search in expression

  Modified files:
    lib/mrb/scripts/expression_size_estimator.rb
    test/query_optimizer/suite/test_estimate_size.rb

  Modified: lib/mrb/scripts/expression_size_estimator.rb (+19 -1)
===================================================================
--- lib/mrb/scripts/expression_size_estimator.rb    2015-02-19 13:48:32 +0900 (51d726a)
+++ lib/mrb/scripts/expression_size_estimator.rb    2015-02-19 13:57:44 +0900 (8da5739)
@@ -6,7 +6,25 @@ module Groonga
     end
 
     def estimate
-      @table.size
+      builder = ScanInfoBuilder.new(@expression, Operator::OR, 0)
+      data_list = builder.build
+      retur****@table***** if data_list.nil?
+
+      sizes = data_list.collect do |data|
+        search_index = data.search_indexes.first
+        if search_index.nil?
+          @table.size
+        else
+          index_column = search_index.index_column
+          if index_column.is_a?(Accessor)
+            # TODO
+            @table.size
+          else
+            index_column.estimate_size(:query => data.query.value)
+          end
+        end
+      end
+      sizes.min
     end
   end
 end

  Modified: test/query_optimizer/suite/test_estimate_size.rb (+4 -2)
===================================================================
--- test/query_optimizer/suite/test_estimate_size.rb    2015-02-19 13:48:32 +0900 (dde01cd)
+++ test/query_optimizer/suite/test_estimate_size.rb    2015-02-19 13:57:44 +0900 (5d7d53b)
@@ -23,7 +23,7 @@ class TestEstimateSize < QueryOptimizerTestCase
 
         schema.create_table("Terms",
                             :type => :patricia_trie,
-                            :default_tokenizer => "TokenBigram",
+                            :default_tokenizer => "TokenBigramSplitSymbolAlpha",
                             :normalizer => "NormalizerAuto") do |table|
           table.index("Logs", "message")
         end
@@ -37,7 +37,9 @@ class TestEstimateSize < QueryOptimizerTestCase
 
     def test_have_record
       @logs.add(:message => "Groonga is fast")
-      assert_equal(1, estimate_size("message @ 'Groonga'"))
+      @logs.add(:message => "Rroonga is fast")
+      @logs.add(:message => "Mroonga is fast")
+      assert_equal(6, estimate_size("message @ 'Groonga'"))
     end
   end
 end
-------------- next part --------------
HTML����������������������������...
Download 



More information about the Groonga-commit mailing list
Back to archive index