postgres.git / summary / log / commit / refs

commit    2ff289d03939498a656a0c6cf2da08623f8357b4
Author:   Peter Eisentraut <peter@eisentraut.org>
Date:     Fri Apr 24 06:18:21 2026 +0000

    Check for stack overflow when rewriting graph queries
    
    generate_queries_for_path_pattern_recurse() and
    generate_setop_from_pathqueries() are recursive functions.  For a
    property graph with hundreds of tables, a graph pattern with a handful
    element patterns can cause stack overflow.  Fix it by calling
    check_stack_depth() at the beginning of these functions.
    
    Author: Satyanarayana Narlapuram <satyanarlapuram@gmail.com>
    Reviewed-by: Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
    Discussion: https://www.postgresql.org/message-id/CAHg+QDfgK0xddH8f3eAb+UVn7sBDOnv8RvM6OkP4HtHAt6aD7w@mail.gmail.com


src/backend/rewrite/rewriteGraphTable.c | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/src/backend/rewrite/rewriteGraphTable.c b/src/backend/rewrite/rewriteGraphTable.c index 3519ea3beae..3aac29f5840 100644 --- a/src/backend/rewrite/rewriteGraphTable.c +++ b/src/backend/rewrite/rewriteGraphTable.c @@ -23,6 +23,7 @@ #include "catalog/pg_propgraph_label.h" #include "catalog/pg_propgraph_label_property.h" #include "catalog/pg_propgraph_property.h" +#include "miscadmin.h" #include "nodes/makefuncs.h" #include "nodes/nodeFuncs.h" #include "optimizer/optimizer.h" @@ -361,6 +362,9 @@ generate_queries_for_path_pattern_recurse(RangeTblEntry *rte, List *pathqueries, { List *path_elems = list_nth_node(List, path_elem_lists, elempos); + /* Guard against stack overflow due to complex path patterns. */ + check_stack_depth(); + foreach_ptr(struct path_element, pe, path_elems) { /* Update current path being built with current element. */ @@ -698,6 +702,9 @@ generate_setop_from_pathqueries(List *pathqueries, List **rtable, List **targetl List *rtargetlist; ParseNamespaceItem *pni; + /* Guard against stack overflow due to many path queries. */ + check_stack_depth(); + /* Recursion termination condition. */ if (list_length(pathqueries) == 0) { [parent: 863c4b827d92]