PostgreSQL parallel queries using SPI possible?

189 Views Asked by At

I am using PostgreSQL's Server Programming Interface (SPI) to build my postgres extension and execute my query. Please see this detailed example, or the following simple code sample:

int ret = SPI_exec("SELECT * FROM ....", 0);

We know that PostgreSQL has parallel query support feature, where a query is executed in parallel using multiple processors. Since the SPI interface hides quite some complexity (communication/locks/cursors/etc), I was wondering whether executing a query in this way limits this parallel query feature in some way or not? Obviously, if it does indeed pose a limit, then maybe it is not worth making use of.

1

There are 1 best solutions below

0
jjanes On

The specific usage in your example does not inhibit parallelism, as can be seen by running SELECT execq('select count(*) from pgbench_accounts', 0); and observing the plan via auto_explain. (I had run pgbench -i -s20, so there 2e6 rows).

Other SPI method, like those involving cursors, will inhibit parallelization.