Skip to content

Commit 15a1dbb

Browse files
committed
Add row prefetching and cursor IN binding
1 parent 1818d37 commit 15a1dbb

20 files changed

+1093
-435
lines changed

CHANGELOG.md

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,14 @@
5050
allowing node-oracledb connection pools to shrink to `poolMin` even when
5151
there is no pool activity.
5252

53+
- Added
54+
[`oracledb.prefetchRows`](https://oracle.github.io/node-oracledb/doc/api.html#propdbprefetchrows)
55+
and equivalent `execute()` option attribute
56+
[`prefetchRows`](https://oracle.github.io/node-oracledb/doc/api.html#propexecprefetchrows)
57+
for query row fetch tuning to optimize round-trips, or disable prefetching
58+
altogether. See [Tuning Fetch
59+
Performance](https://oracle.github.io/node-oracledb/doc/api.html#rowfetching).
60+
5361
- Added support for queries containing cursor expressions that return [nested
5462
cursors](https://oracle.github.io/node-oracledb/doc/api.html#nestedcursors).
5563

@@ -65,6 +73,8 @@ and
6573
to allow preliminary database connections, such as required when starting a
6674
database.
6775

76+
- Added support for ResultSet IN binds to PL/SQL REF CURSOR parameters.
77+
6878
- Added support for PL/SQL Collection Associative Arrays "index-by tables" of
6979
the following types: `oracledb.DB_TYPE_NVARCHAR`, `oracledb.DB_TYPE_CHAR`,
7080
`oracledb.DB_TYPE_NCHAR`, `oracledb.DB_TYPE_BINARY_FLOAT`,

doc/api.md

Lines changed: 509 additions & 267 deletions
Large diffs are not rendered by default.

examples/example.js

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -38,8 +38,8 @@ const dbConfig = require('./dbconfig.js');
3838
// On Windows and macOS, you can specify the directory containing your Oracle
3939
// Client Libraries. If this is not done, then a standard search heuristic is
4040
// used, see the node-oracledb documentation.
41-
// oracledb.initOracleClient({ libDir: 'C:\instantclient_19_3' }); // Windows
42-
// oracledb.initOracleClient({ libDir: '/Users/myname/instantclient_19_3' }); // macOS
41+
// oracledb.initOracleClient({ libDir: 'C:\instantclient_19_3' }); // Windows
42+
// oracledb.initOracleClient({ libDir: '/Users/your_username/instantclient_19_3' }); // macOS
4343

4444
async function run() {
4545
let connection;
@@ -105,9 +105,10 @@ async function run() {
105105

106106
// For a complete list of options see the documentation.
107107
options = {
108-
outFormat: oracledb.OUT_FORMAT_OBJECT // query result format
109-
// extendedMetaData: true, // get extra metadata
110-
// fetchArraySize: 100 // internal buffer allocation size for tuning
108+
outFormat: oracledb.OUT_FORMAT_OBJECT, // query result format
109+
// extendedMetaData: true, // get extra metadata
110+
// prefetchRows: 100, // internal buffer allocation size for tuning
111+
// fetchArraySize: 100 // internal buffer allocation size for tuning
111112
};
112113

113114
result = await connection.execute(sql, binds, options);

examples/resultset1.js

Lines changed: 4 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
/* Copyright (c) 2015, 2019, Oracle and/or its affiliates. All rights reserved. */
1+
/* Copyright (c) 2015, 2020, Oracle and/or its affiliates. All rights reserved. */
22

33
/******************************************************************************
44
*
@@ -31,15 +31,6 @@ const oracledb = require('oracledb');
3131
const dbConfig = require('./dbconfig.js');
3232
const demoSetup = require('./demosetup.js');
3333

34-
// For getRow(), the fetchArraySize property can be adjusted to tune
35-
// data transfer from the Oracle Database to node-oracledb. The value
36-
// of fetchArraySize does not affect how, or when, rows are returned
37-
// by node-oracledb to the application. Buffering is handled by
38-
// internally in node-oracledb. Benchmark to choose the optimal size
39-
// for each application or query.
40-
//
41-
// oracledb.fetchArraySize = 100; // default value is 100
42-
4334
async function run() {
4435
let connection;
4536

@@ -54,7 +45,9 @@ async function run() {
5445
ORDER BY id`,
5546
[], // no bind variables
5647
{
57-
resultSet: true // return a ResultSet (default is false)
48+
resultSet: true, // return a ResultSet (default is false)
49+
// prefetchRows: 100, // internal buffer allocation size for tuning
50+
// fetchArraySize: 100 // internal buffer allocation size for tuning
5851
}
5952
);
6053

examples/rowlimit.js

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
/* Copyright (c) 2015, 2019, Oracle and/or its affiliates. All rights reserved. */
1+
/* Copyright (c) 2015, 2020, Oracle and/or its affiliates. All rights reserved. */
22

33
/******************************************************************************
44
*
@@ -60,7 +60,8 @@ async function run() {
6060

6161
const result = await connection.execute(
6262
sql,
63-
{ offset: myoffset, maxnumrows: mymaxnumrows }
63+
{ offset: myoffset, maxnumrows: mymaxnumrows },
64+
{ prefetchRows: mymaxnumrows + 1, fetchArraySize: mymaxnumrows }
6465
);
6566

6667
console.log("Executed: " + sql);

examples/select1.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
/* Copyright (c) 2015, 2019, Oracle and/or its affiliates. All rights reserved. */
1+
/* Copyright (c) 2015, 2020, Oracle and/or its affiliates. All rights reserved. */
22

33
/******************************************************************************
44
*
@@ -63,6 +63,7 @@ async function run() {
6363
maxRows: 1
6464
//, outFormat: oracledb.OUT_FORMAT_OBJECT // query result format
6565
//, extendedMetaData: true // get extra metadata
66+
//, prefetchRows: 100 // internal buffer allocation size for tuning
6667
//, fetchArraySize: 100 // internal buffer allocation size for tuning
6768
});
6869

examples/select2.js

Lines changed: 8 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
/* Copyright (c) 2015, 2019, Oracle and/or its affiliates. All rights reserved. */
1+
/* Copyright (c) 2015, 2020, Oracle and/or its affiliates. All rights reserved. */
22

33
/******************************************************************************
44
*
@@ -36,14 +36,6 @@ const demoSetup = require('./demosetup.js');
3636
// executions. They can also be set or overridden at the individual
3737
// execute() call level
3838

39-
// fetchArraySize can be adjusted to tune the internal data transfer
40-
// from the Oracle Database to node-oracledb. The value does not
41-
// affect how, or when, rows are returned by node-oracledb to the
42-
// application. Buffering is handled internally by node-oracledb.
43-
// Benchmark to choose the optimal size for each application or query.
44-
//
45-
// oracledb.fetchArraySize = 100; // default value is 100
46-
4739
// This script sets outFormat in the execute() call but it could be set here instead:
4840
//
4941
// oracledb.outFormat = oracledb.OUT_FORMAT_OBJECT;
@@ -75,8 +67,13 @@ async function run() {
7567
// Optional Object Output Format
7668
result = await connection.execute(
7769
sql,
78-
{}, // A bind parameter is needed to disambiguate the following options parameter and avoid ORA-01036
79-
{ outFormat: oracledb.OUT_FORMAT_OBJECT }); // outFormat can be OBJECT or ARRAY. The default is ARRAY
70+
[], // A bind parameter is needed to disambiguate the following options parameter and avoid ORA-01036
71+
{
72+
outFormat: oracledb.OUT_FORMAT_OBJECT, // outFormat can be OBJECT or ARRAY. The default is ARRAY
73+
// prefetchRows: 100, // internal buffer allocation size for tuning
74+
// fetchArraySize: 100 // internal buffer allocation size for tuning
75+
}
76+
);
8077
console.log("----- Banana Farmers (default OBJECT output format) --------");
8178
console.log(result.rows);
8279

examples/selectstream.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,8 @@ async function run() {
4545
ORDER BY id`,
4646
[], // no binds
4747
{
48-
fetchArraySize: 150 // internal buffer size can be adjusted for performance tuning
48+
prefetchRows: 150, // internal buffer sizes can be adjusted for performance tuning
49+
fetchArraySize: 150
4950
}
5051
);
5152

src/njsBaton.c

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -899,6 +899,14 @@ bool njsBaton_isBindValue(njsBaton *baton, napi_env env, napi_value value)
899899
if (check)
900900
return true;
901901

902+
// result sets can be bound directly
903+
status = napi_instanceof(env, value, baton->jsResultSetConstructor,
904+
&check);
905+
if (status != napi_ok)
906+
return false;
907+
if (check)
908+
return true;
909+
902910
// database objects can be bound directly
903911
status = napi_instanceof(env, value, baton->jsBaseDbObjectConstructor,
904912
&check);
@@ -1031,6 +1039,11 @@ bool njsBaton_setConstructors(njsBaton *baton, napi_env env)
10311039
NJS_CHECK_NAPI(env, napi_get_reference_value(env,
10321040
baton->oracleDb->jsLobConstructor, &baton->jsLobConstructor))
10331041

1042+
// acquire the result set constructor
1043+
NJS_CHECK_NAPI(env, napi_get_reference_value(env,
1044+
baton->oracleDb->jsResultSetConstructor,
1045+
&baton->jsResultSetConstructor))
1046+
10341047
// acquire the base database object constructor
10351048
NJS_CHECK_NAPI(env, napi_get_reference_value(env,
10361049
baton->oracleDb->jsBaseDbObjectConstructor,

0 commit comments

Comments
 (0)