Kouhei Sutou
null+****@clear*****
Tue Jan 14 14:16:00 JST 2014
Kouhei Sutou 2014-01-14 14:16:00 +0900 (Tue, 14 Jan 2014) New Revision: 9a7f6edca3b84007575d591aea433dc5a02427f7 https://github.com/groonga/groonga/commit/9a7f6edca3b84007575d591aea433dc5a02427f7 Message: Don't use index for empty query Because we can't use index with empty query. Groonga's table doesn't accept empty key. So we can't register a document to index with empty key. [groonga-dev,02052] Reported by Naoya Murakami. Thanks!!! Added files: test/command/suite/select/index/equal/empty_string.expected test/command/suite/select/index/equal/empty_string.test Modified files: lib/expr.c Modified: lib/expr.c (+4 -0) =================================================================== --- lib/expr.c 2014-01-14 14:06:15 +0900 (7d3c26b) +++ lib/expr.c 2014-01-14 14:16:00 +0900 (78e7653) @@ -4598,6 +4598,10 @@ grn_table_select_index(grn_ctx *ctx, grn_obj *table, scan_info *si, grn_obj *index = GRN_PTR_VALUE(&si->index); switch (si->op) { case GRN_OP_EQUAL : + if (GRN_BULK_VSIZE(si->query) == 0) { + /* We can't use index for empty value. */ + return GRN_FALSE; + } if (si->flags & SCAN_ACCESSOR) { if (index->header.type == GRN_ACCESSOR && !((grn_accessor *)index)->next) { Added: test/command/suite/select/index/equal/empty_string.expected (+48 -0) 100644 =================================================================== --- /dev/null +++ test/command/suite/select/index/equal/empty_string.expected 2014-01-14 14:16:00 +0900 (a37b901) @@ -0,0 +1,48 @@ +table_create Bookmarks TABLE_HASH_KEY ShortText +[[0,0.0,0.0],true] +column_create Bookmarks tag COLUMN_SCALAR ShortText +[[0,0.0,0.0],true] +table_create Tags TABLE_PAT_KEY ShortText +[[0,0.0,0.0],true] +column_create Tags bookmarks_tag COLUMN_INDEX Bookmarks tag +[[0,0.0,0.0],true] +load --table Bookmarks +[ +{"_key": "http://groonga.org/", "tag": "groonga"}, +{"_key": "http://mroonga.org/", "tag": ""} +] +[[0,0.0,0.0],2] +select Bookmarks --query 'tag:\"\"' +[ + [ + 0, + 0.0, + 0.0 + ], + [ + [ + [ + 1 + ], + [ + [ + "_id", + "UInt32" + ], + [ + "_key", + "ShortText" + ], + [ + "tag", + "ShortText" + ] + ], + [ + 2, + "http://mroonga.org/", + "" + ] + ] + ] +] Added: test/command/suite/select/index/equal/empty_string.test (+13 -0) 100644 =================================================================== --- /dev/null +++ test/command/suite/select/index/equal/empty_string.test 2014-01-14 14:16:00 +0900 (ca9c1e7) @@ -0,0 +1,13 @@ +table_create Bookmarks TABLE_HASH_KEY ShortText +column_create Bookmarks tag COLUMN_SCALAR ShortText + +table_create Tags TABLE_PAT_KEY ShortText +column_create Tags bookmarks_tag COLUMN_INDEX Bookmarks tag + +load --table Bookmarks +[ +{"_key": "http://groonga.org/", "tag": "groonga"}, +{"_key": "http://mroonga.org/", "tag": ""} +] + +select Bookmarks --query 'tag:\"\"' -------------- next part -------------- HTML����������������������������...Download