首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >如何在Tarantool中通过二级索引进行选择?

问如何在Tarantool中通过二级索引进行选择?
EN

Stack Overflow用户
提问于 2020-09-23 16:28:34
回答 1查看 97关注 0票数 0

我创建了一个包含两个索引的空间--主索引和次要索引:

代码语言:javascript
复制
box.schema.sequence.create('user_seq', { if_not_exists = true })
box.schema.space.create('user', {
    if_not_exists = true,
    format = {
        { name = 'id', type = 'unsigned'},
        { name = 'bio', type = 'string'}
    }
})
box.space.user:create_index('id', {
     sequence = 'user_seq',
     parts = {'id'}
})
box.space.user:create_index('bio', {
     parts = {'bio'},
     if_not_exists = true,
     unique = false
})

插入元组:

代码语言:javascript
复制
tarantool> box.space.user:insert({ box.sequence.user_seq:next(), 'other stuff'})
---
- [1, 'other stuff']
...

我试过像这样搜索:

代码语言:javascript
复制
box.space.user:select({'other stuff'})

得到了错误:

代码语言:javascript
复制
- error: 'Supplied key type of part 0 does not match index part type: expected unsigned'

我应该如何通过二级索引进行搜索?

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2020-09-23 16:28:34

文件上说:

索引-名称是可选的。如果省略,则假定索引是第一个(主键)索引.因此,对于上面的示例,box.space.tester:select({1},{iterator = 'GT'})将通过“主”索引返回相同的两行。

明确使用该辅助索引:

代码语言:javascript
复制
tarantool> box.space.user.index.bio:select({'other stuff'})
---
- - [1, 'other stuff']
...

了解更多关于it的信息,在文件里。

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/64032368

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档