Re: Remove redundant variable from transformCreateStmt

From: Amul Sul <sulamul(at)gmail(dot)com>
To: Bharath Rupireddy <bharath(dot)rupireddyforpostgres(at)gmail(dot)com>
Cc: PostgreSQL-development <pgsql-hackers(at)postgresql(dot)org>
Subject: Re: Remove redundant variable from transformCreateStmt
Date: 2021-04-15 13:04:11
Message-ID: CAAJ_b97b6ctZh12UeuZbf=bKz51cA1OnComX-guLiPtGVj=vqg@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

On Thu, Apr 15, 2021 at 5:47 PM Bharath Rupireddy
<bharath(dot)rupireddyforpostgres(at)gmail(dot)com> wrote:
>
> On Thu, Apr 15, 2021 at 5:04 PM Amul Sul <sulamul(at)gmail(dot)com> wrote:
> >
> > Hi,
> >
> > Attached patch removes "is_foreign_table" from transformCreateStmt()
> > since it already has cxt.isforeign that can serve the same purpose.
>
> Yeah having that variable as "is_foreign_table" doesn't make sense
> when we have the info in ctx. I'm wondering whether we can do the
> following (like transformFKConstraints). It will be more readable and
> we could also add more comments on why we don't skip validation for
> check constraints i.e. constraint->skip_validation = false in case for
> foreign tables.
>
> bool skip_validation = true;
> if (IsA(stmt, CreateForeignTableStmt))
> {
> cxt.stmtType = "CREATE FOREIGN TABLE";
> cxt.isforeign = true;
> skip_validation = false; ----> <<<add comments here>>>
> }
> transformCheckConstraints(&cxt, skip_validation);
>
> Alternatively, we could also remove skipValidation function parameter
> (since transformCheckConstraints is a static function, I think it's
> okay) and modify transformCheckConstraints, then we can do following:
>
> In transformCreateStmt:
> if (!ctx.isforeign)
> transformCheckConstraints(&ctx);
>
> In transformAlterTableStmt: we can remove transformCheckConstraints
> entirely because calling transformCheckConstraints with skipValidation
> = false does nothing and has no value. This way we could save a
> function call.
>
> I prefer removing the skipValidation parameter from
> transformCheckConstraints. Others might have different opinions.
>

Then we also need to remove the transformCheckConstraints() dummy call
from transformAlterTableStmt() which was added for the readability.
Also, this change to transformCheckConstraints() will make it
inconsistent with transformFKConstraints().

I think we shouldn't worry too much about this function call overhead
here since this is a slow utility path, and that is the reason the
current structure doesn't really bother me.

Regards,
Amul

In response to

Browse pgsql-hackers by date

  From Date Subject
Next Message Rushabh Lathia 2021-04-15 14:03:29 Commit ab596105b55 - BRIN minmax-multi indexes
Previous Message Bharath Rupireddy 2021-04-15 12:17:45 Re: Remove redundant variable from transformCreateStmt