Inverse Distribution Functions

From PostgreSQL wiki
Jump to navigationJump to search

Inverse Distribution Functions

Defined in the SQL standard in Section 10.9 <aggregate function>, inverse distribution functions open whole new vistas both of reporting and of implementation challenges.

Vistas of Reporting

  • MEDIAN! YAY!
  • N-tiles (continuous and discrete)
  • Many others.

Implementation Challenges

  • Parser
    • Mostly done. Thanks, Atri Sharma!
    • WITHIN GROUP clause
    • Changes parser functions to work with new type of functions
    • Adds a new type for identification of ordered set functions from function lookup
    • Modifies pg_proc
    • Currently working on type coercion
    • Changes Aggref struct to identify ordered set functions.No new struct for ordered set functions since they share a lot with aggregate functions.
    • Overloaded functions support
  • Planner/Optimizer
    • In progress
    • Really applies atop FILTER, not yet in master.
    • New element in ProcedureCreate
  • Executor
    • New way to do aggregates: transition function now optional.
    • Directly go to final function, skipping transition functions for ordered set functions.