1

For GWan's key value store can I create more than one index for a given single type of entity? Also can I query more than one index at once such as find a item with age > 5 and height > 100 if I indexed age and height.

Charles
  • 50,943
  • 13
  • 104
  • 142
Phil
  • 46,436
  • 33
  • 110
  • 175

1 Answers1

1

can I create more than one index for a given single type of entity?

If you mean, having several indexes for multiple fields in a record (more than one value for a key) then yes, you can. Just look at the kv.c example: http://gwan.ch/source/kv.c (for any reason, the Stackoverflow text formatting menu is not displayed, so I wrote the link in the text rather than embedded - also, if someone could PLEASE stop the captcha that I must enter to reply to each question, that would be nice).

can I query more than one index at once such as find a item with age > 5 and height > 100 if I indexed age and height?

You can easily write a function to do that and find the records that appear in the first search on the first index AND in the second search for the second index.

This is very fast as the results are returned sorted.

Gil
  • 3,279
  • 1
  • 15
  • 25
  • Query of more than one index, does this return an intersection of the AND's or you just mean I can do two different queries and get two different results (which would result in a union)? Normally in a SQL query if we want to do a WHERE age > 5 AND height > 100 and would like to have an index on age and height, we get an intersection of results back. – Phil Apr 24 '13 at 15:21
  • If you make two requests, then you will get two replies. Then, you will have to find the common records, as explained above. Remember that the G-WAN Key/Value store, while accepting range requests, is NOT an SQL database engine, you can't submit SQL requests. – Gil Apr 29 '13 at 06:47
  • Hi yes, sure. What I was thinking, can it take one request using two index constraints? – Phil Apr 29 '13 at 08:18
  • There is an example about how to just do that in the **kv.c** file which uses the **kv_do()** callback for this very purpose. – Gil May 03 '13 at 09:37