RethinkDB Compound Index Weirdness Using Between

元气小坏坏 提交于 2019-12-12 03:36:15

问题


I've noticed something strange with compound indexes in the between function in RethinkDB. It seems to retrieve results that don't match the query. It's all detailed below.

r.dbCreate('test')

r.db('test').tableCreate('numbers')

r.db('test').table('numbers').insert([
    { first: 1, second: 1 },
    { first: 1, second: 2 },    
    { first: 1, second: 3 },    
    { first: 1, second: 4 },    
    { first: 1, second: 5 },    
    { first: 2, second: 1 },    
    { first: 2, second: 2 },    
    { first: 2, second: 3 },    
    { first: 2, second: 4 },    
    { first: 2, second: 5 },    
    { first: 3, second: 1 },    
    { first: 3, second: 2 },    
    { first: 3, second: 3 },    
    { first: 3, second: 4 },    
    { first: 3, second: 5 },
    { first: 4, second: 1 },    
    { first: 4, second: 2 },    
    { first: 4, second: 3 },    
    { first: 4, second: 4 },    
    { first: 4, second: 5 },    
    { first: 5, second: 1 },    
    { first: 5, second: 2 },    
    { first: 5, second: 3 },    
    { first: 5, second: 4 },    
    { first: 5, second: 5 }
  ])

r.db('test').table('numbers').indexCreate(
    "both", [r.row("first"), r.row("second")])

r.db('test').table('numbers').orderBy({index :'both'}).between(
  [2, 3], [3, 5], {index: 'both', rightBound: 'closed'}).without('id')

// output

{ "first": 3 , 
"second": 3 
} // ok

{ "first": 3 , 
"second": 4 
} // ok

{ "first": 2 , 
"second": 5 
} // ok

{ "first": 3 , 
"second": 1 
} // not ok

{ "first": 3 , 
"second": 5 
} // ok

{ "first": 3 , 
"second": 2 
} // not ok

{ "first": 2 , 
"second": 3 
} // ok

{ "first": 2 , 
"second": 4 
} // ok

The array in the query doesn't appear to act like an AND or an OR. Am I missing something or is this a bug?


回答1:


Ok so thanks to some help from originalexe over on the Slack channel I've figured this out. It's behaving as normal and essentially the array is treated as a single value and the query returns all values that are between the two in an ordered list.



来源:https://stackoverflow.com/questions/35649106/rethinkdb-compound-index-weirdness-using-between

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!