Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.94.2) (envelope-from ) id 1uOroQ-00CfwN-Tc for pgsql-bugs@arkaria.postgresql.org; Tue, 10 Jun 2025 05:46:19 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.94.2) (envelope-from ) id 1uOroN-000BfL-6J for pgsql-bugs@arkaria.postgresql.org; Tue, 10 Jun 2025 05:46:15 +0000 Received: from magus.postgresql.org ([2a02:c0:301:0:ffff::29]) by malur.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.94.2) (envelope-from ) id 1uOroM-000BfC-Ih for pgsql-bugs@lists.postgresql.org; Tue, 10 Jun 2025 05:46:15 +0000 Received: from fout-a8-smtp.messagingengine.com ([103.168.172.151]) by magus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.96) (envelope-from ) id 1uOroK-001BAx-1e for pgsql-bugs@lists.postgresql.org; Tue, 10 Jun 2025 05:46:14 +0000 Received: from phl-compute-04.internal (phl-compute-04.phl.internal [10.202.2.44]) by mailfout.phl.internal (Postfix) with ESMTP id EE494138034C; Tue, 10 Jun 2025 01:46:09 -0400 (EDT) Received: from phl-mailfrontend-02 ([10.202.2.163]) by phl-compute-04.internal (MEProxy); Tue, 10 Jun 2025 01:46:09 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=paquier.xyz; h= cc:cc:content-type:content-type:date:date:from:from:in-reply-to :in-reply-to:message-id:mime-version:references:reply-to:subject :subject:to:to; s=fm1; t=1749534369; x=1749620769; bh=P53eE6ognJ buLHxoxo94ECunRGt1MmdqGfcHXJ3g+MU=; b=dY3zky1msAsFH8WNbqajkzQmTp WYaxN+kt4MZKu/dxsUunge4xAgP9ZVV84aXBMzdsc3TkQutmv8Pmu/l54OZgHmOT HI7POp2eZ6SgkxQEjI19IdD/g3au2WfrNEFtl/VKIln8mDUg50wqqbuDIeonbs1s sgX17f2H5ns1obZBWdZqt1b55IWKvFAGqDnyXg8BAyE3flQUW79q2O8jxT++VGTv x7Szmyj0D2vd9F1I7YNmWFFyS/qU+U1Lr4yoIfiHMt/xw7LDptEFjsU5c/lxanYY xJoOwfkZwMXxpJWp2HXzzQw7aKb3a2wttNrEdZs/giPbw/mZShcT3CItlNWw== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=cc:cc:content-type:content-type:date:date :feedback-id:feedback-id:from:from:in-reply-to:in-reply-to :message-id:mime-version:references:reply-to:subject:subject:to :to:x-me-proxy:x-me-sender:x-me-sender:x-sasl-enc; s=fm1; t= 1749534369; x=1749620769; bh=P53eE6ognJbuLHxoxo94ECunRGt1MmdqGfc HXJ3g+MU=; b=BusjQDO+CgvO/SA3JBKR9r9kVbKg0pe30dqr31bslDZ3YhEZLj3 u/uht5tpLAw2w5hJIb55wTBSzNUq7CouJCxaYBB+20ecJGqL1iUvZuZYrJdS8oK1 fFzcRw4SzKgkC4Mqgr7gZ5ln4rCMI5ikTou3m6dqeVKjbhGRIB9ZoSHAZBGAxXzN uQEyb+lvOa3Kh1kwf4jcloHGUKDPRoAfySQH4DibH+MfVkt3l1dh2e72vtkaSF2w MSwjOrPYzfut9HVDqRmS8YdobDHUrW/Z/nPAW3o0GeB7JRVeLm2Rj3dcF/xikdLi y4I4LpkmrRIBpbgm4Nm+eLtMLbsnWKtiOgQ== X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgeeffedrtddugddutdeffecutefuodetggdotefrod ftvfcurfhrohhfihhlvgemucfhrghsthforghilhdpggftfghnshhusghstghrihgsvgdp uffrtefokffrpgfnqfghnecuuegrihhlohhuthemuceftddtnecusecvtfgvtghiphhivg hnthhsucdlqddutddtmdenfghrlhcuvffnffculdejtddmnecujfgurhepfffhvfevuffk fhggtggujgesghdtreertddtudenucfhrhhomhepofhitghhrggvlhcurfgrqhhuihgvrh cuoehmihgthhgrvghlsehprghquhhivghrrdighiiiqeenucggtffrrghtthgvrhhnpefg heehgfdufedugfefleegieffgeefhfekfeffvdehfedutdehteegleetveekteenucevlh hushhtvghrufhiiigvpedtnecurfgrrhgrmhepmhgrihhlfhhrohhmpehmihgthhgrvghl sehprghquhhivghrrdighiiipdhnsggprhgtphhtthhopeehpdhmohguvgepshhmthhpoh huthdprhgtphhtthhopehmrghsrghordhfuhhjihhisehoshhsrdhnthhtuggrthgrrdgt ohhmpdhrtghpthhtohepughilhhiphgsrghlrghuthesghhmrghilhdrtghomhdprhgtph htthhopegrrdhkohiihhgvmhihrghkihhnsehpohhsthhgrhgvshhprhhordhruhdprhgt phhtthhopehpghhsqhhlqdgsuhhgsheslhhishhtshdrphhoshhtghhrvghsqhhlrdhorh hgpdhrtghpthhtoheprghnthhhohhnihhnrdgsohhnnhgvfhhohiesuggrthgrughoghhh qhdrtghomh X-ME-Proxy: Feedback-ID: i0fe9450f:Fastmail Received: by mail.messagingengine.com (Postfix) with ESMTPA; Tue, 10 Jun 2025 01:46:06 -0400 (EDT) Date: Tue, 10 Jun 2025 14:45:59 +0900 From: Michael Paquier To: Fujii Masao Cc: Dilip Kumar , a.kozhemyakin@postgrespro.ru, pgsql-bugs@lists.postgresql.org, Anthonin Bonnefoy Subject: Re: BUG #18947: TRAP: failed Assert("len_to_wrt >= 0") in pg_stat_statements Message-ID: References: <18947-cdd2668beffe02bf@postgresql.org> <9171ecda-e1f4-4390-ae54-98bc441b98e3@oss.nttdata.com> MIME-Version: 1.0 Content-Type: multipart/signed; micalg=pgp-sha512; protocol="application/pgp-signature"; boundary="1GmVvqWla5uSctnU" Content-Disposition: inline In-Reply-To: <9171ecda-e1f4-4390-ae54-98bc441b98e3@oss.nttdata.com> List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk --1GmVvqWla5uSctnU Content-Type: multipart/mixed; boundary="jDjG+LBZXN/tCVph" Content-Disposition: inline --jDjG+LBZXN/tCVph Content-Type: text/plain; charset=iso-8859-1 Content-Disposition: inline Content-Transfer-Encoding: quoted-printable On Mon, Jun 09, 2025 at 07:07:42PM +0900, Fujii Masao wrote: > Shouldn't this part be skipped in cases where the SELECT with parens is > followed by a clause? At least in those cases, this logic doesn't seem > appropriate. Touch=E9. That means messing with any parent Node that includes or touches select_with_parens, select_no_parens (JSON_ARRAY has one) or SelectStmt (few of these, like in CTAS). That's not cool in the long term because we would expect any new node that englobes a SelectStmt to be able to set up their inner length and location as they should, as far as I get it. I was wondering first if we could have done something with the top-level statement depending on the nesting level of PGSS, but that's not going to fly high, for example with cases like this one (any case that has an inner SELECT): copy ((select 1) union ((select 1)) fetch first 1 row only) to stdout=20 Even with that in mind, a second thing I was wondering is to compile the length within select_with_parens, still there seems to be an extra parenthesis pending at the end of some of the strings. Perhaps I'm missing a simpler concept, of course. Anyway, this is the second bug that we have in this area, and this one is worse. Now that we are in the middle of beta, this is gathering the signs that we should revert the change from the tree for the moment and potentially revisit the whole in v19 with these edge cases handled. So attached is a patch doing a revert of: 499edb09741b, nested statement tracking. 06450c7b8c70, follow-up fix for 499edb09741b. There was also 6b652e6ce85a for the addition of query ID for CREATE TABLE AS and DECLARE, and this is still OK as a standalone change. Its tests are updated with an extra entry added in the non-top-level case, with the query string matching the top-level string as a result of the attached. If you have comments, feel free. -- Michael --jDjG+LBZXN/tCVph Content-Type: text/x-diff; charset=us-ascii Content-Disposition: attachment; filename="0001-Revert-support-for-improved-tracking-of-nested-queri.patch" Content-Transfer-Encoding: quoted-printable =46rom ada21d07b45307efedcc20f83a153daa5368641d Mon Sep 17 00:00:00 2001 =46rom: Michael Paquier Date: Tue, 10 Jun 2025 14:32:16 +0900 Subject: [PATCH] Revert support for improved tracking of nested queries This commit reverts the two following commits: 499edb09741b, track more precisely query locations for nested statements 06450c7b8c70, a follow-up fix of 499edb09741b with query locations. These are proved to have issues with the tracking of SELECT statements, when these use multiple parenthesis which is something supported by the grammar. Incorrect location and lengths are causing pg_stat_statements to become confused, failing its job in query normalization with out-of-bound writes. --- src/include/nodes/parsenodes.h | 10 - src/include/parser/parse_node.h | 16 -- src/backend/parser/analyze.c | 90 +------ src/backend/parser/gram.y | 80 +----- .../expected/pg_overexplain.out | 12 +- .../expected/level_tracking.out | 233 +++++++----------- .../pg_stat_statements/expected/planning.out | 10 +- .../pg_stat_statements/expected/select.out | 2 +- .../pg_stat_statements/expected/utility.out | 2 +- .../pg_stat_statements/sql/level_tracking.sql | 26 -- contrib/pg_stat_statements/sql/planning.sql | 4 +- 11 files changed, 119 insertions(+), 366 deletions(-) diff --git a/src/include/nodes/parsenodes.h b/src/include/nodes/parsenodes.h index dd00ab420b8a..0c1120beff3c 100644 --- a/src/include/nodes/parsenodes.h +++ b/src/include/nodes/parsenodes.h @@ -2100,8 +2100,6 @@ typedef struct InsertStmt ReturningClause *returningClause; /* RETURNING clause */ WithClause *withClause; /* WITH clause */ OverridingKind override; /* OVERRIDING clause */ - ParseLoc stmt_location; /* start location, or -1 if unknown */ - ParseLoc stmt_len; /* length in bytes; 0 means "rest of string" */ } InsertStmt; =20 /* ---------------------- @@ -2116,8 +2114,6 @@ typedef struct DeleteStmt Node *whereClause; /* qualifications */ ReturningClause *returningClause; /* RETURNING clause */ WithClause *withClause; /* WITH clause */ - ParseLoc stmt_location; /* start location, or -1 if unknown */ - ParseLoc stmt_len; /* length in bytes; 0 means "rest of string" */ } DeleteStmt; =20 /* ---------------------- @@ -2133,8 +2129,6 @@ typedef struct UpdateStmt List *fromClause; /* optional from clause for more tables */ ReturningClause *returningClause; /* RETURNING clause */ WithClause *withClause; /* WITH clause */ - ParseLoc stmt_location; /* start location, or -1 if unknown */ - ParseLoc stmt_len; /* length in bytes; 0 means "rest of string" */ } UpdateStmt; =20 /* ---------------------- @@ -2150,8 +2144,6 @@ typedef struct MergeStmt List *mergeWhenClauses; /* list of MergeWhenClause(es) */ ReturningClause *returningClause; /* RETURNING clause */ WithClause *withClause; /* WITH clause */ - ParseLoc stmt_location; /* start location, or -1 if unknown */ - ParseLoc stmt_len; /* length in bytes; 0 means "rest of string" */ } MergeStmt; =20 /* ---------------------- @@ -2221,8 +2213,6 @@ typedef struct SelectStmt bool all; /* ALL specified? */ struct SelectStmt *larg; /* left child */ struct SelectStmt *rarg; /* right child */ - ParseLoc stmt_location; /* start location, or -1 if unknown */ - ParseLoc stmt_len; /* length in bytes; 0 means "rest of string" */ /* Eventually add fields for CORRESPONDING spec here */ } SelectStmt; =20 diff --git a/src/include/parser/parse_node.h b/src/include/parser/parse_nod= e.h index 994284019fbb..f7d07c845425 100644 --- a/src/include/parser/parse_node.h +++ b/src/include/parser/parse_node.h @@ -108,20 +108,6 @@ typedef Node *(*CoerceParamHook) (ParseState *pstate, = Param *param, * byte-wise locations in parse structures to character-wise cursor * positions.) * - * p_stmt_location: location of the top level RawStmt's start. During - * transformation, the Query's location will be set to the statement's - * location if available. Otherwise, the RawStmt's start location will - * be used. Propagating the location through ParseState is needed for - * the Query length calculation (see p_stmt_len below). - * - * p_stmt_len: length of the top level RawStmt. Most of the time, the - * statement's length is not provided by the parser, with the exception - * of SelectStmt within parentheses and PreparableStmt in COPY. If the - * statement's location is provided by the parser, the top-level location - * and length are needed to accurately compute the Query's length. If the - * statement's location is not provided, the RawStmt's length can be used - * directly. - * * p_rtable: list of RTEs that will become the rangetable of the query. * Note that neither relname nor refname of these entries are necessarily * unique; searching the rtable by name is a bad idea. @@ -207,8 +193,6 @@ struct ParseState { ParseState *parentParseState; /* stack link */ const char *p_sourcetext; /* source text, or NULL if not available */ - ParseLoc p_stmt_location; /* start location, or -1 if unknown */ - ParseLoc p_stmt_len; /* length in bytes; 0 means "rest of string" */ List *p_rtable; /* range table so far */ List *p_rteperminfos; /* list of RTEPermissionInfo nodes for each * RTE_RELATION entry in rtable */ diff --git a/src/backend/parser/analyze.c b/src/backend/parser/analyze.c index a16fdd65601d..34f7c17f576e 100644 --- a/src/backend/parser/analyze.c +++ b/src/backend/parser/analyze.c @@ -238,103 +238,24 @@ parse_sub_analyze(Node *parseTree, ParseState *paren= tParseState, return query; } =20 -/* - * setQueryLocationAndLength - * Set query's location and length from statement and ParseState - * - * Some statements, like PreparableStmt, can be located within parentheses. - * For example "(SELECT 1)" or "COPY (UPDATE ...) to x;". For those, we - * cannot use the whole string from the statement's location or the SQL - * string would yield incorrectly. The parser will set stmt_len, reflecti= ng - * the size of the statement within the parentheses. Thus, when stmt_len = is - * available, we need to use it for the Query's stmt_len. - * - * For other cases, the parser can't provide the length of individual - * statements. However, we have the statement's location plus the length - * (p_stmt_len) and location (p_stmt_location) of the top level RawStmt, - * stored in pstate. Thus, the statement's length is the RawStmt's length - * minus how much we've advanced in the RawStmt's string. If p_stmt_len - * is 0, the SQL string is used up to its end. - */ -static void -setQueryLocationAndLength(ParseState *pstate, Query *qry, Node *parseTree) -{ - ParseLoc stmt_len =3D 0; - - switch (nodeTag(parseTree)) - { - case T_InsertStmt: - qry->stmt_location =3D ((InsertStmt *) parseTree)->stmt_location; - stmt_len =3D ((InsertStmt *) parseTree)->stmt_len; - break; - - case T_DeleteStmt: - qry->stmt_location =3D ((DeleteStmt *) parseTree)->stmt_location; - stmt_len =3D ((DeleteStmt *) parseTree)->stmt_len; - break; - - case T_UpdateStmt: - qry->stmt_location =3D ((UpdateStmt *) parseTree)->stmt_location; - stmt_len =3D ((UpdateStmt *) parseTree)->stmt_len; - break; - - case T_MergeStmt: - qry->stmt_location =3D ((MergeStmt *) parseTree)->stmt_location; - stmt_len =3D ((MergeStmt *) parseTree)->stmt_len; - break; - - case T_SelectStmt: - qry->stmt_location =3D ((SelectStmt *) parseTree)->stmt_location; - stmt_len =3D ((SelectStmt *) parseTree)->stmt_len; - break; - - case T_PLAssignStmt: - qry->stmt_location =3D ((PLAssignStmt *) parseTree)->location; - break; - - default: - qry->stmt_location =3D pstate->p_stmt_location; - break; - } - - if (stmt_len > 0) - { - /* Statement's length is known, use it */ - qry->stmt_len =3D stmt_len; - } - else if (pstate->p_stmt_len > 0) - { - /* - * The top RawStmt's length is known, so calculate the statement's - * length from the statement's location and the RawStmt's length and - * location. - */ - qry->stmt_len =3D pstate->p_stmt_len - (qry->stmt_location - pstate->p_s= tmt_location); - } - - /* The calculated statement length should be calculated as positive. */ - Assert(qry->stmt_len >=3D 0); -} - /* * transformTopLevelStmt - * transform a Parse tree into a Query tree. * - * This function is just responsible for storing location data - * from the RawStmt into the ParseState. + * This function is just responsible for transferring statement location d= ata + * from the RawStmt into the finished Query. */ Query * transformTopLevelStmt(ParseState *pstate, RawStmt *parseTree) { Query *result; =20 - /* Store RawStmt's length and location in pstate */ - pstate->p_stmt_len =3D parseTree->stmt_len; - pstate->p_stmt_location =3D parseTree->stmt_location; - /* We're at top level, so allow SELECT INTO */ result =3D transformOptionalSelectInto(pstate, parseTree->stmt); =20 + result->stmt_location =3D parseTree->stmt_location; + result->stmt_len =3D parseTree->stmt_len; + return result; } =20 @@ -503,7 +424,6 @@ transformStmt(ParseState *pstate, Node *parseTree) /* Mark as original query until we learn differently */ result->querySource =3D QSRC_ORIGINAL; result->canSetTag =3D true; - setQueryLocationAndLength(pstate, result, parseTree); =20 return result; } diff --git a/src/backend/parser/gram.y b/src/backend/parser/gram.y index 0b5652071d11..7a9b2ddddecb 100644 --- a/src/backend/parser/gram.y +++ b/src/backend/parser/gram.y @@ -154,7 +154,6 @@ static void base_yyerror(YYLTYPE *yylloc, core_yyscan_t= yyscanner, const char *msg); static RawStmt *makeRawStmt(Node *stmt, int stmt_location); static void updateRawStmtEnd(RawStmt *rs, int end_location); -static void updatePreparableStmtEnd(Node *n, int end_location); static Node *makeColumnRef(char *colname, List *indirection, int location, core_yyscan_t yyscanner); static Node *makeTypeCast(Node *arg, TypeName *typename, int location); @@ -178,7 +177,7 @@ static void insertSelectOptions(SelectStmt *stmt, SelectLimit *limitClause, WithClause *withClause, core_yyscan_t yyscanner); -static Node *makeSetOp(SetOperation op, bool all, Node *larg, Node *rarg, = int location); +static Node *makeSetOp(SetOperation op, bool all, Node *larg, Node *rarg); static Node *doNegate(Node *n, int location); static void doNegateFloat(Float *v); static Node *makeAndExpr(Node *lexpr, Node *rexpr, int location); @@ -3417,7 +3416,6 @@ CopyStmt: COPY opt_binary qualified_name opt_column_l= ist { CopyStmt *n =3D makeNode(CopyStmt); =20 - updatePreparableStmtEnd($3, @4); n->relation =3D NULL; n->query =3D $3; n->attlist =3D NIL; @@ -12240,7 +12238,6 @@ InsertStmt: $5->onConflictClause =3D $6; $5->returningClause =3D $7; $5->withClause =3D $1; - $5->stmt_location =3D @$; $$ =3D (Node *) $5; } ; @@ -12431,7 +12428,6 @@ DeleteStmt: opt_with_clause DELETE_P FROM relation_= expr_opt_alias n->whereClause =3D $6; n->returningClause =3D $7; n->withClause =3D $1; - n->stmt_location =3D @$; $$ =3D (Node *) n; } ; @@ -12506,7 +12502,6 @@ UpdateStmt: opt_with_clause UPDATE relation_expr_op= t_alias n->whereClause =3D $7; n->returningClause =3D $8; n->withClause =3D $1; - n->stmt_location =3D @$; $$ =3D (Node *) n; } ; @@ -12584,7 +12579,6 @@ MergeStmt: m->joinCondition =3D $8; m->mergeWhenClauses =3D $9; m->returningClause =3D $10; - m->stmt_location =3D @$; =20 $$ =3D (Node *) m; } @@ -12825,20 +12819,7 @@ SelectStmt: select_no_parens %prec UMINUS ; =20 select_with_parens: - '(' select_no_parens ')' - { - SelectStmt *n =3D (SelectStmt *) $2; - - /* - * As SelectStmt's location starts at the SELECT keyword, - * we need to track the length of the SelectStmt within - * parentheses to be able to extract the relevant part - * of the query. Without this, the RawStmt's length would - * be used and would include the closing parenthesis. - */ - n->stmt_len =3D @3 - @2; - $$ =3D $2; - } + '(' select_no_parens ')' { $$ =3D $2; } | '(' select_with_parens ')' { $$ =3D $2; } ; =20 @@ -12960,7 +12941,6 @@ simple_select: n->groupDistinct =3D ($7)->distinct; n->havingClause =3D $8; n->windowClause =3D $9; - n->stmt_location =3D @1; $$ =3D (Node *) n; } | SELECT distinct_clause target_list @@ -12978,7 +12958,6 @@ simple_select: n->groupDistinct =3D ($7)->distinct; n->havingClause =3D $8; n->windowClause =3D $9; - n->stmt_location =3D @1; $$ =3D (Node *) n; } | values_clause { $$ =3D $1; } @@ -12999,20 +12978,19 @@ simple_select: =20 n->targetList =3D list_make1(rt); n->fromClause =3D list_make1($2); - n->stmt_location =3D @1; $$ =3D (Node *) n; } | select_clause UNION set_quantifier select_clause { - $$ =3D makeSetOp(SETOP_UNION, $3 =3D=3D SET_QUANTIFIER_ALL, $1, $4, @= 1); + $$ =3D makeSetOp(SETOP_UNION, $3 =3D=3D SET_QUANTIFIER_ALL, $1, $4); } | select_clause INTERSECT set_quantifier select_clause { - $$ =3D makeSetOp(SETOP_INTERSECT, $3 =3D=3D SET_QUANTIFIER_ALL, $1, $= 4, @1); + $$ =3D makeSetOp(SETOP_INTERSECT, $3 =3D=3D SET_QUANTIFIER_ALL, $1, $= 4); } | select_clause EXCEPT set_quantifier select_clause { - $$ =3D makeSetOp(SETOP_EXCEPT, $3 =3D=3D SET_QUANTIFIER_ALL, $1, $4, = @1); + $$ =3D makeSetOp(SETOP_EXCEPT, $3 =3D=3D SET_QUANTIFIER_ALL, $1, $4); } ; =20 @@ -13590,7 +13568,6 @@ values_clause: { SelectStmt *n =3D makeNode(SelectStmt); =20 - n->stmt_location =3D @1; n->valuesLists =3D list_make1($3); $$ =3D (Node *) n; } @@ -18748,47 +18725,6 @@ updateRawStmtEnd(RawStmt *rs, int end_location) rs->stmt_len =3D end_location - rs->stmt_location; } =20 -/* - * Adjust a PreparableStmt to reflect that it doesn't run to the end of the - * string. - */ -static void -updatePreparableStmtEnd(Node *n, int end_location) -{ - if (IsA(n, SelectStmt)) - { - SelectStmt *stmt =3D (SelectStmt *) n; - - stmt->stmt_len =3D end_location - stmt->stmt_location; - } - else if (IsA(n, InsertStmt)) - { - InsertStmt *stmt =3D (InsertStmt *) n; - - stmt->stmt_len =3D end_location - stmt->stmt_location; - } - else if (IsA(n, UpdateStmt)) - { - UpdateStmt *stmt =3D (UpdateStmt *) n; - - stmt->stmt_len =3D end_location - stmt->stmt_location; - } - else if (IsA(n, DeleteStmt)) - { - DeleteStmt *stmt =3D (DeleteStmt *) n; - - stmt->stmt_len =3D end_location - stmt->stmt_location; - } - else if (IsA(n, MergeStmt)) - { - MergeStmt *stmt =3D (MergeStmt *) n; - - stmt->stmt_len =3D end_location - stmt->stmt_location; - } - else - elog(ERROR, "unexpected node type %d", (int) n->type); -} - static Node * makeColumnRef(char *colname, List *indirection, int location, core_yyscan_t yyscanner) @@ -19167,14 +19103,11 @@ insertSelectOptions(SelectStmt *stmt, errmsg("multiple WITH clauses not allowed"), parser_errposition(exprLocation((Node *) withClause)))); stmt->withClause =3D withClause; - - /* Update SelectStmt's location to the start of the WITH clause */ - stmt->stmt_location =3D withClause->location; } } =20 static Node * -makeSetOp(SetOperation op, bool all, Node *larg, Node *rarg, int location) +makeSetOp(SetOperation op, bool all, Node *larg, Node *rarg) { SelectStmt *n =3D makeNode(SelectStmt); =20 @@ -19182,7 +19115,6 @@ makeSetOp(SetOperation op, bool all, Node *larg, No= de *rarg, int location) n->all =3D all; n->larg =3D (SelectStmt *) larg; n->rarg =3D (SelectStmt *) rarg; - n->stmt_location =3D location; return (Node *) n; } =20 diff --git a/contrib/pg_overexplain/expected/pg_overexplain.out b/contrib/p= g_overexplain/expected/pg_overexplain.out index cb5c396c5192..6de02323d7cf 100644 --- a/contrib/pg_overexplain/expected/pg_overexplain.out +++ b/contrib/pg_overexplain/expected/pg_overexplain.out @@ -37,7 +37,7 @@ EXPLAIN (DEBUG) SELECT 1; Subplans Needing Rewind: none Relation OIDs: none Executor Parameter Types: none - Parse Location: 16 for 8 bytes + Parse Location: 0 to end (11 rows) =20 EXPLAIN (RANGE_TABLE) SELECT 1; @@ -119,7 +119,7 @@ $$); Subplans Needing Rewind: none Relation OIDs: NNN... Executor Parameter Types: none - Parse Location: 41 to end + Parse Location: 0 to end RTI 1 (relation, inherited, in-from-clause): Eref: vegetables (id, name, genus) Relation: vegetables @@ -240,7 +240,7 @@ $$); none + NNN... + none + - 53 to end + + 0 to end + + + + @@ -344,7 +344,7 @@ $$); Subplans Needing Rewind: none Relation OIDs: NNN... Executor Parameter Types: none - Parse Location: 28 to end + Parse Location: 0 to end (37 rows) =20 SET debug_parallel_query =3D false; @@ -372,7 +372,7 @@ $$); Subplans Needing Rewind: none Relation OIDs: NNN... Executor Parameter Types: 0 - Parse Location: 28 to end + Parse Location: 0 to end (15 rows) =20 -- Create an index, and then attempt to force a nested loop with inner ind= ex @@ -436,7 +436,7 @@ $$); Subplans Needing Rewind: none Relation OIDs: NNN... Executor Parameter Types: 23 - Parse Location: 75 for 62 bytes + Parse Location: 0 to end (47 rows) =20 RESET enable_hashjoin; diff --git a/contrib/pg_stat_statements/expected/level_tracking.out b/contr= ib/pg_stat_statements/expected/level_tracking.out index 75e785e1719e..f2bd73dc66a1 100644 --- a/contrib/pg_stat_statements/expected/level_tracking.out +++ b/contrib/pg_stat_statements/expected/level_tracking.out @@ -206,37 +206,37 @@ EXPLAIN (COSTS OFF) SELECT 1 UNION SELECT 2; =20 SELECT toplevel, calls, query FROM pg_stat_statements ORDER BY query COLLATE "C"; - toplevel | calls | query = =20 -----------+-------+-------------------------------------------------------= ------------- - f | 1 | DELETE FROM stats_track_tab + toplevel | calls | query = =20 +----------+-------+-------------------------------------------------------= -------------- t | 1 | EXPLAIN (COSTS OFF) (SELECT $1, $2) + f | 1 | EXPLAIN (COSTS OFF) (SELECT $1, $2); t | 1 | EXPLAIN (COSTS OFF) (TABLE test_table) + f | 1 | EXPLAIN (COSTS OFF) (TABLE test_table); t | 1 | EXPLAIN (COSTS OFF) (VALUES ($1, $2)) + f | 1 | EXPLAIN (COSTS OFF) (VALUES ($1, $2)); t | 1 | EXPLAIN (COSTS OFF) DELETE FROM stats_track_tab + f | 1 | EXPLAIN (COSTS OFF) DELETE FROM stats_track_tab; t | 1 | EXPLAIN (COSTS OFF) INSERT INTO stats_track_tab VALUES= (($1)) - t | 1 | EXPLAIN (COSTS OFF) MERGE INTO stats_track_tab = + - | | USING (SELECT id FROM generate_series($1, $2) id) ON= x =3D id + - | | WHEN MATCHED THEN UPDATE SET x =3D id = + + f | 1 | EXPLAIN (COSTS OFF) INSERT INTO stats_track_tab VALUES= (($1)); + t | 1 | EXPLAIN (COSTS OFF) MERGE INTO stats_track_tab = + + | | USING (SELECT id FROM generate_series($1, $2) id) ON= x =3D id + + | | WHEN MATCHED THEN UPDATE SET x =3D id = + | | WHEN NOT MATCHED THEN INSERT (x) VALUES (id) + f | 1 | EXPLAIN (COSTS OFF) MERGE INTO stats_track_tab = + + | | USING (SELECT id FROM generate_series($1, $2) id) ON= x =3D id + + | | WHEN MATCHED THEN UPDATE SET x =3D id = + + | | WHEN NOT MATCHED THEN INSERT (x) VALUES (id); t | 1 | EXPLAIN (COSTS OFF) SELECT $1 t | 1 | EXPLAIN (COSTS OFF) SELECT $1 UNION SELECT $2 + f | 1 | EXPLAIN (COSTS OFF) SELECT $1 UNION SELECT $2; + f | 1 | EXPLAIN (COSTS OFF) SELECT $1; t | 1 | EXPLAIN (COSTS OFF) TABLE stats_track_tab + f | 1 | EXPLAIN (COSTS OFF) TABLE stats_track_tab; t | 1 | EXPLAIN (COSTS OFF) UPDATE stats_track_tab SET x =3D $= 1 WHERE x =3D $2 + f | 1 | EXPLAIN (COSTS OFF) UPDATE stats_track_tab SET x =3D $= 1 WHERE x =3D $2; t | 1 | EXPLAIN (COSTS OFF) VALUES ($1) - f | 1 | INSERT INTO stats_track_tab VALUES (($1)) - f | 1 | MERGE INTO stats_track_tab = + - | | USING (SELECT id FROM generate_series($1, $2) id) ON= x =3D id + - | | WHEN MATCHED THEN UPDATE SET x =3D id = + - | | WHEN NOT MATCHED THEN INSERT (x) VALUES (id) - f | 1 | SELECT $1 - f | 1 | SELECT $1 UNION SELECT $2 - f | 1 | SELECT $1, $2 + f | 1 | EXPLAIN (COSTS OFF) VALUES ($1); t | 1 | SELECT pg_stat_statements_reset() IS NOT NULL AS t - f | 1 | TABLE stats_track_tab - f | 1 | TABLE test_table - f | 1 | UPDATE stats_track_tab SET x =3D $1 WHERE x =3D $2 - f | 1 | VALUES ($1) - f | 1 | VALUES ($1, $2) (23 rows) =20 -- EXPLAIN - top-level tracking. @@ -405,20 +405,20 @@ EXPLAIN (COSTS OFF) SELECT 1, 2 UNION SELECT 3, 4\; E= XPLAIN (COSTS OFF) (SELECT =20 SELECT toplevel, calls, query FROM pg_stat_statements ORDER BY query COLLATE "C"; - toplevel | calls | query = =20 -----------+-------+-------------------------------------------------------= ---------- - f | 1 | (SELECT $1, $2, $3) UNION SELECT $4, $5, $6 + toplevel | calls | = query =20 +----------+-------+-------------------------------------------------------= -------------------------------------------------------------- t | 1 | EXPLAIN (COSTS OFF) (SELECT $1, $2, $3) t | 1 | EXPLAIN (COSTS OFF) (SELECT $1, $2, $3) UNION SELECT $= 4, $5, $6 + f | 1 | EXPLAIN (COSTS OFF) (SELECT $1, $2, $3); EXPLAIN (COST= S OFF) (SELECT 1, 2, 3, 4); t | 1 | EXPLAIN (COSTS OFF) (SELECT $1, $2, $3, $4) + f | 1 | EXPLAIN (COSTS OFF) (SELECT 1, 2, 3); EXPLAIN (COSTS O= FF) (SELECT $1, $2, $3, $4); t | 1 | EXPLAIN (COSTS OFF) SELECT $1 t | 1 | EXPLAIN (COSTS OFF) SELECT $1, $2 t | 1 | EXPLAIN (COSTS OFF) SELECT $1, $2 UNION SELECT $3, $4 - f | 1 | SELECT $1 - f | 1 | SELECT $1, $2 - f | 1 | SELECT $1, $2 UNION SELECT $3, $4 - f | 1 | SELECT $1, $2, $3 - f | 1 | SELECT $1, $2, $3, $4 + f | 1 | EXPLAIN (COSTS OFF) SELECT $1, $2 UNION SELECT $3, $4;= EXPLAIN (COSTS OFF) (SELECT 1, 2, 3) UNION SELECT 3, 4, 5; + f | 1 | EXPLAIN (COSTS OFF) SELECT $1; EXPLAIN (COSTS OFF) SEL= ECT 1, 2; + f | 1 | EXPLAIN (COSTS OFF) SELECT 1, 2 UNION SELECT 3, 4; EXP= LAIN (COSTS OFF) (SELECT $1, $2, $3) UNION SELECT $4, $5, $6; + f | 1 | EXPLAIN (COSTS OFF) SELECT 1; EXPLAIN (COSTS OFF) SELE= CT $1, $2; t | 1 | SELECT pg_stat_statements_reset() IS NOT NULL AS t (13 rows) =20 @@ -494,29 +494,29 @@ EXPLAIN (COSTS OFF) INSERT INTO stats_track_tab VALUE= S ((1))\; EXPLAIN (COSTS OF =20 SELECT toplevel, calls, query FROM pg_stat_statements ORDER BY query COLLATE "C"; - toplevel | calls | query = =20 -----------+-------+-------------------------------------------------------= ------------- - f | 1 | DELETE FROM stats_track_tab - f | 1 | DELETE FROM stats_track_tab WHERE x =3D $1 + toplevel | calls | = query = =20 +----------+-------+-------------------------------------------------------= --------------------------------------------------------------------------- t | 1 | EXPLAIN (COSTS OFF) (TABLE test_table) t | 1 | EXPLAIN (COSTS OFF) (VALUES ($1, $2)) t | 1 | EXPLAIN (COSTS OFF) DELETE FROM stats_track_tab t | 1 | EXPLAIN (COSTS OFF) DELETE FROM stats_track_tab WHERE = x =3D $1 + f | 1 | EXPLAIN (COSTS OFF) DELETE FROM stats_track_tab; EXPLA= IN (COSTS OFF) DELETE FROM stats_track_tab WHERE x =3D $1; + f | 1 | EXPLAIN (COSTS OFF) DELETE FROM stats_track_tab; EXPLA= IN (COSTS OFF) DELETE FROM stats_track_tab WHERE x =3D 1; t | 1 | EXPLAIN (COSTS OFF) INSERT INTO stats_track_tab VALUES= ($1), ($2) t | 1 | EXPLAIN (COSTS OFF) INSERT INTO stats_track_tab VALUES= (($1)) + f | 1 | EXPLAIN (COSTS OFF) INSERT INTO stats_track_tab VALUES= (($1)); EXPLAIN (COSTS OFF) INSERT INTO stats_track_tab VALUES (1), (2); + f | 1 | EXPLAIN (COSTS OFF) INSERT INTO stats_track_tab VALUES= ((1)); EXPLAIN (COSTS OFF) INSERT INTO stats_track_tab VALUES ($1), ($2); t | 1 | EXPLAIN (COSTS OFF) TABLE stats_track_tab + f | 1 | EXPLAIN (COSTS OFF) TABLE stats_track_tab; EXPLAIN (CO= STS OFF) (TABLE test_table); + f | 1 | EXPLAIN (COSTS OFF) TABLE stats_track_tab; EXPLAIN (CO= STS OFF) (TABLE test_table); t | 1 | EXPLAIN (COSTS OFF) UPDATE stats_track_tab SET x =3D $1 t | 1 | EXPLAIN (COSTS OFF) UPDATE stats_track_tab SET x =3D $= 1 WHERE x =3D $2 + f | 1 | EXPLAIN (COSTS OFF) UPDATE stats_track_tab SET x =3D $= 1 WHERE x =3D $2; EXPLAIN (COSTS OFF) UPDATE stats_track_tab SET x =3D 1; + f | 1 | EXPLAIN (COSTS OFF) UPDATE stats_track_tab SET x =3D 1= WHERE x =3D 1; EXPLAIN (COSTS OFF) UPDATE stats_track_tab SET x =3D $1; t | 1 | EXPLAIN (COSTS OFF) VALUES ($1) - f | 1 | INSERT INTO stats_track_tab VALUES ($1), ($2) - f | 1 | INSERT INTO stats_track_tab VALUES (($1)) + f | 1 | EXPLAIN (COSTS OFF) VALUES ($1); EXPLAIN (COSTS OFF) (= VALUES (1, 2)); + f | 1 | EXPLAIN (COSTS OFF) VALUES (1); EXPLAIN (COSTS OFF) (V= ALUES ($1, $2)); t | 1 | SELECT pg_stat_statements_reset() IS NOT NULL AS t - f | 1 | TABLE stats_track_tab - f | 1 | TABLE test_table - f | 1 | UPDATE stats_track_tab SET x =3D $1 - f | 1 | UPDATE stats_track_tab SET x =3D $1 WHERE x =3D $2 - f | 1 | VALUES ($1) - f | 1 | VALUES ($1, $2) (21 rows) =20 SELECT pg_stat_statements_reset() IS NOT NULL AS t; @@ -547,18 +547,21 @@ EXPLAIN (COSTS OFF) MERGE INTO stats_track_tab =20 SELECT toplevel, calls, query FROM pg_stat_statements ORDER BY query COLLATE "C"; - toplevel | calls | query = =20 -----------+-------+-------------------------------------------------------= -------- - t | 1 | EXPLAIN (COSTS OFF) MERGE INTO stats_track_tab = + - | | USING (SELECT id FROM generate_series($1, $2) id) ON= x =3D id+ - | | WHEN MATCHED THEN UPDATE SET x =3D id = + + toplevel | calls | query = =20 +----------+-------+-------------------------------------------------------= ----------------------------------------- + t | 1 | EXPLAIN (COSTS OFF) MERGE INTO stats_track_tab = + + | | USING (SELECT id FROM generate_series($1, $2) id) ON= x =3D id + + | | WHEN MATCHED THEN UPDATE SET x =3D id = + | | WHEN NOT MATCHED THEN INSERT (x) VALUES (id) + f | 1 | EXPLAIN (COSTS OFF) MERGE INTO stats_track_tab = + + | | USING (SELECT id FROM generate_series($1, $2) id) ON= x =3D id + + | | WHEN MATCHED THEN UPDATE SET x =3D id = + + | | WHEN NOT MATCHED THEN INSERT (x) VALUES (id); EXPLAI= N (COSTS OFF) SELECT 1, 2, 3, 4, 5; + f | 1 | EXPLAIN (COSTS OFF) MERGE INTO stats_track_tab = + + | | USING (SELECT id FROM generate_series(1, 10) id) ON = x =3D id + + | | WHEN MATCHED THEN UPDATE SET x =3D id = + + | | WHEN NOT MATCHED THEN INSERT (x) VALUES (id); EXPLAI= N (COSTS OFF) SELECT $1, $2, $3, $4, $5; t | 1 | EXPLAIN (COSTS OFF) SELECT $1, $2, $3, $4, $5 - f | 1 | MERGE INTO stats_track_tab = + - | | USING (SELECT id FROM generate_series($1, $2) id) ON= x =3D id+ - | | WHEN MATCHED THEN UPDATE SET x =3D id = + - | | WHEN NOT MATCHED THEN INSERT (x) VALUES (id) - f | 1 | SELECT $1, $2, $3, $4, $5 t | 1 | SELECT pg_stat_statements_reset() IS NOT NULL AS t (5 rows) =20 @@ -786,29 +789,29 @@ EXPLAIN (COSTS OFF) WITH a AS (select 4) SELECT 1 UNI= ON SELECT 2; =20 SELECT toplevel, calls, query FROM pg_stat_statements ORDER BY query COLLATE "C"; - toplevel | calls | query = =20 -----------+-------+-------------------------------------------------------= ----------------------------------- + toplevel | calls | query = =20 +----------+-------+-------------------------------------------------------= ------------------------------------ t | 1 | EXPLAIN (COSTS OFF) (WITH a AS (SELECT $1) (SELECT $2,= $3)) + f | 1 | EXPLAIN (COSTS OFF) (WITH a AS (SELECT $1) (SELECT $2,= $3)); t | 1 | EXPLAIN (COSTS OFF) WITH a AS (SELECT $1) DELETE FROM = stats_track_tab + f | 1 | EXPLAIN (COSTS OFF) WITH a AS (SELECT $1) DELETE FROM = stats_track_tab; t | 1 | EXPLAIN (COSTS OFF) WITH a AS (SELECT $1) INSERT INTO = stats_track_tab VALUES (($2)) - t | 1 | EXPLAIN (COSTS OFF) WITH a AS (SELECT $1) MERGE INTO s= tats_track_tab + - | | USING (SELECT id FROM generate_series($2, $3) id) ON= x =3D id + - | | WHEN MATCHED THEN UPDATE SET x =3D id = + + f | 1 | EXPLAIN (COSTS OFF) WITH a AS (SELECT $1) INSERT INTO = stats_track_tab VALUES (($2)); + t | 1 | EXPLAIN (COSTS OFF) WITH a AS (SELECT $1) MERGE INTO s= tats_track_tab + + | | USING (SELECT id FROM generate_series($2, $3) id) ON= x =3D id + + | | WHEN MATCHED THEN UPDATE SET x =3D id = + | | WHEN NOT MATCHED THEN INSERT (x) VALUES (id) + f | 1 | EXPLAIN (COSTS OFF) WITH a AS (SELECT $1) MERGE INTO s= tats_track_tab + + | | USING (SELECT id FROM generate_series($2, $3) id) ON= x =3D id + + | | WHEN MATCHED THEN UPDATE SET x =3D id = + + | | WHEN NOT MATCHED THEN INSERT (x) VALUES (id); t | 1 | EXPLAIN (COSTS OFF) WITH a AS (SELECT $1) SELECT $2 + f | 1 | EXPLAIN (COSTS OFF) WITH a AS (SELECT $1) SELECT $2; t | 1 | EXPLAIN (COSTS OFF) WITH a AS (SELECT $1) UPDATE stats= _track_tab SET x =3D $2 WHERE x =3D $3 + f | 1 | EXPLAIN (COSTS OFF) WITH a AS (SELECT $1) UPDATE stats= _track_tab SET x =3D $2 WHERE x =3D $3; t | 1 | EXPLAIN (COSTS OFF) WITH a AS (select $1) SELECT $2 UN= ION SELECT $3 + f | 1 | EXPLAIN (COSTS OFF) WITH a AS (select $1) SELECT $2 UN= ION SELECT $3; t | 1 | SELECT pg_stat_statements_reset() IS NOT NULL AS t - f | 1 | WITH a AS (SELECT $1) (SELECT $2, $3) - f | 1 | WITH a AS (SELECT $1) DELETE FROM stats_track_tab - f | 1 | WITH a AS (SELECT $1) INSERT INTO stats_track_tab VALU= ES (($2)) - f | 1 | WITH a AS (SELECT $1) MERGE INTO stats_track_tab = + - | | USING (SELECT id FROM generate_series($2, $3) id) ON= x =3D id + - | | WHEN MATCHED THEN UPDATE SET x =3D id = + - | | WHEN NOT MATCHED THEN INSERT (x) VALUES (id) - f | 1 | WITH a AS (SELECT $1) SELECT $2 - f | 1 | WITH a AS (SELECT $1) UPDATE stats_track_tab SET x =3D= $2 WHERE x =3D $3 - f | 1 | WITH a AS (select $1) SELECT $2 UNION SELECT $3 (15 rows) =20 -- EXPLAIN with CTEs - top-level tracking @@ -918,13 +921,14 @@ EXPLAIN (ANALYZE, COSTS OFF, SUMMARY OFF, TIMING OFF,= BUFFERS OFF) =20 SELECT toplevel, calls, query FROM pg_stat_statements ORDER BY query COLLATE "C"; - toplevel | calls | query = =20 -----------+-------+-------------------------------------------------------= ----------------------- - t | 1 | EXPLAIN (ANALYZE, COSTS OFF, SUMMARY OFF, TIMING OFF, = BUFFERS OFF) + + toplevel | calls | query = =20 +----------+-------+-------------------------------------------------------= ------------------------ + t | 1 | EXPLAIN (ANALYZE, COSTS OFF, SUMMARY OFF, TIMING OFF, = BUFFERS OFF) + | | DECLARE foocur CURSOR FOR SELECT * FROM stats_track_= tab + f | 1 | EXPLAIN (ANALYZE, COSTS OFF, SUMMARY OFF, TIMING OFF, = BUFFERS OFF) + + | | DECLARE foocur CURSOR FOR SELECT * FROM stats_track_= tab; t | 1 | EXPLAIN (ANALYZE, COSTS OFF, SUMMARY OFF, TIMING OFF, = BUFFERS OFF) SELECT $1 - f | 1 | SELECT $1 - f | 1 | SELECT * FROM stats_track_tab + f | 1 | EXPLAIN (ANALYZE, COSTS OFF, SUMMARY OFF, TIMING OFF, = BUFFERS OFF) SELECT $1; t | 1 | SELECT pg_stat_statements_reset() IS NOT NULL AS t (5 rows) =20 @@ -1047,10 +1051,10 @@ SELECT toplevel, calls, query FROM pg_stat_statemen= ts toplevel | calls | query = =20 ----------+-------+-------------------------------------------------------= ---------- t | 1 | CREATE TEMPORARY TABLE pgss_ctas_1 AS SELECT $1 + f | 1 | CREATE TEMPORARY TABLE pgss_ctas_1 AS SELECT $1; t | 1 | CREATE TEMPORARY TABLE pgss_ctas_2 AS EXECUTE test_pre= pare_pgss - f | 1 | SELECT $1 + f | 1 | PREPARE test_prepare_pgss AS select generate_series($1= , $2) t | 1 | SELECT pg_stat_statements_reset() IS NOT NULL AS t - f | 1 | select generate_series($1, $2) (5 rows) =20 -- CREATE TABLE AS, top-level tracking. @@ -1088,10 +1092,10 @@ EXPLAIN (COSTS OFF) CREATE TEMPORARY TABLE pgss_exp= lain_ctas AS SELECT 1; =20 SELECT toplevel, calls, query FROM pg_stat_statements ORDER BY query COLLATE "C"; - toplevel | calls | query = =20 -----------+-------+-------------------------------------------------------= -------------------- + toplevel | calls | query = =20 +----------+-------+-------------------------------------------------------= --------------------- t | 1 | EXPLAIN (COSTS OFF) CREATE TEMPORARY TABLE pgss_explai= n_ctas AS SELECT $1 - f | 1 | SELECT $1 + f | 1 | EXPLAIN (COSTS OFF) CREATE TEMPORARY TABLE pgss_explai= n_ctas AS SELECT $1; t | 1 | SELECT pg_stat_statements_reset() IS NOT NULL AS t (3 rows) =20 @@ -1136,14 +1140,14 @@ CLOSE foocur; COMMIT; SELECT toplevel, calls, query FROM pg_stat_statements ORDER BY query COLLATE "C"; - toplevel | calls | query = =20 -----------+-------+-------------------------------------------------------= -- + toplevel | calls | query = =20 +----------+-------+-------------------------------------------------------= --- t | 1 | BEGIN t | 1 | CLOSE foocur t | 1 | COMMIT t | 1 | DECLARE FOOCUR CURSOR FOR SELECT * from stats_track_tab + f | 1 | DECLARE FOOCUR CURSOR FOR SELECT * from stats_track_ta= b; t | 1 | FETCH FORWARD 1 FROM foocur - f | 1 | SELECT * from stats_track_tab t | 1 | SELECT pg_stat_statements_reset() IS NOT NULL AS t (7 rows) =20 @@ -1203,25 +1207,25 @@ COPY (DELETE FROM stats_track_tab WHERE x =3D 2 RET= URNING x) TO stdout; 2 SELECT toplevel, calls, query FROM pg_stat_statements ORDER BY query COLLATE "C"; - toplevel | calls | query = =20 -----------+-------+-------------------------------------------------------= -------------------- + toplevel | calls | query = =20 +----------+-------+-------------------------------------------------------= ---------------------- + f | 1 | COPY (DELETE FROM stats_track_tab WHERE x =3D $1 RETUR= NING x) TO stdout t | 1 | COPY (DELETE FROM stats_track_tab WHERE x =3D 2 RETURN= ING x) TO stdout + f | 1 | COPY (INSERT INTO stats_track_tab (x) VALUES ($1) RETU= RNING x) TO stdout t | 1 | COPY (INSERT INTO stats_track_tab (x) VALUES (1) RETUR= NING x) TO stdout - t | 1 | COPY (MERGE INTO stats_track_tab USING (SELECT 1 id) O= N x =3D id + - | | WHEN MATCHED THEN UPDATE SET x =3D id = + + f | 1 | COPY (MERGE INTO stats_track_tab USING (SELECT $1 id) = ON x =3D id + + | | WHEN MATCHED THEN UPDATE SET x =3D id = + | | WHEN NOT MATCHED THEN INSERT (x) VALUES (id) RETURNI= NG x) TO stdout + t | 1 | COPY (MERGE INTO stats_track_tab USING (SELECT 1 id) O= N x =3D id + + | | WHEN MATCHED THEN UPDATE SET x =3D id = + + | | WHEN NOT MATCHED THEN INSERT (x) VALUES (id) RETURNI= NG x) TO stdout + f | 1 | COPY (SELECT $1 UNION SELECT $2) TO stdout + f | 1 | COPY (SELECT $1) TO stdout t | 1 | COPY (SELECT 1 UNION SELECT 2) TO stdout t | 1 | COPY (SELECT 1) TO stdout + f | 1 | COPY (UPDATE stats_track_tab SET x =3D $1 WHERE x =3D = $2 RETURNING x) TO stdout t | 1 | COPY (UPDATE stats_track_tab SET x =3D 2 WHERE x =3D 1= RETURNING x) TO stdout - f | 1 | DELETE FROM stats_track_tab WHERE x =3D $1 RETURNING x - f | 1 | INSERT INTO stats_track_tab (x) VALUES ($1) RETURNING x - f | 1 | MERGE INTO stats_track_tab USING (SELECT $1 id) ON x = =3D id + - | | WHEN MATCHED THEN UPDATE SET x =3D id = + - | | WHEN NOT MATCHED THEN INSERT (x) VALUES (id) RETURNI= NG x - f | 1 | SELECT $1 - f | 1 | SELECT $1 UNION SELECT $2 t | 1 | SELECT pg_stat_statements_reset() IS NOT NULL AS t - f | 1 | UPDATE stats_track_tab SET x =3D $1 WHERE x =3D $2 RET= URNING x (13 rows) =20 -- COPY - top-level tracking. @@ -1319,57 +1323,6 @@ SELECT toplevel, calls, query FROM pg_stat_statements t | 1 | SELECT pg_stat_statements_reset() IS NOT NULL AS t (4 rows) =20 --- DO block --- multiple inner queries with separators -SET pg_stat_statements.track =3D 'all'; -SET pg_stat_statements.track_utility =3D TRUE; -CREATE TABLE pgss_do_util_tab_1 (a int); -CREATE TABLE pgss_do_util_tab_2 (a int); -SELECT pg_stat_statements_reset() IS NOT NULL AS t; - t=20 ---- - t -(1 row) - -DO $$ -DECLARE BEGIN - EXECUTE 'CREATE TABLE pgss_do_table (id INT); DROP TABLE pgss_do_table'; - EXECUTE 'SELECT a FROM pgss_do_util_tab_1; SELECT a FROM pgss_do_util_ta= b_2'; -END $$; -SELECT toplevel, calls, rows, query FROM pg_stat_statements - WHERE toplevel IS FALSE - ORDER BY query COLLATE "C"; - toplevel | calls | rows | query =20 -----------+-------+------+------------------------------------- - f | 1 | 0 | CREATE TABLE pgss_do_table (id INT) - f | 1 | 0 | DROP TABLE pgss_do_table - f | 1 | 0 | SELECT a FROM pgss_do_util_tab_1 - f | 1 | 0 | SELECT a FROM pgss_do_util_tab_2 -(4 rows) - -SELECT pg_stat_statements_reset() IS NOT NULL AS t; - t=20 ---- - t -(1 row) - --- Note the extra semicolon at the end of the query. -DO $$ -DECLARE BEGIN - EXECUTE 'CREATE TABLE pgss_do_table (id INT); DROP TABLE pgss_do_table;'; - EXECUTE 'SELECT a FROM pgss_do_util_tab_1; SELECT a FROM pgss_do_util_ta= b_2;'; -END $$; -SELECT toplevel, calls, rows, query FROM pg_stat_statements - WHERE toplevel IS FALSE - ORDER BY query COLLATE "C"; - toplevel | calls | rows | query =20 -----------+-------+------+------------------------------------- - f | 1 | 0 | CREATE TABLE pgss_do_table (id INT) - f | 1 | 0 | DROP TABLE pgss_do_table - f | 1 | 0 | SELECT a FROM pgss_do_util_tab_1 - f | 1 | 0 | SELECT a FROM pgss_do_util_tab_2 -(4 rows) - -DROP TABLE pgss_do_util_tab_1, pgss_do_util_tab_2; -- PL/pgSQL function - top-level tracking. SET pg_stat_statements.track =3D 'top'; SET pg_stat_statements.track_utility =3D FALSE; diff --git a/contrib/pg_stat_statements/expected/planning.out b/contrib/pg_= stat_statements/expected/planning.out index 3ee1928cbe94..9effd11fdc85 100644 --- a/contrib/pg_stat_statements/expected/planning.out +++ b/contrib/pg_stat_statements/expected/planning.out @@ -58,7 +58,7 @@ SELECT 42; (1 row) =20 SELECT plans, calls, rows, query FROM pg_stat_statements - WHERE query NOT LIKE 'SELECT COUNT%' ORDER BY query COLLATE "C"; + WHERE query NOT LIKE 'PREPARE%' ORDER BY query COLLATE "C"; plans | calls | rows | query = =20 -------+-------+------+---------------------------------------------------= ------- 0 | 1 | 0 | ALTER TABLE stats_plan_test ADD COLUMN x int @@ -72,10 +72,10 @@ SELECT plans, calls, rows, query FROM pg_stat_statements -- for the prepared statement we expect at least one replan, but cache -- invalidations could force more SELECT plans >=3D 2 AND plans <=3D calls AS plans_ok, calls, rows, query F= ROM pg_stat_statements - WHERE query LIKE 'SELECT COUNT%' ORDER BY query COLLATE "C"; - plans_ok | calls | rows | query =20 -----------+-------+------+-------------------------------------- - t | 4 | 4 | SELECT COUNT(*) FROM stats_plan_test + WHERE query LIKE 'PREPARE%' ORDER BY query COLLATE "C"; + plans_ok | calls | rows | query = =20 +----------+-------+------+------------------------------------------------= ------- + t | 4 | 4 | PREPARE prep1 AS SELECT COUNT(*) FROM stats_pla= n_test (1 row) =20 -- Cleanup diff --git a/contrib/pg_stat_statements/expected/select.out b/contrib/pg_st= at_statements/expected/select.out index 038ae1103645..e87835085f52 100644 --- a/contrib/pg_stat_statements/expected/select.out +++ b/contrib/pg_stat_statements/expected/select.out @@ -208,6 +208,7 @@ DEALLOCATE pgss_test; SELECT calls, rows, query FROM pg_stat_statements ORDER BY query COLLATE "= C"; calls | rows | query = =20 -------+------+-----------------------------------------------------------= ------------------- + 1 | 1 | PREPARE pgss_test (int) AS SELECT $1, $2 LIMIT $3 4 | 4 | SELECT $1 = + | | -- but this one will appear = + | | AS "text" @@ -221,7 +222,6 @@ SELECT calls, rows, query FROM pg_stat_statements ORDER= BY query COLLATE "C"; 2 | 2 | SELECT $1 AS "int" ORDER BY 1 1 | 2 | SELECT $1 AS i UNION SELECT $2 ORDER BY i 1 | 1 | SELECT $1 || $2 - 1 | 1 | SELECT $1, $2 LIMIT $3 2 | 2 | SELECT DISTINCT $1 AS "int" 0 | 0 | SELECT calls, rows, query FROM pg_stat_statements ORDER BY= query COLLATE "C" 1 | 1 | SELECT pg_stat_statements_reset() IS NOT NULL AS t diff --git a/contrib/pg_stat_statements/expected/utility.out b/contrib/pg_s= tat_statements/expected/utility.out index aa4f0f7e6280..060d4416dd74 100644 --- a/contrib/pg_stat_statements/expected/utility.out +++ b/contrib/pg_stat_statements/expected/utility.out @@ -540,7 +540,7 @@ SELECT calls, rows, query FROM pg_stat_statements ORDER= BY query COLLATE "C"; -------+------+---------------------------------------------------- 2 | 0 | DEALLOCATE $1 2 | 0 | DEALLOCATE ALL - 2 | 2 | SELECT $1 AS a + 2 | 2 | PREPARE stat_select AS SELECT $1 AS a 1 | 1 | SELECT $1 as a 1 | 1 | SELECT pg_stat_statements_reset() IS NOT NULL AS t (5 rows) diff --git a/contrib/pg_stat_statements/sql/level_tracking.sql b/contrib/pg= _stat_statements/sql/level_tracking.sql index 86f007e85524..6b81230f1869 100644 --- a/contrib/pg_stat_statements/sql/level_tracking.sql +++ b/contrib/pg_stat_statements/sql/level_tracking.sql @@ -334,32 +334,6 @@ END; $$; SELECT toplevel, calls, query FROM pg_stat_statements ORDER BY query COLLATE "C", toplevel; =20 --- DO block --- multiple inner queries with separators -SET pg_stat_statements.track =3D 'all'; -SET pg_stat_statements.track_utility =3D TRUE; -CREATE TABLE pgss_do_util_tab_1 (a int); -CREATE TABLE pgss_do_util_tab_2 (a int); -SELECT pg_stat_statements_reset() IS NOT NULL AS t; -DO $$ -DECLARE BEGIN - EXECUTE 'CREATE TABLE pgss_do_table (id INT); DROP TABLE pgss_do_table'; - EXECUTE 'SELECT a FROM pgss_do_util_tab_1; SELECT a FROM pgss_do_util_ta= b_2'; -END $$; -SELECT toplevel, calls, rows, query FROM pg_stat_statements - WHERE toplevel IS FALSE - ORDER BY query COLLATE "C"; -SELECT pg_stat_statements_reset() IS NOT NULL AS t; --- Note the extra semicolon at the end of the query. -DO $$ -DECLARE BEGIN - EXECUTE 'CREATE TABLE pgss_do_table (id INT); DROP TABLE pgss_do_table;'; - EXECUTE 'SELECT a FROM pgss_do_util_tab_1; SELECT a FROM pgss_do_util_ta= b_2;'; -END $$; -SELECT toplevel, calls, rows, query FROM pg_stat_statements - WHERE toplevel IS FALSE - ORDER BY query COLLATE "C"; -DROP TABLE pgss_do_util_tab_1, pgss_do_util_tab_2; - -- PL/pgSQL function - top-level tracking. SET pg_stat_statements.track =3D 'top'; SET pg_stat_statements.track_utility =3D FALSE; diff --git a/contrib/pg_stat_statements/sql/planning.sql b/contrib/pg_stat_= statements/sql/planning.sql index 9cfe206b3b04..46f5d9b951c4 100644 --- a/contrib/pg_stat_statements/sql/planning.sql +++ b/contrib/pg_stat_statements/sql/planning.sql @@ -20,11 +20,11 @@ SELECT 42; SELECT 42; SELECT 42; SELECT plans, calls, rows, query FROM pg_stat_statements - WHERE query NOT LIKE 'SELECT COUNT%' ORDER BY query COLLATE "C"; + WHERE query NOT LIKE 'PREPARE%' ORDER BY query COLLATE "C"; -- for the prepared statement we expect at least one replan, but cache -- invalidations could force more SELECT plans >=3D 2 AND plans <=3D calls AS plans_ok, calls, rows, query F= ROM pg_stat_statements - WHERE query LIKE 'SELECT COUNT%' ORDER BY query COLLATE "C"; + WHERE query LIKE 'PREPARE%' ORDER BY query COLLATE "C"; =20 -- Cleanup DROP TABLE stats_plan_test; --=20 2.49.0 --jDjG+LBZXN/tCVph-- --1GmVvqWla5uSctnU Content-Type: application/pgp-signature; name="signature.asc" -----BEGIN PGP SIGNATURE----- iQIzBAABCgAdFiEEG72nH6vTowiyblFKnvQgOdbyQH0FAmhHxpcACgkQnvQgOdby QH0vnA//dwTmKOs3bldkiu0V67q0gdGytQAuPBWRCSu365j/yZ4Jt4CfSjFgnvtW U96xkMVSrOUIqkhdnqIXqB8SY+NUpBZRXio0P3519/Hvfyz5zyWpmaekYGrTYKR4 DJK4l9Qh6EZmaOMa03Ok+pv/SLMT76xuV/oGXZxCvFOhmBXb61Gze7EkZL7fpW1E zNmc+YlLQbvL89g4WJjkKT5MhlAYzFuWm2D1Mn6AdJH44Fl7OwuJgWulk4ZRC0Es zTcBgurIC2tR7x5gLJ0lah9JVkWL7zRsfqfLIsPkMGfL9z6BbclojVrniTjotVxO xoHRothKWbPv2L6zbJx8icoZK7VzO+FpFlBnEtueOBgWuOhWgqE/KFRhnqFcXUWk oyvpelIbvJZFLzxY6IgstY3jF5/WhCyH3LH9uuJlcWyYQx3P2kuKuZ/sdgfbFt7W qoB2X2y6pW7RF5l2cqY1kRtSQuSTW8mEjJQcRPCBsl/nv9ZnxVZvuJxDh84+zYO7 fNf4p0hXiwVd0mfLasyGftDgOxSwYT8baBUCT3TADy+TyQfgsTuoHiDmKaRf5HXC MJwk5AWtlnpWCAIPsCKI3XnS7XW6Y9y1ukq7U+e/FkZAUq8ZqP9Vfz8iP+wHs1nx 76NBAeYbuCGJ0S8UcDs0hVHRkSeMvOGgKiqA41WhVVwfSWHuNVI= =OdzM -----END PGP SIGNATURE----- --1GmVvqWla5uSctnU--