Skip to content

gp_percentile_agg

Ordered-set aggregate support for the Greenplum optimizer

gp_percentile_agg · Ordered-set aggregate support for the Greenplum optimizer

Overview

IDExtensionPackageVersionCategoryLicenseLanguage
102200gp_percentile_agggp_percentile_agg1.0.0FUNCApache-2.0C

Usage

Sources:

gp_percentile_agg supplies aggregates used by Greenplum GPORCA to optimize percentile and median queries. Version 1.0.0 is a Greenplum 6 module; applications normally keep using the built-in ordered-set aggregate syntax.

Core Workflow

CREATE EXTENSION gp_percentile_agg;
SET optimizer_enable_orderedagg = on;
CREATE TABLE measurements (value double precision);
INSERT INTO measurements VALUES (10), (20), (30);
SELECT percentile_cont(0.5) WITHIN GROUP (ORDER BY value)
FROM measurements;

Operational Boundaries

With GPORCA in use, enable optimizer_enable_orderedagg in the query session. The documented optimization requires a direct, noncomputed sort column, a constant scalar fraction rather than an array, and no GROUP BY. This is an eligibility boundary, not a guarantee that every percentile query runs faster.

The module defines gp_percentile_cont overloads for floating-point, interval, timestamp, and timestamp-with-time-zone values, plus polymorphic gp_percentile_disc. These helpers expect sorted input and the total-row and peer-group counts; use the ordinary percentile_cont, percentile_disc, or median interface for application queries.

Register the module as a superuser in each database. Its C library loads on demand without preload configuration. The extension is relocatable. The official guide requires dropping and recreating the module when upgrading an installation that used Greenplum 6.21.x to the corrected implementation in 6.22.0; review dependent objects before such maintenance. No upstream PostgreSQL major compatibility is claimed here.

Table reader