The following two functions manipulate indexes on existing tables:
- mnesia:add table index(Tab, AttributeName) -> {aborted, R} |fatomic, ok}
- mnesia:del table index(Tab, AttributeName) -> {aborted, R} |fatomic, ok}
1 > mnesia:add_table_index(employee, salary).
The indexing capabilities of Mnesia are utilized with the following three functions, which retrieve and match records on the basis of index entries in the database.
- mnesia:index read(Tab, SecondaryKey, AttributeName) -> transaction abort | RecordList. Avoids an exhaustive search of the entire table, by looking up the SecondaryKey in the index to find the primary keys.
- mnesia:index match object(Pattern, AttributeName) -> transaction abort | RecordList. Avoids an exhaustive search of the entire table, by looking up the secondary key in the index to find the primary keys. The secondary key is found in the AttributeName field of the Pattern. The secondary key must be bound.
- mnesia:match object(Pattern) -> transaction abort | RecordList. Uses indices to avoid exhaustive search of the entire table. Unlike the other functions above, this function may utilize any index as long as the secondary key is bound.
0 意見