|
1 | 1 | # Mnesia
|
2 | 2 |
|
3 |
| -- Mnesia combines many concepts found in traditional databases such as transactions and queries with concepts found in data management systems for telecommunications applications such as very fast realtime operations, configurable degree of fault tolerance (by means of replication) and the ability to reconfigure the system without stopping or suspending it. |
| 3 | +- Mnesia combines many concepts found in traditional databases such as transactions and queries with concepts found in data management systems for telecommunications applications such as very fast real-time operations, configurable degree of fault tolerance (using replication), and the ability to reconfigure the system without stopping or suspending it. |
4 | 4 |
|
5 | 5 | - Mnesia is also interesting due to its tight coupling to the programming language Erlang, thus almost turning Erlang into a database programming language.
|
6 | 6 |
|
7 |
| -- This has many benefits, the foremost being that the impedance mismatch between data format used by the DBMS and data format used by the programming language which is being used to manipulate the data, completely disappears. |
| 7 | +- This has many benefits, the foremost being that the impedance mismatch between the data format used by the DBMS and the data format used by the programming language that is being used to manipulate the data, completely disappears. |
8 | 8 |
|
9 |
| -- Mnesia has four methods of reading from database: read, match_object, select, qlc. |
10 |
| - - `read` always uses a Key-lookup on the keypos. It is basically the key-value lookup. |
| 9 | +- Mnesia has four methods of reading from the database: read, match_object, select, qlc. |
| 10 | + - `read` always uses a key lookup on the key position. It is the key-value lookup. |
11 | 11 | - `match_object` and select will optimize the query if it can on the keypos key. That is, it only uses that key for optimization. It never utilizes further index types.
|
12 |
| - - `qlc` has a query-compiler and will attempt to use additional indexes if possible, but it all depends on the query planner and if it triggers. erl -man qlc has the details and you can ask it to output its plan. |
| 12 | + - `qlc` has a query compiler and will attempt to use additional indexes if possible, but it all depends on the query planner and if it triggers. Erl -man qlc has the details and you can ask it to output its plan. |
13 | 13 | - read is just a `key-value` lookup, also functions `index_read` and `index_write`
|
14 | 14 |
|
15 | 15 | - A power of two number of fragments is simply related to the fact the default fragmentation module `mnesia_frag` uses linear hashing so using `2^n` fragments assures that records are equally distributed (more or less, obviously) between fragments.
|
16 | 16 |
|
17 | 17 | - Using `disc_only_copies` most of the time is spent in two operations:
|
18 | 18 | - Decide which fragment holds which record
|
19 |
| - - Retrieve the record from corresponding dets table (Mnesia backend) |
| 19 | + - Retrieve the record from the corresponding dets table (Mnesia backend) |
20 | 20 |
|
21 | 21 | - `DCD` and `DCL` files represent `disc_copies` tables. The `DCD` is an image of the contents from the latest time the table was "dumped", while the `DCL` contains a log of the side-effects made to that table since it was dumped. A dump creates a new `DCD` and removes the `DCL`.
|
22 | 22 |
|
23 |
| -- `DAT` files are `DETS:es` which contain `disc_only_copies` tables. |
| 23 | +- `DAT` files are `DETS: es` which contain `disc_only_copies` tables. |
24 | 24 |
|
25 | 25 | - `SCHEMA.DAT` is a special DETS that contains the schema for that Mnesia instance.
|
26 | 26 |
|
|
29 | 29 | - Applies argument `Fun` to all records in the table.
|
30 | 30 | - `Fun` is a function that takes a record of the old type and returns a transformed record of the new type.
|
31 | 31 | - Argument `Fun` can also be the atom ignore, which indicates that only the metadata about the table is updated.
|
32 |
| -- Use of ignore is not recommended, but included as a possibility for the user do to an own transformation. |
| 32 | +- Use of ignore is not recommended but included as a possibility for the user do to their own transformation. |
33 | 33 |
|
34 | 34 | - `NewAttributeList` and `NewRecordName` specify the attributes and the new record type of the converted table.
|
35 | 35 |
|
36 | 36 | - Table name always remains unchanged. If `record_name` is changed, only the Mnesia functions that use table identifiers work, for example, `mnesia:write/3` works, but not `mnesia:write/1`.
|
37 | 37 |
|
38 |
| -- A good solution could be to have more fragments and less records per fragment but trying at the same time to find the middle ground and not lose the advantages of some hard disk performance boosts like buffers and caches. |
| 38 | +- A good solution could be to have more fragments and fewer records per fragment but trying at the same time to find the middle ground and not lose the advantages of some hard disk performance boosts like buffers and caches. |
39 | 39 |
|
40 |
| -- Very often start with a few `ETS` tables when prototyping (or even on early versions of features in production), then start finding places I need data serialized and on disk, then realize I need multiple indexes, etc. and wind up moving a lot of the data management stuff that was initially in ETS into Mnesia anyway. |
| 40 | +- Very often start with a few `ETS` tables when prototyping (or even on early versions of features in production), then start finding places I need data serialized and on disk, then realize I need multiple indexes, etc., and wind up moving a lot of the data management stuff that was initially in ETS into Mnesia anyway. |
41 | 41 |
|
42 | 42 | - If abstracted away the concept of data access properly it is not an issue to change the implementation of this part of your system either way.
|
43 | 43 |
|
|
0 commit comments