【问题标题】:Reference Search in TarantoolTarantool 中的参考搜索
【发布时间】:2016-04-05 18:04:57
【问题描述】:

我有两个表:useruser_matching。我想在 1 个查询中从两个表中获取项目。例如,类似 SQL 的查询:

select * from user where user.id = (select id from user_matching where id = user_matching_id)

通常我应该在 NoSQL DB 中使用 2 个查询。现在我这样做:

  1. user_matching user_id
  2. 获取
  3. 使用 user_id 从 user 获取

我可以使用 Tarantool 仅用 1 个查询替换它吗?以及如何做?

【问题讨论】:

    标签: tarantool


    【解决方案1】:

    您需要创建存储过程,将两个选择的结果组合在一起,例如:

    function select_user_by_matching_id(matching_id)
        local id = box.space.user_matching:get{matching_id} # or :select
        local user_data = box.space.user:get{id} # or :select
        # work with user_data
        return user_data
    end
    

    创建此过程后,您可以通过 Tarantool 驱动程序调用此过程并获取组合结果。

    更多细节在这里:http://tarantool.org/doc/book/app/c-lua_tutorial.html?highlight=call

    【讨论】:

    猜你喜欢
    • 2021-05-23
    • 1970-01-01
    • 2021-08-19
    • 2017-07-03
    • 2018-05-05
    • 2019-11-18
    • 1970-01-01
    • 2016-02-19
    • 2021-08-23
    相关资源
    最近更新 更多