Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

between() seems not to use an index when used with a bitwise AND (&) #235

Closed
s-yata opened this issue Oct 27, 2014 · 4 comments
Closed

between() seems not to use an index when used with a bitwise AND (&) #235

s-yata opened this issue Oct 27, 2014 · 4 comments

Comments

@s-yata
Copy link
Contributor

s-yata commented Oct 27, 2014

Description

When between() is used with a bitwise AND &, it seems not to use an index.

The following shows a list of commands to create a table.

table_create --name Data --flags TABLE_NO_KEY
column_create --table Data --name Value --type Int32
column_create --table Data --name Flag --type UInt32
load --table Data '[{"Value":860,"Flag":4}]'
...  // Value: [0, 1024), Flag: 1, 2, ..., or 512, #rows: 1M.
load --table Data '[{"Value":75,"Flag":2}]'
table_create --name DataValue --flags TABLE_PAT_KEY --key_type Int32
column_create --table DataValue --name Index --flags COLUMN_INDEX --type Data --source Value

Then, the first select is too slow compared with the other two selects.

> select --table Data --filter 'between(Value, 0, "include", 100, "include") && ((Flag & 1) != 0)'
[[0,1414418631.38877,5.48378705978394],[[[10283],...

> select --table Data --filter 'between(Value, 0, "include", 100, "include")'
[[0,1414418638.27391,0.0533609390258789],[[[103719],...

> select --table Data --filter 'between(Value, 0, "include", 100, "include") && (Flag == 1)'
[[0,1414418654.59622,0.0734946727752686],[[[10283],...

Also, if the index is disabled, the result is as follows:

> select --table Data --filter 'between(Value, 0, "include", 100, "include") && ((Flag & 1) != 0)'
[[0,1414417393.46272,5.49005770683289],[[[10283],...

> select --table Data --filter 'between(Value, 0, "include", 100, "include")'
[[0,1414417404.07405,4.96082067489624],[[[103719],...

> select --table Data --filter 'between(Value, 0, "include", 100, "include") && (Flag == 1)'
[[0,1414417416.61478,4.91911029815674],[[[10283],...
@kou
Copy link
Member

kou commented Nov 2, 2014

少し調べたんですが、1箇所でもビット演算子(&とか)または算術演算子(+とか)を使ってしまうと、全体で1つもインデックスを使わなくなってしまうようでした。

クエリーオプティマイザー(scan_info_build())ががんばらないといけないところなんですが、Cで書くのはツライので、mrubyを有効にしたときだけインデックスを使えるようになる、というのはありですかねぃ。。。

@kou kou closed this as completed in 9a49a5a Nov 3, 2014
@kou
Copy link
Member

kou commented Nov 3, 2014

Rubyで書いてみたらCでも簡単に書けるやつだったのでmrubyなしでもがんばるようにしました。

で、たぶん、masterだと直っていると思うので確認してもらえませんか?

@s-yata
Copy link
Contributor Author

s-yata commented Nov 4, 2014

確認してみたところ,索引ありの状態で以下に示す結果となりました.
一つ目の & を含むクエリでも索引が効いているようです.
検索結果にも問題ありません.

> select --table Data --filter 'between(Value, 0, "include", 100, "include") && ((Flag & 1) != 0)'
[[0,1415062629.88284,0.089080810546875],[[[10283],...

> select --table Data --filter 'between(Value, 0, "include", 100, "include")'
[[0,1415062633.69047,0.0181918144226074],[[[103719],...

> select --table Data --filter 'between(Value, 0, "include", 100, "include") && (Flag == 1)'
[[0,1415062636.64962,0.0799901485443115],[[[10283],...

Bravo!

@kou
Copy link
Member

kou commented Nov 4, 2014

よかったです!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants