* Deparse given Var node into context->buf. * * If the Var belongs to the foreign relation, just print its remote name. * Otherwise, it's effectively a Param (and will in fact be a Param at * run time). Handle it the same way we handle plain Params --- see * deparseParam for comments. */
| 2536 | * deparseParam for comments. |
| 2537 | */ |
| 2538 | static void |
| 2539 | deparseVar(Var *node, deparse_expr_cxt *context) |
| 2540 | { |
| 2541 | Relids relids = context->scanrel->relids; |
| 2542 | int relno; |
| 2543 | int colno; |
| 2544 | |
| 2545 | /* Qualify columns when multiple relations are involved. */ |
| 2546 | bool qualify_col = (bms_membership(relids) == BMS_MULTIPLE); |
| 2547 | |
| 2548 | /* |
| 2549 | * If the Var belongs to the foreign relation that is deparsed as a |
| 2550 | * subquery, use the relation and column alias to the Var provided by the |
| 2551 | * subquery, instead of the remote name. |
| 2552 | */ |
| 2553 | if (is_subquery_var(node, context->scanrel, &relno, &colno)) |
| 2554 | { |
| 2555 | appendStringInfo(context->buf, "%s%d.%s%d", |
| 2556 | SUBQUERY_REL_ALIAS_PREFIX, relno, |
| 2557 | SUBQUERY_COL_ALIAS_PREFIX, colno); |
| 2558 | return; |
| 2559 | } |
| 2560 | |
| 2561 | if (bms_is_member(node->varno, relids) && node->varlevelsup == 0) |
| 2562 | deparseColumnRef(context->buf, node->varno, node->varattno, |
| 2563 | planner_rt_fetch(node->varno, context->root), |
| 2564 | qualify_col); |
| 2565 | else |
| 2566 | { |
| 2567 | /* Treat like a Param */ |
| 2568 | if (context->params_list) |
| 2569 | { |
| 2570 | int pindex = 0; |
| 2571 | ListCell *lc; |
| 2572 | |
| 2573 | /* find its index in params_list */ |
| 2574 | foreach(lc, *context->params_list) |
| 2575 | { |
| 2576 | pindex++; |
| 2577 | if (equal(node, (Node *) lfirst(lc))) |
| 2578 | break; |
| 2579 | } |
| 2580 | if (lc == NULL) |
| 2581 | { |
| 2582 | /* not in list, so add it */ |
| 2583 | pindex++; |
| 2584 | *context->params_list = lappend(*context->params_list, node); |
| 2585 | } |
| 2586 | |
| 2587 | printRemoteParam(pindex, node->vartype, node->vartypmod, context); |
| 2588 | } |
| 2589 | else |
| 2590 | { |
| 2591 | printRemotePlaceholder(node->vartype, node->vartypmod, context); |
| 2592 | } |
| 2593 | } |
| 2594 | } |
| 2595 |
no test coverage detected