Skip to content
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

Support RETURNING on mariadb > 10.5 #258

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,5 @@
/results/
*.o
*.so
.idea
*.bc
41 changes: 40 additions & 1 deletion deparse.c
Original file line number Diff line number Diff line change
Expand Up @@ -446,12 +446,47 @@ mysql_deparse_from_expr(List *quals, deparse_expr_cxt *context)
}
}

/**
* convertReturningList()
*
* Generate RETURNING clause of a INSERT/UPDATE/DELETE ... RETURNING
* statement.
*/
static void
convertReturningList(StringInfo buf, PlannerInfo *root, Index rtindex,
Relation rel, bool doNothing, List *returningList)
{
bool first;
ListCell *lc;

elog(ERROR, "entering function %s", __func__);

/* Insert column names into the local query's RETURNING list */
if (returningList) {
elog(ERROR, "entering function %s with returningList", __func__);
appendStringInfoString(buf, " RETURNING ");
first = true;
elog(ERROR, "query: %s", (char*)buf);
foreach(lc, returningList)
{
int attnum = lfirst_int(lc);

if (!first)
appendStringInfoString(buf, ", ");
first = false;

elog(ERROR, "query: %s", (char*)buf);
mysql_deparse_column_ref(buf, rtindex, attnum, root, true);
}
}
}

/*
* Deparse remote INSERT statement
*/
void
mysql_deparse_insert(StringInfo buf, PlannerInfo *root, Index rtindex,
Relation rel, List *targetAttrs, bool doNothing)
Relation rel, List *targetAttrs, bool doNothing, List *returningList)
{
ListCell *lc;
#if PG_VERSION_NUM >= 140000
Expand Down Expand Up @@ -505,6 +540,10 @@ mysql_deparse_insert(StringInfo buf, PlannerInfo *root, Index rtindex,
}
else
appendStringInfoString(buf, " DEFAULT VALUES");
convertReturningList(buf, root, rtindex, rel,
doNothing, returningList);
elog(ERROR, "query: %s", (char*)buf);

}

void
Expand Down
12 changes: 6 additions & 6 deletions mysql_fdw.c
Original file line number Diff line number Diff line change
Expand Up @@ -1593,6 +1593,7 @@ mysqlPlanForeignModify(PlannerInfo *root,
RangeTblEntry *rte = planner_rt_fetch(resultRelation, root);
Relation rel;
List *targetAttrs = NIL;
List *returningList = NIL;
StringInfoData sql;
char *attname;
Oid foreignTableId;
Expand Down Expand Up @@ -1677,6 +1678,10 @@ mysqlPlanForeignModify(PlannerInfo *root,
#else
attname = get_relid_attribute_name(foreignTableId, 1);
#endif

/* Extract the relevant RETURNING list, if any */
if (plan->returningLists)
returningList = (List *) list_nth(plan->returningLists, subplan_index);

/*
* Construct the SQL command string.
Expand All @@ -1685,7 +1690,7 @@ mysqlPlanForeignModify(PlannerInfo *root,
{
case CMD_INSERT:
mysql_deparse_insert(&sql, root, resultRelation, rel, targetAttrs,
doNothing);
doNothing, returningList);
break;
case CMD_UPDATE:
mysql_deparse_update(&sql, root, resultRelation, rel, targetAttrs,
Expand All @@ -1699,11 +1704,6 @@ mysqlPlanForeignModify(PlannerInfo *root,
break;
}

if (plan->returningLists)
ereport(ERROR,
(errcode(ERRCODE_FDW_UNABLE_TO_CREATE_EXECUTION),
errmsg("RETURNING is not supported by this FDW")));

#if PG_VERSION_NUM < 130000
heap_close(rel, NoLock);
#else
Expand Down
4 changes: 3 additions & 1 deletion mysql_fdw.h
Original file line number Diff line number Diff line change
Expand Up @@ -306,7 +306,7 @@ extern mysql_opt *mysql_get_options(Oid foreigntableid, bool is_foreigntable);
/* depare.c headers */
extern void mysql_deparse_insert(StringInfo buf, PlannerInfo *root,
Index rtindex, Relation rel,
List *targetAttrs, bool doNothing);
List *targetAttrs, bool doNothing, List *returningList);
extern void mysql_deparse_update(StringInfo buf, PlannerInfo *root,
Index rtindex, Relation rel,
List *targetAttrs, char *attname);
Expand All @@ -324,6 +324,8 @@ extern void mysql_deparse_select_stmt_for_rel(StringInfo buf,
bool has_limit,
List **retrieved_attrs,
List **params_list);
//extern static void convertReturningList(StringInfo buf, PlannerInfo *root, Index rtindex,
// Relation rel, bool doNothing, List *returningList);
extern const char *mysql_get_jointype_name(JoinType jointype);
extern bool mysql_is_foreign_param(PlannerInfo *root, RelOptInfo *baserel,
Expr *expr);
Expand Down