Buffering multiple results
The am_getnext purpose function can find and store several qualified rows in shared memory before it returns control to the database server.
About this task
Procedure
- Call mi_tab_setniorows() in am_open or am_beginscan to set the number of rows that the access method can return in one scan.
- Call mi_tab_niorows() at the start of am_getnext to find out how many rows to return.
- Loop through mi_tab_setnextrow() in am_getnext until the number of qualifying rows matches the return value of mi_tab_niorows() or until no more qualifying rows remain.
Example
The following figure shows the preceding steps.
The find_good_row() function is not shown here. If there is a row to return from the external data source, find_good_row() retrieves and assembles values and NULLs into arrays of MI_DATUM and mi_boolean, creates a row with mi_row_create(), sets nextrow and nextrowid accordingly, and returns. If there is no row to return, it sets nextrow to NULL.