AW: Get the name of the target Relation from Query struct?

From: Ernst-Georg Schmid <ernst-georg(dot)schmid(at)bayer(dot)com>
To: David Rowley <david(dot)rowley(at)2ndquadrant(dot)com>
Cc: "pgsql-hackers(at)postgresql(dot)org" <pgsql-hackers(at)postgresql(dot)org>
Subject: AW: Get the name of the target Relation from Query struct?
Date: 2018-04-06 08:38:46
Message-ID: b07b0a8c21454d3fbf62fa5f3202ea48@BYEX19.de.bayer.cnb
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

Hello again,

unfortunately this:

>The list_nth(query->rtable, query->resultRelation) will give you a
>RangeTblEntry which has a property called relid, which is the
>Relation's OID as per pg_class.oid.

gives me a Signal 11.

I can get the resultRelation and it is 1 (which matches the Documentation that says that it would be 0 for a SELECT but I exclude SELECTs as you suggested).

But the list_nth() reliably crashes the backend with a Signal 11.

Here is the complete function:

static PlannedStmt *
limit_func(Query *parse, int cursorOptions, ParamListInfo boundParams)
{
PlannedStmt *result;
RangeTblEntry *rte;
char *target_table;
char *target_schema;

/* this way we can daisy chain planner hooks if necessary */
if (prev_planner_hook != NULL)
result = (*prev_planner_hook) (parse, cursorOptions, boundParams);
else
result = standard_planner(parse, cursorOptions, boundParams);

if(parse->commandType != CMD_SELECT) {
int resultRelation = parse->resultRelation;

rte = (RangeTblEntry *) list_nth(parse->rtable, resultRelation);

//target_table = get_rel_name(rte->relid);

//target_schema = get_namespace_name(get_rel_namespace(rte->relid));

ereport(NOTICE, (errcode(ERRCODE_SUCCESSFUL_COMPLETION), errmsg("%i", resultRelation)));
}

return result;
}

If I comment out the line: rte = (RangeTblEntry *) list_nth(parse->rtable, resultRelation);

it works and sends me the resultRelation to a NOTICE in the log output.

What am I doing wrong? It's a 10.3 on Ubuntu 16.04 compiled from sources. Everything else, e.g. multicorn and other extensions work, so I guess it must be my code and not a problem of the build system or PostgreSQL itself.

Best regards,

Ernst-Georg

In response to

Responses

Browse pgsql-hackers by date

  From Date Subject
Next Message amul sul 2018-04-06 08:49:02 Re: [HACKERS] Restrict concurrent update/delete with UPDATE of partition key
Previous Message Kyotaro HORIGUCHI 2018-04-06 08:33:08 Re: [HACKERS] GUC for cleanup indexes threshold.