首页 文章

Ignite SqlFieldsQuery特定键

提问于
浏览
0

使用ignite C API,我试图找到一种方法来执行SqlFieldsQuery来选择特定字段,但是想要为一组键执行此操作 .

一种方法是,像这样做SqlFieldsQuery,

SqlFieldsQuery("select field from Table where _key in (" + keys_string + ")")

其中 keys_string 是以逗号分隔的字符串的键列表 .

不幸的是,与仅为密钥集 keys 执行 cache.GetAll(keys) 相比,这需要很长时间 .

是否有另一种更快的方法从点火缓存中获取一组键的特定字段?

EDIT:

阅读完答案后,我尝试将查询更改为:

auto query = SqlFieldsQuery("select field from Table t join table(_key bigint = ?) i on t._key = i._key")

然后我从我的一组键中添加参数,如下所示:

for(const auto& key: keys) query.AddArgument(key);

但是在运行查询时,我收到错误:

Failed to bind parameter [idx=2, obj=159957, stmt=prep0: select field from Table t join table(_key bigint = ?) i on t._key = i._key {1: 159956}]

显然,这不起作用,因为只有一个'?' .

所以我接着尝试传递一个 vector<int64_t> 的键,但是我得到了一个错误,基本上说 std::vector<int64_t> 没有专门点燃 BinaryType . 所以我按照定义here做了这个 . 当打电话时

writer.WriteInt64Array("data", data.data(), data.size())

我给了字段任意名称“数据” . 这会导致错误:

Failed to run map query remotely.

不幸的是,C API既没有很好的文档记录,也没有完整,所以我缺少一些东西,或者API不允许将数组作为参数传递给 SqlFieldsQuery .

2 回答

  • 1

    使用 IN 子句的查询并不总是正确使用索引 . 此处描述了解决方法:https://apacheignite.readme.io/docs/sql-performance-and-debugging#sql-performance-and-usability-considerations

    此外,如果您可以选择 GetAll 而直接按键查找,那么您应该使用它 . 无论如何,它可能会更有效 .

  • 1

    使用运算符“IN”的查询不会始终使用索引 . 作为解决方法,您可以通过以下方式重写查询:

    select field from Table t join table(id bigint = ?) i on t.id = i.id
    

    然后调用它:

    new SqlFieldsQuery(
          "select field from Table t join table(id bigint = ?) i on t.id = i.id")
           .setArgs(new Object[]{ new Integer[] {2, 3, 4} }))
    

相关问题