This module connected SQL tuning tools with the development practices that make their results useful. In Oracle AI Database 26ai, performance work begins with the application requirement: the correct answer, acceptable response time or throughput, and sustainable resource use. A tool can reveal a plan or a wait, but the team must decide what that evidence means for the business operation.
The five lessons developed a shared process for developers and DBAs. Identify the workload, establish a baseline, apply testable standards, investigate collaboratively, and design database APIs deliberately. These activities reinforce one another. A well-written procedure still needs suitable SQL; an effective index still needs a workload justification; a faster query still needs to return the right result.
| Lesson | Main responsibility | Useful outcome |
|---|---|---|
| SQL tuning tools and development practices | Define the operation and choose appropriate evidence. | A measurable target and reproducible baseline. |
| DBA responsibilities | Connect application activity with database conditions. | A supported diagnosis and accountable change owner. |
| SQL standards | Make correctness, access, and performance rules testable. | Review criteria backed by concrete checks. |
| Working with developers | Compare alternatives without changing the required result. | A measured improvement with documented tradeoffs. |
| SQL inside stored procedures | Choose reusable interfaces, privileges, and transaction ownership. | A controlled database API with explicit limits. |
Lesson 1 established the distinction between database work and application experience. A request can wait for a pooled connection, make repeated network calls, fetch many rows, and spend time formatting them after SQL execution finishes. Improving one database statement does not prove that the entire request improved.
Response time and throughput also answer different questions. An interactive search needs useful results promptly; a batch process needs to complete its total work within an agreed window. Increasing resource consumption to accelerate one request may interfere with other users. State the expected data volume, concurrency, and result consumption before choosing a test.
Make the requirement precise enough to reproduce. Record whether the client fetches the first screen or every row, which parameter values matter, and how the result must be ordered. Preserve null handling and duplicate behavior when comparing rewrites. A query that returns fewer required rows has changed the question, even if its timing looks better.
Connection pooling, statement caching, and bind variables address different sources of overhead. Pooling reuses connections; statement caching can reuse prepared work; binds separate changing values from statement text. None excuses leaving transactions unresolved or returning a pooled session with misleading request state.
Lesson 2 described the DBA as a partner in diagnosis and operational control. The developer supplies application semantics and calling behavior. The DBA contributes knowledge of shared resources, plans, statistics, privileges, and competing workloads. The service owner helps define acceptable behavior and release priorities.
SQL can originate in interactive clients, embedded SQL programs, drivers, or stored code. Identifying its source helps connect a database observation to an application operation. Direct SQL does not have to pass through a stored procedure, and using a particular client does not grant unrestricted database access. The authenticated identity and applicable privileges still matter.
Use stable module and action labels, along with the service, session context, SQL ID, and relevant child cursor, to support investigation. Clean up request-specific labels when using pooled connections. Diagnostic labels help explain activity; they are not evidence that a caller is authorized to perform an operation.
Prioritize both business impact and aggregate work. A critical but infrequent operation can deserve attention, while a small query executed repeatedly may consume substantial resources over time. Compare measurements over appropriate intervals. Cumulative counters from cursors with different lifetimes are not automatically a fair comparison.
Changes to statistics, indexes, parallelism, or memory can affect other workloads. The DBA should help evaluate those effects rather than simply apply a requested setting. An index may help a selective lookup while increasing write costs. A statistics change may improve estimates but also alter plans. Each proposal needs a reason, tests, and a recovery approach.
The module emphasized that an explained plan and an observed execution are different kinds of evidence. EXPLAIN PLAN describes a proposed plan without executing the target SQL. A changed environment or cursor context can make it differ from the plan used by the application.
DBMS_XPLAN.DISPLAY_CURSOR can display a loaded cursor's plan. Runtime row-source information must have been collected for the execution being examined. A display format such as ALLSTATS LAST does not recover statistics that were never gathered. Identify the correct SQL ID and child cursor, especially when a client executes helper statements between the query and the diagnostic call.
Scoped SQL Trace and TKPROF can help distinguish parse, execute, and fetch work. Historical, sampled, advisory, and monitored-execution facilities answer additional questions. Obtain the required access and check edition or service entitlement before using advanced facilities. Visibility of a menu or package does not establish permission or licensing.
Use Oracle's execution-plan guidance, DBMS_XPLAN reference, and licensing information to confirm the requirements for the actual investigation. Distinguish displaying a cached cursor from accessing AWR history.
Lesson 3 replaced vague advice with rules that produce evidence. A useful standard explains what is required, why it matters, how it is checked, and who reviews an exception. Formatting conventions improve readability, but they do not establish authorization, correct results, or acceptable performance.
Practical standards cover typed parameters, result columns and ordering, null and boundary behavior, transaction ownership, error propagation, and resource cleanup. They also specify how a performance-sensitive change is tested. Avoid universal bans on valid SQL constructs merely because they appeared in one slow query.
Bind data values separately from SQL syntax. A bind represents a value, not a table name, sort keyword, or arbitrary fragment. When an application genuinely needs a dynamic identifier, map a reviewed choice to an allowed identifier instead of inserting unrestricted input. Validation of an identifier is not proof that the caller may access it.
Enforce access at the database boundary using appropriately scoped accounts, roles, object privileges, and reviewed APIs. EXECUTE is an object privilege that can be granted to a user or role; it is not a replacement for roles. Review all effective grant paths before claiming an application can access data only through one interface.
Legacy client-specific restrictions do not supply a modern database-wide policy. In particular, the module retired PRODUCT_USER_PROFILE setup guidance in favor of current authorization and engineering controls. Keep standards aligned with the supported release and the actual client interface rather than rebuilding an obsolete mechanism because it appears in an old script.
Lesson 4 showed why performance claims require a controlled comparison. Before changing query shape, agree on the intended result. NOT IN and NOT EXISTS are not interchangeable for every nullable dataset. Adding DISTINCT may conceal a join error, while removing ordering may break the application contract.
The dictionary example identified users without matching role-grant records, not users with no effective privileges. That distinction illustrates a broader principle: describe exactly what the SQL proves. Do not turn a narrow query result into a security conclusion that it does not support.
Likewise, a table named temp1 is not necessarily temporary. Ordinary CREATE TABLE ... AS SELECT creates a permanent table. If a proposed optimization copies data, include setup, refresh, storage, transaction implications, and cleanup in the design and measurements. Timing only the final query can hide most of the added work.
Inspect actual work rather than judging by operation names. A full scan may be appropriate; an index can still lead to excessive block visits. Compare estimated and actual rows carefully, accounting for repeated starts where relevant. Historical rule-based optimizer comparisons and unsupported speed ratios are not evidence for a current Oracle 26ai decision.
Change one justified factor, check results, and repeat measurements under comparable conditions. Include important parameter ranges and concurrent activity. Record variability and regressions rather than choosing only the fastest run. A collaborative review should end with a supported decision, not a preference for a particular-looking plan.
Lesson 5 explained how a stored procedure can expose a named, reusable operation. A package can separate its public contract from implementation details and group related behavior. This can reduce duplicated logic and provide a deliberate access boundary, but a central change can affect many callers, so compatibility still requires review.
A carefully designed definer-rights routine may perform permitted work without giving its caller general table access. It does not transfer table grants to that caller. Invoker-rights code follows a different privilege model. Choose the rights model and provisioning together, and test using the actual runtime identity.
Static SQL binds protect the separation between values and syntax. Unsafe dynamic SQL inside a procedure remains vulnerable. Input shape and operation authorization also differ: a valid part number does not establish that the caller may change that part. Encapsulation narrows a contract only when the implementation and privileges support it.
The inventory example placed the availability condition in the update itself, validated the quantity, and checked whether a row changed. It used normal database locking and left commit control to the caller. It was not a lock-free or retry-safe order-processing system. Those limits are part of understanding the example, not details to omit when adapting it.
A normal procedure participates in its caller's transaction. An unexpected commit can finalize earlier caller work, while an indiscriminate rollback can undo unrelated pending changes. Decide transaction ownership explicitly. If a response is lost after a possible commit, retrying can duplicate an effect unless the operation has an appropriate idempotency design. Oracle's transaction documentation explains the underlying controls.
Do not equate stored compilation with a permanently fixed SQL plan. Cursor reuse can reduce work, but invalidation and execution context still matter. Client drivers can also bind, cache, and batch. Prefer set-based SQL where it expresses the operation correctly; use procedural batching when justified and test its costs.
Consider a hypothetical order-search operation that slows during busy periods. The example below is a review exercise, not a benchmark or a report of commands executed for this module. Its purpose is to connect responsibilities that are easy to treat separately.
Suppose the evidence instead shows that the application issues one query for every displayed row. Consolidating that request pattern may be more useful than tuning each small query independently. Alternatively, if the main delay is a transaction holding a lock, an access-path change may not address the cause. The process should be able to reject the team's first explanation.
If a stored API is proposed, ask which responsibility it centralizes. It may help coordinate a genuinely shared operation, but wrapping an unchanged inefficient query does not remove the inefficiency. Review the interface, privilege model, and transaction behavior alongside the performance proposal.
A good change record lets another engineer understand both the result and its limits. Include the SQL or API revision, workload description, relevant environment, expected results, and before-and-after measurements. Keep sensitive values protected while retaining enough representative information to reproduce the issue.
Document what was not established. A development test may not reproduce production concurrency. A cached plan may lack runtime row-source statistics. An explained plan may be useful without demonstrating observed execution time. Naming these limits is more useful than treating every available output as proof of the same thing.
Keep correctness tests predictable and performance tests appropriately controlled. Result values, required ordering, and privilege checks should have clear expected outcomes. Timing varies with conditions, so define tolerances and investigate sustained changes rather than treating one noisy sample as a complete diagnosis.
Consider the cost outside the target request. An index changes maintenance work, a materialized intermediate result needs lifecycle management, and a more aggressive resource setting can affect other sessions. Preserve rollback information and assign someone to review the outcome after deployment. Tuning remains an operational responsibility after the code review ends.
You should now be able to explain these distinctions without relying on a particular tool interface:
If one distinction is unclear, return to the linked lesson and its example before attempting the assessment. In particular, review the conditional-update procedure's transaction boundary and the difference between predicted and executed plans. These ideas recur when interpreting more detailed plan output.
Use the quiz to check your understanding of SQL responsibilities, standards, developer collaboration, and stored database interfaces.
The next module introduces the EXPLAIN PLAN utility in more detail. Carry forward the same discipline: identify the operation, understand what the plan represents, and connect its operations to evidence. A plan is a structured explanation to investigate, not a substitute for result validation or workload measurement.