From: Tom Lane <tgl@sss.pgh.pa.us>
To: Simon Riggs <simon@2ndQuadrant.com>
Cc: Gregory Stark <stark@enterprisedb.com>
Cc: Alvaro Herrera <alvherre@commandprompt.com>
Cc: List pgsql-patches <pgsql-patches@postgresql.org>
Subject: Re: [HACKERS] get_relation_stats_hook()
Date: Sun, 28 Sep 2008 15:57:49 -0400
Message-ID: <18588.1222631869@sss.pgh.pa.us> (raw)
In-Reply-To: <1222440740.4445.966.camel@ebony.2ndQuadrant>
References: <1214490037.3845.136.camel@ebony.site>
<16415.1214493494@sss.pgh.pa.us>
<1214496170.3845.196.camel@ebony.site>
<17759.1214499056@sss.pgh.pa.us>
<1214858056.3845.514.camel@ebony.site>
<12400.1215716369@sss.pgh.pa.us>
<1218037047.4549.291.camel@ebony.2ndQuadrant>
<1218062303.4549.302.camel@ebony.2ndQuadrant>
<1222440740.4445.966.camel@ebony.2ndQuadrant>
Simon Riggs <simon@2ndQuadrant.com> writes:
> New version of Postgres patch, v5. Implements suggested changes.
> Ready for review and apply.
Applied with some revisions. The method for passing back freefunc
didn't work, so I made it pass the whole VariableStatsData struct
instead; this might allow some additional flexibility by changing other
fields besides the intended statsTuple and freefunc. Also, I was still
unhappy about adding a hook in the midst of code that clearly needs
improvement, without making it possible for the hook to override the
adjacent broken code paths; so I refactored the API a bit for that too.
The plugin function would now be something like this:
static bool
plugin_get_relation_stats(PlannerInfo *root,
RangeTblEntry *rte,
AttrNumber attnum,
VariableStatData *vardata)
{
HeapTuple statstup = NULL;
/* For now, we only cover the simple-relation case */
if (rte->rtekind != RTE_RELATION || rte->inh)
return false;
if (!get_tom_stats_tupletable(rte->relid, attnum))
return false;
/*
* Get stats if present. We asked for only one row, so no need for loops.
*/
if (SPI_processed > 0)
statstup = SPI_copytuple(SPI_tuptable->vals[0]);
SPI_freetuptable(SPI_tuptable);
SPI_finish();
if (!statstup)
return false; /* should this happen? */
vardata->statsTuple = statstup;
/* define function to use when time to free the tuple */
vardata->freefunc = heap_freetuple;
return true;
}
and if you want to insert stats for expression indexes then there's a
separate get_index_stats_hook for that.
regards, tom lane
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Reply to all the recipients using the --to and --cc options:
reply via email
To: pgsql-patches@postgresql.org
Cc: tgl@sss.pgh.pa.us, simon@2ndQuadrant.com, stark@enterprisedb.com, alvherre@commandprompt.com
Subject: Re: [HACKERS] get_relation_stats_hook()
In-Reply-To: <18588.1222631869@sss.pgh.pa.us>
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox