How to properly use the Executor interface?

From: Kai Kratz <kai(dot)kratz(at)swarm64(dot)com>
To: PostgreSQL-development <pgsql-hackers(at)postgresql(dot)org>
Subject: How to properly use the Executor interface?
Date: 2018-10-31 17:30:59
Message-ID: FRAPR01MB08526F1FFAC32C954AE8288AF6CD0@FRAPR01MB0852.DEUPRD01.PROD.OUTLOOK.DE
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

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/

Responses

Browse pgsql-hackers by date

  From Date Subject
Next Message Robert Haas 2018-10-31 17:45:27 Re: Speeding up INSERTs and UPDATEs to partitioned tables
Previous Message Robert Haas 2018-10-31 17:30:52 Re: Is there way to detect uncommitted 'new table' in pg_class?