Skip to content

Commit 782a23d

Browse files
committed
CRC doc tweaks
1 parent 3e8a08a commit 782a23d

File tree

1 file changed

+61
-27
lines changed

1 file changed

+61
-27
lines changed

doc/api.md

Lines changed: 61 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -538,7 +538,7 @@ For installation information, see the [Node-oracledb Installation Instructions][
538538
- 31.1 [Tuning Fetch Performance](#rowfetching)
539539
- 31.2 [Database Round-trips](#roundtrips)
540540
- 31.3 [Statement Caching](#stmtcache)
541-
- 31.4 [Client Result Cache](#clientresultcache)
541+
- 31.4 [Client Result Caching (CRC)](#clientresultcache)
542542
32. [Tracing SQL and PL/SQL Statements](#tracingsql)
543543
33. [Node.js Programming Styles and node-oracledb](#programstyles)
544544
- 33.1 [Callbacks and node-oracledb](#callbackoverview)
@@ -16957,35 +16957,56 @@ satisfaction.
1695716957
[SODA](#sodaoverview) internally makes SQL calls, so tuning the statement cache
1695816958
is also beneficial for SODA applications.
1695916959

16960-
### <a name="clientresultcache"></a> 31.4 Client Result Cache
16960+
### <a name="clientresultcache"></a> 31.4 Client Result Caching (CRC)
1696116961

16962-
Node-oracledb applications can use Oracle Database's [Client Result Cache][180].
16963-
The CRC enables client-side caching of SQL query (SELECT statement) results in
16964-
client memory for immediate use when the same query is re-executed. This is
16965-
useful for reducing the cost of queries for small, mostly static, lookup tables,
16966-
such as for postal codes. CRC reduces network [round-trips](#roundtrips), and
16967-
also reduces database server CPU usage.
16962+
Node-oracledb applications can use Oracle Database's [Client Result Cache][180]
16963+
(CRC). This enables client-side caching of SQL query (SELECT statement)
16964+
results in client memory for immediate use when the same query is re-executed.
16965+
This is useful for reducing the cost of queries for small, mostly static,
16966+
lookup tables, such as for postal codes. CRC reduces network
16967+
[round-trips](#roundtrips) and also reduces database server CPU usage.
1696816968

1696916969
The cache is at the application process level. Access and invalidation is
1697016970
managed by the Oracle Client libraries. This removes the need for extra
16971-
application logic, or external utilities, to implement a cache.
16971+
application logic, or external utilities, to implement a cache. Pooled
16972+
connections can use CRC. Repeated statement execution on a standalone
16973+
connection will also use it, but sequences of calls using standalone
16974+
connections like `oracledb.getConnection({user:
16975+
...})`/`execute()`/`connection.close()` will not. CRC requires [statement
16976+
caching](#stmtcache) to be enabled, which is true by default.
1697216977

16973-
CRC can be enabled by setting the [database parameters][181]
16974-
`CLIENT_RESULT_CACHE_SIZE` and `CLIENT_RESULT_CACHE_LAG`, and then restarting
16975-
the database, for example:
16978+
##### Configuring CRC
16979+
16980+
Client Result Caching can be enabled by setting the [database parameters][181]
16981+
`CLIENT_RESULT_CACHE_SIZE` and `CLIENT_RESULT_CACHE_LAG`, for example:
1697616982

1697716983
```sql
1697816984
SQL> ALTER SYSTEM SET CLIENT_RESULT_CACHE_LAG = 3000 SCOPE=SPFILE;
1697916985
SQL> ALTER SYSTEM SET CLIENT_RESULT_CACHE_SIZE = 64K SCOPE=SPFILE;
16986+
```
16987+
16988+
Then restart the database:
16989+
16990+
```
1698016991
SQL> STARTUP FORCE
1698116992
```
1698216993

16983-
Once CRC has been enabled in the database, the values used by the cache in
16984-
Node.js can be tuned in an [`oraaccess.xml`](#oraaccess) file, see [Client
16985-
Configuration Parameters][182].
16994+
or restart the [pluggable database](#startupshutdownpdb), for example:
16995+
16996+
```
16997+
SQL> ALTER PLUGGABLE DATABASE CLOSE;
16998+
SQL> ALTER PLUGGABLE DATABASE OPEN;
16999+
```
17000+
17001+
Once CRC has been enabled in the database, the values used by the cache can
17002+
optionally be tuned in an [`oraaccess.xml`](#oraaccess) file, see [Client
17003+
Configuration Parameters][182]. Also see [Tuning the Result Cache][203], which
17004+
discusses CRC and also the Server Result Cache.
17005+
17006+
##### Using CRC
1698617007

16987-
Tables can be created, or altered, so repeated queries use CRC. This allows
16988-
existing applications to use CRC without needing modification. For example:
17008+
Tables can be created, or altered, so queries use CRC. This allows
17009+
applications to use CRC without needing modification. For example:
1698917010

1699017011
```sql
1699117012
SQL> CREATE TABLE cities (id NUMBER, name VARCHAR2(40)) RESULT_CACHE (MODE FORCE);
@@ -16998,39 +17019,51 @@ Alternatively, hints can be used in SQL statements. For example:
1699817019
SELECT /*+ result_cache */ postal_code FROM locations
1699917020
```
1700017021

17022+
##### Verifying CRC
17023+
1700117024
To verify that CRC is working, you can check the number of executions of your
17002-
query from `V$SQLAREA` and compare it with an uncached query. When CRC is
17003-
enabled, the number of statement executions is reduced because the statement is
17004-
not sent to the database unnecessarily.
17025+
query in `V$SQLAREA`. When CRC is enabled in the database, the number of
17026+
statement executions is reduced because the statement is not sent to the
17027+
database unnecessarily.
1700517028

1700617029
```javascript
1700717030
// Run some load
1700817031
const q = `SELECT postal_code FROM locations`;
1700917032
const qc = `SELECT /*+ RESULT_CACHE */ postal_code FROM locations`;
17033+
1701017034
for (let i = 0; i < 100; i++) {
17035+
connection = await oracledb.getConnection();
1701117036
result = await connection.execute(q);
17037+
await connection.close();
17038+
}
17039+
17040+
for (let i = 0; i < 100; i++) {
17041+
connection = await oracledb.getConnection();
1701217042
result = await connection.execute(qc);
17043+
await connection.close();
1701317044
}
1701417045

17015-
// Compare behaviors
17046+
// Compare behaviors (using a connection as SYSTEM)
1701617047
const m = `SELECT executions FROM v$sqlarea WHERE sql_text = :q1`;
17048+
1701717049
result = await systemconn.execute(m, [q]);
17018-
console.log('No CRC:', result.rows[0][0], 'executions');
17050+
console.log('No hint:', result.rows[0][0], 'executions');
17051+
1701917052
result = await systemconn.execute(m, [qc]);
17020-
console.log('CRC:', result.rows[0][0], 'executions');
17053+
console.log('CRC hint:', result.rows[0][0], 'executions');
1702117054
```
1702217055

1702317056
When CRC is enabled, output will be like:
1702417057

1702517058
```
17026-
No CRC: 100 executions
17027-
CRC: 1 executions
17059+
No hint: 100 executions
17060+
CRC hint: 1 executions
1702817061
```
1702917062

1703017063
If CRC is not enabled, output will be like:
1703117064
```
17032-
No CRC: 100 executions
17033-
CRC: 100 executions
17065+
No hint: 100 executions
17066+
CRC hint: 100 executions
1703417067
```
1703517068

1703617069
## <a name="bindtrace"></a> <a name="tracingsql"></a> 32. Tracing SQL and PL/SQL Statements
@@ -17618,3 +17651,4 @@ can be asked at [AskTom][158].
1761817651
[200]: https://blogs.oracle.com/opal/demo:-graphql-with-node-oracledb
1761917652
[201]: https://www.oracle.com/pls/topic/lookup?ctx=dblatest&id=GUID-19E0F73C-A959-41E4-A168-91E436DEE1F1
1762017653
[202]: https://www.oracle.com/pls/topic/lookup?ctx=dblatest&id=GUID-C941CE9D-97E1-42F8-91ED-4949B2B710BF
17654+
[203]: https://www.oracle.com/pls/topic/lookup?ctx=dblatest&id=GUID-39C521D4-5C6E-44B1-B7C7-DEADD7D9CAF0

0 commit comments

Comments
 (0)