I have a query which generates a fairly large XML document (~30k) as a query column for each record of a large table, of the form...
SELECT recordKey, lastUpdatedDate, ( SELECT ... FOR XML PATH( 'elemName' ), TYPE )
FROM largeTable
ORDER BY lastUpdateDate
If I run this query from SQLServer management studio, the query returns almost instantly, showing the first rows, as I would expect, and continues to run in the background.
However, when I run this query from the Camel JDBC component in StreamList mode, it appears to cache the entire resultset at the point of querying, which means I run out of memory.
I've checked the JDBC driver properties, and explicitly set the responseBuffering
property to adaptive
, and have also tried setting the selectMethod
to cursor
, neither of which appear to make any difference to my query.
Is this a characteristic of querying XML with JDBC, or are there some parameters I need to set differently?
The query result set can be cached in the following ways: The server-side and client result set caches are most useful for read-only or read-mostly data. They may reduce performance for queries with highly dynamic results. Both server-side and client result set caches use memory. So, caching very large result sets can cause performance problems.
Since Oracle Database 11 g Release 1, support for client result cache has been introduced for JDBC OCI driver. The client result cache improves performance of applications by caching query result sets in a way that subsequent query executions can access the cached result set without fetching rows from the server.
Statement caching improves performance by caching executable statements that are used repeatedly, such as in a loop or in a method that is called repeatedly. Starting from JDBC 3.0, JDBC standards define a statement-caching interface. Statement caching can do the following: This section covers the following topics:
The result is of xml type. The method returns an instance of untyped XML. To view Transact-SQL syntax for SQL Server 2014 and earlier, see Previous versions documentation. Is a string, an XQuery expression, that queries for XML nodes, such as elements and attributes, in an XML instance.
However, when I run this query from the Camel JDBC component in StreamList mode, it appears to cache the entire resultset at the point of querying, which means I run out of memory.
camel-sql introduce the 'StreamList' output type in v2.18.x. Since you are using v2.17.6, your configuration may be falling back to 'SelectList' (default value). This causes the load of whole result set as list in memory. Having xml type in your query/result set doesn not have any influence on this behavior.
You may find this code at: org.apache.camel.component.sql.SqlConsumer.poll()
I suggest you to upgrade camel-sql version to v18.x ( or latest)
Hope this helps.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With