[groonga-dev,04251] Mroongaの同値でのfast_order_limitでoffsetの結果が壊れる

Back to archive index

murata satoshi murat****@gmail*****
2017年 1月 21日 (土) 19:52:22 JST


村田です。お世話になっております。
fast_order_limitが有効な場合にoffsetの結果が壊れるケースがありましたので報告します。
同値でのorder byの場合に発生するようです。

以下、簡単な再現用です。
---
mysql> CREATE TABLE m_fol_test (
  _id int,
  title varchar(255) not null,
  price int unsigned not null,
  PRIMARY KEY(_id) USING HASH,
  FULLTEXT KEY(title) COMMENT 'tokenizer "TokenBigramSplitSymbolAlphaDigit"',
  KEY (price)
) ENGINE=Mroonga;

mysql> INSERT INTO m_fol_test (_id, title, price) VALUES
(NULL, 'mroonga01', 500),
(NULL, 'mroonga02', 500),
(NULL, 'mroonga03', 500),
(NULL, 'mroonga04', 500),
(NULL, 'mroonga05', 500),
(NULL, 'mroonga06', 500),
(NULL, 'mroonga07', 500),
(NULL, 'mroonga08', 500),
(NULL, 'mroonga09', 500),
(NULL, 'mroonga10', 500);

mysql> select _id from m_fol_test where match(title) against('+mroonga' IN BOOLEAN MODE) order by price asc limit 0, 10; 
+-----+
| _id |
+-----+
|   1 |
|   2 |
|   3 |
|   4 |
|   5 |
|   6 |
|   7 |
|   8 |
|   9 |
|  10 |
+-----+

--- 条件なし
mysql> select _id from m_fol_test where match(title) against('+mroonga' IN BOOLEAN MODE) order by price asc limit 0, 5;
+-----+
| _id |
+-----+
|   1 |
|   3 |
|   4 |
|   5 |
|  10 |
+-----+
mysql> select _id from m_fol_test where match(title) against('+mroonga' IN BOOLEAN MODE) order by price asc limit 5, 5;
+-----+
| _id |
+-----+
|   6 |
|   7 |
|   8 |
|   9 |
|  10 |
+-----+
並び順が変わる。10が被り、2が消失。

--- 条件付与(=)
mysql> select _id from m_fol_test where match(title) against('+roonga' IN BOOLEAN MODE) and price = 500 order by price asc limit 0, 5;
+-----+
| _id |
+-----+
|   1 |
|  10 |
|   3 |
|   5 |
|   4 |
+-----+
mysql> select _id from m_fol_test where match(title) against('+roonga' IN BOOLEAN MODE) and price = 500 order by price asc limit 5, 5;
+-----+
| _id |
+-----+
|   6 |
|   9 |
|   8 |
|   7 |
|   2 |
+-----+
並び順は変わるが被り・消失はない。

--- 条件付与(range)
mysql> select _id from m_fol_test where match(title) against('+roonga' IN BOOLEAN MODE) and price between 300 and 1000 order by price asc limit 0, 5;
+-----+
| _id |
+-----+
|   1 |
|   3 |
|   4 |
|   5 |
|  10 |
+-----+
mysql> select _id from m_fol_test where match(title) against('+roonga' IN BOOLEAN MODE) and price between 300 and 1000 order by price asc limit 5, 5;
+-----+
| _id |
+-----+
|   6 |
|   7 |
|   8 |
|   9 |
|  10 |
+-----+
並び順が変わる。10が被り、2が消失。

---
- asc | desc関係なく発生します。
- ユニークなソート条件を足すと発生しません。(order by price asc, _id asc...)
- mroonga_enable_optimizationをOFFにした場合は発生しません。(fast_order_limitにならないので..)
- groongaで同等の問い合わせをすると、上記[条件付与(=)]と同じ結果になります。

以上報告になります。
よろしくお願いします。

むらた



groonga-dev メーリングリストの案内
Back to archive index