All Products
Search
Document Center

PolarDB:Use Elastic Parallel Query to accelerate index creation

Last Updated:Mar 28, 2026

Creating B-tree indexes on large tables can take significant time, blocking maintenance windows and slowing schema migrations. Elastic Parallel Query (EPQ) parallelizes the heap table scan during index creation, reducing build time to approximately one-fifth of the native serial method.

How it works

Without EPQ, PolarDB for PostgreSQL (Compatible with Oracle) scans the heap table sequentially to build index entries, then constructs the B-tree from those entries.

With EPQ enabled, a query coordinator (QC) process distributes the heap scan across parallel workers. Each worker scans a partition of the table and forwards results to the index-creation process, which assembles the final B-tree.

Limitations

LimitationDetails
Column typesEPQ only accelerates index creation on general columns. Expression columns are not supported.
SyntaxThe CONCURRENTLY and INCLUDE options are not supported with EPQ.

Parameters

Configure the following parameters before creating indexes with EPQ.

ParameterDefaultRecommendedDescription
polar_px_enable_btbuildoffonEnables EPQ-accelerated index creation.
polar_px_dop_per_node18 or 16Degree of parallelism (DOP) per node. Also controls DOP for .
polar_px_enable_replay_wait(auto)Activates automatically for the current session when polar_px_enable_btbuild=on. Ensures the most recent table entries are indexed. Resets to the database default after index creation completes.
polar_bt_write_page_buffer_size04096Controls write I/O behavior during index creation. Unit: block. Maximum: 8192. Setting this to 4096 reduces index creation time by up to 20%.

polar_bt_write_page_buffer_size behavior

  • `0` (default): Flushes index entries to disk block-by-block as each index page fills up.

  • Non-zero value: Buffers index entries in a kernel buffer of the specified size and flushes them all at once when the buffer is full, reducing frequent I/O scheduling overhead.

Create a B-tree index with EPQ

Prerequisites

Before you begin, ensure that you have:

  • A PolarDB for PostgreSQL (Compatible with Oracle) cluster

  • Access to run DDL statements on the target table

Procedure

The following example creates a table named test and builds an index using EPQ.

1. Create the test table.

CREATE TABLE test(id int, id2 int);

Verify the table schema:

\d test

Expected output:

               Table "public.test"
 Column |  Type   | Collation | Nullable | Default
--------+---------+-----------+----------+---------
 id     | integer |           |          |
 id2    | integer |           |          |

2. Enable EPQ-accelerated index creation.

SET polar_px_enable_btbuild=on;

Verify the setting:

SHOW polar_px_enable_btbuild;

Expected output:

 polar_px_enable_btbuild
-------------------------
 on
(1 row)

3. Create the index.

Add WITH (px_build=on) to the CREATE INDEX statement to use EPQ for this build:

CREATE INDEX t ON test(id) WITH(px_build=on);
polar_px_enable_btbuild=on alone does not activate EPQ for a specific index build. You must include WITH (px_build=on) in the CREATE INDEX statement. Without it, PolarDB uses the native (serial) index creation method, and the resulting index shows no px_build annotation.

4. Verify the index was created with EPQ.

\d test

Expected output:

               Table "public.test"
 Column |  Type   | Collation | Nullable | Default
--------+---------+-----------+----------+---------
 id     | integer |           |          |
 id2    | integer |           |          |
Indexes:
    "t" btree (id) WITH (px_build=finish)

The (px_build=finish) field confirms that EPQ was used.

Performance data

EPQ creates indexes for large tables approximately five times faster than the native method.

The following figure compares global index creation performance before and after enabling EPQ, using 130 GB of data.

Performance comparison

What's next