Home | Previous Page | Next Page   Design Decisions > Enhancing Performance >

Buffering Multiple Results

The am_getnext purpose function can find and store several qualified index entries in shared memory before it returns control to the database server. The following steps set up and fill a multiple-index entry buffer in shared memory:

To set up and fill a multiple-index entry buffer in shared memory
  1. Call mi_tab_setniorows() in am_open or am_beginscan to set the number of index entries that the access method can return in one scan.
  2. Call mi_tab_niorows() at the start of am_getnext to find out how many index entries to return.
  3. Loop through mi_tab_setnextrow() in am_getnext until the number of qualifying index entries matches the return value of mi_tab_niorows() or until no more qualifying rows remain.

Figure 15 shows the preceding steps. For more information about these functions, refer to Descriptor Function Reference.

Figure 15. Storing Multiple Results In a Buffer
mi_integer sample_beginscan(MI_AM_SCAN_DESC *sd)
{
   mi_integer     nrows = 512;
   MI_AM_TABLE_DESC *td=mi_scan_table(sd);
   mi_tab_setniorows(td, nrows);
}

mi_integer sample_getnext(MI_AM_SCAN_DESC  *sd, MI_ROW **retrow, 

               MI_AM_ROWID_DESC *ridDesc)
{
   mi_integer     nrows, row, nextrowid, nextfragid;
   MI_ROW        *nextrow=NULL; /* MI_ROW structure is not typically
used.*/
   
   MI_AM_TABLE_DESC *td =mi_scan_table(sd);
   nrows = mi_tab_niorows(td);

   if (nrows > 0)
   {/*Store qualified results in shared memory.buffer.*/
      for (row = 0; row < nrows; ++row)
      {    /* Evaluate rows until we get one to return to caller. */
         find_good_row(sd, &nextrow, &nextrowid, &fragid);
         mi_tab_setnextrow(td, nextrow, nextrowid, nextfragid);
      } /* End of loop for nrows times to fill shared memory.*/
   }/*End (nrows > 0). */
   else
   {/*Only one result per call to am_getnext. */
      find_good_row(sd, &nextrow, &nextrowid, &nextfragid);

      mi_id_setrowid(ridDesc, nextrowid);
      mi_id_setfragid(ridDesc, nextfragid);
   }
   /* When reach the end of data, return MI_NO_MORE_RESULTS, else return
MI_ROWS. */
}

Typically, a secondary access method does not create rows from key data. However, if you intend to set the am_keyscan purpose flag for a secondary access method, the access method must create an MI_ROW structure that contains key values in the appropriate order and of the appropriate data type to match the query specifications for a projected row.

Warning:
Although a user can index UDTs, the database server issues an exception if the secondary access method creates and returns a row from index keys that contain UDTs.

For information about am_keyscan, refer to Bypassing Table Scans.

Home | [ Top of Page | Previous Page | Next Page | Contents | Index ]