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

Поиск
Список
Период
Сортировка
От Ernst-Georg Schmid
Тема AW: Get the name of the target Relation from Query struct?
Дата
Msg-id b07b0a8c21454d3fbf62fa5f3202ea48@BYEX19.de.bayer.cnb
обсуждение исходный текст
Ответ на Re: Get the name of the target Relation from Query struct?  (David Rowley <david.rowley@2ndquadrant.com>)
Ответы Re: Get the name of the target Relation from Query struct?  (David Rowley <david.rowley@2ndquadrant.com>)
Re: Get the name of the target Relation from Query struct?  (Ashutosh Bapat <ashutosh.bapat@enterprisedb.com>)
Список 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
Iexclude 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
extensionswork, so I guess it must be my code and not a problem of the build system or PostgreSQL itself.
 

Best regards,

Ernst-Georg

В списке pgsql-hackers по дате отправления:

Предыдущее
От: Kyotaro HORIGUCHI
Дата:
Сообщение: Re: [HACKERS] GUC for cleanup indexes threshold.
Следующее
От: amul sul
Дата:
Сообщение: Re: [HACKERS] Restrict concurrent update/delete with UPDATE ofpartition key