Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to prevent SQLServer JDBC Query with XML type caching entire resultset at query?

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?

like image 207
Screwtape Avatar asked Dec 18 '18 13:12

Screwtape


People also ask

How can the query result set be cached?

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.

What is client result cache in JDBC OCI?

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.

What is JDBC statement caching?

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:

What is the result type of the XML query?

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.


Video Answer


1 Answers

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.

like image 145
skadya Avatar answered Oct 31 '22 06:10

skadya