1. Trang chủ
  2. » Công Nghệ Thông Tin

Tài liệu Oracle Unleashed- P19 pptx

50 344 0

Đang tải... (xem toàn văn)

Tài liệu hạn chế xem trước, để xem đầy đủ mời bạn chọn Tải xuống

THÔNG TIN TÀI LIỆU

Thông tin cơ bản

Định dạng
Số trang 50
Dung lượng 191,97 KB

Nội dung

EXEC IAF PUT GLOBAL.OT_TAXES VALUES ( :taxes ); EXEC IAF PUT GLOBAL.OT_GRAND_TOTAL VALUES ( :grand_total ); return(IAPSUCC); } } To call this user exit from a SQL*Forms trigger, you insert the following code: user_exit('order_total'); Utilizing dynamic SQL or user exits can create problems with performance, and if your program is in a high-demand system this could become very undesirable. The next section of this chapter will look how to tune your SQL to improve performance. Performance Tuning When developing applications with embedded SQL, performance can become a major issue depending on what type of platform you may be using. This section provides easy-to-apply methods for improving the performance of your applications. It looks at what causes poor performance and how performance can be improved. See Chapter 15, "Performance Tuning and Optimizing," for more information about performance tuning. Poor Performance One of the first causes of poor performance is high Oracle communication overhead. Oracle processes each SQL statement one at a time, which results in numerous calls to Oracle. If you are operating in a network environment, each call creates additional traffic on the network. The more traffic you have, the slower the performance will become. The second cause of poor performance is inefficient SQL statements. Just because SQL statements can be written in several different ways and still get the same results, this does not mean that every statement is running efficiently. In some cases, full table scans will be occurring (which is time consuming if the table is large); in other cases, using indexes greatly speeds up the search. The third cause of poor performance is managing cursors inefficiently. The result of not managing cursors correctly is additional parsing and binding, which adds noticeable processing overhead for Oracle. These problems can be improved by reducing Oracle communication overhead or reducing processing overhead. The next section provides methods that will help reduce overhead and improve performance. Improving Performance Improving performance can make a dramatic difference in the way your application functions under normal or high usage. Two areas always should be considered when writing an SQL statement: Oracle communications and processing overhead. Please purchase PDF Split-Merge on www.verypdf.com to remove this watermark. Reducing Oracle Communication Overhead There are two methods that can be used to reduce Oracle communication overhead: host arrays and PL/SQL blocks. Using host arrays can dramatically boost your applications performance. You can issue one SQL statement to manipulate numerous rows, instead of issuing a SQL statement for each row. For example, if you wanted to update 1200 student grades, you could issue one SQL statement with a host array instead of 1200 with just a host variable. For more information, see the section on host arrays. The second method to reducing Oracle communication overhead is to use embedded PL/SQL. If your application is database intensive, you can utilize PL/SQL blocks to group SQL statements together and then send the block to Oracle for processing. After reducing the Oracle communication overhead, your next step should be to reduce processing overhead. Reducing Processing Overhead In order to reduce processing overhead, your SQL statement should be analyzed to ensure it is using the appropriate indexes, it is using row-locking properly, and it is managing cursors effectively. To ensure that indexes are being used properly, Oracle has provided tools that will help to identify problem areas. The trace facility in conjunction with the EXPLAIN PLAN statement will generate statistics enabling you to identify which SQL statements are taking a lot of time to execute. This explain plan describes what database operations need to be carried out by Oracle to complete processing of the SQL statement that you have written. One of the most common problems with SQL statements is that full table scans are being done instead of indexes being utilized. The explain plan indicates if full table scans are being done; from this you can alter the SQL statements to utilize indexes. Another area that can improve performance is how the database is locking data. To increase performance you want to lock only at the row level. This will enable many users (instead of just one) to access the table. Applications that do online transactions can drastically benefit from row locking verses table locking. The default value is different depending on what version of Oracle you are using. In Oracle Version 6, row-locking is the default. Managing cursors can create an enormous amount of processing overhead. The easiest way to manage cursors is to declare them explicitly. This gives you the flexibility to control them as you need resources. Remember that you need to PREPARE, DECLARE, OPEN, and CLOSE explicit cursors in dynamic SQL—especially with methods three and four. After a cursor has been PREPAREd (which does the parsing), it can be used multiple times until it is CLOSEd. This can drastically reduce the parsing and binding that is done with each cursor. Now that you have stepped through each part of creating an embedded SQL host program, it would be advisable to stay current on what new features the precompilers have. Oracle has taken extra effort in improving its tools with each step; as a programmer, you should capitalize on these features. New Features in Version 1.4 The new features in Version 1.4 precompilers help meet the needs of professional software developers. Some of the features are as follows: ● New debugging aid. The SQLCA stores additional runtime information about the outcome of SQL operations. ● Enhanced WHENEVER statement. The improved WHENEVER statement now lets you take actions when an error or warning is detected. With previous versions you only had three choices: GOTO, CONTINUE, or STOP. Added to version 1.4 is the DO statement, which allows for procedural functions to be taken. Please purchase PDF Split-Merge on www.verypdf.com to remove this watermark. ● Revised HOST option. With previous versions of precompilers, the HOST parameter indicated what host language was being used. Version 1.4 uses separate precompilers executables each designed for a specify language. ● In previous versions of Oracle precompilers, options for setting the area size (which is initially set for cursor) had to be specified. With the current version of precompilers, resizing is automatically done. This feature makes the AREASIZE and REBIND options obsolete. ● Previous versions of precompilers generated several database calls per embedded SQL statement. In Version 1.4, precompilers generate only one (bundled) database call per embedded SQL statement. Remember to try and keep current on the new features Oracle includes in its precompilers. This could make a dramatic difference in the performance and functionality of your program. Summary ORACLE precompilers provide an excellent tool for programmers to create dynamic applications. This chapter provided information on what a precompiler does, the benefits of being able to embed SQL statements, how to use it a precompiler, and how to create a host program. This concludes the section on precompilers. I hope that the information has been beneficial to you and has given you some quick tips to enhance performance. Previous Page TOC Next Page Home Please purchase PDF Split-Merge on www.verypdf.com to remove this watermark. Previous Page TOC Next Page Home ● 51 ❍ ODBC Applications ■ Components of ODBC ■ Configuring an ODBC Data Source ■ Connecting to an ODBC Data Source using the ODBC API ■ Setting Connection Options ■ Applying SQL Transactions ■ Retrieving Result Sets ■ Handling Errors ■ Calling Stored Procedures and Functions ■ Disconnecting and Freeing Resources ■ Debugging ODBC Applications ■ Limitations of ODBC ■ Summary 51 ODBC Applications ODBC (Open Database Connectivity) is an industry standard programming interface that enables applications to access a variety of database management systems, residing on many different platforms. ODBC provides a large degree of database independence through a standard SQL syntax, which can be translated by database-specific drivers to the native SQL of the DBMS. Database independence and ease of use are the primary advantages to using ODBC. It is supported by many popular development tools, including Visual Basic, PowerBuilder, Delphi, and SQLWindows. These tools and numerous others provide their own interfaces to ODBC, making ODBC easier to use by insulating the developer from many of the complexities of the ODBC API. Components of ODBC ODBC software is made up of several distinct components. The application layer contains embedded SQL and logic for data entry, preparing transactions, and displaying result sets. It calls API functions exported by the driver manager to connect to the data source, apply SQL, and retrieve results and error codes. The driver manager provides the common ODBC interface, loads database-specific drivers as requested by the application, performs call-level validations, and maps ODBC calls to functions exported by the database-specific driver. The database-specific driver processes the ODBC function calls, optionally converting SQL and data types to the native syntax of the DBMS, and formats DBMS error codes into a standard format. It also returns result sets and error codes to the driver manager. The data source consists of the DBMS itself, in addition to any network or operating system software required to connect to it. Figure 51.1 illustrates these layers. Figure 51.1. This is a visual representation of the components of ODBC. For local desktop databases, the data source might simply consist of the name of local server or database file. When the Please purchase PDF Split-Merge on www.verypdf.com to remove this watermark. DBMS resides on a remote server, however, the data source includes any network software required to access the remote host. For example, if you attempt to access Oracle on a remote server, SQL*Net must be installed and properly configured. Although this software is not actually part of ODBC, it is considered part of the data source because it is required by ODBC to connect to the database. Configuring an ODBC Data Source The process of configuring an ODBC data source is simply a matter of providing some information to the driver manager and the DBMS-specific driver. The driver manager uses entries in ODBC.INI to determine what driver to load for a particular data source name. The specific driver may use ODBC.INI to determine the server name and the values of any database-specific parameters required to connect. The ODBC administration program ships with nearly all Windows development tools that support ODBC and is typically installed as part of the Windows Control Panel applet. This program, ODBCADM.EXE, and a DLL, ODBCINST.DLL, are used to install specific drivers and configure data sources. The following instructions on how to use the driver manager are based on version 1.02 of ODBCADM.EXE. This application may vary slightly from version to version, but the functions provided are essentially the same. Always use the ODBC administration program to install drivers and configure data sources. ODBC.INI and ODBCINST.INI should not be edited manually, unless it becomes absolutely necessary because of corruption or other extreme problems. If this situation arises, the files should be backed up prior to editing. When the administration application is started, a list of defined data sources is presented, as shown in Figure 51.2. Figure 51.2. The Data Sources dialog displays a list of defined data sources. The Close and Help buttons should be self-explanatory, and the Options button will be discussed later, in the section on debugging. Add is used to define a new data source for one of the installed drivers. Delete is used to delete an existing data source, but does not delete the driver. The configuration of the selected data source can be edited by clicking on the Setup button. The Drivers button is used to install additional DBMS-specific ODBC drivers. The following examples illustrate the installation of the Oracle ODBC driver and the configuration of an Oracle data source. This process begins with the installation of the Oracle ODBC driver. First, select Drivers from the Data Sources dialog. When this button is clicked, all installed drivers are displayed, as shown in Figure 51.3. Figure 51.3. The Drivers dialog displays a list of installed drivers. To install the Oracle ODBC driver, click the Add button. This will display a dialog requesting the location of the drivers. Select the drive and directory containing the ODBC.INF file and click OK. The dialog box shown in Figure 51.4 indicates that the Oracle ODBC driver was located. Figure 51.4. The Install Drivers dialog displays a list of drivers available for installation. The Advanced button displays a dialog that allows the user to specify installation of the driver manager and code page translators. The Versions button in the lower-right corner brings up a second dialog that can be used to view extended version information about each component available to install. These two dialogs are shown in Figure 51.5. Please purchase PDF Split-Merge on www.verypdf.com to remove this watermark. Figure 51.5. The Advanced Installation Options and Versions dialogs can be used to control the installation of the Oracle ODBC driver. The Install selected driver(s) with version checking should be selected. This will cause the installation program to prompt before overwriting an existing driver if it is the same or a newer version of the driver being installed. The version checking options should also be used for the installation of the Driver Manager and translators. Newer versions of these DLLs should not be overwritten if they exist. Code page translators are used to translate between different character sets and languages. In some cases, they are used for encryption or data type conversion. Although a translator is not needed in most cases, you can install them for possible future use. After making your selections from these options, click the OK button to return to the Install Drivers dialog. To complete the installation of the Oracle7 driver, make sure that Oracle7 is highlighted in the list box and click the OK button. The Drivers dialog should now appear as shown in Figure 51.6. Figure 51.6. The Drivers dialog shows that the Oracle ODBC driver was successfully installed. Click the Close button to complete driver installation. Configuring the data source is simply a matter of specifying a driver, naming the data source, and providing some additional information for the driver to use when connecting to the database. Refer to the Data Sources dialog in Figure 51.2. From this dialog, click Add to configure a new Oracle data source. The next dialog, Add Data Sources, requires the selection of an installed driver. Select Oracle7 from the list and click the OK button. Next, the Oracle7 ODBC Setup dialog prompts the user for a data source name, description, and SQL*Net connect string, as illustrated in Figure 51.7. Figure 51.7. This is the Oracle7 ODBC Setup dialog. The connect string is specific to the network transport (if any), the hostname or address of the server, and the system ID of the database to be accessed (if more than one Oracle database exists on the host). The syntax of the connect string is transport_code:host_name:database The transport_code is a single character used to specify the SQL*Net driver to be used (T for TCP/IP, X for IPX/SPX, and so on). The host_name is the name, alias, or network address of the server. The database argument is necessary only if more than one Oracle database exists on the host. In this case, the argument should be the system name of the database, as specified when the database was created with the CREATE DATABASE command. Consult the Oracle ODBC driver release notes and the SQL*Net documentation for further information on the SQL*Net Connect String. For the purposes of this example, assume that the database resides on a UNIX host and will be accessed from the Windows workstation using TCP/IP. Enter ORACLE for the data source name, Oracle 7.1 for the description, and T: ORACLE_SERVER for the SQL*Net connect string. The dialog should now look like the one shown in Figure 51.8. Figure 51.8. The Oracle7 ODBC Setup dialog requires a name and a SQL*Net Connect String. The description is optional. Please purchase PDF Split-Merge on www.verypdf.com to remove this watermark. The Options button enables the user to select a code page translator, assuming that a translator was installed with the driver. In most cases, no translation is necessary. Click OK to complete the data source setup. The new data source should appear in the Data Sources dialog as shown in Figure 51.9. Figure 51.9. The Data Sources dialog shows that the new Oracle7 Data Source was successfully added. The data source is now fully configured and ready to be accessed by an application. Note that the setup routine in Figure 51.7 and Figure 51.8 is specific to the driver (Oracle 7.1 version 1.11.0002, in this case). This setup dialog will vary slightly from driver to driver, but will always require similar information. Connecting to an ODBC Data Source using the ODBC API Before your application connects to the ODBC data source, some memory allocation and initialization must be performed. First, the application must call SQLAllocEnv, passing a pointer to memory allocated to store an environment handle. This handle will be used to establish connections and for transaction processing. The application might need to establish more than one environment handle, but a single environment handle is usually sufficient, except in multithreaded environments. Next, the application should call SQLAllocConnect, passing the previously established environment handle and a pointer to storage allocated for the connection handle. The driver manager allocates storage for connection information and associates the resulting connection handle with the environment handle. Multiple connections can be established for a single environment handle, but each connection can only be associated with a single environment. The connection handle will be used to allocate statement handles and process embedded SQL transactions. Finally, the application may call either SQLConnect or SQLDriverConnect, passing the connection handle instantiated by the call to SQLAllocConnect. The primary difference between these two functions is that SQLDriverConnect accepts a full connection string, rather than separate arguments for the data source name, userid, and password. This allows for additional database-specific parameters to be passed to the driver as part of the connection string. Additionally, SQLDriverConnect provides an argument used to define the behavior of the driver manager and a window handle to be used as the parent of the data sources dialog (if one will be presented). The arguments to SQLDriverConnect are, in order: ● An allocated connection handle. ● The handle of the parent window from the Data Sources dialog (or NULL, if no dialog will be presented). ● A connection string. ● The length of the connection string. ● A pointer to storage for the connection string actually used by the driver. (It may add information to the connection string it receives.) ● A pointer to storage to hold the length of the completed connection string. ● An integer constant used to control the behavior of the driver manager. A typical connection string looks like this: DSN=ORACLE;UID=scotty;PWD=tiger; Additional database-specific parameters may be provided, or the connection string may be partial, or empty, in which Please purchase PDF Split-Merge on www.verypdf.com to remove this watermark. case the driver will provide a dialog requesting the information required to connect. If SQL_DRIVER_NOPROMPT is passed as the completion constant, the application must provide all required information in the connection string. C applications should include ODBC.H (or SQL.H and SQLEXT.H, depending on the compiler), which contains all function prototypes, data types, and constants available in the ODBC API. When using other development tools, the developer must provide prototypes for all ODBC functions used by the application. Listings 51.1 and 51.2 demonstrate connecting to an ODBC data source in C and Visual Basic, in a Microsoft Windows application context. Listing 51.1. This C function establishes a single connection to a data source. int ConnectToDataSource( HENV *hEnv, /* used to store the environment handle */ HDBC *hDBc) /* used to store the connection handle */ { UCHAR *szConnect; UCHAR szConnectOut[SQL_MAX_MESSAGE_LENGTH]; SWORD iConnectOutLen; RETCODE iError; szConnect = strdup(ÒDSN=ORACLE;UID=scotty;PWD=tiger;Ó); iError = SQLAllocEnv(hEnv); if (iError == SQL_SUCCESS) iError = SQLAllocConnect(*hEnv, hDBc); if (iError == SQL_SUCCESS) iError = SQLDriverConnect(*hDBc, NULL, szConnect, SQL_NTS, szConnectOut, (SQL_MAX_MESSAGE_LENGTH - 1), &iConnectOutLen, SQL_DRIVER_NOPROMPT); return(iError); } Listing 51.2. This Visual Basic function establishes a connection to a data source. Please purchase PDF Split-Merge on www.verypdf.com to remove this watermark. ' include these prototypes in the module: Declare Function SQLAllocEnv Lib "odbc.dll" (hEnv As Long) As Integer Declare Function SQLAllocConnect Lib "odbc.dll" (ByVal hEnv As Long, hDBc As Long) As Integer Declare Function SQLDriverConnect Lib "odbc.dll" (ByVal hDBc As Long, ByVal hWnd As Integer, ByVal szCSin As String, ByVal iCSinLen As Integer, ByVal szCSOut As String, ByVal iCSOutMaxLen As Integer, iCSOutLen As Integer, ByVal iDriverComplete As Integer) As Integer ' also define these constants: Global Const SQL_SUCCESS = 0 Global Const SQL_SUCCESS_WITH_INFO = 1 Global Const SQL_STILL_EXECUTING = 2 Global Const SQL_NEED_DATA = 99 Global Const SQL_NO_DATA_FOUND = 100 Global Const SQL_ERROR = 1 Global Const SQL_INVALID_HANDLE = 2 Global Const SQL_NTS = 3 Global Const SQL_DRIVER_NOPROMPT = 0 Global Const SQL_MAX_MESSAGE_LENGTH = 512 Function ConnectToDataSource(hEnv As Long, hDBc As Long) As Integer Dim szConnect As String Please purchase PDF Split-Merge on www.verypdf.com to remove this watermark. Dim szConnectOut As String Dim iConnectOutLen As Integer Dim iError As Integer szConnectOut = Space$(SQL_MAX_MESSAGE_LENGTH) szConnect = ÒDSN=ORACLE;UID=scotty;PWD=tiger;Ó iError = SQLAllocEnv(hEnv) If (iError = SQL_SUCCESS) Then iError = SQLAllocConnect(hEnv, hDBc) End If If (iError = SQL_SUCCESS) Then iError = SQLDriverConnect(hDBc, 0, szConnect, SQL_NTS, szConnectOut, (SQL_MAX_MESSAGE_LENGTH - 1), iConnectOutLen, SQL_DRIVER_NOPROMPT) End If ConnectToDataSource = iError End Function Although the preceding examples might be somewhat oversimplified, they should be sufficient to illustrate the steps necessary to connect to a data source using the ODBC API. For clarification of the data types and constants used in the examples, consult the ODBC.H header file included in the Microsoft ODBC SDK. Setting Connection Options After you allocate a connection, options can be set to control the behavior of statements processed by the connection, using SQLSetConnectOption. There are numerous parameters available, the most significant of which is the SQL_AUTOCOMMIT option. By default, this option is enabled, which means that transactions are committed as sent, with no possibility of rollback. This can be very dangerous if the application uses multiple statements to process one logical transaction. For DBMSs that do not support stored procedures and triggers, this situation is nearly unavoidable. The function examples in Listing 51.3 demonstrates the ODBC API call to set a connection option. Listing 51.3. This C function disables the AUTOCOMMIT option for a connection. /* not part of ODBC.H */ enum ConnectOptionValues { Please purchase PDF Split-Merge on www.verypdf.com to remove this watermark. [...]... operations Each subsequent release of the Oracle7 server has added significant functional and performance improvements to this initial offering This section provides an outline of Oracle' s server architecture and an overview of the dynamic parallel query execution technology Oracle Parallel Server Technology The Oracle Parallel Server technology is at the heart of Oracle' s server implementation on loosely... the same file server with this feature Oracle Parallel Query employs "Query Slaves" that actually provide the scheduling of these Parallel job streams These Parallel features are developed by Oracle Corporation, in conjunction with the Parallel Platform designers from each of the hardware vendors, and they are transparent to the Oracle programmers and users! Oracle7 .1 delivers the Parallel Query Option... that an Oracle connect string be entered by the user, the user can simply press Enter on the keyboard to substitute the connect string or alias from the manually set LOCAL=TNS:your_connect_string or "alias" line in the /windows /oracle. ini file This will then facilitate the user's connection to the first available Oracle database through that database's already running listener process The Oracle parallel... purchase PDF Split-Merge on www.verypdf.com to remove this watermark q 32-kilobyte Oracle data blocks for faster parallel reads and writes q 64-bit executable code for Oracle7 .2 q 64-bit executable code for both Oracle Pro*C and Pro*COBOL Comparing Parallel Processing to Mainframes The following test results provided by the Oracle Corporation illustrate how these newer parallel processing platforms are... Platforms s Comparing Parallel Processing to Mainframes s Test Results s Oracle7 Server Scalable Parallel Architecture for Open Data Warehousing s Parallel Hardware Systems s The Shared-Nothing Approach s The Shared-Disk Approach s What the Real World Needs s Oracle7 Parallel Architecture: An Overview s Oracle Parallel Server Technology s Oracle Parallel Query Technology s Dynamic Parallel Execution: Key... s Cross or Remote Mounted Disk Drives s Disk Drive Allocation s Disk Partitioning s Maximizing Parallel Platform Database and Disk Performance Through Balancing the Oracle Processes s Disk Optimization For Oracle7 and the Parallel Server Oracle7 Option s Disk Storage Devices s Optical Storage s RAID Versus the Speed of Disk Mirroring s Mirrored Disk Drives s Parallel Processor Types, Smart Controller... updated separately from the master database The Oracle7 .2 64-bit Option allows for many unlimited and amazing Parallel Processing capabilities, including actual performance increases of up to 107 times faster than 32-bit systems, as well as the ability to leverage the following: q Tens of gigabytes of RAM for any Oracle instance q Tens of gigabytes of RAM for any Oracle data files that can be cached in memory... software all totaling from between $20,000.00 to $4,239,200.00 complete Leveraging Parallel Processing Platforms How does Oracle7 leverage these newer parallel processing platforms? The Oracle7 Enterprise Edition has some very "advanced" features The major enhanced features lacking in the Oracle7 Workgroup Server that the Enterprise Edition leverages for parallel processing are the following options: q Parallel... excellent resource utilization and fault tolerance Oracle7 Parallel Architecture: An Overview The Oracle server was the first open relational database product to provide complete support for all parallel hardware architectures, with production availability on a variety of SMP systems for several years, and on loosely coupled cluster and MPP systems since 1990 The Oracle Parallel Server technology with its... are currently unsupported by the Oracle ODBC driver Although third-party driver vendors might supply some of these functions, the code examples in this section will focus on bound and unbound fetches using prepared and direct execution These examples use core functions and level 1 extensions, all of which are supported by the current Oracle ODBC driver available from Oracle Corporation Although the . performance is high Oracle communication overhead. Oracle processes each SQL statement one at a time, which results in numerous calls to Oracle. If you are. installation of the Oracle ODBC driver and the configuration of an Oracle data source. This process begins with the installation of the Oracle ODBC driver.

Ngày đăng: 15/12/2013, 05:15