SPI Concurrency Precautions?

From: Tom Mercha <mercha_t(at)hotmail(dot)com>
To: "pgsql-hackers(at)postgresql(dot)org" <pgsql-hackers(at)postgresql(dot)org>
Subject: SPI Concurrency Precautions?
Date: 2020-02-17 20:24:43
Message-ID: DB7PR05MB508322D30B743D57A9E77771F4160@DB7PR05MB5083.eurprd05.prod.outlook.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

Dear Hackers

I've been working on an extension and using SPI to execute some queries.
I am in a situation where I have the option to issue multiple queries
concurrently, ideally under same snapshot and transaction. In short, I
am achieving this by creating multiple dynamic background workers, each
one of them executing a query at the same time using
SPI_execute(sql_string, ...). To be more precise, sometimes I am also
opting to issue a 'CREATE TABLE AS <sql_query>' command, an SPI utility
command.

I was however wondering whether I can indeed achieve concurrency in this
way. My initial results are not showing much difference compared to a
not concurrent implementation. If there would be a large lock somewhere
in SPI implementation obviously this can be counterintuitive. What would
be the precautions I would need to consider when working with SPI in
this manner?

Thanks,
Tom

Responses

Browse pgsql-hackers by date

  From Date Subject
Next Message Alvaro Herrera 2020-02-17 21:56:41 pg_trigger.tgparentid
Previous Message Daniel Verite 2020-02-17 19:14:03 Re: Unicode normalization SQL functions