2010年3月15日月曜日

SQLクエリ

以前のエントリで、データをプロパティに分解して格納する方法、検索方法がどのように変わるか検討してみた。

通常
<Person>テーブル

ID Name Age Address Sex

  1. Select * From Person Where Age >= 20 And Age <= 29 And Sex='男'  

20代男性を検索

分割
<Person>テーブル


IDPropertyNameValue
  1. Select * From Person Where ID in  
  2. (Select Id From Person Where PropertyName = 'Age' And Value >= 20 And Value <= 29  
  3. Intersect  
  4. Select Id From Person Where PropertyName = 'Sex' And Value = '男')  

AndはIntersectに、ORはUnionに変換すれば良さそう。でもパフォーマンス大丈夫か?

0 件のコメント: