-
Notifications
You must be signed in to change notification settings - Fork 718
WIP Fix issue #7674 about UPDATE SET(..), with indirection #7675
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
base: main
Are you sure you want to change the base?
Changes from all commits
7d2a5be
dfc26f9
7ceb490
2a6b9ff
dcdaaaa
c8aba9b
ca52681
06224c3
e188579
fd099d1
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3542,6 +3542,9 @@ get_update_query_targetlist_def(Query *query, List *targetList, | |
SubLink *cur_ma_sublink; | ||
List *ma_sublinks; | ||
|
||
AttrNumber previous_attnum = InvalidAttrNumber; | ||
int paramid_increment = 0; | ||
|
||
/* | ||
* Prepare to deal with MULTIEXPR assignments: collect the source SubLinks | ||
* into a list. We expect them to appear, in ID order, in resjunk tlist | ||
|
@@ -3664,11 +3667,48 @@ get_update_query_targetlist_def(Query *query, List *targetList, | |
*/ | ||
if (cur_ma_sublink != NULL) | ||
{ | ||
AttrNumber attnum = InvalidAttrNumber; | ||
if (IsA(expr, Param)) | ||
{ | ||
Param *param = (Param *) expr; | ||
attnum = param->paramid + paramid_increment; | ||
} | ||
else if (IsA(expr, FuncExpr)) | ||
{ | ||
FuncExpr *func = (FuncExpr *) expr; | ||
ListCell *lc; | ||
|
||
/* Iterate through the arguments of the FuncExpr */ | ||
foreach(lc, func->args) | ||
{ | ||
Node *arg = (Node *) lfirst(lc); | ||
|
||
/* Check if the argument is a PARAM node */ | ||
if (IsA(arg, Param)) | ||
{ | ||
Param *param = (Param *) arg; | ||
attnum = param->paramid + paramid_increment; | ||
|
||
break; /* Exit loop once we find the PARAM node */ | ||
} | ||
} | ||
} | ||
|
||
if (previous_attnum >= attnum) | ||
ereport(ERROR, (errcode(ERRCODE_WRONG_OBJECT_TYPE), | ||
errmsg( | ||
"cannot plan distributed UPDATE SET (..) = (SELECT ...) query when not sorted by physical order"), | ||
errhint("Sort the columns on the left side by physical order."))); | ||
|
||
previous_attnum = attnum; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Currently in the PR PG17 and PG15 ruleutils error out if the target columns are not in attribute order, is this intended to alert users to the problem ? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
It was some tests in this direction: fixing the bug is great, informing users if we detect they have probably been exposed is important IMO. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Something like: DefineCustomStringVariable(
"citus.log_pr_error_list",
gettext_noop("Comma-separated list of PR numbers for ERROR trapping"),
gettext_noop("set ERROR when a query enter a path changed by said pull request number"),
&pr_error_list_raw,
"",
PGC_USERSET,
GUC_STANDARD,
NULL,
PRErrorListGucAssignHook,
NULL); There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Hm, perhaps this kind of mechanism could be put into a separate PR ? We appreciate the intent, but it may be easier to consider in a separate contribution. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. true, I will work on this new PR so it can be used for this UPDATE SET case. |
||
|
||
if (--remaining_ma_columns > 0) | ||
continue; /* not the last column of multiassignment */ | ||
|
||
appendStringInfoChar(buf, ')'); | ||
expr = (Node *) cur_ma_sublink; | ||
cur_ma_sublink = NULL; | ||
paramid_increment = previous_attnum; | ||
} | ||
|
||
appendStringInfoString(buf, " = "); | ||
|
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 we have
citus_ruleutils.c
export one function that can be used by the supported PG ruleutils ? For example, a function:which is called by each supported
get_update_query_targetlist_def()
when the parse tree has MULTIEXPR assignments, maybe right after the sublinks have been collected. Basically, to keep the changes to each supported PG ruleutils to a minimum.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.
If I'm correct, it's adding a new traversal of the target list, I understand the motivation to reduce the diff, I was trying to not add too much extra processing. I check what is possible.
Uh oh!
There was an error while loading. Please reload this page.
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.
Yes there is a maintainability/processing tradeoff, but given that this is at plan-time and most of the time a sort will probably not be necessary the tradeoff for maintainability is worth making, unless there is a compelling counter-case.