-
Notifications
You must be signed in to change notification settings - Fork 640
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Convert relabeltype into collateexpr in deparser #4580
Convert relabeltype into collateexpr in deparser #4580
Conversation
c3dd954
to
5357176
Compare
Codecov Report
@@ Coverage Diff @@
## master #4580 +/- ##
=======================================
Coverage 92.69% 92.69%
=======================================
Files 212 212
Lines 42701 42707 +6
=======================================
+ Hits 39580 39588 +8
+ Misses 3121 3119 -2 |
5357176
to
11fdc26
Compare
c3213b4
to
2944406
Compare
@@ -4812,6 +4812,8 @@ get_rule_expr(Node *node, deparse_context *context, | |||
CHECK_FOR_INTERRUPTS(); | |||
check_stack_depth(); | |||
|
|||
node = RelabelTypeMutator(node); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
get_rule_expr gets called a lot, so this walker will likely cause excessive CPU.
Is there a way to integrate the logic from RelabelTypeMutator into the switch statement below?
case T_CollateExpr: | ||
{ | ||
node = RelabelTypeMutator(node); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do we still need a mutator if we already know this is a RelabelType?
f7a2508
to
4b885f9
Compare
@@ -4881,6 +4881,12 @@ get_rule_expr(Node *node, deparse_context *context, | |||
CHECK_FOR_INTERRUPTS(); | |||
check_stack_depth(); | |||
|
|||
if (nodeTag(node) == T_RelabelType && | |||
((RelabelType *)node)->resultcollid != InvalidOid) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
why not do this in the switch statement below?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It didn't work. I guess the reason is: Switch statement checks the initial node only; however, the node we are looking for might be somewhere we can reach by recursive search. @halilozanakgul what do you think?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hmz, I don't follow.
How can
if (nodeTag(node) == T_RelabelType && ((RelabelType *) node)->resultcollid != InvalidOid)
{
node = RelabelTypeMutator(node);
}
switch (nodeTag(node))
{
case T_RelabelType:
{
...
}
}
be different from
switch (nodeTag(node))
{
case T_RelabelType:
{
RelabelType *relabel = (RelabelType *) node;
Node *arg = (Node *) relabel->arg;
if (relabel->resultcollid != InvalidOid)
{
node = RelabelTypeMutator(node);
}
...
}
}
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ah, you're right. I've misunderstood
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ah, because in the first case we go into the CollateExpr switch instead.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
what if we do:
case T_RelabelType:
{
RelabelType *relabel = (RelabelType *) node;
Node *arg = (Node *) relabel->arg;
/*
* Citus modification:
* The planner rewrites CollateExpr to RelabelType, hence we print
* RelabelType with a collation ID as a COLLATE expression.
*/
if (relabel->resultcollid != InvalidOid)
{
if (!PRETTY_PAREN(context))
appendStringInfoChar(buf, '(');
get_rule_expr_paren(arg, context, showimplicit, node);
appendStringInfo(buf, " COLLATE %s",
generate_collation_name(collate->collOid));
if (!PRETTY_PAREN(context))
appendStringInfoChar(buf, ')');
break;
}
...
}
return (Node *) query_tree_mutator((Query *) originalNode, RelabelTypeMutator, | ||
(void *) NULL, 0); | ||
} | ||
return expression_tree_mutator(originalNode, RelabelTypeMutator, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
since the nodes will be visited recursively by the deparsing logic, do we still need a mutator?
3b05616
to
84a544b
Compare
|
||
if (relabel->relabelformat == COERCE_IMPLICIT_CAST && | ||
!showimplicit) | ||
if (relabel->resultcollid != InvalidOid) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
can you add a comment that this is a Citus-specific modification? That will make adding support for future PG releases slightly easier.
relabel->resulttype, | ||
relabel->resulttypmod, | ||
node); | ||
else { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
strange formatting
CollateExpr * | ||
RelabelTypeMutator(RelabelType *relabelType) | ||
{ | ||
if (relabelType == NULL) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
do we need this?
{ | ||
/* don't show the implicit cast */ | ||
get_rule_expr_paren(arg, context, false, node); | ||
CollateExpr *collate = RelabelTypeMutator(relabel); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe RelabelTypeMutator -> RelabelTypeToCollateExpr?
84a544b
to
0d31931
Compare
0d31931
to
5dd2a3d
Compare
… deparsing (#6391) Adjusts query's CoerceViaIO & RelabelType nodes that are improper for deparsing The standard planner converts some `::text` casts to `::cstring` and here we convert back because `cstring` is a pseudotype and it cannot be casted to most types. This problem occurs in CoerceViaIO nodes. There was another problem with RelabelType nodes fixed in the following PR: #4580 We undo the changes in that PR, and fix both CoerceViaIO and RelabelType nodes in the planning phase (not in the deparsing phase in ruleutils) Fixes #5646 Fixes #5033 Fixes #6061
… deparsing (#6391) Adjusts query's CoerceViaIO & RelabelType nodes that are improper for deparsing The standard planner converts some `::text` casts to `::cstring` and here we convert back because `cstring` is a pseudotype and it cannot be casted to most types. This problem occurs in CoerceViaIO nodes. There was another problem with RelabelType nodes fixed in the following PR: #4580 We undo the changes in that PR, and fix both CoerceViaIO and RelabelType nodes in the planning phase (not in the deparsing phase in ruleutils) Fixes #5646 Fixes #5033 Fixes #6061
Moves the RelabelTypeMutator calls to the get_rule_expr function
Fixes #4010