How do I use the Oracle ODBC driver's OCI_ATTR_PREFETCH_ROWS and OCI_ATTR_PREFETCH_MEMORY attributes?

If you set both attributes, the OCI_ATTR_PREFETCH_MEMORY value takes precedence. Which attribute to use depends on numerous factors such as network speed and the amount of client-side memory available. Both parameters are ignored when you bind arrays of columns.

If you specify OCI_ATTR_PREFETCH_MEMORY, this amount of memory is allocated. If OCI_ATTR_PREFETCH_ROWS is set, the memory allocated is this value multiplied by the row size. When a call to fetch data is made, all the memory allocated is used to store records from the server. The first call gets back n rows and subsequent calls to fetch don't make a network call until all n records have been returned from the client.

Use OCI_ATTR_PREFETCH_MEMORY if your records vary greatly in length, but note that not all the memory will be used when fetching a result set much smaller than the allocated memory. This is not an exact science, so try alternative settings until there is no detectable performance increase.