SPI refactoring

From: Mark Dilger <hornschnorter(at)gmail(dot)com>
To: PostgreSQL-development <pgsql-hackers(at)postgresql(dot)org>
Subject: SPI refactoring
Date: 2019-11-07 23:38:51
Message-ID: cc57ea5c-592a-6c27-aca6-7ad2a166c379@gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

Hackers,

As discussed with Tom in [1] and again with Pavel and Alvaro in [2],
here is a partial WIP refactoring of the SPI interface. The goal is to
remove as many of the SPI_ERROR_xxx codes as possible from the
interface, replacing them with elog(ERROR), without removing the ability
of callers to check meaningful return codes and make their own decisions
about what to do next. The crucial point here is that many of the error
codes in SPI are "can't happen" or "you made a programmatic mistake"
type errors that don't require run time remediation, but rather require
fixing the C code and recompiling. Those seem better handled as an
elog(ERROR) to avoid the need for tests against such error codes
sprinkled throughout the system.

One upshot of the refactoring is that some of the SPI functions that
previously returned an error code can be changed to return void. Tom
suggested a nice way to use macros to provide backward compatibility
with older third-party software, and I used his suggestion.

I need guidance with SPI_ERROR_ARGUMENT because it is used by functions
that don't return an integer error code, but rather return a SPIPlanPtr,
such as SPI_prepare. Those functions return NULL and set a global
variable named SPI_result to the error code. I'd be happy to just
convert this to throwing an error, too, but it is a greater API break
than anything implemented in the attached patches so far. How do others
feel about it?

If more places like this can be converted to use elog(ERROR), it may be
possible to convert more functions to return void.

[1] https://www.postgresql.org/message-id/13404.1558558354%40sss.pgh.pa.us

[2]
https://www.postgresql.org/message-id/20191106151112.GA12251%40alvherre.pgsql
--
Mark Dilger

Attachment Content-Type Size
v1-0001-Deprecating-unused-SPI-error-codes.patch text/x-patch 4.2 KB
v1-0002-Changing-SPI_connect-and-SPI_connect_ext-to-retur.patch text/x-patch 13.1 KB
v1-0003-Refactoring-SPI-trigger-related-errors.patch text/x-patch 4.4 KB
v1-0004-Refactoring-SPI-execute-related-errors.patch text/x-patch 3.2 KB
v1-0005-Refactoring-SPI-related-errors.patch text/x-patch 2.7 KB

Responses

Browse pgsql-hackers by date

  From Date Subject
Next Message Andres Freund 2019-11-07 23:41:04 Re: log bind parameter values on error
Previous Message Mark Dilger 2019-11-07 22:28:24 Re: TestLib::command_fails_like enhancement