@@ -11040,7 +11040,9 @@ const result = await connection.execute(
1104011040 FROM employees
1104111041 ORDER BY last_name
1104211042 OFFSET :offset ROWS FETCH NEXT :maxnumrows ROWS ONLY`,
11043- {offset: myoffset, maxnumrows: mymaxnumrows});
11043+ { offset: myoffset, maxnumrows: mymaxnumrows },
11044+ { prefetchRows: mymaxnumrows + 1, fetchArraySize: mymaxnumrows }
11045+ );
1104411046```
1104511047
1104611048A runnable example is in [rowlimit.js][84].
@@ -15549,69 +15551,79 @@ already buffered in the Oracle Client libraries. Reducing round-trips helps
1554915551performance and scalability. An overhead of prefetching is the need for an
1555015552additional data copy from Oracle Client's prefetch buffers.
1555115553
15552- To tune queries that return an unknown number of rows, estimate the number of
15553- rows returned and start with an appropriate `fetchArraySize` value. The default
15554- is 100. Then set `prefetchRows` to the `fetchArraySize` value. Do not make the
15555- sizes unnecessarily large. Keep `fetchArraySize` as big, or bigger than,
15556- `prefetchRows`. For example:
15557-
15558- ```javascript
15559- result = await connection.execute(
15560- `SELECT * FROM very_big_table`,
15561- [],
15562- {
15563- prefetchRows: 1000,
15564- fetchArraySize: 1000,
15565- resultSet: true
15566- }
15567- );
15568- ```
15554+ ##### Choosing values for `fetchArraySize` and `prefetchRows`
1556915555
15570- For a large quantity of rows or very "wide" rows on fast networks you may prefer
15571- to leave `prefetchRows` at its default value of 2. Adjust the values as needed
15572- for performance, memory and round-trip usage. The documentation in [Database
15556+ The best `fetchArraySize` and `prefetchRows` values can be found by
15557+ experimenting with your application under the expected load of normal
15558+ application use. This is because the cost of the extra memory copy
15559+ from the prefetch buffers when fetching a large quantity of rows or
15560+ very "wide" rows may outweigh the cost of a round-trip for a single
15561+ node-oracledb user on a fast network. However under production
15562+ application load, the reduction of round-trips may help performance
15563+ and overall system scalability. The documentation in [Database
1557315564Round-trips](#roundtrips) shows how to measure round-trips.
1557415565
15575- If you are fetching a fixed number of rows, start your tuning by setting
15576- `fetchArraySize` to the number of expected rows, and set `prefetchRows` to one
15577- greater than this value. (Adding one removes the need for a round-trip to check
15578- for end-of-fetch). For example, if you are querying 20 rows, perhaps to
15579- [display a page](#pagingdata) of data, set `prefetchRows` to 21 and
15580- `fetchArraySize` to 20:
15566+ Here are some suggestions for the starting point to being your tuning
1558115567
15582- ```javascript
15583- const myoffset = 0; // do not skip any rows (start at row 1)
15584- const mymaxnumrows = 20; // get 20 rows
15568+ - To tune queries that return an unknown number of rows, estimate the
15569+ number of rows returned and start with an appropriate
15570+ `fetchArraySize` value. The default is 100. Then set
15571+ `prefetchRows` to the `fetchArraySize` value. Do not make the sizes
15572+ unnecessarily large. For example:
1558515573
15586- sql = `SELECT last_name
15587- FROM employees
15588- ORDER BY last_name
15589- OFFSET :offset ROWS FETCH NEXT :maxnumrows ROWS ONLY`;
15574+ ```javascript
15575+ result = await connection.execute(
15576+ `SELECT * FROM very_big_table`,
15577+ [],
15578+ {
15579+ prefetchRows: 1000,
15580+ fetchArraySize: 1000,
15581+ resultSet: true
15582+ }
15583+ );
15584+ ```
1559015585
15591- binds = { offset: myoffset, maxnumrows: mymaxnumrows };
15586+ Adjust the values as needed for performance, memory and round-trip
15587+ usage. For a large quantity of rows or very "wide" rows on fast
15588+ networks you may prefer to leave `prefetchRows` at its default
15589+ value of 2. Keep `fetchArraySize` equal to, or bigger than,
15590+ `prefetchRows`.
1559215591
15593- options = { prefetchRows: mymaxnumrows + 1, fetchArraySize: mymaxnumrows };
15592+ - If you are fetching a fixed number of rows, start your tuning by
15593+ setting `fetchArraySize` to the number of expected rows, and set
15594+ `prefetchRows` to one greater than this value. (Adding one removes
15595+ the need for a round-trip to check for end-of-fetch). For example,
15596+ if you are querying 20 rows, perhaps to [display a
15597+ page](#pagingdata) of data, set `prefetchRows` to 21 and
15598+ `fetchArraySize` to 20:
1559415599
15595- result = await connection.execute(sql, binds, options);
15596- ```
15600+ ```javascript
15601+ const myoffset = 0; // do not skip any rows (start at row 1)
15602+ const mymaxnumrows = 20; // get 20 rows
1559715603
15598- This will return all rows for the query in one round-trip.
15604+ sql = `SELECT last_name
15605+ FROM employees
15606+ ORDER BY last_name
15607+ OFFSET :offset ROWS FETCH NEXT :maxnumrows ROWS ONLY`;
1559915608
15600- If you know that a query returns just one row then set `fetchArraySize` to 1 to
15601- minimize memory usage. The default prefetch value of 2 allows minimal
15602- round-trips for single-row queries:
15609+ binds = { offset: myoffset, maxnumrows: mymaxnumrows };
1560315610
15604- ```javascript
15605- result = await connection.execute(`SELECT * FROM mytable WHERE id = 1`, [], {fetchArraySize: 1});
15606- ```
15611+ options = { prefetchRows: mymaxnumrows + 1, fetchArraySize: mymaxnumrows };
1560715612
15608- The best `fetchArraySize` and `prefetchRows` values can be found by
15609- experimenting with your application under the expected load of normal
15610- application use. This is because the cost of the extra memory copy from the
15611- prefetch buffers when fetching a large quantity of rows or very "wide" rows may
15612- outweigh the cost of a round-trip for a single node-oracledb user on a fast
15613- network. However under production application load, the reduction of
15614- round-trips may help performance and overall system scalability.
15613+ result = await connection.execute(sql, binds, options);
15614+ ```
15615+
15616+ This will return all rows for the query in one round-trip.
15617+
15618+
15619+ - If you know that a query returns just one row then set
15620+ `fetchArraySize` to 1 to minimize memory usage. The default
15621+ prefetch value of 2 allows minimal round-trips for single-row
15622+ queries:
15623+
15624+ ```javascript
15625+ result = await connection.execute(`SELECT * FROM mytable WHERE id = 1`, [], {fetchArraySize: 1});
15626+ ```
1561515627
1561615628There are two cases that will benefit from disabling row prefetching
1561715629by setting `prefetchRows` to 0:
0 commit comments