2017-02-27 47 views
0
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是基於而不是零,還是在其他地方玩?爲什麼我的mnesia索引在這個位置?

回答

4

Mnesia表包含具有類似記錄格式的元組。在你的榜樣存儲在:users表中的元組看起來像:

{:users, 1, "[email protected]", "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上。

+0

好酷,所以erlang元組使用1基礎索引,謝謝 – blu

相關問題