postgresql/src/test/modules/test_predtest
Tom Lane 218527d014 Don't bother checking the result of SPI_connect[_ext] anymore.
SPI_connect/SPI_connect_ext have not returned any value other than
SPI_OK_CONNECT since commit 1833f1a1c in v10; any errors are thrown
via ereport.  (The most likely failure is out-of-memory, which has
always been thrown that way, so callers had better be prepared for
such errors.)  This makes it somewhat pointless to check these
functions' result, and some callers within our code haven't been
bothering; indeed, the only usage example within spi.sgml doesn't
bother.  So it's likely that the omission has propagated into
extensions too.

Hence, let's standardize on not checking, and document the return
value as historical, while not actually changing these functions'
behavior.  (The original proposal was to change their return type
to "void", but that would needlessly break extensions that are
conforming to the old practice.)  This saves a small amount of
boilerplate code in a lot of places.

Stepan Neretin

Discussion: https://postgr.es/m/CAMaYL5Z9Uk8cD9qGz9QaZ2UBJFOu7jFx5Mwbznz-1tBbPDQZow@mail.gmail.com
2024-09-09 12:18:34 -04:00
..
expected Teach optimizer's predtest.c more things about ScalarArrayOpExpr. 2019-03-01 17:14:17 -05:00
sql Teach optimizer's predtest.c more things about ScalarArrayOpExpr. 2019-03-01 17:14:17 -05:00
.gitignore Add test scaffolding for exercising optimizer's predicate-proof logic. 2018-03-08 13:25:26 -05:00
Makefile Split all OBJS style lines in makefiles into one-line-per-entry style. 2019-11-05 14:41:07 -08:00
meson.build Update copyright for 2024 2024-01-03 20:49:05 -05:00
README Add test scaffolding for exercising optimizer's predicate-proof logic. 2018-03-08 13:25:26 -05:00
test_predtest--1.0.sql Add test scaffolding for exercising optimizer's predicate-proof logic. 2018-03-08 13:25:26 -05:00
test_predtest.c Don't bother checking the result of SPI_connect[_ext] anymore. 2024-09-09 12:18:34 -04:00
test_predtest.control Add test scaffolding for exercising optimizer's predicate-proof logic. 2018-03-08 13:25:26 -05:00

test_predtest is a module for checking the correctness of the optimizer's
predicate-proof logic, in src/backend/optimizer/util/predtest.c.

The module provides a function that allows direct application of
predtest.c's exposed functions, predicate_implied_by() and
predicate_refuted_by(), to arbitrary boolean expressions, with direct
inspection of the results.  This could be done indirectly by checking
planner results, but it can be difficult to construct end-to-end test
cases that prove that the expected results were obtained.

In general, the use of this function is like
	select * from test_predtest('query string')
where the query string must be a SELECT returning two boolean
columns, for example

	select * from test_predtest($$
	select x, not x
	from (values (false), (true), (null)) as v(x)
	$$);

The function parses and plans the given query, and then applies the
predtest.c code to the two boolean expressions in the SELECT list, to see
if the first expression can be proven or refuted by the second.  It also
executes the query, and checks the resulting rows to see whether any
claimed implication or refutation relationship actually holds.  If the
query is designed to exercise the expressions on a full set of possible
input values, as in the example above, then this provides a mechanical
cross-check as to whether the proof code has given a correct answer.