Enabling the Pivotal Query Optimizer

To enable Pivotal Query Optimizer, you set Greenplum Database server configuration parameters.
Note: You can disable the ability to enable or disable the Pivotal Query Optimizer with the server configuration parameter optimizer_control. For information about the server configuration parameters, see the Greenplum Database Reference Guide.
Important: If you intend to execute queries on partitioned tables with the Pivotal Query Optimizer enabled, you must collect statistics on the partitioned table root partition with the ANALYZE ROOTPARTITION command. The command ANALYZE ROOTPARTITION collects statistics on the root partition of a partitioned table without collecting statistics on the leaf partitions. If you specify a list of column names for a partitioned table, the statistics for the columns and the root partition are collected. For information on the ANALYZE command, see the Greenplum Database Reference Guide.

You can also use the Greenplum Database utility analyzedb to update table statistics. The Greenplum Database utility analyzedb can update statistics for multiple tables in parallel. The utility can also check table statistics and update statistics only if the statistics are not current or do not exist. For information about the analyzedb utility, see the Greenplum Database Utility Guide.

As part of routine database maintenance, Pivotal recommends refreshing statistics on the root partition when there are significant changes to child leaf partition data.

Setting the optimizer_analyze_root_partition Parameter

When the configuration parameter optimizer_analyze_root_partition is set to on, root partition statistics will be collected when ANALYZE is run on a partitioned table. Root partition statistics are required by the Pivotal Query Optimizer.

  1. Log into the Greenplum Database master host as gpadmin, the Greenplum Database administrator.
  2. Set the values of the server configuration parameters. These Greenplum Database gpconfig utility commands sets the value of the parameters to on:
    $ gpconfig -c optimizer_analyze_root_partition -v on --masteronly
  3. Restart Greenplum Database. This Greenplum Database gpstop utility command reloads the postgresql.conf files of the master and segments without shutting down Greenplum Database.
    gpstop -u

Enabling the Pivotal Query Optimizer for a System

Set the server configuration parameter optimizer for the Greenplum Database system.

  1. Log into the Greenplum Database master host as gpadmin, the Greenplum Database administrator.
  2. Set the values of the server configuration parameters. These Greenplum Database gpconfig utility commands sets the value of the parameters to on:
    $ gpconfig -c optimizer -v on --masteronly
  3. Restart Greenplum Database. This Greenplum Database gpstop utility command reloads the postgresql.conf files of the master and segments without shutting down Greenplum Database.
    gpstop -u

Enabling the Pivotal Query Optimizer for a Database

Set the server configuration parameter optimizer for individual Greenplum databases with the ALTER DATABASE command. For example, this command enables Pivotal Query Optimizer for the database test_db.
> ALTER DATABASE test_db SET OPTIMIZER = ON ;

Enabling the Pivotal Query Optimizer for a Session or a Query

You can use the SET command to set optimizer server configuration parameter for a session. For example, after you use the psql utility to connect to Greenplum Database, this SET command enables the Pivotal Query Optimizer:
> set optimizer on ;

To set the parameter for a specific query, include the SET command prior to running the query.