Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit44468f4

Browse files
committed
Add test scaffolding for exercising optimizer's predicate-proof logic.
The predicate-proof code in predtest.c is a bit hard to test as-is:you have to construct a query whose plan changes depending on the successof a test, and in tests that have been around for awhile, it's alwayspossible that the plan shape is now being determined by some other factor.Our existing regression tests aren't doing real well at providing fullcode coverage of predtest.c, either. So, let's add a small test modulethat allows directly inspecting the results of predicate_implied_by()and predicate_refuted_by() for arbitrary boolean expressions.I chose the set of tests committed here in order to get reasonablycomplete code coverage of predtest.c just from running this testmodule, and to cover some cases called out as being interesting inthe existing comments. We might want to add more later. But thisset already shows a few cases where perhaps things could be improved.Indeed, this exercise proves that predicate_refuted_by() is buggy forthe case of clause_is_check = true, though fortunately we aren't usingthat case anywhere yet. I'll look into doing something about that ina separate commit. For now, just memorialize the current behavior.Discussion:https://postgr.es/m/5983.1520487191@sss.pgh.pa.us
1 parent04e7eca commit44468f4

File tree

9 files changed

+1356
-0
lines changed

9 files changed

+1356
-0
lines changed

‎src/test/modules/Makefile

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ SUBDIRS = \
1313
test_extensions\
1414
test_parser\
1515
test_pg_dump\
16+
test_predtest\
1617
test_rbtree\
1718
test_rls_hooks\
1819
test_shm_mq\
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
# Generated subdirectories
2+
/log/
3+
/results/
4+
/tmp_check/
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
# src/test/modules/test_predtest/Makefile
2+
3+
MODULE_big = test_predtest
4+
OBJS = test_predtest.o$(WIN32RES)
5+
PGFILEDESC = "test_predtest - test code for optimizer/util/predtest.c"
6+
7+
EXTENSION = test_predtest
8+
DATA = test_predtest--1.0.sql
9+
10+
REGRESS = test_predtest
11+
12+
ifdefUSE_PGXS
13+
PG_CONFIG = pg_config
14+
PGXS :=$(shell$(PG_CONFIG) --pgxs)
15+
include$(PGXS)
16+
else
17+
subdir = src/test/modules/test_predtest
18+
top_builddir = ../../../..
19+
include$(top_builddir)/src/Makefile.global
20+
include$(top_srcdir)/contrib/contrib-global.mk
21+
endif

‎src/test/modules/test_predtest/README

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
test_predtest is a module for checking the correctness of the optimizer's
2+
predicate-proof logic, in src/backend/optimizer/util/predtest.c.
3+
4+
The module provides a function that allows direct application of
5+
predtest.c's exposed functions, predicate_implied_by() and
6+
predicate_refuted_by(), to arbitrary boolean expressions, with direct
7+
inspection of the results. This could be done indirectly by checking
8+
planner results, but it can be difficult to construct end-to-end test
9+
cases that prove that the expected results were obtained.
10+
11+
In general, the use of this function is like
12+
select * from test_predtest('query string')
13+
where the query string must be a SELECT returning two boolean
14+
columns, for example
15+
16+
select * from test_predtest($$
17+
select x, not x
18+
from (values (false), (true), (null)) as v(x)
19+
$$);
20+
21+
The function parses and plans the given query, and then applies the
22+
predtest.c code to the two boolean expressions in the SELECT list, to see
23+
if the first expression can be proven or refuted by the second. It also
24+
executes the query, and checks the resulting rows to see whether any
25+
claimed implication or refutation relationship actually holds. If the
26+
query is designed to exercise the expressions on a full set of possible
27+
input values, as in the example above, then this provides a mechanical
28+
cross-check as to whether the proof code has given a correct answer.

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp