* postgresReScanForeignScan * Restart the scan. */
| 1641 | * Restart the scan. |
| 1642 | */ |
| 1643 | static void |
| 1644 | postgresReScanForeignScan(ForeignScanState *node) |
| 1645 | { |
| 1646 | PgFdwScanState *fsstate = (PgFdwScanState *) node->fdw_state; |
| 1647 | char sql[64]; |
| 1648 | PGresult *res; |
| 1649 | |
| 1650 | /* If we haven't created the cursor yet, nothing to do. */ |
| 1651 | if (!fsstate->cursor_exists) |
| 1652 | return; |
| 1653 | |
| 1654 | /* |
| 1655 | * If the node is async-capable, and an asynchronous fetch for it has been |
| 1656 | * begun, the asynchronous fetch might not have yet completed. Check if |
| 1657 | * the node is async-capable, and an asynchronous fetch for it is still in |
| 1658 | * progress; if so, complete the asynchronous fetch before restarting the |
| 1659 | * scan. |
| 1660 | */ |
| 1661 | if (fsstate->async_capable && |
| 1662 | fsstate->conn_state->pendingAreq && |
| 1663 | fsstate->conn_state->pendingAreq->requestee == (PlanState *) node) |
| 1664 | fetch_more_data(node); |
| 1665 | |
| 1666 | /* |
| 1667 | * If any internal parameters affecting this node have changed, we'd |
| 1668 | * better destroy and recreate the cursor. Otherwise, rewinding it should |
| 1669 | * be good enough. If we've only fetched zero or one batch, we needn't |
| 1670 | * even rewind the cursor, just rescan what we have. |
| 1671 | */ |
| 1672 | if (node->ss.ps.chgParam != NULL) |
| 1673 | { |
| 1674 | fsstate->cursor_exists = false; |
| 1675 | snprintf(sql, sizeof(sql), "CLOSE c%u", |
| 1676 | fsstate->cursor_number); |
| 1677 | } |
| 1678 | else if (fsstate->fetch_ct_2 > 1) |
| 1679 | { |
| 1680 | snprintf(sql, sizeof(sql), "MOVE BACKWARD ALL IN c%u", |
| 1681 | fsstate->cursor_number); |
| 1682 | } |
| 1683 | else |
| 1684 | { |
| 1685 | /* Easy: just rescan what we already have in memory, if anything */ |
| 1686 | fsstate->next_tuple = 0; |
| 1687 | return; |
| 1688 | } |
| 1689 | |
| 1690 | /* |
| 1691 | * We don't use a PG_TRY block here, so be careful not to throw error |
| 1692 | * without releasing the PGresult. |
| 1693 | */ |
| 1694 | res = pgfdw_exec_query(fsstate->conn, sql, fsstate->conn_state); |
| 1695 | if (PQresultStatus(res) != PGRES_COMMAND_OK) |
| 1696 | pgfdw_report_error(ERROR, res, fsstate->conn, true, sql); |
| 1697 | PQclear(res); |
| 1698 | |
| 1699 | /* Now force a fresh FETCH. */ |
| 1700 | fsstate->tuples = NULL; |
nothing calls this directly
no test coverage detected