mirror of https://github.com/citusdata/citus.git
Introduce a workaround for join aliases
When there is a join alias, var->varnosync will point to the alias and var->varno will point to the table itself, but we need to use the alias when deparsing the query. Hence a workaround is introduced to solve this problem in ruleutils. Normally this case can be understood with dpns->plan == NULL check but in our case, dpns->plan is always NULL. We should sync our ruleutils at some point with postgres ruleutils. This could be a wrong solution as well but the tests pass.pull/3900/head
parent
c5c9ec288f
commit
108a2972c2
|
@ -16,6 +16,8 @@
|
||||||
*/
|
*/
|
||||||
#include "distributed/pg_version_constants.h"
|
#include "distributed/pg_version_constants.h"
|
||||||
|
|
||||||
|
#pragma GCC optimize ("O0")
|
||||||
|
|
||||||
#include "pg_config.h"
|
#include "pg_config.h"
|
||||||
|
|
||||||
#if (PG_VERSION_NUM >= PG_VERSION_13) && (PG_VERSION_NUM < PG_VERSION_14)
|
#if (PG_VERSION_NUM >= PG_VERSION_13) && (PG_VERSION_NUM < PG_VERSION_14)
|
||||||
|
@ -3544,24 +3546,22 @@ get_variable(Var *var, int levelsup, bool istoplevel, deparse_context *context)
|
||||||
var->varlevelsup, levelsup);
|
var->varlevelsup, levelsup);
|
||||||
dpns = (deparse_namespace *) list_nth(context->namespaces,
|
dpns = (deparse_namespace *) list_nth(context->namespaces,
|
||||||
netlevelsup);
|
netlevelsup);
|
||||||
/*
|
|
||||||
* If we have a syntactic referent for the Var, and we're working from a
|
varno = var->varno;
|
||||||
* parse tree, prefer to use the syntactic referent. Otherwise, fall back
|
varattno = var->varattno;
|
||||||
* on the semantic referent. (Forcing use of the semantic referent when
|
|
||||||
* printing plan trees is a design choice that's perhaps more motivated by
|
|
||||||
* backwards compatibility than anything else. But it does have the
|
if (var->varnosyn > 0 && var->varnosyn <= list_length(dpns->rtable) && dpns->plan == NULL) {
|
||||||
* advantage of making plans more explicit.)
|
rte = rt_fetch(var->varnosyn, dpns->rtable);
|
||||||
*/
|
|
||||||
// if (var->varnosyn > 0 && dpns->plan == NULL)
|
// if the rte var->varnosync points to is not a regular table and it is a join
|
||||||
// {
|
// then the correct relname will be found with var->varnosync and var->varattnosync
|
||||||
// varno = var->varnosyn;
|
// TODO:: this is a workaround and it can be simplified.
|
||||||
// varattno = var->varattnosyn;
|
if (rte->rtekind == RTE_JOIN && rte->relid == 0 && var->varnosyn != var->varno) {
|
||||||
// }
|
varno = var->varnosyn;
|
||||||
// else
|
varattno = var->varattnosyn;
|
||||||
// {
|
}
|
||||||
varno = var->varno;
|
}
|
||||||
varattno = var->varattno;
|
|
||||||
// }
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Try to find the relevant RTE in this rtable. In a plan tree, it's
|
* Try to find the relevant RTE in this rtable. In a plan tree, it's
|
||||||
|
|
Loading…
Reference in New Issue