今月、2つの異なる作業で同じ問題が発生しました。
Version 1: User 1 & User 2 are friends
Version 2: Axis 1 & Axis 2 when graphed should have the quadrants colored...
問題は、RDBMSを使用して、この情報を保存および照会するための洗練された方法が見当たらないことです。
2つの明白なアプローチがあります:
アプローチ1:
store the information twice (i.e. two db rows rows per relationship):
u1, u2, true
u2, u1, true
u..n, u..i, true
u..i, u..n, true
have rules to always look for the inverse on updates:
on read, no management needed
on create, create inverse
on delete, delete inverse
on update, update inverse
Advantage: management logic is always the same.
Disadvantage: possibility of race conditions, extra storage (which is admittedly cheap, but feels wrong)
アプローチ2:
store the information once (i.e. one db row per relationship)
u1, u2, true
u..n, u..i, true
have rules to check for corollaries:
on read, if u1, u2 fails, check for u2, u1
on create u1, u2: check for u2, u1, if it doesn't exist, create u1, u2
on delete, no management needed
on update, optionally redo same check as create
Advantage: Only store once
Disadvantage: Management requires different set of cleanup depending on the operation
「f(x、y)を使用するキー」の線に沿った3番目のアプローチがあるかどうか疑問に思います。ここで、f(x、y)はすべてのx、yの組み合わせに対して一意であり、f(x、y)=== f(y、x)」
私の腸は、これらの要件を満たすことができるビット単位の演算のいくつかの組み合わせが必要であると私に言います。2列のようなもの:
key1 = x && y key2 = x + y
数学科でより多くの時間を過ごし、社会学部でより少ない時間を過ごした人々が、これの可能性または不可能性の証拠を見て、迅速に「[You moron、]その簡単に証明された(im)可能です。このリンクを参照してください」(名前の呼び出しはオプション)
他のエレガントなアプローチも大歓迎です。
ありがとう