|
|
||||||||||||||||||||
| Home > Guidelines for managing data updates to optimize ODBC performance | |
| Chapter Download: |
|
||
Table of Contents
Use the guidelines in this section to manage your updates more efficiently.
Using SQLSpecialColumns to Optimize Updates and Deletes
rc = SQLExecDirect (hstmt, "SELECT first_name, last_name," + Many databases support pseudo-columns that are not explicitly defined in the table definition but are hidden columns of every table (for example, ROWID for Oracle). Because pseudo-columns are not part of the explicit table definition, they're not retrieved when SQLColumns is called. To determine if pseudo-columns exist, your application must call SQLSpecialColumns. For example:
... If your data source doesn't contain pseudo-columns, the result set of SQLSpecialColumns consists of the columns of the most optimal unique index on the specified table (if a unique index exists). Therefore, your application doesn't need to call SQLStatistics to find the smallest unique index. Using Catalog Functions
Minimizing the Use of Catalog Functions In addition to avoid executing catalog functions multiple times, you should cache information retrieved from result sets generated by catalog functions. For example, call SQLGetTypeInfo once, and cache the elements of the result set that your application depends on. It's unlikely that any application will use all elements of the result set generated by a catalog function, so the cache of information shouldn't be difficult to maintain.
Catalog functions support arguments that can limit the amount of data retrieved. Using null values or search patterns, such as %A%, for these arguments often generates time-consuming queries. In addition, network traffic can increase because of unnecessary results. In the following example, an application uses the SQLTables function to determine whether the table named WSTable exists and provides null values for most of the arguments:
rc = SQLTables(hstmt, null, 0, null, 0, "WSTable", The driver interprets the request as follows: Retrieve all tables, views, system tables, synonyms, temporary tables, and aliases named WSTable that exist in any database schema in the database catalog. In contrast, the following request provides non-null values for all arguments, allowing the driver to process the request more efficiently:
rc = SQLTables(hstmt, "cat1", SQL_NTS, "johng", SQL_NTS,
Sometimes little is known about the object that you are requesting information for. Any information that the application can provide the driver when calling catalog functions can result in improved performance and reliability.
Using a Dummy Query to Determine Table Characteristics The following examples show the benefit of using the SQLDescribeCol function over the SQLColumns function.
rc = SQLColumns (... "UnknownTable" ...); A simple query that retrieves result set information is prepared, but the query is not executed and result rows are not retrieved by the driver. Only information about the result set is retrieved (the same information retrieved by SQLColumns in Example A).
// prepare dummy query
What if the database server, such as a Microsoft SQL Server server does not support prepared statements by default? The performance of Example A wouldn't change, but the performance of Example B would decrease slightly because the dummy query is evaluated in addition to being prepared. Because the Where clause of the query always evaluates to FALSE, the query generates no result rows and executes the statement without retrieving result rows. So, even with a slight decrease in performance, Example B still outperforms Example A. Summary The performance of ODBC applications can suffer if they fail to reduce network traffic, limit disk I/O, simplify queries, and optimize the interaction between the application and driver. Reducing network communication probably is the most important technique for improving performance. For example, when you need to update large amounts of data, using arrays of parameters rather than executing an Insert statement multiple times reduces the number of network round trips required to complete the operation. Typically, creating a connection is the most performance-expensive task your application performs. Connection pooling can help you manage your connections efficiently, particularly if your application has numerous users. Regardless of whether your application uses connection pooling, make sure that your application closes connections immediately after the user is finished with them. Making smart choices about how to handle transactions can also improve performance. For example, using manual commits instead of auto-commit mode provides better control over when work is committed. Similarly, if you don't need the protection of distributed transactions, using local transactions can improve performance. Inefficient SQL queries slow the performance of ODBC applications. Some SQL queries don't filter data, causing the driver to retrieve unnecessary data. Your application pays a huge penalty in performance when that unnecessary data is long data, such as data stored as a Blob or Clob. Even well-formed SQL queries can be more or less effective depending on how they are executed. For example, using SQLExtendedFetch instead of SQLFetch and using SQLBindCol instead of SQLGetData reduces ODBC calls and improves performance. More on accessing data:
'); // -->
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| About Us | Contact Us | For Advertisers | For Business Partners | Site Index | RSS |
|
|
|
|||||||