Conversation
checkCanOptSelectLockingClause scans a raw WHERE tree before deciding
whether to use the row-locking optimization. An EXISTS SubLink has a
NULL testexpr, which the raw walker passes to queryNodeSearch. The
callback dereferenced that NULL with IsA(node, Query), crashing during
parse analysis. It also stopped on the first non-query child instead of
recursing through the raw tree.
Handle NULL nodes, recurse through raw expressions, and stop once a
SubLink or Query is found. Add an isolation case with GDD enabled and
the Postgres optimizer selected.
Reproducer as the non-superuser role sqlscan:
SELECT * FROM pg_catalog.pg_class WHERE EXISTS (SELECT 1) FOR NO KEY UPDATE;
Verbatim client output before the fix:
server closed the connection unexpectedly
This probably means the server terminated abnormally
before or while processing the request.
connection to server was lost
GDB used a preceding SELECT pg_sleep(15) on the same connection so it
could attach before parsing the reproducer.
Verbatim backend log:
2026-12-01 22:48:37.317462 MSK,,,p3042112,th123456,,,2026-12-01 22:48:22 MSK,0,,cmd3,seg-1,,,,,"PANIC","XX000","Unexpected internal error: Segment process received signal SIGSEGV",,,,,,,0,,,,"1 0x55ce71184387 postgres StandardHandlerForSigillSigsegvSigbus_OnMainThread + 0x177
2 0x7f78c1bb9330 libc.so.6 <symbol not found> + 0xc1bb9330
3 0x55ce70c57b14 postgres <symbol not found> + 0x70c57b14
4 0x55ce70e12666 postgres raw_expression_tree_walker_impl + 0xc6
5 0x55ce70c58c9d postgres checkCanOptSelectLockingClause + 0x9d
6 0x55ce70c5c19b postgres transformTopLevelStmt + 0x7b
7 0x55ce70c5c2b1 postgres parse_analyze_fixedparams + 0x51
8 0x55ce70ff269e postgres pg_analyze_and_rewrite_fixedparams + 0x1e
9 0x55ce70ff3393 postgres exec_simple_query + 0x943
10 0x55ce70ff7934 postgres PostgresMain + 0x1ef4
11 0x55ce70f436f4 postgres <symbol not found> + 0x70f436f4
12 0x55ce70f4495a postgres PostmasterMain + 0xf8a
13 0x55ce70b045e8 postgres main + 0x5d8
14 0x7f78c1b9e1ca libc.so.6 <symbol not found> + 0xc1b9e1ca
15 0x7f78c1b9e28b libc.so.6 __libc_start_main + 0x8b
16 0x55ce70b06865 postgres _start + 0x25
"
GDB backtrace:
Breakpoint 1, 0x000055ce70c58c00 in checkCanOptSelectLockingClause ()
#0 0x000055ce70c58c00 in checkCanOptSelectLockingClause ()
#1 0x000055ce70c5c19b in transformTopLevelStmt ()
#2 0x000055ce70c5c2b1 in parse_analyze_fixedparams ()
#3 0x000055ce70ff269e in pg_analyze_and_rewrite_fixedparams ()
#4 0x000055ce70ff3393 in exec_simple_query ()
#5 0x000055ce70ff7934 in PostgresMain ()
#6 0x000055ce70f436f4 in ServerLoop.isra.0 ()
apache#7 0x000055ce70f4495a in PostmasterMain ()
Program received signal SIGSEGV, Segmentation fault.
0x000055ce70c57b14 in queryNodeSearch ()
#0 0x000055ce70c57b14 in queryNodeSearch ()
#1 0x000055ce70e12666 in raw_expression_tree_walker_impl ()
#2 0x000055ce70c58c9d in checkCanOptSelectLockingClause ()
#3 0x000055ce70c5c19b in transformTopLevelStmt ()
#4 0x000055ce70c5c2b1 in parse_analyze_fixedparams ()
#5 0x000055ce70ff269e in pg_analyze_and_rewrite_fixedparams ()
#6 0x000055ce70ff3393 in exec_simple_query ()
apache#7 0x000055ce70ff7934 in PostgresMain ()
apache#8 0x000055ce70f436f4 in ServerLoop.isra.0 ()
apache#9 0x000055ce70f4495a in PostmasterMain ()
#10 0x000055ce70b045e8 in main ()
[Inferior 1 (process 3042112) detached]
Contributor
|
PTAL issues found by claude:
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
checkCanOptSelectLockingClause scans a raw WHERE tree before deciding whether to use the row-locking optimization. An EXISTS SubLink has a NULL testexpr, which the raw walker passes to queryNodeSearch. The callback dereferenced that NULL with IsA(node, Query), crashing during parse analysis. It also stopped on the first non-query child instead of recursing through the raw tree.
Handle NULL nodes, recurse through raw expressions, and stop once a SubLink or Query is found. Add an isolation case with GDD enabled and the Postgres optimizer selected.
Reproducer as the non-superuser role sqlscan:
Verbatim client output before the fix:
GDB used a preceding SELECT pg_sleep(15) on the same connection so it could attach before parsing the reproducer.
Verbatim backend log:
2026-12-01 22:48:37.317462 MSK,,,p3042112,th123456,,,2026-12-01 22:48:22 MSK,0,,cmd3,seg-1,,,,,"PANIC","XX000","Unexpected internal error: Segment process received signal SIGSEGV",,,,,,,0,,,,"1 0x55ce71184387 postgres StandardHandlerForSigillSigsegvSigbus_OnMainThread + 0x177
2 0x7f78c1bb9330 libc.so.6 + 0xc1bb9330
3 0x55ce70c57b14 postgres + 0x70c57b14
4 0x55ce70e12666 postgres raw_expression_tree_walker_impl + 0xc6
5 0x55ce70c58c9d postgres checkCanOptSelectLockingClause + 0x9d
6 0x55ce70c5c19b postgres transformTopLevelStmt + 0x7b
7 0x55ce70c5c2b1 postgres parse_analyze_fixedparams + 0x51
8 0x55ce70ff269e postgres pg_analyze_and_rewrite_fixedparams + 0x1e
9 0x55ce70ff3393 postgres exec_simple_query + 0x943
10 0x55ce70ff7934 postgres PostgresMain + 0x1ef4
11 0x55ce70f436f4 postgres + 0x70f436f4
12 0x55ce70f4495a postgres PostmasterMain + 0xf8a
13 0x55ce70b045e8 postgres main + 0x5d8
14 0x7f78c1b9e1ca libc.so.6 + 0xc1b9e1ca
15 0x7f78c1b9e28b libc.so.6 __libc_start_main + 0x8b
16 0x55ce70b06865 postgres _start + 0x25
"
GDB backtrace:
Breakpoint 1, 0x000055ce70c58c00 in checkCanOptSelectLockingClause () #0 0x000055ce70c58c00 in checkCanOptSelectLockingClause () #1 0x000055ce70c5c19b in transformTopLevelStmt () #2 0x000055ce70c5c2b1 in parse_analyze_fixedparams () #3 0x000055ce70ff269e in pg_analyze_and_rewrite_fixedparams () #4 0x000055ce70ff3393 in exec_simple_query ()
#5 0x000055ce70ff7934 in PostgresMain ()
#6 0x000055ce70f436f4 in ServerLoop.isra.0 ()
#7 0x000055ce70f4495a in PostmasterMain ()
Program received signal SIGSEGV, Segmentation fault. 0x000055ce70c57b14 in queryNodeSearch ()
#0 0x000055ce70c57b14 in queryNodeSearch ()
#1 0x000055ce70e12666 in raw_expression_tree_walker_impl () #2 0x000055ce70c58c9d in checkCanOptSelectLockingClause () #3 0x000055ce70c5c19b in transformTopLevelStmt () #4 0x000055ce70c5c2b1 in parse_analyze_fixedparams () #5 0x000055ce70ff269e in pg_analyze_and_rewrite_fixedparams () #6 0x000055ce70ff3393 in exec_simple_query ()
#7 0x000055ce70ff7934 in PostgresMain ()
#8 0x000055ce70f436f4 in ServerLoop.isra.0 ()
#9 0x000055ce70f4495a in PostmasterMain ()
#10 0x000055ce70b045e8 in main ()
[Inferior 1 (process 3042112) detached]
Fixes #ISSUE_Number
What does this PR do?
Type of Change
Breaking Changes
Test Plan
make installcheckmake -C src/test installcheck-cbdb-parallelImpact
Performance:
User-facing changes:
Dependencies:
Checklist
Additional Context