Help Center/ GaussDB/ Developer Guide(Centralized_8.x)/ FAQ/ How do I create indexes in parallel?
Updated on 2024-06-03 GMT+08:00

How do I create indexes in parallel?

Answer: Refer to the following method:

-- Set maintenance_work_mem based on the actual situation.
gaussdb=#SET maintenance_work_mem = '8GB';

-- Create a table.
gaussdb=#CREATE TABLE table_name (col1 int, col2 int);

-- Change the number of threads for creating indexes for a table based on the actual situation.
gaussdb=#ALTER TABLE table_name SET (parallel_workers=4);

-- Create an index.
gaussdb=#CREATE INDEX index_name ON table_name(col1);

-- Reset the parallel_workers parameter for the table.
gaussdb=#ALTER TABLE table_name RESET (parallel_workers);

-- Delete the index.
DROP INDEX index_name;

-- Drop the table.
gaussdb=#DROP TABLE table_name;