8.2 xquery slow eval - is there an index fn?
Added by Anonymous almost 20 years ago
Legacy ID: #2952227 Legacy Poster: Scott Ellsworth (scottellsworth)
Hi, all. I just started experimenting with xquery, and have run into surprising performance characteristics. Were this a relational database, I would want to slap an index on a name column as a first step, but I am a bit out of my depth here. Saxon 8.2, JDK 1.5.0. I have examined the trace, but since it does not say how much time was spent in each element of the trace, it is not clear to me where my time is going, and how to fix it. I am processing a 3k line file listing dependencies for our projects to get the dependencies of that project and all subprojects. This should take seconds, IMO, and takes minutes. A project's entry looks like: <project name="persist" directory="metagraph/persistence/persist" cvs.packages="metagraph/persistence/persist"> <depend type="library" name="log4j"/> <depend type="project" name="metagraph_utility_resource"/> </project> I would want persist to list log4j and metagraph_utility_resource, plus all of the dependencies of metagraph_utility_resource. Projects have up to a few dozen such dependencies, and may go down as much as four or five steps. Since I am not very familiar with xq, it may well be that I have a poorly written xquery. This would not surprise me at all. The xquery: declare function local:unique-nodes-by-name($list as node()) as node() { for $n in fn:distinct-values($list/@name) order by $n return let $all := $list[@name=$n] return $all[1] }; declare function local:deps-of-project($projects as node(), $depend_name as xs:string) as node() { ( for $d in $projects[@name = $depend_name]/depend return ( $d, local:deps-of-project($projects, xs:string($d/@name)) ) ) }; <Projects> { let $projects := doc("pr2.xml")/project-list/project for $p in $projects let $dep-element := ( for $d in $p/depend return ( $d, local:deps-of-project($projects, $d/@name) ) ) order by $p/@name return ( element {"project"} { ( $p/@*, local:unique-nodes-by-name($dep-element) ) } ) } </Projects> Here is a 200 line excerpt of the file: <?xml version="1.0"?> <project-list> <project name="build" cvs.packages="build" build="false" javadoc="false"/> <project name="libraries" cvs.packages="libraries" build="false" javadoc="false" /> <project name="template" cvs.packages="template" build="false" javadoc="false" /> <project name="documents" cvs.packages="documents" build="false" javadoc="false" /> <project name="websupport" cvs.packages="websupport" build="false" javadoc="false"/> <!-- metagraph utility --> <project name="metagraph_utility_resource" directory="metagraph/utility/resource" cvs.packages="metagraph/utility/resource"> </project> <project name="metagraph_utility_thread" directory="metagraph/utility/thread" cvs.packages="metagraph/utility/thread"> </project> <project name="metagraph_utility_debug" directory="metagraph/utility/debug" cvs.packages="metagraph/utility/debug"> <depend type="library" name="log4j"/> </project> <project name="metagraph_utility_comb" directory="build/temp-build/metagraph_utility_comb" javadoc="false" jar.bundle="true"> <depend type="project" name="metagraph_utility_resource"/> <depend type="project" name="metagraph_utility_thread"/> <depend type="project" name="metagraph_utility_debug"/> </project> <!-- metagraph persistence --> <project name="persist" directory="metagraph/persistence/persist" cvs.packages="metagraph/persistence/persist"> <depend type="library" name="log4j"/> <depend type="project" name="metagraph_utility_resource"/> </project> <project name="persist_jdbc" directory="metagraph/persistence/persist_jdbc" cvs.packages="metagraph/persistence/persist_jdbc"> <depend type="library" name="log4j"/> <depend type="library" name="oracle"/> <depend type="project" name="persist"/> <depend type="project" name="metagraph_utility_thread"/> <depend type="project" name="metagraph_utility_resource"/> <depend type="project" name="metagraph_utility_debug"/> </project> <project name="metagraph_persistence_comb" directory="build/temp-build/metagraph_persistence_comb" javadoc="false" jar.bundle="true"> <depend type="project" name="persist"/> <depend type="project" name="persist_jdbc"/> <depend type="project" name="metagraph_utility_thread"/> <depend type="project" name="metagraph_utility_resource"/> <depend type="project" name="metagraph_utility_debug"/> </project> <!-- metagraph nodes --> <project name="node_model" directory="metagraph/persistence/node_model" cvs.packages="metagraph/persistence/node_model"> <depend type="library" name="log4j"/> <depend type="project" name="persist"/> <depend type="project" name="metagraph_utility_resource"/> <intercalate plist-directory="metagraph/persistence/node_template" plist="metagraph.plist" template-directory="metagraph/persistence/node_template" template="typelist.template" relativeoutput="org/metagraph/node/model/"/> <intercalate plist-directory="metagraph/persistence/node_template" plist="metagraph.plist" template-directory="metagraph/persistence/node_template" template="model.template" relativeoutput="org/metagraph/node/model/"/> <intercalate plist-directory="metagraph/persistence/node_template" plist="metagraph.plist" template-directory="metagraph/persistence/node_template" template="modelquery.template" relativeoutput="org/metagraph/node/model/query"/> <depend type="project-data" name="node_template"/> </project> <project name="node_template" directory="metagraph/persistence/node_template" cvs.packages="metagraph/persistence/node_template" build="false" javadoc="false"/> <project name="node_jdbc" directory="metagraph/persistence/node_jdbc" cvs.packages="metagraph/persistence/node_jdbc"> <depend type="library" name="log4j"/> <depend type="project" name="persist"/> <depend type="project" name="metagraph_utility_resource"/> <depend type="project" name="node_model"/> <depend type="project" name="persist_jdbc"/> <intercalate plist-directory="metagraph/persistence/node_template" plist="metagraph.plist" template-directory="metagraph/persistence/node_template" template="jdbc.template" relativeoutput="org/metagraph/node/jdbc/"/> <intercalate plist-directory="metagraph/persistence/node_template" plist="metagraph.plist" template-directory="metagraph/persistence/node_template" template="jdbcquery.template" relativeoutput="org/metagraph/node/jdbc/query"/> <intercalate-data plist-directory="metagraph/persistence/node_template" plist="metagraph.plist" template="mysql.template" relativeoutput="sql-generated/mysql/"/> <depend type="project-data" name="node_template"/> </project> <project name="node_memory" directory="metagraph/persistence/node_memory" cvs.packages="metagraph/persistence/node_memory"> <depend type="library" name="log4j"/> <depend type="project" name="persist"/> <depend type="project" name="metagraph_utility_resource"/> <depend type="project" name="node_model"/> <intercalate plist-directory="metagraph/persistence/node_template" plist="metagraph.plist" template-directory="metagraph/persistence/node_template" template="memory.template" relativeoutput="org/metagraph/node/memory/"/> </project> <project name="node_utility" directory="metagraph/persistence/node_utility" cvs.packages="metagraph/persistence/node_utility"> <depend type="library" name="log4j"/> <depend type="project" name="node_model"/> <depend type="project" name="persist"/> <depend type="project" name="metagraph_utility_resource"/> </project> <project name="node_units" directory="metagraph/persistence/node_units" cvs.packages="metagraph/persistence/node_units"> <depend type="library" name="log4j"/> <depend type="project" name="persist"/> <depend type="project" name="node_model"/> <depend type="project" name="metagraph_utility_resource"/> </project> <project name="cluster" directory="metagraph/persistence/cluster" cvs.packages="metagraph/persistence/cluster"> <depend type="library" name="log4j"/> <depend type="library" name="jdom"/> <depend type="project" name="persist"/> <depend type="project" name="node_model"/> <depend type="project" name="node_utility"/> <depend type="project" name="node_units"/> </project> <project name="cluster_definition" directory="metagraph/persistence/cluster_definition" cvs.packages="metagraph/persistence/cluster_definition"> <depend type="library" name="log4j"/> <depend type="library" name="jdom"/> <depend type="project" name="persist"/> <depend type="project" name="node_model"/> <depend type="project" name="node_utility"/> <depend type="project" name="cluster"/> <intercalate plist="cluster.plist" template="cluster.template" relativeoutput="org/metagraph/cluster/definition/"/> <intercalate plist="cluster.plist" template="NodeClusterFactory.template" relativeoutput="org/metagraph/cluster/definition/"/> <!-- xml file defining clusters --> <intercalate-data plist="cluster.plist" template="xmlcluster.template" relativeoutput="resources/org/metagraph/cluster/definition/"/> <!-- xml cluster model classes --> <intercalate plist="cluster.plist" template="javamodel.template" relativeoutput="org/metagraph/cluster/definition/model/"/> <intercalate plist="cluster.plist" template="ClusterType.template" relativeoutput="org/metagraph/cluster/definition/model/"/> <intercalate plist="cluster.plist" template="javamodelquery.template" relativeoutput="org/metagraph/cluster/definition/model/query/"/> <!-- xml cluster implementation classes --> <intercalate plist="cluster.plist" template="javaxml.template" relativeoutput="org/metagraph/cluster/definition/javaxml/"/> <intercalate plist="cluster.plist" template="javaxmlquery.template" relativeoutput="org/metagraph/cluster/definition/javaxml/query/"/> </project> <project name="metagraph_node_comb" directory="build/temp-build/metagraph_node_comb" javadoc="false" jar.bundle="true"> <depend type="project" name="persist"/> <depend type="project" name="persist_jdbc"/> <depend type="project" name="metagraph_utility_thread"/> <depend type="project" name="metagraph_utility_resource"/> <depend type="project" name="metagraph_utility_debug"/> <depend type="project" name="node_jdbc"/> <depend type="project" name="node_memory"/> <depend type="project" name="node_model"/> <depend type="project" name="node_units"/> <depend type="project" name="node_utility"/> <depend type="project" name="cluster"/> <depend type="project" name="cluster_genetrove"/> <depend type="project" name="cluster_definition"/> </project> <project name="test_comb" directory="build/temp-build/metagraph_node_comb" javadoc="false" jar.bundle="true"> <depend type="project" name="metagraph_node_comb"/> </project> </project-list>
Replies (1)
RE: 8.2 xquery slow eval - is there an index - Added by Anonymous almost 20 years ago
Legacy ID: #2961534 Legacy Poster: Michael Kay (mhkay)
Unfortunately XQuery has no equivalent of XSLT's xsl:key facility, which would solve this performance problem at a stroke. I'm hoping to add such a capability, but it will be a Saxon extension. Michael Kay
Please register to reply