ビューに基づくテキスト索引は、ストアード・プロシージャーや表値関数を使用して作成できますが、スカラー関数 (たとえば CONTAINS) を含めることはできません。
もう 1 つの大きな欠点として、ビュー上でトリガーを作成できないため、 基礎を成す基本表での変更を認識できないという点があります。
したがって、インクリメンタル更新の場合、 ユーザーは、テキスト索引とデータベースを同期化するために、 追加、更新または削除を行った文書を知っている必要があります。 このためには、すべての変更をログ表に追加する必要があります。 この処理を以下のサンプルで示します。
db2 "create table sample (key INTEGER not null PRIMARY KEY, name VARCHAR(50) not null, comment VARCHAR(90))"
db2 "insert into sample values(1,'Claus','works in room 301')" db2 "insert into sample values(2,'Manja','is in the same office as Juergen')" db2 "insert into sample values(2,'Juergen','has the longest way to Raiko')" db2 "insert into sample values(3,'Raiko','is sitting in the office besides Claus ')"
db2 "create view sampleview as select key, comment from sample"
db2text "create index indexview for text on hde.sampleview(comment) cache table (comment) maximum cache size 1 key columns for index on view (key)" db2text "update index indexview for text" db2text "activate cache for index indexview for text"
注 |
---|
ビューに基づくテキスト索引を作成するには、キャッシュ表を指定する必要があります。 正しいログ表を作成するには、ビュー上の索引に関するキー列を指定しなければなりません。 この方法で索引を作成する場合、表値関数を含む索引も使用できます。 分散データベース環境でストアード・プロシージャー検索を使用する場合は、単一ノード上の管理表の表スペースを明示的に指定し、 明示的にこのノードに接続しなければなりません。 適切なノードと接続するためには、DB2NODE 環境変数を使用します。 |
db2 "insert into sample values(4,'Bernhard','is working in the same floor as Manja, but not as Claus')" db2 "insert into sample values(5,'Guenter','shares the office with Raiko')"
db2 "select INDSCHEMA,INDNAME,LOGVIEWSCHEMA,LOGVIEWNAME from db2ext.textindexes"以下にログ表のレイアウトを示します。
sqltype sqllen sqlname.data sqlname.length -------------------- ------ ----------------------- -------------- 496 INTEGER 4 OPERATION 9 392 TIMESTAMP 26 TIME 4 497 INTEGER 4 PK01 4ログ表に項目を追加するには、 以下のコマンドを使用します。
db2 "insert into sample values(0,CURRENT TIMESTAMP,4)" db2 "insert into sample values(0,CURRENT TIMESTAMP,5)"最初の値は、 操作 (0= 挿入、1 = 更新、2 = 削除) を示します。 2 番目の値は、常に CURRENT TIMESTAMP で、最後の値は挿入されたキーです。
db2text "update index indexview for text"
これで、ストアード・プロシージャーを使用して新しい値を検索できるようになりました。