Update Query optimization ...

0 views
Skip to first unread message

Ashok Hariharan

unread,
Jan 24, 2013, 7:04:24 AM1/24/13
to bungen...@googlegroups.com

I was suggesting, instead of the following (which puts update within a loop)   

for $signatory in collection(cmn:get-lex-db())/bu:ontology[@for='document']/bu:signatories/bu:signatory
        let $user := collection(cmn:get-lex-db())/bu:ontology/bu:user[bu:userId eq $signatory/bu:userId][1]
        let $user-uri := $user/@uri
        let $user-name := concat($user/bu:lastName,", ",$user/bu:firstName)
        return 
            (: safe-guarding multiple <bu:person/> nodes since 2012! :)
            if (empty($signatory/bu:person)) then
                update insert <bu:person isA="TLCPerson" href="{$user-uri}" showAs="{$user-name}" /> into $signatory
            else
                ()
                
                
something like the following - which puts the data collation within the loop and the update statement is just a single one : 

update insert
for $signatory in collection(cmn:get-lex-db())/bu:ontology[@for='document']/bu:signatories/bu:signatory 
       let $user := collection(cmn:get-lex-db())/bu:ontology/bu:user[bu:userId eq $signatory/bu:userId][1]
       let $user-uri := $user/@uri
       let $user-name := concat($user/bu:lastName,", ",$user/bu:firstName)
       where empty($signatory/bu:person)
    return <bu:person isA="TLCPerson" href="{$user-uri}" showAs="{$user-name}" /> 
into $signatory  
                 
Reply all
Reply to author
Forward
0 new messages