【问题标题】:Why is my mnesia index in this position?为什么我的失忆指数在这个位置?
【发布时间】:2017-07-17 14:25:19
【问题描述】:
iex(6)> :mnesia.table_info(:users, :attributes)
[:id, :email, :foo, :inserted_at, :updated_at]

iex(7)> :mnesia.table_info(:users, :index)     
[3]

iex(8)> :mnesia.add_table_index(:users, :email)
{:aborted, {:already_exists, :users, 3}}

我知道Tab 是第一个索引,但为什么不是2 上的索引而不是3?索引是基于 1 而不是零,还是有其他因素在起作用?

【问题讨论】:

    标签: erlang elixir mnesia


    【解决方案1】:

    Mnesia 表包含具有类似记录格式的元组。在您的示例中,存储在 :users 表中的元组类似于:

    {:users, 1, "f@b.com", "foo", {2016, 12, 24}, {2016, 12, 31}}
    

    映射到:

    Index |   1    |   2   |   3    |  4   |      5       |     6       |
    Name  | :users |  :id  | :email | :foo | :inserted_at | :updated_at |
    

    由于元组是从 1 开始的,为 :email 值创建的索引将在元组的位置 3 上创建。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2016-01-18
      • 1970-01-01
      • 1970-01-01
      • 2014-01-21
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多