Skip to content

Instantly share code, notes, and snippets.

@cjbj
Created May 3, 2021 22:11
Show Gist options
  • Save cjbj/b147c04cf9b85a2384e5a1a17ba00064 to your computer and use it in GitHub Desktop.
Save cjbj/b147c04cf9b85a2384e5a1a17ba00064 to your computer and use it in GitHub Desktop.
const oracledb = require('oracledb');
const dbConfig = require('./dbconfig.js');
if (process.platform === 'darwin') {
oracledb.initOracleClient({libDir: process.env.HOME + '/Downloads/instantclient_19_8'});
}
let result;
async function run() {
try {
const connection = await oracledb.getConnection(dbConfig);
const systemconn = await oracledb.getConnection({user: 'system', password: 'oracle', connectString: dbConfig.connectString});
// Setup schema
const stmts = [
`drop table crc_tab`,
`create table crc_tab (id number)`,
`insert into crc_tab values (1)`,
];
for (const s of stmts) {
try {
await connection.execute(s, [], { autoCommit: true });
} catch(e) {
if (e.errorNum != 942)
console.error(s, e);
}
}
// Run some load
const q = `select id from crc_tab`;
const qc = `select /*+ result_cache */ id from crc_tab`;
for (let i = 0; i < 100; i++) {
result = await connection.execute(q);
result = await connection.execute(qc);
}
// Compare behaviors
const m = `select executions from v$sqlarea where sql_text = :q1`;
result = await systemconn.execute(m, [q]);
console.log('No CRC', result.rows[0][0], 'executions');
result = await systemconn.execute(m, [qc]);
console.log('CRC', result.rows[0][0], 'executions');
} catch (err) {
console.error(err);
}
}
run();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment