diff options
author | Dan Gudmundsson <[email protected]> | 2015-09-10 10:09:28 +0200 |
---|---|---|
committer | Dan Gudmundsson <[email protected]> | 2015-09-10 10:09:28 +0200 |
commit | 027726da70f31541bd3c4813bf464489a808ae91 (patch) | |
tree | 22b47c65f19c1e2cd5bf872f50a63ef9c72690a4 /lib/mnesia/src | |
parent | bfdc9f97f1738d072d09b98a8980b0b59639db0b (diff) | |
download | otp-027726da70f31541bd3c4813bf464489a808ae91.tar.gz otp-027726da70f31541bd3c4813bf464489a808ae91.tar.bz2 otp-027726da70f31541bd3c4813bf464489a808ae91.zip |
mnesia: Improve index updates
There is no need to update the index table if a record is updated in non
indexed field. This removes one timing glitch where dirty_index_read would
return an empty list for records that where updated.
There is still an issue with dirty_index_read when updates are made to
the index field, it have been reduced but the real table updates are made
after the index table references have been added.
Originally reported by Nick Marino in erl-questions mailing list, thanks.
Diffstat (limited to 'lib/mnesia/src')
-rw-r--r-- | lib/mnesia/src/mnesia_index.erl | 27 |
1 files changed, 17 insertions, 10 deletions
diff --git a/lib/mnesia/src/mnesia_index.erl b/lib/mnesia/src/mnesia_index.erl index 81ed5a8f1a..0c882c0df6 100644 --- a/lib/mnesia/src/mnesia_index.erl +++ b/lib/mnesia/src/mnesia_index.erl @@ -70,17 +70,24 @@ add_index(Index, Tab, Key, Obj, Old) -> add_index2([{Pos, Ixt} |Tail], bag, Tab, K, Obj, OldRecs) -> db_put(Ixt, {element(Pos, Obj), K}), add_index2(Tail, bag, Tab, K, Obj, OldRecs); -add_index2([{Pos, Ixt} |Tail], Type, Tab, K, Obj, OldRecs) -> +add_index2([{Pos, Ixt} |Tail], Type, Tab, K, Obj, OldRecs0) -> %% Remove old tuples in index if Tab is updated - case OldRecs of - undefined -> - Old = mnesia_lib:db_get(Tab, K), - del_ixes(Ixt, Old, Pos, K); - Old -> - del_ixes(Ixt, Old, Pos, K) - end, - db_put(Ixt, {element(Pos, Obj), K}), - add_index2(Tail, Type, Tab, K, Obj, OldRecs); + OldRecs1 = case OldRecs0 of + undefined -> mnesia_lib:db_get(Tab, K); + _ -> OldRecs0 + end, + IdxVal = element(Pos, Obj), + case [Old || Old <- OldRecs1, element(Pos, Old) =/= IdxVal] of + [] when OldRecs1 =:= [] -> %% Write + db_put(Ixt, {element(Pos, Obj), K}), + add_index2(Tail, Type, Tab, K, Obj, OldRecs0); + [] -> %% when OldRecs1 =/= [] Update without modifying index field + add_index2(Tail, Type, Tab, K, Obj, OldRecs0); + OldRecs -> %% Update + db_put(Ixt, {element(Pos, Obj), K}), + del_ixes(Ixt, OldRecs, Pos, K), + add_index2(Tail, Type, Tab, K, Obj, OldRecs0) + end; add_index2([], _, _Tab, _K, _Obj, _) -> ok. delete_index(Index, Tab, K) -> |