Have an impact on changes in copy/change/return index?

Hello

I use the latest version of Berkeley DB XML (2.4.16).
I use it to store relevant xml of .docx files archives... you can consider them as models in a document-generation application.

The transformation of copy/change/return is used in several places.
I also added the clues which can improve the queries that I am trying to make.

I am interested in finding if index impact when using the transformations of copy/modify/back (it does not seem they help on the tests I've done).

Here is the XQuery script that I use (I also wrote an xpath evaluation function that deals with simple XPath expressions that may contain attributes or the index... but it doesn't have an impact on the overall execution time):
declare variable $productView as node() external;
declare variable $templateName as xs:string external;
declare variable $expressionValues as node() external;
declare variable $docxMetadata as node() := doc('dbxml:/docxTemplates/templates.dbxml/metadata.xml')/templates;
declare variable $customIdentifier as xs:string := fn:data($docxMetadata/template[name = $templateName]/dsStoreItemId) cast as xs:string;

declare function local:getCustomXmlBlocksNode($template as xs:string) 
{
     doc(fn:concat('dbxml:/docxTemplates/templates.dbxml/', $template, '_blocks.xml'))/*
};

declare function local:if-absent( $arg as item()* ,
    $value as item()* )  as item()* {
       
    if (exists($arg))
    then $arg
    else $value
};
 
declare function local:replace-multi($arg as xs:string?, $changeFrom as xs:string*, $changeTo as xs:string*) as xs:string? 
{
     if (count($changeFrom)>0)
     then local:replace-multi
     (
          replace($arg, $changeFrom[1], local:if-absent($changeTo[1],'')), 
          $changeFrom[position() > 1], 
          $changeTo[position() > 1]
     )
        else $arg
};

declare function local:copy-attributes($copyTo as element(), $copyFrom as element())  as element() 
{
     element { node-name($copyTo)}
                { $copyTo/@*[not(node-name(.) = $copyFrom/@*/node-name(.))],
              $copyFrom/@*,
              $copyTo/node() }
 };
 
declare function local:add-attributes 
  ( $elements as element()* ,
    $attrNames as xs:QName* ,
    $attrValues as xs:anyAtomicType* )  as element()? {
       
   for $element in $elements
   return element { node-name($element)}
                  { for $attrName at $seq in $attrNames
                    return if ($element/@*[node-name(.) = $attrName])
                           then ()
                           else attribute {$attrName}
                                          {$attrValues[$seq]},
                    $element/@*,
                    $element/node() }
};

declare function local:getEvaluation($expr as xs:string) as xs:string
 {
      fn:string($expressionValues/expressions/expression[name eq $expr]/value)
 };

declare function local:renderSelectionParts($selPartName as xs:string*) as element()*
{
     for $name in $selPartName
     return local:renderDocumentPart($name)
};

declare function local:evalPath($path as xs:string, $xml as node()*) as node()*
{
   local:evalPathImpl(tokenize($path, "/"), $xml)
};

declare function local:evalPathImpl($steps as xs:string*, $xml as node()*) as node()*
{
   if(empty($steps)) then $xml
   else if($steps[1] = "") then local:evalPathImpl(subsequence($steps, 2), $xml/root())
   else if(starts-with($steps[1], "@")) then local:evalPathImpl(subsequence($steps, 2), $xml/@*[name() = substring($steps[1], 2)])
   else if(ends-with($steps[1], "]")) then local:evalPathImpl(subsequence($steps, 2), $xml/*[name() = substring-before($steps[1],  "[")][fn:string(position()) = substring-before(substring-after($steps[1], "["), "]" )])
   else local:evalPathImpl(subsequence($steps, 2), $xml/*[name() = $steps[1]])
};

declare function local:renderRepeater($docPartName as xs:string, $blockNode as node(), $content as node(), $indexNames as xs:string*, $indexValues as xs:string*) as node()*
{
     let $count := fn:count(local:evalPath(local:replace-multi(fn:string($blockNode/iw:ProductViewXPath), $indexNames, $indexValues), $productView))
     for $index in 1 to $count
          return local:renderRepeaterI($docPartName, $blockNode/iw:CCId, $content, ($indexNames, $blockNode/iw:KIdx/text()), ($indexValues, fn:string($index)))
};

declare function local:renderRepeaterI($docPartName as xs:string, $parentCCId as xs:string, $content as node(), $indexNames as xs:string*, $indexValues as xs:string*) as node()*
{
     copy $c := $content
     modify (
          for $ccBlock in local:getCustomXmlBlocksNode($docPartName)/iw:Block[fn:string(iw:ParentContentControlId) eq $parentCCId]
          let $cc := $c//w:sdt[w:sdtPr/w:id/@w:val eq $ccBlock/iw:CCId]
          return
          (
               if($ccBlock/iw:Type eq 'CalculatedControl') then 
                    insert node local:getDataBindingNode(local:replace-multi(fn:string($ccBlock/iw:ProductViewXPath), $indexNames, $indexValues)) into $cc/w:sdtPr
               else if($ccBlock/iw:Type eq 'RepeaterDocPart') then
                    replace node $cc/w:sdtContent with element w:sdtContent { local:renderRepeater($docPartName, $ccBlock, $cc/w:sdtContent, $indexNames, $indexValues) }
               else if($ccBlock/iw:Type eq 'RepeaterTable') then
                    replace node $cc/w:sdtContent/w:tbl/w:tr[last()] with local:renderRepeater($docPartName, $ccBlock, element content {$cc/w:sdtContent/w:tbl/w:tr[last()]}, $indexNames, $indexValues )
               else ()               
          )
     )
     return $c/*
};

declare function local:getDataBindingNode($xpath as xs:string) as node()
{
     local:add-attributes( element w:dataBinding{}, 
          ( xs:QName('w:prefixMappings'), xs:QName('w:xpath'), xs:QName('w:storeItemID') ), 
          ( "xmlns:iwpvp='http://interwoven.com/WordML07/ProductViewPlaceholders'", $xpath, $customIdentifier ) 
     )
};

declare function local:renderDocumentPart($docPartName as xs:string) 
{
     copy $c := doc(fn:concat('dbxml:/docxTemplates/templates.dbxml/', $docPartName, '.xml'))/w:document/w:body
     modify (
          for $sectPr in $c/w:sectPr
          return delete nodes $sectPr,
          for $ccBlock in local:getCustomXmlBlocksNode($docPartName)/iw:Block[fn:string-length(iw:ParentContentControlId)=0]
          let $cc := $c//w:sdt[w:sdtPr/w:id/@w:val eq $ccBlock/iw:CCId]
          return
          (
               if($ccBlock/iw:Type eq 'Expression') then 
                    replace node $cc/w:sdtContent/w:p with local:copy-attributes( element w:p {element w:r { element w:t { local:getEvaluation($ccBlock/iw:BindValue) } } }, $cc/w:sdtContent/w:p )
               else if($ccBlock/iw:Type eq 'Switch') then
                    replace node $cc/w:sdtContent/* with local:renderDocumentPart(fn:string($ccBlock/iw:Items/iw:Item[local:getEvaluation(fn:string(iw:Info)) eq local:getEvaluation(fn:string($ccBlock/iw:BindValue))]/iw:DocPart))
               else if($ccBlock/iw:Type eq 'Selection') then
                    replace node $cc/w:sdtContent/* with local:renderSelectionParts(fn:string($ccBlock/iw:Items/iw:Item[iw:Selected eq 'True']/iw:DocPart))
               else if($ccBlock/iw:Type eq 'RepeaterDocPart') then
                    replace node $cc/w:sdtContent with element w:sdtContent { local:renderRepeater($docPartName, $ccBlock, $cc/w:sdtContent, (" "), ("")) }
               else if($ccBlock/iw:Type eq 'RepeaterTable') then 
               (
                    let $tr := $cc/w:sdtContent/w:tbl/w:tr[last()]
                    return replace node $tr with local:renderRepeater($docPartName, $ccBlock, element content {$tr}, (" "), (""))
               )
               else if($ccBlock/iw:Type eq 'DocumentPart') then
                    replace node $cc/w:sdtContent/* with local:renderDocumentPart($ccBlock/iw:BindValue cast as xs:string)
               else ()               
          )
     ) 
     return $c/*
};

declare function local:renderDocument() 
{
     copy $c := doc(fn:concat('dbxml:/docxTemplates/templates.dbxml/', $templateName, '.xml'))/w:document
     modify 
     (
          for $ccBlock in local:getCustomXmlBlocksNode($templateName)/iw:Block[fn:string-length(iw:ParentContentControlId)=0]
          let $cc := $c//w:sdt[w:sdtPr/w:id/@w:val eq $ccBlock/iw:CCId]
          return
          (
               if($ccBlock/iw:Type eq 'Expression') then 
                    replace node $cc/w:sdtContent/w:p with local:copy-attributes( element w:p {element w:r { element w:t { local:getEvaluation($ccBlock/iw:BindValue) } } }, $cc/w:sdtContent/w:p )
               else if($ccBlock/iw:Type eq 'Switch') then
                    replace node $cc/w:sdtContent/* with local:renderDocumentPart(fn:string($ccBlock/iw:Items/iw:Item[local:getEvaluation(fn:string(iw:Info)) eq local:getEvaluation(fn:string($ccBlock/iw:BindValue))]/iw:DocPart))
               else if($ccBlock/iw:Type eq 'Selection') then
                    replace node $cc/w:sdtContent/* with local:renderSelectionParts(fn:string($ccBlock/iw:Items/iw:Item[iw:Selected eq 'True']/iw:DocPart))
               else if($ccBlock/iw:Type eq 'RepeaterDocPart') then
                    replace node $cc/w:sdtContent with element w:sdtContent { local:renderRepeater($templateName, $ccBlock, $cc/w:sdtContent, (" "), ("")) }
               else if($ccBlock/iw:Type eq 'RepeaterTable') then 
               (
                    let $tr := $cc/w:sdtContent/w:tbl/w:tr[last()]
                    return replace node $tr with local:renderRepeater($templateName, $ccBlock, element content {$tr}, (" "), (""))
               )
               else if($ccBlock/iw:Type eq 'DocumentPart') then
                    replace node $cc/w:sdtContent/* with local:renderDocumentPart($ccBlock/iw:BindValue cast as xs:string)
               else ()               
          )
     ) 
     return $c
};

element mainDocumentContent 
{
     copy $c := local:renderDocument()
     modify 
     (
          for $cc in $c//w:sdt
          where fn:starts-with($cc/w:sdtPr/w:tag/@w:val, 'iw')
          return delete nodes $cc/w:sdtPr/w:placeholder/*,
          for $pictureCC in $c//w:sdt
          where $pictureCC/w:sdtPr/w:tag/@w:val eq 'iwPictureBlock'
          return delete nodes $pictureCC/w:sdtContent//a:blip/@r:embed,
          for $simpleCC in $c//w:sdt
          where fn:exists( fn:index-of( ('iwValueBlock', 'iwDateBlock', 'iwPictureBlock'), $simpleCC/w:sdtPr/w:tag/@w:val ) )
          return replace value of node $simpleCC/w:sdtPr/w:dataBinding/@w:storeItemID with $customIdentifier,
          let $sdtNodes := $c//w:sdt
          for $i in 1 to fn:count($sdtNodes)
          return replace value of node $sdtNodes[$i]/w:sdtPr/w:id/@w:val with $i
     ) 
     return $c
}, 
element customXmlPvpUri 
{ 
     fn:string($docxMetadata/template[name = $templateName]/customXmlPvpUri) 
}
,
element templatePath
{
     fn:string($docxMetadata/template[name = $templateName]/path) 
}
Published by: donde on November 3, 2008 07:59

Hello

Index will not help the copied data. The indexes are limited to a particular container. Queries on this container will search for the appropriate indexes to optimize the query expression. Copied content is placed in a temporary storage that actually has a lot as a container, but is created without index so that queries that operate on this temporary copied content can be optimized using indexes.

It's an interesting idea to think about the indexing of content, but there are all kinds of questions, I can think of that might occur. In any case, it's something to think about.

If there is any way for you to cache and reuse the partially processed templates in a real (indexed) container'd win you indexes a bit more. Such a container could be in memory, so it serves as a pure cache. Should still transactions if you have concurrent access but it would disappear when the application is restarted. Just a thought.

Kind regards
George

Tags: Database

Similar Questions

Maybe you are looking for

  • To update iPhone 5 c 6 I have a question...

    OK, so I am now eligible to proceed my iPhone 5 c to last 6, but I had just a quick question before I go out in reality to swap my iPhone current 5 c for a new... I have a few apps installed on my current iPhone 5 c which cannot be updated because it

  • Qosmio X 770-BSODS and Crash Dump driver failed to load

    Hello I have a Qosmio X 770 and his blue screening occasioanly but I can't find out why as the crash dump driver fails to load at startup. I gave google and tried to recreate the page, Delete file, it restart, rebuild again, affecting also devote dum

  • my macbook gives me an electric shock while I load it

    my macbook gives me an electric shock while I load it even when I use the plug 3 charger to Earth.

  • Satellite L670 - update driver for ATI 5650

    Hiya, After a few months I just around the audit, if there is no driver update for my model: Satellite L670 with ATI 5650. Apperently Toshiba must approve the pilots to become available to us. Because ATI already has new drivers available, but we are

  • Find a power supply for my HP PC

    I have the HP m9340f with a 350W power supply, I'm interested to upgrade to a 500w power supply, namely this one http://www.newegg.com/Product/Product.aspx?Item=N82E16817438012. No one knows if this computer can process the 500w PSU.