Re: VALUES clause memory optimization - Mailing list pgsql-hackers

From Joe Conway
Subject Re: VALUES clause memory optimization
Date
Msg-id 44F0AA23.9030800@joeconway.com
Whole thread Raw
In response to Re: VALUES clause memory optimization  (Bruce Momjian <bruce@momjian.us>)
List pgsql-hackers
Bruce Momjian wrote:
> Has this been addressed?
> 
>>Tom Lane wrote:
>>>The reason we could safely list_free inside transformInsertRow is that
>>>we know all its callers have just built the passed-in list and so there
>>>are no other pointers to it.  That doesn't apply in the general case of
>>>grammar output.

After another look, even in this case there could be other pointers. 
Starting around line 667 of analyze.c:

8<------------------    foreach(lc, selectQuery->targetList)    {        TargetEntry *tle = (TargetEntry *) lfirst(lc);
      Expr       *expr;
 
        if (tle->resjunk)            continue;        if (tle->expr &&            (IsA(tle->expr, Const)
||IsA(tle->expr,Param)) &&            exprType((Node *) tle->expr) == UNKNOWNOID)            expr = tle->expr;
else           expr = (Expr *) makeVar(rtr->rtindex,                                    tle->resno,
              exprType((Node *) tle->expr),                                    exprTypmod((Node *) tle->expr),
                         0);         exprList = lappend(exprList, expr);    }
 
    /* Prepare row for assignment to target table */    exprList = transformInsertRow(pstate, exprList,
                stmt->cols,                                  icolumns, attrnos);
 

8<------------------

So in the UNKNOWNOID case, it wouldn't be safe to free the node after 
transformation because it originates in the grammar output. The *only* 
safe thing to free up would be a the input exprList itself. Not much to 
be saved there.

>>>My advice is to get that low-hanging fruit
>>>in transformInsertRow and leave the other ideas for 8.3.

This one case doesn't provide that much memory savings by itself anyway. 
I guess we'll just live with it until we can come up with a safe way to 
free grammar output.

Joe


pgsql-hackers by date:

Previous
From: "Jim C. Nasby"
Date:
Subject: Re: [Pgsqlrpms-hackers] Safer auto-initdb for RPM init script
Next
From: "Joshua D. Drake"
Date:
Subject: Re: [DOCS] New XML section for documentation