diff --git a/src/backend/parser/analyze.c b/src/backend/parser/analyze.c index ca8e9201f7..7adf0d0975 100644 --- a/src/backend/parser/analyze.c +++ b/src/backend/parser/analyze.c @@ -3004,6 +3004,12 @@ transformExplainStmt(ParseState *pstate, ExplainStmt *stmt) setup_parse_variable_parameters(pstate, ¶mTypes, &numParams); } + if (IsA(stmt->query, SelectStmt)) + { + SelectStmt *sel_stmt = (SelectStmt *) stmt->query; + sel_stmt->location = stmt->location; + } + /* transform contained query, allowing SELECT INTO */ stmt->query = (Node *) transformOptionalSelectInto(pstate, stmt->query); diff --git a/src/backend/parser/gram.y b/src/backend/parser/gram.y index 5a800f1e6b..7f6793f226 100644 --- a/src/backend/parser/gram.y +++ b/src/backend/parser/gram.y @@ -11978,6 +11978,7 @@ ExplainStmt: ExplainStmt *n = makeNode(ExplainStmt); n->query = $2; + n->location = @2; n->options = NIL;; $$ = (Node *) n; } @@ -11986,6 +11987,7 @@ ExplainStmt: ExplainStmt *n = makeNode(ExplainStmt); n->query = $4; + n->location = @4; n->options = list_make1(makeDefElem("analyze", NULL, @2)); if ($3) n->options = lappend(n->options, @@ -11997,6 +11999,7 @@ ExplainStmt: ExplainStmt *n = makeNode(ExplainStmt); n->query = $3; + n->location = @3; n->options = list_make1(makeDefElem("verbose", NULL, @2)); $$ = (Node *) n; } @@ -12005,6 +12008,7 @@ ExplainStmt: ExplainStmt *n = makeNode(ExplainStmt); n->query = $5; + n->location = @5; n->options = $3; $$ = (Node *) n; } diff --git a/src/include/nodes/parsenodes.h b/src/include/nodes/parsenodes.h index aa73e2b242..d30869595e 100644 --- a/src/include/nodes/parsenodes.h +++ b/src/include/nodes/parsenodes.h @@ -3893,6 +3893,7 @@ typedef struct ExplainStmt NodeTag type; Node *query; /* the query (see comments above) */ List *options; /* list of DefElem nodes */ + ParseLoc location; /* location of the statement being explained */ } ExplainStmt; /* ----------------------