BIND - Database package creation
BIND is the process in IBM DB2 for z/OS that converts SQL statements embedded in an application program (like COBOL or PL/I) into an executable form, known as an **access path**. This process creates a `package` or `plan` in the DB2 catalog, defining how DB2 will efficiently access data for those SQL statements.
Key Characteristics
-
- Input: The primary input is a
Database Request Module(DBRM), which contains the SQL statements extracted from the application program by the DB2 precompiler. - Output: The BIND process generates a
package(or an olderplan) that is stored in the DB2 catalog and contains the optimized access paths. - Optimization: During BIND, the DB2 optimizer analyzes the SQL statements, database statistics, and available indexes to determine the most efficient method (access path) for data retrieval and manipulation.
- Static SQL: BIND is primarily used for static SQL, where SQL statements are fixed and known at compile time. Dynamic SQL undergoes a similar optimization process at runtime.
- Dependencies: The resulting
packagerecords dependencies on specific database objects (tables, views, indexes), ensuring that if these objects change, the package can be flagged as invalid. - Privilege Requirement: The user or ID performing the BIND operation must have appropriate DB2 privileges (e.g.,
BINDADD,BINDAGENT,BINDon the collection, and necessary object privileges likeSELECT,INSERT,UPDATE,DELETE).
- Input: The primary input is a
Use Cases
-
- New Program Deployment: After a new COBOL program with embedded SQL is compiled, its DBRM must be bound to create the necessary DB2 package before the program can be executed.
- Application Code Changes: Whenever the SQL statements within an existing application program are modified, the program must be re-precompiled, re-compiled, and its DBRM re-bound to update the corresponding DB2 package.
- Database Schema Modifications: If underlying database objects (e.g., tables, indexes) are altered, or new indexes are created, a
REBINDoperation can be performed on affected packages to allow DB2 to re-optimize access paths based on the new structure. - Performance Tuning: Rebinding a package can be used to force the DB2 optimizer to re-evaluate access paths, especially after
RUNSTATShas been executed to update table and index statistics, potentially leading to improved query performance.
Related Concepts
BIND is a crucial step in the application development lifecycle for DB2 on z/OS, directly linking application code to the database. It takes the DBRM (generated by the DB2 precompiler from COBOL/PL/I source) as input and stores the optimized package in the DB2 Catalog. This package is then referenced by the application program at runtime to execute its SQL, making JCL essential for invoking the DB2 BIND utility. The output, the access path, dictates how DB2 interacts with tables and indexes, directly impacting application performance.
- Utilize Packages: Always bind into
packagesrather thanplansfor better modularity, easier version control, improved concurrency, and reduced contention in the DB2 catalog. - Maintain Current Statistics: Ensure
RUNSTATSis regularly executed on all relevant tablespaces and indexes to provide the DB2 optimizer with accurate and up-to-date statistics, which are critical for choosing optimal access paths during BIND. - Monitor Access Paths with EXPLAIN: Use the
EXPLAINfacility to analyze the access paths chosen by the optimizer for critical SQL statements, identifying potential performance bottlenecks and opportunities for index creation or SQL tuning. - Version Control DBRMs: Treat DBRMs as critical artifacts and manage them under a robust version control system alongside their corresponding application source code.
- REBIND Strategically: Consider performing a
REBINDon affected packages after significant database schema changes,RUNSTATSupdates, or DB2 subsystem upgrades to leverage new optimizations or access paths. - Grant Minimal Privileges: Adhere to the principle of least privilege by granting only the necessary
BINDand object privileges to the user IDs or groups responsible for performing bind operations.