EvanCarroll / pg-srf-repeat-benchmark

A testing repo comparing an SRF that is dually implemented as ValuePerCall and Materialize

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

PostgreSQL Set-Returning-Function (SRF) C-Extension Benchmarks

This repo consists of multiple implementations of a simple SRF that repeats it input.

repeat_implementation( what int4, row_count int4 )

The output of this function is a set of row_count rows of int4 columns that just repeat what.

Implementations

There are three current implementations both with the same signature described above.

Raison d'être

This exists because the doc says,

C-language functions have two options for returning sets (multiple rows). In one method, called ValuePerCall mode, a set-returning function is called repeatedly (passing the same arguments each time) and it returns one new row on each call, until it has no more rows to return and signals that by returning NULL. The set-returning function (SRF) must therefore save enough state across calls to remember what it was doing and return the correct next item on each call. In the other method, called Materialize mode, an SRF fills and returns a tuplestore object containing its entire result; then only one call occurs for the whole result, and no inter-call state is needed.

I asked under which case would the performance of one be greater than the other. There was almost no documentation advising one or the other for performance, so I created this repo to help understand the call-convention overhead of these two methods.

Research

Patches Accepted

Please open up issues if any of these examples can be reduced in complexity or made more performant.

Idiot disclaimer: I really don't have any idea what I'm doing.

About

A testing repo comparing an SRF that is dually implemented as ValuePerCall and Materialize


Languages

Language:C 65.1%Language:Shell 31.7%Language:Makefile 3.2%