Download Informix CLI Programmer`s Manual, Version 2.8

Transcript
Using SQLSetStmtOption to Reduce the Size of Data Retrieved
Using SQLSetStmtOption to Reduce the Size of Data
Retrieved
When you retrieve long data, your result set can be huge. To reduce the size
of the result set data to a manageable level, call SQLSetStmtOption with the
SQL_MAX_LENGTH option.
The SQL_MAX_LENGTH option reduces network traffic and improves performance by allowing the driver to communicate to the database server that
only n bytes of data are pertinent to the client. The database server responds
by sending only the first n bytes of data for all result columns.
A common assumption among application developers is that if an application calls SQLGetData with a container of size x, then the driver retrieves
only x bytes of information from the server. On the contrary, because an
application can call SQLGetData multiple times for any one column, the
INFORMIX-CLI driver retrieves long data in large chunks to optimize network
use; it then returns the long data to the user upon request. The following code
example illustrates the impact on performance:
char CaseContainer[1000];
...
rc = SQLExecDirect (hstmt, “SELECT CaseHistory FROM Cases
WHERE CaseNo = 71164”, SQL_NTS);
...
rc = SQLFetch (hstmt);
rc = SQLGetData (hstmt, 1, CaseContainer,(SWORD)
sizeof(CaseContainer), ...);
At this point, the driver is more likely to retrieve 64 kilobytes of information
from the server instead of 1000 bytes. (In terms of network access, one 64
kilobytes retrieval is less expensive than sixty-four 1000-byte retrievals.)
Unfortunately, the application might not call SQLGetData again; thus, the
first and only retrieval of CaseHistory is slowed because 64 kilobytes of data
has to be sent across the network.
In this example, only one row is returned. The performance impact is significant when, for example, 100 rows are returned in the result set. This example
further illustrates how you can limit the size of the data retrieved with the
SQL_MAX_LENGTH option of SQLSetStmtOption to improve performance.
10-8
INFORMIX-CLI Programmer’s Manual