Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit edf46f9

Browse files
committed
small fixes
1 parent 6afa610 commit edf46f9

File tree

1 file changed

+14
-9
lines changed

1 file changed

+14
-9
lines changed

src/planner_tree_modification.c

+14-9
Original file line numberDiff line numberDiff line change
@@ -93,15 +93,14 @@ typedef struct
9393
CommonTableExpr *parent_cte;
9494
} transform_query_cxt;
9595

96-
9796
typedef struct
9897
{
9998
Index child_varno;
99+
Oid parent_relid;
100100
List *translated_vars;
101101
} adjust_appendrel_varnos_cxt;
102102

103103

104-
105104
static bool pathman_transform_query_walker(Node *node, void *context);
106105

107106
static void disable_standard_inheritance(Query *parse, transform_query_cxt *context);
@@ -473,9 +472,9 @@ handle_modification_query(Query *parse, transform_query_cxt *context)
473472

474473
/* Translate varnos for this child */
475474
aav_cxt.child_varno = result_rti;
475+
aav_cxt.parent_relid = parent;
476476
aav_cxt.translated_vars = translated_vars;
477-
if (adjust_appendrel_varnos((Node *) parse, &aav_cxt))
478-
return; /* failed to perform rewrites */
477+
adjust_appendrel_varnos((Node *) parse, &aav_cxt);
479478

480479
/* Translate column privileges for this child */
481480
rte->selectedCols = translate_col_privs(rte->selectedCols, translated_vars);
@@ -561,6 +560,7 @@ eval_extern_params_mutator(Node *node, ParamListInfo params)
561560
(void *) params);
562561
}
563562

563+
/* Remap parent's attributes to child ones s*/
564564
static bool
565565
adjust_appendrel_varnos(Node *node, adjust_appendrel_varnos_cxt *context)
566566
{
@@ -572,6 +572,7 @@ adjust_appendrel_varnos(Node *node, adjust_appendrel_varnos_cxt *context)
572572
Query *query = (Query *) node;
573573
ListCell *lc;
574574

575+
/* FIXME: we might need to reorder TargetEntries */
575576
foreach (lc, query->targetList)
576577
{
577578
TargetEntry *te = (TargetEntry *) lfirst(lc);
@@ -581,11 +582,13 @@ adjust_appendrel_varnos(Node *node, adjust_appendrel_varnos_cxt *context)
581582
continue;
582583

583584
if (te->resno > list_length(context->translated_vars))
584-
return true;
585+
elog(ERROR, "attribute %d of relation \"%s\" does not exist",
586+
te->resno, get_rel_name(context->parent_relid));
585587

586588
child_var = list_nth(context->translated_vars, te->resno - 1);
587589
if (!child_var)
588-
return true;
590+
elog(ERROR, "attribute %d of relation \"%s\" does not exist",
591+
te->resno, get_rel_name(context->parent_relid));
589592

590593
/* Transform attribute number */
591594
te->resno = child_var->varattno;
@@ -601,17 +604,19 @@ adjust_appendrel_varnos(Node *node, adjust_appendrel_varnos_cxt *context)
601604
{
602605
Var *var = (Var *) node;
603606

604-
/* Don't tranform system columns & other relations' Vars */
607+
/* Don't transform system columns & other relations' Vars */
605608
if (var->varoattno > 0 && var->varno == context->child_varno)
606609
{
607610
Var *child_var;
608611

609612
if (var->varattno > list_length(context->translated_vars))
610-
return true;
613+
elog(ERROR, "attribute %d of relation \"%s\" does not exist",
614+
var->varattno, get_rel_name(context->parent_relid));
611615

612616
child_var = list_nth(context->translated_vars, var->varattno - 1);
613617
if (!child_var)
614-
return true;
618+
elog(ERROR, "attribute %d of relation \"%s\" does not exist",
619+
var->varattno, get_rel_name(context->parent_relid));
615620

616621
/* Transform attribute number */
617622
var->varattno = child_var->varattno;

0 commit comments

Comments
 (0)