How to properly use the Executor interface?

Started by Kai Kratzover 7 years ago2 messageshackers
Jump to latest
#1Kai Kratz
kai.kratz@swarm64.com

Hi Hackers,

first time writing to the hackers list, so I hope this is the right place to ask. I recently joined Swarm64 and we are building a postgres extension with the fdw interface.

I am trying to evaluate sql statements with ExecutorBeing, -Run, -End, -Finish calls during ExecForeignInsert. I set up a QueryDesc and call ExecutorStart during BeginForeignModify and store the QueryDesc in the fdwState to call ExecutorRun / Rewind on each ExecForeignInsert. On EndForeignModify ExecutorFinish and ExecutorEnd are called. The statement is used to generate an additional column generated from the value of one ore more present columns, e.g. hashing a string.

I am now not really sure if I am abusing the interface and if this is save to be used in such a way. I noticed there are hooks for Start, Run, End and Finish and I am unsure what requirements this places on my usage.

Initially I tried to keep the started Executor around beyond the lifetime of a query and only clean up when the worker process shuts down. This did not end well (as in SIGSEGV) as soon as I loaded auto_explain which tried to report on the 'slow query' outside of a portal.

Give the comments in execMain.c I am also wondering what cleanup I need to do in case the insert fails after ExecutorStart.

Cheers
--
Kai Kratz
Swarm64: https://swarm64.com/

#2Tom Lane
tgl@sss.pgh.pa.us
In reply to: Kai Kratz (#1)
Re: How to properly use the Executor interface?

Kai Kratz <kai.kratz@swarm64.com> writes:

first time writing to the hackers list, so I hope this is the right place to ask. I recently joined Swarm64 and we are building a postgres extension with the fdw interface.

I am trying to evaluate sql statements with ExecutorBeing, -Run, -End, -Finish calls during ExecForeignInsert.

This seems ... uh ... really bizarre. Why would you want an FDW to push
actions back into the executor? I'm having a hard time envisioning
use-cases that wouldn't be better handled by, say, updatable views.

Anyway, you might be better off to go through SPI rather than try to call
the executor directly. It's better documented and we try to avoid
breaking those APIs, whereas the core executor APIs change regularly.

regards, tom lane