From: Raul D. <r.d...@dm...> - 2007-08-15 16:42:13
|
Hello, I'm experimenting a weird behaviour between two XQueries that do the saem thing. They get a collection, iterate over the nodes, get the parent's parent node, and create a result. In the first one, I'm using the xpath $pricing/input/requests/request[@type='value' and @name='mtm']/shift inline in the construction of the result, in the second one I'm defining a variable with it. Both get executed inside the loop. The first one seems to get the result for this XPath from the retrieved collection, whereas the second one seems to be querying the database again (the logs show it cannot find an index for it once for each iteration in the loop) The first one takes 3687 ms to execute, the second one 243917 ms. Here is the code and the traces: xquery version "1.0"; declare namespace tools="java:test.XQuery"; let $resultdoc := document{ <results> { let $results := collection("/db/results/")/pricing/results/result[@type='value' and @name='mtm'] for $result in $results let $pricing :=$result/ancestor::node()/ancestor::node() return( <result>{concat($pricing/@id,",",$pricing/input/user,",",1,",",0,",",",",tools:normalise(tools:round($result,9),$pricing/input/requests/request[@type='value' and @name='mtm']/shift))}</result> ) } </results> } for $line in $resultdoc/results/result return $line/text() 2007-08-15 17:31:04,822 DEBUG [main] xquery.XQuery (XQuery.java:156) - Compilation took 156 2007-08-15 17:31:04,838 DEBUG [main] xmldb.LocalXPathQueryService (LocalXPathQueryService.java:226) - compilation took 438 2007-08-15 17:31:05,369 TRACE [main] xquery.GeneralComparison (GeneralComparison.java:407) - found an index of type: xs:string 2007-08-15 17:31:05,369 TRACE [main] xquery.GeneralComparison (GeneralComparison.java:452) - Checking if range index can be used for key: value 2007-08-15 17:31:05,384 TRACE [main] xquery.GeneralComparison (GeneralComparison.java:457) - Using range index for key: value 2007-08-15 17:31:05,525 TRACE [main] xquery.GeneralComparison (GeneralComparison.java:407) - found an index of type: xs:string 2007-08-15 17:31:05,525 TRACE [main] xquery.GeneralComparison (GeneralComparison.java:452) - Checking if range index can be used for key: mtm 2007-08-15 17:31:05,525 TRACE [main] xquery.GeneralComparison (GeneralComparison.java:457) - Using range index for key: mtm 2007-08-15 17:31:08,259 DEBUG [main] storage.NativeBroker (NativeBroker.java:660) - Creating collection '/db/system/temp'... 2007-08-15 17:31:08,291 DEBUG [main] collections.CollectionConfigurationManager (CollectionConfigurationManager.java:165) - Reading collection configuration for '/db/system/temp' from index configuration 2007-08-15 17:31:08,447 DEBUG [main] storage.CacheManager (CacheManager.java:180) - Growing cache elements.dbx (a org.exist.storage.cache.LRUCache) from 64 to 80 2007-08-15 17:31:08,447 DEBUG [main] xquery.XQueryContext (XQueryContext.java:1634) - Stored: 3462: /db/system/temp/352e01d0f21fe847a2aa460ebaff055a.xml 2007-08-15 17:31:08,509 DEBUG [main] util.HTTPUtils (HTTPUtils.java:61) - mostRecentDocumentTime: 1187195468259 2007-08-15 17:31:08,525 DEBUG [main] xmldb.LocalXPathQueryService (LocalXPathQueryService.java:374) - query took 3687 ms. ---------------------------------- ################# --------------------------------- xquery version "1.0"; declare namespace tools="java:test.XQuery"; let $resultdoc := document{ <results> { let $results := collection("/db/results/")/pricing/results/result[@type='value' and @name='mtm'] for $result in $results let $pricing :=$result/ancestor::node()/ancestor::node() let $shift := $pricing/input/requests/request[@type='value' and @name='mtm']/shift return( <result>{concat($pricing/@id,",",$pricing/input/user,",",1,",",0,",",",",tools:normalise(tools:round($result,9),$shift))}</result> ) } </results> } for $line in $resultdoc/results/result return $line/text() 2007-08-15 17:33:25,741 DEBUG [main] xquery.XQuery (XQuery.java:156) - Compilation took 156 2007-08-15 17:33:25,741 DEBUG [main] xmldb.LocalXPathQueryService (LocalXPathQueryService.java:226) - compilation took 422 2007-08-15 17:33:26,304 TRACE [main] xquery.GeneralComparison (GeneralComparison.java:407) - found an index of type: xs:string 2007-08-15 17:33:26,304 TRACE [main] xquery.GeneralComparison (GeneralComparison.java:452) - Checking if range index can be used for key: value 2007-08-15 17:33:26,304 TRACE [main] xquery.GeneralComparison (GeneralComparison.java:457) - Using range index for key: value 2007-08-15 17:33:26,444 TRACE [main] xquery.GeneralComparison (GeneralComparison.java:407) - found an index of type: xs:string 2007-08-15 17:33:26,444 TRACE [main] xquery.GeneralComparison (GeneralComparison.java:452) - Checking if range index can be used for key: mtm 2007-08-15 17:33:26,444 TRACE [main] xquery.GeneralComparison (GeneralComparison.java:457) - Using range index for key: mtm 2007-08-15 17:33:26,616 TRACE [main] xquery.GeneralComparison (GeneralComparison.java:518) - No suitable index found for key: value 2007-08-15 17:33:26,616 TRACE [main] xquery.GeneralComparison (GeneralComparison.java:301) - No index: fall back to nodeSetCompare 2007-08-15 17:33:26,647 TRACE [main] xquery.GeneralComparison (GeneralComparison.java:518) - No suitable index found for key: mtm 2007-08-15 17:33:26,647 TRACE [main] xquery.GeneralComparison (GeneralComparison.java:301) - No index: fall back to nodeSetCompare 2007-08-15 17:33:26,725 TRACE [main] xquery.GeneralComparison (GeneralComparison.java:518) - No suitable index found for key: value 2007-08-15 17:33:26,725 TRACE [main] xquery.GeneralComparison (GeneralComparison.java:301) - No index: fall back to nodeSetCompare 2007-08-15 17:33:26,725 TRACE [main] xquery.GeneralComparison (GeneralComparison.java:518) - No suitable index found for key: mtm 2007-08-15 17:33:26,725 TRACE [main] xquery.GeneralComparison (GeneralComparison.java:301) - No index: fall back to nodeSetCompare 2007-08-15 17:33:26,788 TRACE [main] xquery.GeneralComparison (GeneralComparison.java:518) - No suitable index found for key: value 2007-08-15 17:33:26,788 TRACE [main] xquery.GeneralComparison (GeneralComparison.java:301) - No index: fall back to nodeSetCompare 2007-08-15 17:33:26,804 TRACE [main] xquery.GeneralComparison (GeneralComparison.java:518) - No suitable index found for key: mtm 2007-08-15 17:33:26,804 TRACE [main] xquery.GeneralComparison (GeneralComparison.java:301) - No index: fall back to nodeSetCompare ... (thousands of times) 2007-08-15 17:37:29,299 TRACE [main] xquery.GeneralComparison (GeneralComparison.java:518) - No suitable index found for key: value 2007-08-15 17:37:29,299 TRACE [main] xquery.GeneralComparison (GeneralComparison.java:301) - No index: fall back to nodeSetCompare 2007-08-15 17:37:29,315 TRACE [main] xquery.GeneralComparison (GeneralComparison.java:518) - No suitable index found for key: mtm 2007-08-15 17:37:29,315 TRACE [main] xquery.GeneralComparison (GeneralComparison.java:301) - No index: fall back to nodeSetCompare 2007-08-15 17:37:29,361 DEBUG [main] storage.NativeBroker (NativeBroker.java:660) - Creating collection '/db/system/temp'... 2007-08-15 17:37:29,377 DEBUG [main] collections.CollectionConfigurationManager (CollectionConfigurationManager.java:165) - Reading collection configuration for '/db/system/temp' from index configuration 2007-08-15 17:37:29,549 DEBUG [main] xquery.XQueryContext (XQueryContext.java:1634) - Stored: 3462: /db/system/temp/1e0e1e578aa1b0f850cd2f5746d4cef2.xml 2007-08-15 17:37:29,658 DEBUG [main] util.HTTPUtils (HTTPUtils.java:61) - mostRecentDocumentTime: 1187195849361 2007-08-15 17:37:29,658 DEBUG [main] xmldb.LocalXPathQueryService (LocalXPathQueryService.java:374) - query took 243917 ms. Any clues? Many thanks and best regards, Raul |