Re: Useless field ispartitioned in CreateStmtContext - Mailing list pgsql-hackers

From Alena Rybakina
Subject Re: Useless field ispartitioned in CreateStmtContext
Date
Msg-id 20da2524-3f06-4485-8f61-386c7179963c@postgrespro.ru
Whole thread Raw
In response to Useless field ispartitioned in CreateStmtContext  (hugo <2689496754@qq.com>)
Responses Re: Useless field ispartitioned in CreateStmtContext
List pgsql-hackers

Hi!

On 24.10.2024 16:07, hugo wrote:
@font-face {font-family:"Cambria Math"; panose-1:2 4 5 3 5 4 6 3 2 4;}@font-face {font-family:DengXian; panose-1:2 1 6 0 3 1 1 1 1 1;}@font-face {font-family:"\@等线"; panose-1:2 1 6 0 3 1 1 1 1 1;}p.MsoNormal, li.MsoNormal, div.MsoNormal {margin:0cm; font-size:11.0pt; font-family:DengXian; mso-ligatures:standardcontextual;}span.EmailStyle17 {mso-style-type:personal-compose; font-family:DengXian; color:windowtext;}.MsoChpDefault {mso-style-type:export-only;}div.WordSection1 {page:WordSection1;}

Hi!

       When looking at the partition-related code, I found that the ispartitioned

field in CreateStmtContext is not used. It looks like we can safely remove it and

avoid invalid assignment logic.

 

Here's a very simple fixany suggestion?

 

diff --git a/src/backend/parser/parse_utilcmd.c b/src/backend/parser/parse_utilcmd.c

index 1e15ce10b48..6dea85cc2dc 100644

--- a/src/backend/parser/parse_utilcmd.c

+++ b/src/backend/parser/parse_utilcmd.c

@@ -89,7 +89,6 @@ typedef struct

        List       *alist;                      /* "after list" of things to do after creating

                                                                 * the table */

        IndexStmt  *pkey;                       /* PRIMARY KEY index, if any */

-       bool            ispartitioned;  /* true if table is partitioned */

        PartitionBoundSpec *partbound;  /* transformed FOR VALUES */

        bool            ofType;                 /* true if statement contains OF typename */

} CreateStmtContext;

@@ -246,7 +245,6 @@ transformCreateStmt(CreateStmt *stmt, const char *queryString)

        cxt.blist = NIL;

        cxt.alist = NIL;

        cxt.pkey = NULL;

-       cxt.ispartitioned = stmt->partspec != NULL;

        cxt.partbound = stmt->partbound;

        cxt.ofType = (stmt->ofTypename != NULL);

@@ -3401,7 +3399,6 @@ transformAlterTableStmt(Oid relid, AlterTableStmt *stmt,

        cxt.blist = NIL;

        cxt.alist = NIL;

        cxt.pkey = NULL;

-       cxt.ispartitioned = (rel->rd_rel->relkind == RELKIND_PARTITIONED_TABLE);

        cxt.partbound = NULL;

        cxt.ofType = false;

 

I absolutely agree with you. I found that ispartitioned parameter has been defined but it is never used during optimization.

I also noticed that its local copy is being redefined in the ATExecDropIdentity, ATExecSetIdentity and ATExecAddIdentity functions.

So, I'm willing to agree with you.

BTW, the regression tests were successful.

-- 
Regards,
Alena Rybakina
Postgres Professional

pgsql-hackers by date:

Previous
From: Alexander Lakhin
Date:
Subject: Re: [BUG] Fix DETACH with FK pointing to a partitioned table fails
Next
From: Junwang Zhao
Date:
Subject: Re: general purpose array_sort