diff --git a/reference/oci8/functions/oci-set-prefetch.xml b/reference/oci8/functions/oci-set-prefetch.xml index 6a39e24c1c..c2a10d44d6 100644 --- a/reference/oci8/functions/oci-set-prefetch.xml +++ b/reference/oci8/functions/oci-set-prefetch.xml @@ -3,7 +3,7 @@ oci_set_prefetch - Sets number of rows to be prefetched + Sets number of rows to be prefetched by queries @@ -14,26 +14,47 @@ introws - Sets the number of rows to be prefetched after a successful call to - oci_execute. For queries returning a large - number of rows, performance can be improved by increasing the - prefetch count above the - default oci8_.default_prefetch + Sets the number of rows to be buffered by the Oracle Client + libraries after a successful query call + to oci_execute and for each subsequent + internal fetch request to the database. For queries returning a + large number of rows, performance can be significantly improved by + increasing the prefetch count above the + default oci8.default_prefetch value. Prefetching is Oracle's efficient way of returning more than one data row from the database in each network request. This can - result in better network and CPU utilization. The behavior of OCI8 - fetching functions is unchanged regardless of the prefetch count. + result in better network and CPU utilization. The buffering of + rows is internal to OCI8 and the behavior of OCI8 fetching + functions is unchanged regardless of the prefetch count. For + example, oci_fetch_row will always return one + row. The prefetch buffer is per-statement and is not used by + re-executed statements or by other connections. + + + Call oci_set_prefetch before + calling oci_execute. + + + A tuning goal is to set the prefetch value to a reasonable size + for the network and database to handle. For queries returning a + very large number of rows, overall system efficiency might be + better if rows are retrieved from the database in several chunks + (i.e set the prefetch value smaller than the number of rows). + This allows the database to handle other users' statements while + your script is processing the current set of rows. Query prefetching was introduced in Oracle 8i. REF CURSOR prefetching was introduced in Oracle 11gR2 and occurs when PHP is - linked with Oracle 11gR2 libraries and connected to 11gR2 or + linked with Oracle 11gR2 Client libraries and connected to 11gR2 or previous versions of the database. Nested cursor prefetching was introduced in Oracle 11gR2 and requires both the Oracle Client - libraries and the database to be version 11gR2. + libraries and the database to be version 11gR2. The prefetch value + is ignored and single-row fetches will be used when prefetching is + not supported. @@ -56,7 +77,7 @@ The number of rows to be prefetched. - From PHP 5.3.2 and PECL oci8 1.4, rows may be >= 0. Prior versions required rows >= 1. + From PHP 5.3.2 and PECL OCI8 1.4, rows may be >= 0. Prior versions required rows >= 1. @@ -73,6 +94,14 @@ &reftitle.notes; + + + Prior to PHP 5.3 (Prior to PECL OCI8 1.3.4) the prefetch count was + limited to the lessor of rows rows and + 1024 * rows bytes. The byte size + restriction has now been removed. + + In PHP versions before 5.0.0 you must use ocisetprefetch instead. &oci.name.compat.note; @@ -80,12 +109,136 @@ + + &reftitle.examples; + + + Changing the default prefetch value for a query + +\n"; +while ($row = oci_fetch_array($stid, OCI_ASSOC+OCI_RETURN_NULLS)) { + echo "\n"; + foreach ($row as $item) { + echo " ".($item !== null ? htmlentities($item, ENT_QUOTES) : " ")."\n"; + } + echo "\n"; +} +echo "\n"; + +oci_free_statement($stid); +oci_close($conn); + +?> +]]> + + + + + + Changing the default prefetch for a REF CURSOR fetch + +\n"; +while ($row = oci_fetch_array($refcur, OCI_ASSOC+OCI_RETURN_NULLS)) { + echo "\n"; + foreach ($row as $item) { + echo " ".($item !== null ? htmlentities($item, ENT_QUOTES) : " ")."\n"; + } + echo "\n"; +} +echo "\n"; + +oci_free_statement($refcur); +oci_free_statement($stid); +oci_close($conn); + +?> +]]> + + + + + If PHP OCI8 fetches from a REF CURSOR and then passes the REF + CURSOR back to a second PL/SQL procedure for further processing, + then set the REF CURSOR prefetch count to 0 to + avoid rows being "lost" from the result set. The prefetch value is + the number of extra rows fetched in each OCI8 internal request to + the database, so setting it to 0 means only + fetch one row at a time. + + Setting the prefetch value when passing a REF CURSOR back to Oracle + + +]]> + + + + + &reftitle.seealso; - oci8_.default_prefetch + oci8.default_prefetch ini option