Permalink
Browse files

Implement rescan. Unfortunately this requires the entire MySQL resultset

to be copied to the client (PostgreSQL), because the MySQL C API seems
be too unable to allow us to reset the current position in the resultset
on the server side. This appears to be the case using either regular or
prepared statements.
  • Loading branch information...
1 parent 65a604f commit 106bd29848a84151c56ae7ce2ad347de3e478dbf @dpage dpage committed Aug 1, 2011
Showing with 4 additions and 12 deletions.
  1. +0 −2 README
  2. +4 −10 mysql_fdw.c
View
2 README
@@ -33,8 +33,6 @@ Limitations
- The MySQL connection used to plan queries isn't currently reused
during execution.
-- Rescan currently does nothing.
-
Usage
-----
View
@@ -85,13 +85,7 @@ typedef struct MySQLFdwExecutionState
MYSQL *conn;
MYSQL_RES *result;
AttInMetadata *attinmeta;
- char *address;
- int port;
- char *username;
- char *password;
- char *database;
char *query;
- char *table;
} MySQLFdwExecutionState;
/*
@@ -536,8 +530,6 @@ mysqlBeginForeignScan(ForeignScanState *node, int eflags)
festate = (MySQLFdwExecutionState *) palloc(sizeof(MySQLFdwExecutionState));
node->fdw_state = (void *) festate;
festate->conn = conn;
- festate->address = svr_address;
- festate->port = svr_port;
festate->query = query;
/* OK, we connected. If this is an EXPLAIN, bail out now */
@@ -556,7 +548,7 @@ mysqlBeginForeignScan(ForeignScanState *node, int eflags)
}
/* Guess the query succeeded then */
- festate->result = mysql_use_result(conn);
+ festate->result = mysql_store_result(conn);
/* Store the additional state info */
festate->attinmeta = TupleDescGetAttInMetadata(node->ss.ss_currentRelation->rd_att);
@@ -612,7 +604,7 @@ mysqlEndForeignScan(ForeignScanState *node)
festate->result = NULL;
}
- if (festate->result)
+ if (festate->conn)
{
mysql_close(festate->conn);
festate->conn = NULL;
@@ -626,6 +618,8 @@ mysqlEndForeignScan(ForeignScanState *node)
static void
mysqlReScanForeignScan(ForeignScanState *node)
{
+ MySQLFdwExecutionState *festate = (MySQLFdwExecutionState *) node->fdw_state;
+ mysql_row_seek(festate->result, 0);
}

0 comments on commit 106bd29

Please sign in to comment.