スケーラブルデータベースサーバ HiRDB Version 8 システム導入・設計ガイド(UNIX(R)用)
ここでは,HiRDB XML Extensionが提供する抽象データ型(XML型)を定義した表の作成方法について説明します。
ここでは,書籍管理表を作成します。書籍管理表の作成条件を次に示します。
CREATE TABLEで書籍管理表を定義します。定義例を次に示します。
CREATE TABLE 書籍管理表 (書籍ID INTEGER, 書籍情報 XML) IN RDAREA01
XML型の列には,特定の部分構造をキーとし,その値をキー値としたインデクスを定義できます。このインデクスを利用すると,XMLEXISTS述語やXMLQUERY関数のXQuery式中に,部分構造インデクスを定義した構造に対する述語を指定した場合,行の絞り込みの処理時間を削減できることがあります。
部分構造インデクスを利用できるXQuery式中の述語を次に示します。
インデクスの使用条件については,「(4) インデクスの使用条件」で説明します。
部分構造インデクスを使用した検索については,マニュアル「HiRDB Version 8 UAP開発ガイド」を参照してください。
XML型の列には,XML型の値に対する全文検索用のn-gramインデクス(IXXML)を定義できます。XML型全文検索用インデクスを定義することで,XMLEXISTS述語のXQuery式中で文字列一致などの全文検索条件を含む述語を記述した場合に,行の絞り込みの処理時間を削減できることがあります。
XML型全文検索の条件となるXQuery式中の述語を次に示します。
インデクスの使用条件については,「(4) インデクスの使用条件」で説明します。
XML型全文検索用インデクスを使用した検索については,マニュアル「HiRDB Version 8 UAP開発ガイド」を参照してください。
表へデータを格納する場合の入力データには,次の二つがあります。入力データの種類によって,データの格納方法が異なります。
データベース作成ユティリティ(pdload)で表にデータを格納する場合の手順を次に示します。
〈手順〉
上記のコマンドとユティリティの詳細及びこれらのコマンドとユティリティの実行結果の確認方法については,マニュアル「HiRDB Version 8 コマンドリファレンス」を参照してください。
INSERT INTO 書籍管理表 VALUES ( 310494321, XML(:bookinfo AS BINARY(102400)))
INSERT INTO 書籍管理表 VALUES ( 310494321, XMLPARSE(DOCUMENT :bookdoc AS BINARY(32000)))
ここでは,(2)で説明した二つのインデクスの使用条件について説明します。
表7-3 部分構造インデクスの使用条件
USING UNIQUE TAGの指定 | XQuery指定箇所 | XQuery中の演算子又は関数 | 部分構造インデクスの使用条件※ |
---|---|---|---|
あり | XMLEXISTS述語 | = | (a)1,2,3 (b)1,2,5,6,7,8,9 |
!=,>,>=,<,<=,<>,eq,ne,gt,ge,lt,le, fn:contains, fn:starts-wtih, fn:ends-with |
(a)1,2,3 (b)1,2,4,6,7,8,9 |
||
XMLQUERY関数 | = | (c)1,2,3 | |
なし | XMLEXISTS述語 | = | (a)1,2,3 (b)1,3,5,6,7,8,9 |
!=,>,>=,<,<=,<> | (a)1,2,3 (b)1,3,4,6,7,8,9 |
||
fn:contains fn:starts-wtih fn:ends-with |
(a)1,2,3 (b)1,3,4,6,7,8,10 |
||
XMLQUERY関数 | = | (c)1,2,3 |
表7-4 XML型全文検索用インデクスの使用条件
XQuery指定箇所 | XQuery中の演算子又は関数 | XML型全文検索用インデクスの使用条件※ |
---|---|---|
XMLEXISTS述語 | = fn:contains fn:starts-wtih fn:ends-with |
(a)1,2,3 (d)1,2,4,5,6,7,8 |
hi-fn:contains | (a)1,2,3 (d)1,3,4,5,6,7,8 |
なお,HiRDBが見積もるアクセスコストによっては,これらのインデクスを使用しないことがあります。インデクスを使用した検索が行われたかどうかについては,アクセスパス表示ユティリティ(pdvwopt)で確認してください。
また,XMLEXISTS述語のXQuery問合せ中に指定した,部分構造インデクス,又はXML型全文検索インデクスを使用できる述語については,最大で255個しかインデクスを用いて評価しません。
部分構造インデクス,及びXML全文検索用インデクスの両方が使用可能なXQuery中の演算子,又は関数を使用して検索する場合,使用されるインデクスは演算子,又は関数によって決まります。異なるインデクスを使用したい場合は,マニュアル「HiRDB Version 8 SQLリファレンス」の「使用インデクスのSQL最適化指定」で使用するインデクスを指定することができます。
表7-5 複数のインデクスが使用可能な演算子又は関数の場合に使用されるインデクス
部分構造インデクス,及びXML型全文検索用インデクスの両方が使用可能なXQuery中の演算子又は関数 | 検索に使用されるインデクス |
---|---|
= | 部分構造インデクス |
fn:contains | XML型全文検索用インデクス |
fn:starts-wtih | 部分構造インデクス |
fn:ends-with | XML型全文検索用インデクス |
部分構造インデクス及びXML型全文検索用インデクス共通の使用条件を次に示します。
なお,次のように定義したインデクスを例文中で使用します。
create index idx1 on t1(c1) key using unique tag from '/root/elm1/@attr1' as varchar(10)
select c2 from t1 where xmlexists('/root/elm1[@attr1 eq "ABC"]' passing by value c1,'DEF' as A)
select c2 from t1 where xmlexists('/root/elm1[./@attr1 eq "ABC"]' passing by value c1)
select c2 from t1 where xmlexists('/root[elm1/@attr1 = "ABC" or elm1/@attr1 = "DEF"]' passing by value c1)
部分構造インデクスの使用条件を次に示します。
なお,1.,2.,4.〜9.では,次のように定義したインデクスを例文中で使用します。
create index idx1 on t1(c1) key using unique tag from '/root/elm1/@attr1' as varchar(10) create index idx4 on t1(c1) key using unique tag from '/root/elm1/elm2 ' as varchar(10)
3.,10.では,次のように定義したインデクスを例文中で使用します。
create index idx2 on t1(c1) key from '/root/elm1/@attr1' as varchar(10) create index idx5 on t1(c1) key from '/root/elm1/elm2' as varchar(10)
select c2 from t1 where xmlexists('/root/elm1[@attr1 eq "ABC"]' passing by value c1)
select c2 from t1 where xmlexists('/root/elm1[@attr1 eq "ABC"]' passing by value c1)
select c2 from t1 where xmlexists('/root/elm1[@attr1 = "ABC"]' passing by value c1)
select c2 from t1 where xmlexists('/root/elm1[@attr1 >= "ABC"]' passing by value c1)
select c2 from t1 where xmlexists('/root/elm1[starts-with(@attr1,"ABC")]' passing by value c1)
select c2 from t1 where xmlexists('/root/elm1[@attr1 = ("ABC","DEF","GHI")]' passing by value c1)
select c2 from t1 where xmlexists('/root/elm1[@attr1 = "ABC"]' passing by value c1)
select c2 from t1 where xmlexists('/root[elm1/@attr1 = "ABC" or elm1/@attr1 = "DEF"]' passing by value c1)
select c2 from t1 where xmlexists('/root/elm1[@attr1 eq $A]' passing by value c1,'ABC' as A)
部分構造パス:: = 〔XML名前空間宣言〕…部分構造パス式 XML名前空間宣言::={declare namespace 接頭辞 = XML名前空間URI; | declare default element namespace XML名前空間URI;} 部分構造パス式:: = 〔/ステップ式…〕/ステップ式 ステップ式:: = {〔{child:: | attribute:: | @ }〕 修飾名 | 文脈項目式} 文脈項目式:: = ピリオド ピリオド::= . 修飾名:: = 〔接頭辞:〕局所名
select c2 from t1 where xmlexists('/root/child::elm1[@attr1 eq "ABC"]' passing by value c1)
select c2 from t1 where xmlexists('/root/child::elm1[child::elm2 eq "ABC"]' passing by value c1)
select c2 from t1 where xmlexists('/root/child::elm1/elm2[ . eq "ABC"]' passing by value c1)
select c2 from t1 where xmlexists('/root/elm1[fn:starts-with(@attr1 ,"ABC")]' passing by value c1)
select c2 from t1 where xmlexists('/root/elm1[fn:starts-with(elm2 ,"ABC")]' passing by value c1)
select c2 from t1 where xmlexists('/root/elm1/@attr1[fn:starts-with( . ,"ABC")]' passing by value c1)
部分構造パス:: = 〔XML名前空間宣言〕…部分構造パス式 XML名前空間宣言::={declare namespace 接頭辞 = XML名前空間URI; | declare default element namespace XML名前空間URI;} 部分構造パス式:: = 〔/ステップ式…〕/ステップ式終端 ステップ式:: = {〔{child:: | attribute:: | @ }〕 修飾名 | 文脈項目式} ステップ式終端:: = {{attribute:: | @ } 修飾名 | 文脈項目式} 文脈項目式:: = ピリオド ピリオド::= . 修飾名:: = 〔接頭辞:〕局所名
select c2 from t1 where xmlexists('/root/elm1[fn:starts-with(@attr1 ,"ABC")]' passing by value c1)
select c2 from t1 where xmlexists('/root/elm1/@attr1[fn:starts-with( . ,"ABC")]' passing by value c1)
XMLQUERY関数のXQueryに関する部分構造インデクスの使用条件を次に示します。
なお,1.及び2.では,次のように定義したインデクスを例文中で使用します。
create index idx1 on t1(c1) key using unique tag from '/root/elm1' as varchar(10)
select xmlserialize(xmlquery('$VAR1/root[elm1 = $VAR1/root[elm2 = "ABC"]/elm1]/elm1' passing by value xmlagg(c1) as VAR1 empty on empty) as varchar(32000)) from t1
XML型全文検索用インデクスの使用条件を次に示します。
create index idx3 using type ixxml on t2(c1) in (LOB1)
部分構造パス:: = 〔XML名前空間宣言〕… 部分構造パス式 XML名前空間宣言:: = {declare default element namespace "http://www.w3.org/XML/1998/namespace"; |declare namespace 接頭辞 = XML名前空間URI;※ |declare default element namespace XML名前空間URI;※} 部分構造パス式:: = 〔{/ | //※}ステップ式 …〕 {/ | //※}{テキストステップ式 | 属性ステップ式終端} ステップ式:: = {〔child::〕 名前テスト | 文脈項目式} テキストステップ式:: = 〔{child::|descendant::}〕テキストテスト /テキストステップ式終端 テキストステップ式終端:: = 文脈項目式 属性ステップ式終端:: = {{attribute:: | @} 名前テスト | 〔{attribute:: | @}〕 属性テスト} 文脈項目式:: = ピリオド ピリオド:: = . 名前テスト:: = {修飾名|*※|接頭辞:*※|*:局所名※} 修飾名:: = 〔接頭辞:〕局所名
select c2 from t2 where xmlexists('/root/child::elm1[fn:contains(@attr1,"ABC")]' passing by value c1)
select c2 from t2 where xmlexists('/root/child::elm1[fn:contains(@attribute(),"ABC")]' passing by value c1)
select c2 from t2 where xmlexists('/root/child::elm1[fn:contains(attribute(),"ABC")]' passing by value c1)
select c2 from t2 where xmlexists('/root/child::elm1/text()[fn:contains( . ,"ABC")]' passing by value c1)
部分構造パス:: = 〔XML名前空間宣言〕… 部分構造パス式 XML名前空間宣言:: = {declare namespace 接頭辞 = XML名前空間URI; |declare default element namespace XML名前空間URI;} 部分構造パス式:: = 〔{/ | //}ステップ式 …〕 {/ | //}{テキストステップ式 | 属性ステップ式終端} ステップ式:: = {〔child::〕 名前テスト | 文脈項目式} テキストステップ式:: = 〔{child::|descendant::}〕テキストテスト 〔/テキストステップ式終端〕 テキストステップ式終端:: = 文脈項目式 属性ステップ式終端:: = {{attribute:: | @} 名前テスト | 〔{attribute:: | @}〕 属性テスト} 文脈項目式:: = ピリオド ピリオド:: = . 名前テスト:: = {修飾名 | * | 接頭辞:* | *:局所名} 修飾名:: = 〔接頭辞:〕局所名
select c2 from t2 where xmlexists('/root/elm1[hi-fn:contains(text(),"""ABC AND DEF""")]' passing by value c1)
select c2 from t2 where xmlexists('/root/elm1[hi-fn:contains(descendant::text(),"""ABC AND DEF""")]' passing by value c1)
select c2 from t2 where xmlexists('/root/elm1[hi-fn:contains(text()/.,"""ABC AND DEF""")]' passing by value c1)
select c2 from t2 where xmlexists('/root/elm1[hi-fn:contains(descendant::text()/.,"""ABC AND DEF""")]' passing by value c1)
select c2 from t2 where xmlexists('/root/elm1/text()[hi-fn:contains( . ,"""ABC AND DEF""")]' passing by value c1)
select c2 from t2 where xmlexists('/root/elm1/ descendant::text()[hi-fn:contains( . ,"""ABC AND DEF""")]' passing by value c1)
select c2 from t2 where xmlexists('/root/elm1[hi-fn:contains(@attr1,"""ABC AND DEF" "")]' passing by value c1)
select c2 from t2 where xmlexists('/root/elm1[hi-fn:contains(@attribute(),"""ABC AND DEF""")]' passing by value c1)
select c2 from t2 where xmlexists('/root/elm1[hi-fn:contains(attribute(),"""ABC AND DEF")]' passing by value c1)
select c2 from t2 where xmlexists('/root/elm1[fn:contains(@attr1,"ABCDEF")]' passing by value c1)
select c2 from t2 where xmlexists('/root/child::elm1[fn:contains(@attr1,"ABC")]' passing by value c1)
select c2 from t2 where xmlexists('/root/elm1[fn:contains(@attr1,"ABCDEF")]' passing by value c1)
select c2 from t2 where xmlexists('/root//elm1[fn:contains(@attr1,"ABCDEF")]' passing by value c1)
create index idx6 using type ixxml on t2(c1) in (LOB1) PLUGIN'SAMECASE= ON,SAMEWIDE=ON,SAMEY=ON,SAMED=ON,DELcode=ON'
次に示す1.〜4.の場合は,部分構造インデクス又はXML型全文検索用インデクスを使用しません。
なお,1.,3.では,次のように定義したインデクスを例文中で使用します。
create index idx1 on t1(c1) key using unique tag from '/root/elm1/@attr1' as archar(10)
2.,4.では次のように定義したインデクスを例文中で使用します。
create index idx3 using type ixxml on t2(c1) in (LOB1)
select c2 from t1 where xmlexists('/root[elm1/@attr1 = "ABC"] or /root[elm1/@attr1 = "DEF"]' passing by value c1)
select c2 from t1 where xmlexists('/root[elm1/@attr1 = "ABC" or elm1/@attr1 = "DEF"]' passing by value c1)
select c2 from t2 where xmlexists('/root[fn:contains(elm1/text(),"ABC")]' passing by value c1)
select c2 from t2 where xmlexists('/root/elm1/text()[fn:contains( . ,"ABC")]' passing by value c1)
select c2 from t1 where xmlexists('$A/root/elm1[@attr1 eq "ABC"]' passing by value c1,c1 as A)
select c2 from t1 where xmlexists('/root/elm1[@attr1 eq "ABC"]' passing by value c1,c1 as A)
select c2 from t2 where xmlexists('/root/elm1[hi-fn:contains(text(),"""01ABC""")]' passing by value c1) or xmlexists('/root/elm1[hi-fn:contains(text(),"""02ABC""")]' passing by value c1) ・・・(省略)・・・ or xmlexists('/root/elm1[hi-fn:contains(text(),"""30ABC""")]' passing by value c1)
select c2 from t2 with index(idx3,idx3) where xmlexists('/root/elm1[hi-fn:contains(text(),"""01ABC""")]' passing by value c1) or xmlexists('/root/elm1[hi-fn:contains(text(),"""02ABC""")]' passing by value c1) ・・・(省略)・・・ or xmlexists('/root/elm1[hi-fn:contains(text(),"""30ABC""")]' passing by value c1)
All Rights Reserved. Copyright (C) 2006, 2016, Hitachi, Ltd.