Skip to content

Commit e82cf64

Browse files
committed
Fix crash with COPY FROM and/or foreign partition routing operations.
COPY FROM and/or foreign partition routing code path in core assumes that FDW has BeginForeignInsert() APIs present and thus later executes ExecForeignInsert(). However, mysql_fdw does not support routable foreign-table partitions and/or executing COPY FROM on foreign tables and thus do not have BeginForeignInsert() API implemented. But as it has ExecForeignInsert() API, it gets called for these operations and results in the server crash. To fix this, add the BeginForeignInsert() API that throws an error. Also, add EndForeignInsert() similar to the Begin API. Reported on GitHub through issue #208 and an initial patch by Ian Barwick (ibarwick). FDW-224, patch further revised by Suraj Kharage, reviewed by Jeevan Ladhe.
1 parent a2932f4 commit e82cf64

File tree

1 file changed

+46
-0
lines changed

1 file changed

+46
-0
lines changed

mysql_fdw.c

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -188,6 +188,13 @@ static List *mysqlImportForeignSchema(ImportForeignSchemaStmt *stmt,
188188
Oid serverOid);
189189
#endif
190190

191+
#if PG_VERSION_NUM >= 110000
192+
static void mysqlBeginForeignInsert(ModifyTableState *mtstate,
193+
ResultRelInfo *resultRelInfo);
194+
static void mysqlEndForeignInsert(EState *estate,
195+
ResultRelInfo *resultRelInfo);
196+
#endif
197+
191198
/*
192199
* Helper functions
193200
*/
@@ -418,6 +425,12 @@ mysql_fdw_handler(PG_FUNCTION_ARGS)
418425
fdwroutine->ImportForeignSchema = mysqlImportForeignSchema;
419426
#endif
420427

428+
#if PG_VERSION_NUM >= 110000
429+
/* Partition routing and/or COPY from */
430+
fdwroutine->BeginForeignInsert = mysqlBeginForeignInsert;
431+
fdwroutine->EndForeignInsert = mysqlEndForeignInsert;
432+
#endif
433+
421434
PG_RETURN_POINTER(fdwroutine);
422435
}
423436

@@ -1873,6 +1886,39 @@ mysqlImportForeignSchema(ImportForeignSchemaStmt *stmt, Oid serverOid)
18731886
}
18741887
#endif
18751888

1889+
#if PG_VERSION_NUM >= 110000
1890+
/*
1891+
* mysqlBeginForeignInsert
1892+
* Prepare for an insert operation triggered by partition routing
1893+
* or COPY FROM.
1894+
*
1895+
* This is not yet supported, so raise an error.
1896+
*/
1897+
static void
1898+
mysqlBeginForeignInsert(ModifyTableState *mtstate,
1899+
ResultRelInfo *resultRelInfo)
1900+
{
1901+
ereport(ERROR,
1902+
(errcode(ERRCODE_FDW_UNABLE_TO_CREATE_EXECUTION),
1903+
errmsg("COPY and foreign partition routing not supported in mysql_fdw")));
1904+
}
1905+
1906+
/*
1907+
* mysqlEndForeignInsert
1908+
* BeginForeignInsert() is not yet implemented, hence we do not
1909+
* have anything to cleanup as of now. We throw an error here just
1910+
* to make sure when we do that we do not forget to cleanup
1911+
* resources.
1912+
*/
1913+
static void
1914+
mysqlEndForeignInsert(EState *estate, ResultRelInfo *resultRelInfo)
1915+
{
1916+
ereport(ERROR,
1917+
(errcode(ERRCODE_FDW_UNABLE_TO_CREATE_EXECUTION),
1918+
errmsg("COPY and foreign partition routing not supported in mysql_fdw")));
1919+
}
1920+
#endif
1921+
18761922
/*
18771923
* Prepare for processing of parameters used in remote query.
18781924
*/

0 commit comments

Comments
 (0)