Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1oTeRg-0000Sq-6w for pgsql-hackers@arkaria.postgresql.org; Thu, 01 Sep 2022 07:17:01 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.92) (envelope-from ) id 1oTeRf-00018M-0c for pgsql-hackers@arkaria.postgresql.org; Thu, 01 Sep 2022 07:16:59 +0000 Received: from magus.postgresql.org ([2a02:c0:301:0:ffff::29]) by malur.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1oTeRe-000187-6C for pgsql-hackers@lists.postgresql.org; Thu, 01 Sep 2022 07:16:58 +0000 Received: from smtp-fw-6002.amazon.com ([52.95.49.90]) by magus.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1oTeRb-000550-0s for pgsql-hackers@lists.postgresql.org; Thu, 01 Sep 2022 07:16:57 +0000 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=amazon.com; i=@amazon.com; q=dns/txt; s=amazon201209; t=1662016616; x=1693552616; h=message-id:date:mime-version:subject:to:cc:references: from:in-reply-to; bh=PaDd53OcP6DWeeSC/hpri/r+OExBWHh+S8dUU2bCU6E=; b=GjZyldypaCRhxtAFM/6YBB2Jz0fhA+Sb1zoR9pE23iHr9QAJQkYDnnLw C777IM+Xgm+KOnnUqt5t4PYPD0v3rpDZrNVPbIai9hG9GlwY9GTZKr0WJ hdcDqD0m6Rrd1eRxQ9NXP1v92gADq+l3/Y4H8XHVxrSo4NuSB0Lwc8xsy c=; X-IronPort-AV: E=Sophos;i="5.93,280,1654560000"; d="scan'208,217";a="239835433" Received: from iad12-co-svc-p1-lb1-vlan3.amazon.com (HELO email-inbound-relay-iad-1e-26daedd8.us-east-1.amazon.com) ([10.43.8.6]) by smtp-border-fw-6002.iad6.amazon.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 01 Sep 2022 07:16:43 +0000 Received: from EX13D03EUC003.ant.amazon.com (iad12-ws-svc-p26-lb9-vlan2.iad.amazon.com [10.40.163.34]) by email-inbound-relay-iad-1e-26daedd8.us-east-1.amazon.com (Postfix) with ESMTPS id 0E03E8156F; Thu, 1 Sep 2022 07:16:41 +0000 (UTC) Received: from [10.95.84.20] (10.43.161.228) by EX13D03EUC003.ant.amazon.com (10.43.164.192) with Microsoft SMTP Server (TLS) id 15.0.1497.38; Thu, 1 Sep 2022 07:16:39 +0000 Content-Type: multipart/alternative; boundary="------------qX52K2qRemt230QOzQQLohKy" Message-ID: Date: Thu, 1 Sep 2022 09:16:35 +0200 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.15; rv:102.0) Gecko/20100101 Thunderbird/102.2.0 Subject: Re: [PATCH] Query Jumbling for CALL and SET utility statements Content-Language: en-US To: Andres Freund CC: PostgreSQL Hackers , "Schneider (AWS), Jeremy" References: <36e5bffe-e989-194f-85c8-06e7bc88e6f7@amazon.com> <20220831160839.wseeotr7rckucpmv@awork3.anarazel.de> From: "Drouvot, Bertrand" In-Reply-To: <20220831160839.wseeotr7rckucpmv@awork3.anarazel.de> X-Originating-IP: [10.43.161.228] X-ClientProxiedBy: EX13D48UWB004.ant.amazon.com (10.43.163.74) To EX13D03EUC003.ant.amazon.com (10.43.164.192) List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk --------------qX52K2qRemt230QOzQQLohKy Content-Type: text/plain; charset="UTF-8"; format=flowed Content-Transfer-Encoding: 8bit Hi, On 8/31/22 6:08 PM, Andres Freund wrote: > Hi, > > On 2022-08-31 17:33:44 +0200, Drouvot, Bertrand wrote: >> @@ -383,6 +384,30 @@ JumbleExpr(JumbleState *jstate, Node *node) >> APP_JUMB(var->varlevelsup); >> } >> break; >> + case T_CallStmt: >> + { >> + CallStmt *stmt = (CallStmt *) node; >> + FuncExpr *expr = stmt->funcexpr; >> + >> + APP_JUMB(expr->funcid); >> + JumbleExpr(jstate, (Node *) expr->args); >> + } >> + break; > Why do we need to take the arguments into account? Thanks for looking at it! Agree that It's not needed to "solve" the Lock contention issue, but I think it's needed for the "render". Without it we would get, things like: postgres=# call MY_PROC(10); CALL postgres=# call MY_PROC(100000000); CALL postgres=# SELECT query, calls, rows FROM pg_stat_statements;                query               | calls | rows -----------------------------------+-------+------  select pg_stat_statements_reset() |     1 |    1  call MY_PROC(10)                  |     2 |    0 (2 rows) instead of postgres=# SELECT query, calls, rows FROM pg_stat_statements;                query               | calls | rows -----------------------------------+-------+------  select pg_stat_statements_reset() |     1 |    1  call MY_PROC($1)                  |     2 |    0 (2 rows) > > >> + case T_VariableSetStmt: >> + { >> + VariableSetStmt *stmt = (VariableSetStmt *) node; >> + >> + APP_JUMB_STRING(stmt->name); >> + JumbleExpr(jstate, (Node *) stmt->args); >> + } >> + break; > Same? yeah, same reason. Without it we would get things like: postgres=# set enable_seqscan=false; SET postgres=# set enable_seqscan=true; SET postgres=# SELECT query, calls, rows FROM pg_stat_statements;                query               | calls | rows -----------------------------------+-------+------  select pg_stat_statements_reset() |     1 |    1  set enable_seqscan=false          |     2 |    0 (2 rows) instead of postgres=# SELECT query, calls, rows FROM pg_stat_statements;                query               | calls | rows -----------------------------------+-------+------  set enable_seqscan=$1             |     2 |    0  select pg_stat_statements_reset() |     1 |    1 (2 rows) > >> + case T_A_Const: >> + { >> + int loc = ((const A_Const *) node)->location; >> + >> + RecordConstLocation(jstate, loc); >> + } >> + break; > I suspect we only need this because of the jumbling of unparsed arguments I > questioned above? Right but only for the T_VariableSetStmt case. > If we do end up needing it, shouldn't we include the type > in the jumbling? I don't think so as this is only for the T_VariableSetStmt case. And looking closer I don't see such as thing as "consttype" (that we can find in the Const struct) in the A_Const struct. Regards, -- Bertrand Drouvot Amazon Web Services:https://aws.amazon.com --------------qX52K2qRemt230QOzQQLohKy Content-Type: text/html; charset="UTF-8" Content-Transfer-Encoding: 8bit

Hi,

On 8/31/22 6:08 PM, Andres Freund wrote:
Hi,

On 2022-08-31 17:33:44 +0200, Drouvot, Bertrand wrote:
@@ -383,6 +384,30 @@ JumbleExpr(JumbleState *jstate, Node *node)
                              APP_JUMB(var->varlevelsup);
                      }
                      break;
+             case T_CallStmt:
+                     {
+                             CallStmt   *stmt = (CallStmt *) node;
+                             FuncExpr   *expr = stmt->funcexpr;
+
+                             APP_JUMB(expr->funcid);
+                             JumbleExpr(jstate, (Node *) expr->args);
+                     }
+                     break;
Why do we need to take the arguments into account?

Thanks for looking at it!

Agree that It's not needed to "solve" the Lock contention issue, but I think it's needed for the "render".

Without it we would get, things like:

postgres=# call MY_PROC(10);
CALL
postgres=# call MY_PROC(100000000);
CALL
postgres=# SELECT query, calls, rows FROM pg_stat_statements;
               query               | calls | rows
-----------------------------------+-------+------
 select pg_stat_statements_reset() |     1 |    1
 call MY_PROC(10)                  |     2 |    0
(2 rows)

instead of

postgres=# SELECT query, calls, rows FROM pg_stat_statements;
               query               | calls | rows
-----------------------------------+-------+------
 select pg_stat_statements_reset() |     1 |    1
 call MY_PROC($1)                  |     2 |    0
(2 rows)



+             case T_VariableSetStmt:
+                     {
+                             VariableSetStmt *stmt = (VariableSetStmt *) node;
+
+                             APP_JUMB_STRING(stmt->name);
+                             JumbleExpr(jstate, (Node *) stmt->args);
+                     }
+                     break;
Same?

yeah, same reason. Without it we would get things like:

postgres=# set enable_seqscan=false;
SET
postgres=# set enable_seqscan=true;
SET
postgres=# SELECT query, calls, rows FROM pg_stat_statements;
               query               | calls | rows
-----------------------------------+-------+------
 select pg_stat_statements_reset() |     1 |    1
 set enable_seqscan=false          |     2 |    0
(2 rows)

instead of

postgres=# SELECT query, calls, rows FROM pg_stat_statements;
               query               | calls | rows
-----------------------------------+-------+------
 set enable_seqscan=$1             |     2 |    0
 select pg_stat_statements_reset() |     1 |    1
(2 rows)


+             case T_A_Const:
+                     {
+                             int                     loc = ((const A_Const *) node)->location;
+
+                             RecordConstLocation(jstate, loc);
+                     }
+                     break;
I suspect we only need this because of the jumbling of unparsed arguments I
questioned above? 

Right but only for the T_VariableSetStmt case.

 If we do end up needing it, shouldn't we include the type
in the jumbling?

I don't think so as this is only for the T_VariableSetStmt case.

And looking closer I don't see such as thing as "consttype" (that we can find in the Const struct) in the A_Const struct.

Regards,

-- 
Bertrand Drouvot
Amazon Web Services: https://aws.amazon.com
--------------qX52K2qRemt230QOzQQLohKy--