Sunday, November 29, 2026

Oracle Database Performance: Avoiding Unnecessary Table Scans

Oracle Database Performance: Avoiding Unnecessary Table Scans

One of the common recommendations in database performance tuning is to avoid full table scans on large tables.

However, there is an important distinction:

A Full Table Scan (TABLE ACCESS FULL) is not necessarily a performance problem. An inefficient access path is.

The objective of SQL tuning should not be to eliminate table scans, but to ensure that the optimizer chooses the most efficient access path based on the query, data distribution, available indexes, and system workload.

1. When Can a Table Scan Become a Problem?

A table scan reads all relevant table blocks, regardless of how many rows ultimately satisfy the query predicate.

For example, consider a PRODUCT table containing millions of rows:

CREATE TABLE product (

    sku         CHAR(6)       NOT NULL,

    type        CHAR(1)       NOT NULL,

    name        VARCHAR2(50)  NOT NULL,

    description VARCHAR2(200)

);

CREATE UNIQUE INDEX i1 ON product(sku);

CREATE INDEX i2 ON product(name);

CREATE INDEX i3 ON product(type);

Consider the following query:

SELECT * FROM product WHERE sku = 'a12345';

Because SKU is uniquely indexed, Oracle can efficiently locate the required row using an index access path, typically an INDEX UNIQUE SCAN followed by TABLE ACCESS BY INDEX ROWID.

This is an excellent example of a highly selective predicate.

2. An Index Does Not Automatically Guarantee Good Performance

Consider:

SELECT * FROM product WHERE sku > 'abc';

Although SKU is indexed, this condition might match a significant percentage of the table.

If the optimizer estimates that many rows will be returned, a Full Table Scan may be cheaper than accessing the index and subsequently retrieving table blocks through ROWIDs.

Remember: Index availability does not mean index usage is always desirable.

3. Leading Wildcards and Index Access

Consider:

SELECT * ROM product WHERE description LIKE '%shoes%';

A conventional B-tree index on DESCRIPTION generally cannot support an efficient range scan for this predicate because the search pattern starts with a wildcard.

Compare it with:

SELECT * FROM product WHERE name LIKE 'stereo%';

A conventional B-tree index may be usable for this prefix search, subject to data types, collation, and optimizer conditions.

However, for substring searches, alternative approaches such as Oracle Text indexes may be more appropriate, depending on the search requirements.

4. Use Partitioning to Reduce the Amount of Data Scanned

For very large tables, indexing is not the only solution. Partitioning can significantly reduce the amount of data Oracle needs to access.

Oracle Partitioning divides a large logical table into smaller, manageable physical segments based on a partitioning key.

For example, consider a transaction table containing several years of banking transactions.

CREATE TABLE transactions (

    transaction_id NUMBER,

    transaction_date DATE,

    account_id NUMBER,

    amount NUMBER

)

PARTITION BY RANGE (transaction_date)

INTERVAL (NUMTOYMINTERVAL(1, 'MONTH'))

(

    PARTITION p_initial

    VALUES LESS THAN (DATE '2025-01-01')

);

Now consider:

SELECT * FROM transactions WHERE transaction_date >= DATE '2026-01-01'

  AND transaction_date <  DATE '2026-02-01';

Instead of scanning the entire table, Oracle can use Partition Pruning to eliminate partitions that cannot contain matching rows.

Benefits include:

  • Reduced I/O by accessing only relevant partitions.
  • Improved query performance for partition-key predicates.
  • Easier data lifecycle management, including archival and purging.
  • Better manageability of large tables.
  • Support for partition-level maintenance operations.

Important: Partitioning does not automatically eliminate Full Table Scans. Oracle may still perform a Full Table Scan, but only on the relevant partition or partitions.

Also, partitioning is not a replacement for indexing. Depending on the workload, local or global indexes may complement partitioning.

5. What Should We Consider Before Blaming TABLE ACCESS FULL?

When investigating a Full Table Scan, consider these factors:

• Table Size: Scanning a small table can be cheaper than using an index.

• Selectivity: How many rows are expected to satisfy the predicate?

• Clustering Factor: How efficiently are table rows physically organized relative to index key order?

• Data Distribution: Are optimizer statistics and histograms representative of the actual data?

• Selected Columns: Does the query require most of the table's rows or columns?

• Multiblock I/O: Full Table Scans can benefit from multiblock reads and efficient sequential I/O.

• System Workload: Oracle's optimizer considers factors such as system statistics and the relative costs of CPU and I/O.

6. Practical Performance Tuning Recommendation

Instead of blindly forcing index access with hints, investigate the actual execution plan and runtime statistics.

For example:

SELECT * FROM product WHERE sku = 'a12345';

SELECT *FROM TABLE (DBMS_XPLAN.DISPLAY_CURSOR (NULL, NULL, 'ALLSTATS LAST +PREDICATE’));

 

Pay attention to:

  • E-Rows vs. A-Rows (estimated vs. actual rows).
  • Buffers (logical reads).
  • Physical reads.
  • Predicate information.
  • Access paths and execution time.

7. Use Oracle SQL Access Advisor

Beyond manual SQL tuning and execution plan analysis, Oracle provides SQL Access Advisor, which helps identify opportunities to improve SQL workload performance through appropriate access structures.

SQL Access Advisor analyzes a representative SQL workload and can recommend:

  • Creating or modifying indexes.
  • Implementing partitioning strategies.
  • Using materialized views where appropriate.
  • Improving existing access structures based on workload characteristics.

 The advisor provides the following advantages:

  • Does not require you to have expert knowledge
  • Makes decisions based on rules that reside in the optimizer
  • Covers all aspects of SQL access in a single advisor
  • Provides simple, user-friendly GUI wizards in Cloud Control
  • Generates scripts for implementation of recommendations

 

Rather than creating indexes based on individual queries, SQL Access Advisor considers the broader workload to help identify access structures that can provide performance benefits.

This is particularly useful in environments with large tables, complex SQL workloads, and recurring queries where selecting the right combination of indexes and partitioning strategies can make a significant difference.

The advisor can recommend that you create database objects such as the following:

  • Indexes

SQL Access Advisor index recommendations include bitmap, function-based, and B-tree indexes. A bitmap index offers a reduced response time for many types of ad hoc queries and reduced storage requirements compared to other indexing techniques. B-tree indexes are most commonly used in a data warehouse to index unique or near-unique keys. SQL Access Advisor materialized view recommendations include fast refreshable and full refreshable materialized views, for either general rewrite or exact text match rewrite.

  • Materialized views

SQL Access Advisor, using the TUNE_MVIEW procedure, also recommends how to optimize materialized views so that they can be fast refreshable and take advantage of general query rewrite.

  • Materialized view logs

A materialized view log is a table at the materialized view's primary site or primary materialized view site that records all DML changes to the primary table or primary materialized view. A fast refresh of a materialized view is possible only if the materialized view's primary has a materialized view log.

  • Partitions

SQL Access Advisor can recommend partitioning on an existing unpartitioned base table to improve performance. Furthermore, it may recommend new indexes and materialized views that are themselves partitioned.

While creating new partitioned indexes and materialized view is no different from the unpartitioned case, partition existing base tables with care. This is especially true when indexes, views, constraints, or triggers are defined on the table.

To make recommendations, SQL Access Advisor relies on structural statistics about table and index cardinalities of dimension level columns, JOIN KEY columns, and fact table key columns. You can gather exact or estimated statistics with the DBMS_STATS package.

8. Using partial Index

In Oracle Database, partial indexes work in two distinct ways depending on whether your table is partitioned or non-partitioned:

  1. Native Partial Indexes (Partitioned Tables Only): Introduced in Oracle 12c, this allows you to index only specific partitions of a table.
  2. Simulated Partial Indexes (Any Table): Because Oracle does not natively support a CREATE INDEX ... WHERE clause (unlike PostgreSQL or SQL Server), you simulate row-level partial indexes using Function-Based Indexes or Virtual Columns.

 

8.1. Native Partial Indexes (For Partitioned Tables)

If you have a partitioned table (e.g., partitioned by date), you often only want to index recent, active partitions while leaving historical partitions unindexed to save storage and reduce DML overhead.

  • Step 1: Set the indexing property on table partitions. You can set INDEXING OFF for partitions you want to exclude (the default is ON).

CREATE TABLE sales (

    sale_id NUMBER,

    sale_date DATE,

    amount NUMBER

)

PARTITION BY RANGE (sale_date) (

    PARTITION p_2025 VALUES LESS THAN (DATE '2026-01-01') INDEXING OFF,

    PARTITION p_2026 VALUES LESS THAN (DATE '2027-01-01') INDEXING ON

);

  • Step 2: Create the index with INDEXING PARTIAL. This works for both local and global indexes.

CREATE INDEX idx_sales_amount ON sales(amount) LOCAL INDEXING PARTIAL;

Result: Oracle builds usable index segments only for p_2026 and marks p_2025 as UNUSABLE (consuming zero space).

8.2. Row-Level Partial Indexes (For Non-Partitioned Tables)

To index a specific subset of rows (e.g., WHERE status = 'PENDING'), you exploit a core Oracle behavior: standard B-tree indexes do not store entries where all indexed columns evaluate to NULL.

Method A: Function-Based Index

Use a CASE expression inside the CREATE INDEX statement so that unwanted rows evaluate to NULL:

CREATE INDEX idx_orders_pending ON orders (

    CASE WHEN status = 'PENDING' THEN order_id ELSE NULL END);

  • Crucial Caveat: To use this index, your query's WHERE clause must match the exact CASE expression:

SELECT * FROM orders

WHERE (CASE WHEN status = 'PENDING' THEN order_id ELSE NULL END) = 105;

Method B: Virtual Column (Cleaner for Queries)

Instead of repeating complex CASE logic in every query, define the condition once on the table:

ALTER TABLE orders ADD (

    pending_order_id GENERATED ALWAYS AS (

        CASE WHEN status = 'PENDING' THEN order_id ELSE NULL END

    ) VIRTUAL

);

CREATE INDEX idx_orders_pending ON orders(pending_order_id);

You can then query the virtual column directly (WHERE pending_order_id = 105), and the index will only contain rows where status = 'PENDING'.

 

Enforcing Conditional Uniqueness

This technique is frequently used to enforce unique constraints on a subset of rows (for example, ensuring a user can only have one active order at a time, while allowing multiple completed orders):

CREATE UNIQUE INDEX uq_one_active_order ON orders (

    CASE WHEN status = 'ACTIVE' THEN customer_id ELSE NULL END

);

 

Quick Comparison

Approach

Scope

Use Case

Query Impact

INDEXING PARTIAL

Partition-level

Skipping old/archive partitions

Transparent to queries

Function-Based Index

Row-level

Indexing rare statuses or conditional uniqueness

Requires matching expression in WHERE

Virtual Column + Index

Row-level

Same as above, with cleaner SQL

Query the virtual column name directly

Tips to considering partial index:

  • Whether your table is partitioned or non-partitioned
  • Your filtering condition (e.g., specific status or date range)
  • Whether you need a unique constraint or just faster lookups

 

Final Thought

A well-designed database does not necessarily have zero Full Table Scans.

It has execution plans where the chosen access path is appropriate for the workload.

Ø  The real tuning question is not: "Why is Oracle performing a Full Table Scan?"

It is:

Ø  "Given the table size, selectivity, data distribution, and workload, is a Full Table Scan actually more expensive than the available alternatives?"

And some tips:

LIKE '%value%': A conventional B-tree index generally cannot provide a normal index range scan for this predicate. Oracle Text is worth considering for genuine text-search workloads.

Selectivity is not the only factor: Clustering factor, table block count, multiblock read characteristics, and the cost of accessing table rows can make a Full Table Scan preferable.

Don't use INDEX hints as a default solution: Forcing index access can actually increase logical reads and degrade performance.

Use SQL Patch or Oracle SPM to modify/ tune execution plan in some scenario.

Use Extended statistics and check histograms to achieve better plan.

*****************************

What is your approach when you encounter TABLE ACCESS FULL on a large Oracle table?

 

References:

https://docs.oracle.com/en/database/oracle/oracle-database/26/tgsql/optimizer-access-paths.html

https://docs.oracle.com/en/database/oracle/oracle-database/21/tgsql/sql-access-advisor.html

https://docs.oracle.com/en/database/oracle/oracle-database/19/sqlrf/CREATE-INDEX.html

 

 

 

 

 


Saturday, November 28, 2026

Oracle Database I/O Performance Tuning for Write-Intensive Workloads - Part3

Oracle Database I/O Performance Tuning for Write-Intensive Workloads

n  Part III

6. Oracle ASM Storage Architecture

6.1. Disk Group Design

ASM provides striping and mirroring across disks within a disk group.

A typical architecture may use:

  • +DATA for database data files.
  • +RECO for recovery-related files.
  • Separate storage resources for redo logs where justified by measured contention and supported by the storage architecture.

However, creating separate disk groups does not necessarily mean that the underlying physical disks or storage controllers are independent.

If two ASM disk groups are backed by the same SAN pool or physical storage devices, separating them logically may not eliminate the actual I/O bottleneck.

Before redesigning disk groups, identify:

  1. Which database files generate the highest I/O.
  2. Whether the bottleneck is read or write latency.
  3. Whether the storage array is saturated.
  4. Whether redo and data-file I/O compete for the same resources.
  5. Whether the workload is limited by IOPS, bandwidth, or latency.

Oracle's I/O configuration guidance emphasizes investigating high-I/O files before segregating storage. Also consider optimum physical block size such as 4k for redo logs or using more disk spindles for applications with huge redo generation rate. Also considering better redundancy architecture in ASM layer…

6.2. ASM Redundancy

ASM supports several redundancy models.

Redundancy

Protection

Typical use

External

No ASM mirroring

Storage already provides suitable redundancy

Normal

Two-way mirroring

General-purpose deployments

High

Three-way mirroring

Environments requiring additional protection

Flex

Flexible file-level redundancy

Architectures requiring flexible protection policies

 

The correct choice depends on the underlying storage architecture, failure domains, and availability requirements.

Do not switch from Normal to External redundancy merely to improve I/O performance.

That decision changes the data protection architecture and should be made only after reviewing the storage redundancy and failure scenarios.

6.3. ASM Striping

ASM supports Fine and Coarse striping.

These settings influence how ASM distributes file data across disks.

However, the original recommendation to configure Fine striping for redo logs and Coarse striping for all data files is too simplistic.

ASM file templates and file-type defaults should generally be retained unless a specific requirement justifies changing them.

In Oracle ASM, most file types use Coarse striping by default, while some file types, such as control files, use Fine striping by default.

6.4. ASM AU_SIZE

The AU size is determined when creating a disk group.

For Oracle Database 19c, the standard default for external, normal, and high redundancy disk groups is 1 MB, while Flex disk groups default to 4 MB.

Larger AU sizes can be useful in specific environments, especially when large sequential I/O workloads justify them.

However:

  • Larger AU does not automatically improve write throughput.
  • AU size is not a substitute for proper storage striping.
  • It should not be changed based solely on the OLTP or DWH classification.
  • Existing disk groups should not be redesigned without a clear architectural reason.

6.5. Evaluate and load testing using Oracle Orion – Storage I/O Calibration

Oracle Orion is a storage benchmarking tool designed to simulate Oracle Database I/O workloads without requiring an installed or running database.

It can simulate storage workloads similar to those generated by Oracle databases, including ASM striping behavior.

Orion can measure:

  • IOPS.
  • MB/s throughput.
  • I/O latency.
  • Performance under different queue depths.
  • Random and sequential I/O performance.
  • Small and large I/O behavior.

Supported workload patterns

Workload

Description

Typical use case

Small Random

Small random I/O

OLTP

Large Random

Large random I/O

Mixed workloads

Large Sequential

Sequential I/O streams

DWH, backups

Mixed read/write

Configurable read/write ratio

Write-intensive workloads

 Mandatory parameters:

 run Type of workload to run (simple, normal, advanced, dss, oltp).

   simple - Tests random small (8K) IOs at various loads, then random large (1M) IOs at various loads.

   normal - Tests combinations of random small (8K) IOs and random large (1M) IOs.

   advanced - Tests the workload specified by the user using optional parameters.

   dss - Tests with random large (1M) IOs at increasing loads to determine the maximum throughput.

   oltp - Tests with random small (8K) IOs at increasing loads to determine the maximum IOPS.

 

[root@kamrani bin]# cd /u01/app/oracle/product/19.19.0/dbhome_1/bin/

[root@kamrani bin]# ./orion -run advanced -type rand -size_small 8 -size_large 128 -num_disks 1 -num_small 1 -num_large 1 -matrix max -testname pop -hugenotneeded -cache_size 2000

ORION: ORacle IO Numbers -- Version RDBMS_19.3.0.0.0DBRU_LINUX.X64_190417

pop_20261117_0813

Calibration will take approximately 5 minutes.

Using a large value for -cache_size may take longer.

Setting ftype=0

Maximum Large MBPS=18.09 @ Small=1 and Large=1

Maximum Small IOPS=206 @ Small=1 and Large=1

Small Read Latency: avg=4842.555 us, min=66.113 us, max=37056.596 us, std dev=3212.132 us @ Small=1 and Large=1

Minimum Small Latency=4842.555 usecs @ Small=1 and Large=1

Small Read Latency: avg=4842.555 us, min=66.113 us, max=37056.596 us, std dev=3212.132 us @ Small=1 and Large=1

Small Read / Write Latency Histogram @ Small=1 and Large=1

        Latency:                         # of IOs (read)          # of IOs (write)

        0 - 64         us:                     0 (  0.00%)                 0 (  0.00%)

       64 - 128        us:                 13 (  0.10%)                0 (  0.00%)

      128 - 256        us:                15 (  0.23%)                0 (  0.00%)

      256 - 512        us:                391 (  3.38%)              0 (  0.00%)

      512 - 1024       us:               169 (  4.75%)              0 (  0.00%)

     1024 - 2048       us:              1231 ( 14.69%)           0 (  0.00%)

     2048 - 4096       us:              3641 ( 44.08%)           0 (  0.00%)

     4096 - 8192       us:               5892 ( 91.65%)          0 (  0.00%)

     8192 - 16384      us:             888 ( 98.82%)            0 (  0.00%)

    16384 - 32768      us:             142 ( 99.97%)            0 (  0.00%)

    32768 - 65536      us:              4 (100.00%)              0 (  0.00%)

    65536 - 268435456  us:         0 (100.00%)              0 (  0.00%)

[root@kamrani bin]#

 

Important for your ASM storage testing

I recommend:

  1. Start with -run oltp to establish an OLTP-oriented storage baseline.
  2. Use -run advanced to investigate specific random I/O sizes and concurrency levels.
  3. Compare latency, IOPS, and throughput rather than looking only at maximum IOPS.
  4. Correlate Orion results with actual ASM and database workload measurements.

One important safety warning: Orion tests can overwrite data on the LUNs configured in its input file. Never run write tests against active production ASM disks. Use dedicated disposable test LUNs.

How can you safely test ASM storage?

My recommendation:

  1. Provision a separate test LUN from the same storage system.
  2. Ensure it has comparable characteristics (multipathing, storage tier, cache policy and RAID configuration).
  3. Do not add this LUN to a production ASM disk group.
  4. Configure Orion to use only this dedicated test LUN.
  5. Run read-only and write tests separately.

One more important detail: Orion's.lun input file must reference the actual test device paths. Do not assume that specifying -num_disks 1 protects the first production disk or automatically selects a safe device.

6.6. SLOB – Simulating Real Oracle Database Workloads (https://github.com/therealkevinc/SLOB_2.5.4)

Unlike Orion, SLOB generates workloads through an actual Oracle Database.

It is designed to stress Oracle database I/O and evaluate how the database and storage infrastructure behave under concurrent workloads.

SLOB is an excellent tool for testing I/O performance as seen by Oracle.  Unlike Swingbench which mimics a real application and therefore spends much of its execution cycle on the server CPU, SLOB concentrates exclusively on generating I/O from the Oracle stack.

Note: SLOB installs against an Oracle database.  It does not install against a pluggable database.

SLOB possesses the following characteristics:

  1. SLOB supports testing Oracle logical read (SGA buffer gets) scaling
  2. SLOB supports testing physical random single-block reads (db file sequential read)
  3. SLOB supports testing random single block writes (DBWR flushing capacity)
  4. SLOB supports testing extreme REDO logging I/O
  5. SLOB consists of simple PL/SQL
  6. SLOB is entirely free of all application contention

SLOB is particularly useful for evaluating:

  • Random read workloads.
  • Random read/write workloads.
  • Concurrent UPDATE operations.
  • Storage scalability.
  • Buffer cache pressure.
  • I/O latency under concurrent database sessions.

To more info about SLOB usage visit: https://kevinclosson.net

 

The discussion continues in the next part….

 

References and further reading

Ø  Oracle 19c – Managing Operating System Resources.

https://docs.oracle.com/en/database/oracle/oracle-database/19/tgdba/managing-operating-system-resources.html

Ø  Oracle 19c – I/O Configuration and Design.

https://docs.oracle.com/en/database/oracle/oracle-database/19/tgdba/IO-configuration-and-design.html

Ø  Oracle 19c – ASM Storage Requirements and AU Size.

https://docs.oracle.com/en/database/oracle/oracle-database/19/cwhpx/identifying-storage-requirements-for-oracle-automatic-storage-management.html

Ø  Oracle 19c – Administering ASM Disk Groups.

https://docs.oracle.com/en/database/oracle/oracle-database/19/ostmg/part-ii-oracle-asm-instances-and-disk-groups/administering-oracle-asm-disk-groups.html

Ø  Oracle Database – COMMIT_WAIT.

https://docs.oracle.com/en/database/oracle/oracle-database/26/refrn/COMMIT_WAIT.html

Ø  Oracle Database – COMMIT Statement.

https://docs.oracle.com/en/database/oracle/oracle-database/19/sqlrf/COMMIT.html

Ø  Red Hat – Factors Affecting I/O and Filesystem Performance.

https://docs.redhat.com/en/documentation/red_hat_enterprise_linux/8/html/monitoring_and_managing_system_status_and_performance/factors-affecting-i-o-and-file-system-performance_monitoring-and-managing-system-status-and-performance

Ø  Red Hat – Setting the Disk Scheduler.

https://docs.redhat.com/en/documentation/red_hat_enterprise_linux/8/pdf/managing_storage_devices/discarding-unused-blocks_managing-storage-devices

Ø  Red Hat – Discarding Unused Blocks.

https://access.redhat.com/documentation/en-us/red_hat_enterprise_linux/8/pdf/managing_storage_devices/managing-storage-devices.pdf

Ø  GitHub Kevin:    https://github.com/therealkevinc , https://kevinclosson.net

 

Ø  Oracle Memory Architecture: https://docs.oracle.com/en/database/oracle/oracle-database/21/cncpt/memory-architecture.html

Ø  Oracle 26ai – Using Parallel Execution: https://docs.oracle.com/en/database/oracle/oracle-database/26/vldbg/using-parallel.html

Ø  https://tanelpoder.com/2013/11/27/when-do-oracle-parallel-execution-slaves-issue-buffered-physical-reads-part-1/

Ø  https://docs.oracle.com/en/database/oracle/oracle-database/19/refrn/DB_BIG_TABLE_CACHE_PERCENT_TARGET.html

 

Part 1: https://database-box.blogspot.com/2026/11/oracle-database-io-performance-tuning.html

Part 2: https://database-box.blogspot.com/2026/11/oracle-database-io-performance-tuning_01361558103.html

*****************Alireza Kamrani**********************

Oracle Database Performance: Avoiding Unnecessary Table Scans

Oracle Database Performance: Avoiding Unnecessary Table Scans One of the common recommendations in database performance tuning is to avoid...