Re: VALUES clause memory optimization

From: Joe Conway <mail(at)joeconway(dot)com>
To: Bruce Momjian <bruce(at)momjian(dot)us>
Cc: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>, "Hackers (PostgreSQL)" <pgsql-hackers(at)postgresql(dot)org>
Subject: Re: VALUES clause memory optimization
Date: 2006-08-26 20:08:03
Message-ID: 44F0AA23.9030800@joeconway.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-docs pgsql-hackers pgsql-patches

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

In response to

Browse pgsql-docs by date

  From Date Subject
Next Message Joshua D. Drake 2006-08-26 20:31:08 Re: [HACKERS] New XML section for documentation
Previous Message David Fetter 2006-08-26 18:56:41 Re: [HACKERS] New XML section for documentation

Browse pgsql-hackers by date

  From Date Subject
Next Message Joshua D. Drake 2006-08-26 20:31:08 Re: [HACKERS] New XML section for documentation
Previous Message Jim C. Nasby 2006-08-26 19:48:43 Re: [Pgsqlrpms-hackers] Safer auto-initdb for RPM init script

Browse pgsql-patches by date

  From Date Subject
Next Message Alvaro Herrera 2006-08-27 01:03:20 Re: Hierarchical Queries--Status
Previous Message Zoltan Boszormenyi 2006-08-26 19:36:14 Re: [HACKERS] Performance testing of COPY (SELECT) TO