mysql_fdw icon indicating copy to clipboard operation
mysql_fdw copied to clipboard

Support Batch insert like postgres_fdw of postgresql-14

Open MinhLA1410 opened this issue 2 years ago • 0 comments

Currently, we already implement batch insert like postgres_fdw from postgresql-14. I would like to contribute them into repository and community. If you have interest? I will create pull request for share this feature.

Summary modification:

  • Add 2 foreign routine: mysqlExecForeignBatchInsert; mysqlGetForeignModifyBatchSize;

  • For batch insert, we can use prepared statement with bind API https://dev.mysql.com/doc/c-api/5.7/en/mysql-stmt-bind-param.html

    • Rebuild the SQL with place holder "INSERT INTO tbl VALUES (?), (?), (?)" - Prepare the statement.
    • Bind the place holder parameter
    • Execute the statement.

Reference testcase of postgres_fdw.sql in postgres_fdw:

alter server mysql_svr options (add batch_size '10');

explain (verbose, costs off)
insert into grem1 (a) values (1), (2);
                                             QUERY PLAN                                             
----------------------------------------------------------------------------------------------------
 Insert on public.grem1
   Remote query: INSERT INTO `mysql_fdw_post`.`gloc1_post14`(`id`, `a`, `b`) VALUES (?, ?, DEFAULT)
   Batch Size: 10
   ->  Values Scan on "*VALUES*"
         Output: NULL::integer, "*VALUES*".column1, NULL::integer
(5 rows)

MinhLA1410 avatar Mar 29 '22 09:03 MinhLA1410