Repository navigation
fix: use bind parameters in the Oracle catalog queries - #18498
Conversation
|
Note Reviews pausedIt looks like this branch is under active development. To avoid overwhelming you with review comments due to an influx of new commits, CodeRabbit has automatically paused this review. You can configure this behavior by changing the Use the following commands to manage reviews:
Use the checkboxes below for quick actions:
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info
📝 Walkthrough
Merge Risk: ⚪ Minimal · up to
|
f30d1a4 to
45c2d7c
Compare
|
@coderabbitai review |
✅ Action performedReview finished.
|
45c2d7c to
329d510
Compare
Oracle hard parses every distinct SQL text. Because the table name was inlined, every showIndex call (which Model.sync runs for each model) was hard parsed against the dictionary views, which takes hundreds of milliseconds on Oracle 23. Co-Authored-By: Claude Opus 5.5 <[email protected]>
Moves the showIndex SQL builder to an internal module instead of adding a public showIndexesQueryWithBind method to OracleQueryGenerator, and tests the bind parameters through queryInterface.showIndex. Co-Authored-By: Claude Opus 5.5 <[email protected]>
Co-Authored-By: Claude Opus 5.5 <[email protected]>
…aller binds Co-Authored-By: Claude Opus 5.5 <[email protected]>
Co-Authored-By: Claude Opus 5.5 <[email protected]>
Follow-up to the showIndex change: the describeTable and showConstraints dictionary queries (including the foreign key lookup used by sync and dropAllTables) also inlined the table name, so Oracle hard parsed them on every call. The abstract query interface post-processes the results of these queries, so running them moves to overridable methods on AbstractQueryInterfaceInternal, which the Oracle dialect overrides. Co-Authored-By: Claude Opus 5.5 <[email protected]>
Oracle now passes the schema to describeTable as a bind parameter, so the schema is in the logged parameters instead of the SQL. Co-Authored-By: Claude Opus 5.5 <[email protected]>
…omments Co-Authored-By: Claude Opus 5.5 <[email protected]>
…ind them through the internal query interface Moves the bind variants of showIndexesQuery, describeTableQuery, showConstraintsQuery and getForeignKeysQuery into the query generator (parameterStyle: BIND returns a BoundQuery), removes the separate catalog-queries module, and runs showIndex through a new AbstractQueryInterfaceInternal#showIndexRaw so all three Oracle catalog calls use the same seam. The Oracle calls enable logQueryParameters so the logged queries still show the names. Co-Authored-By: Claude Opus 5.5 <[email protected]>
9139c6f to
2b072b6
Compare
…en there is no default schema Co-Authored-By: Claude Opus 5.5 <[email protected]>
2b072b6 to
63a5263
Compare
…og binds, keep the describeTable SQL - add an overload returning string | BoundQuery for a parameterStyle that is not a literal - only accept strings as catalog query bind parameters, as escape() did for objects - keep the WHERE atc.OWNER = USER text of describeTableQuery when there is no owner Co-Authored-By: Claude Opus 5.5 <[email protected]>
…eIdentifiers false, option forwarding and the driver binds Co-Authored-By: Claude Opus 5.5 <[email protected]>
ccf5b7e to
e7639b3
Compare
Co-Authored-By: Claude Opus 5.5 <[email protected]>
* origin/main: (54 commits) fix: use bind parameters in the Oracle catalog queries (sequelize#18498) meta: update mysql docker tag to v8.4.13 (sequelize#18577) meta: update dependency eslint-plugin-jsdoc to v65.4.0 (sequelize#18575) meta: update dependency node to v24.22.1 (sequelize#18574) meta: update dependency @oclif/core to ^5.1.9 (sequelize#18573) fix(core): skip removing foreign keys in dropAllTables when dropping with cascade (sequelize#18497) fix(core): drop each model only once in Sequelize#drop (sequelize#18572) fix(postgres): drop the enum types of a model when its table is dropped (sequelize#18554) fix(core): avoid lodash omit in the Model constructor (sequelize#18556) meta(core): support async functions in expectPerDialect (sequelize#18569) meta: update dependency ibm_db to ^4.1.0 (sequelize#18571) fix(core): make rejectInvalidOptions iterate supportable options and accept undefined (sequelize#18557) fix(core): respect the omitNull option of calls and models, fix query generator typings (sequelize#18565) meta(core): convert unit/model tests to TypeScript (sequelize#18564) meta(core): convert unit/instance tests to TypeScript (sequelize#18563) meta: update sequelize AUTHORS (sequelize#18549) feat(mssql): add useUnicodeStrings dialect option (sequelize#18548) meta: retry image pulls in the database start scripts (sequelize#18340) meta(core): follow-ups to the isModelStatic cache from sequelize#18234 (sequelize#18559) meta: update dependency uuid to v14 (sequelize#18544) ... # Conflicts: # packages/postgres/src/query-interface.js
* origin/main: (26 commits) fix: use bind parameters in the Oracle catalog queries (sequelize#18498) meta: update mysql docker tag to v8.4.13 (sequelize#18577) meta: update dependency eslint-plugin-jsdoc to v65.4.0 (sequelize#18575) meta: update dependency node to v24.22.1 (sequelize#18574) meta: update dependency @oclif/core to ^5.1.9 (sequelize#18573) fix(core): skip removing foreign keys in dropAllTables when dropping with cascade (sequelize#18497) fix(core): drop each model only once in Sequelize#drop (sequelize#18572) fix(postgres): drop the enum types of a model when its table is dropped (sequelize#18554) fix(core): avoid lodash omit in the Model constructor (sequelize#18556) meta(core): support async functions in expectPerDialect (sequelize#18569) meta: update dependency ibm_db to ^4.1.0 (sequelize#18571) fix(core): make rejectInvalidOptions iterate supportable options and accept undefined (sequelize#18557) fix(core): respect the omitNull option of calls and models, fix query generator typings (sequelize#18565) meta(core): convert unit/model tests to TypeScript (sequelize#18564) meta(core): convert unit/instance tests to TypeScript (sequelize#18563) meta: update sequelize AUTHORS (sequelize#18549) feat(mssql): add useUnicodeStrings dialect option (sequelize#18548) meta: retry image pulls in the database start scripts (sequelize#18340) meta(core): follow-ups to the isModelStatic cache from sequelize#18234 (sequelize#18559) meta: update dependency uuid to v14 (sequelize#18544) ... # Conflicts: # packages/core/src/abstract-dialect/query-generator.js # packages/core/src/abstract-dialect/query-interface-typescript.ts # packages/core/test/unit/model/bulk-create.test.js # packages/core/test/unit/sql/insert.test.js
Description of Changes
Model.sync(),sync({ alter }),dropAllTables()and the test-suite resets callshowIndex(),describeTable()andshowConstraints()for every model. On Oracle, these queries put the table and schema names in the SQL as literals. Every table then produces a new SQL text, which Oracle has to hard parse against the largeALL_*dictionary views. On Oracle 23 that takes hundreds of milliseconds per call, and it is the main reason the "oracle latest" CI job is the slowest.This PR passes the names as bind parameters, so Oracle reuses the parsed statements across tables:
showIndexesQuery(),describeTableQuery(),showConstraintsQuery()andgetForeignKeysQuery()accept the existingparameterStyleoption. WithparameterStyle: ParameterStyle.BINDthey return aBoundQuery({ query, bind }). Without it they return the same SQL string as before, so the existing query-generator tests are unchanged. IfparameterStyleis not a literal type, the return type isstring | BoundQuery. Likeescape()did for objects, theBINDvariants only accept strings as values and throw aTypeErrorotherwise. node-oracledb would otherwise read an object such as{ dir, maxSize }as a bind definition.AbstractQueryInterfaceInternal(not public API) getsshowIndexRaw(),describeTableRaw()andshowConstraintsRaw(), which run the query and return the unprocessed result.AbstractQueryInterface#showIndex,#describeTableand#showConstraintscall them and keep all of their post-processing and error handling. Other dialects behave exactly as before.OracleQueryInterfaceInternaloverrides the three methods to run theBINDvariants. It setslogQueryParameters: trueon these calls, so the query logs still show the names, as; with parameters [ 'users', 'MYSCHEMA' ]. A caller'sbindoption can't override the generated values.logQueryParametersper query. This option already worked per query at runtime, but it wasn't in the publicLoggingtype. It is now typed next tobenchmark.showConstraintsQuery()without a schema usedC.OWNER = '', which isNULLin Oracle, when the default schema is empty (e.g. external authentication without a username), so it found no constraints. It now falls back toUSER, like the other catalog queries. All four queries now share one owner fallback. Guarded Oracle cases in thedescribe-table-query,show-indexes-queryandshow-constraints-querytests pin theUSERtext of all four queries.No new public functions are added.
Results
Local, against a fresh
gvenzl/oracle-free:23.26.3-slimcontainer (the image CI uses),test/integration/associations/**(276 tests):showIndexcall, new table name each timeshowIndextotal (650 calls)CI, median duration of the "Integration Tests" step against 30 recent runs on the same main (measured with
showIndexand with all three; the difference between the two is within CI noise):Tests
test/unit/query-interface/show-index.test.ts,describe-table.test.tsandshow-constraints.test.tsrun on every dialect.queryRaw, with its bind parameters put back in, equals the query generator's SQL. So every placeholder must replace exactly one literal. SQLite3 is the exception forshowConstraints, because it reads its constraints from theCREATE TABLEstatement.logQueryParameters.bindcan't override the generated values.quoteIdentifiers: falseand the no-default-schema case, and they check that the caller's options (such asuseMaster) are passed on. Two Oracle-only cases complete the coverage:connectionshows that the names reach the driver as positional:1/:2binds.The comparison uses a new test helper,
inlineBindParameters, intest/support.ts.This also folds in #18499, which is now closed.
List of Breaking Changes
None.
🤖 Generated with Claude Code
Summary by CodeRabbit