Skip to content

fix: use bind parameters in the Oracle catalog queries - #18498

Merged
WikiRik merged 15 commits into
mainfrom
wikirik-agent/oracle-show-index-bind
Oct 22, 2026
Merged

WikiRik merged 15 commits into
mainfrom
wikirik-agent/oracle-show-index-bind

Conversation

@wikirik-agent

@wikirik-agent wikirik-agent commented Sep 26, 2026 •

Copy link
Copy Markdown
Contributor

Description of Changes

Model.sync(), sync({ alter }), dropAllTables() and the test-suite resets call showIndex(), describeTable() and showConstraints() 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 large ALL_* 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:

  • Query generator (Oracle). showIndexesQuery(), describeTableQuery(), showConstraintsQuery() and getForeignKeysQuery() accept the existing parameterStyle option. With parameterStyle: ParameterStyle.BIND they return a BoundQuery ({ query, bind }). Without it they return the same SQL string as before, so the existing query-generator tests are unchanged. If parameterStyle is not a literal type, the return type is string | BoundQuery. Like escape() did for objects, the BIND variants only accept strings as values and throw a TypeError otherwise. node-oracledb would otherwise read an object such as { dir, maxSize } as a bind definition.
  • Query interface. AbstractQueryInterfaceInternal (not public API) gets showIndexRaw(), describeTableRaw() and showConstraintsRaw(), which run the query and return the unprocessed result. AbstractQueryInterface#showIndex, #describeTable and #showConstraints call them and keep all of their post-processing and error handling. Other dialects behave exactly as before.
  • OracleQueryInterfaceInternal overrides the three methods to run the BIND variants. It sets logQueryParameters: true on these calls, so the query logs still show the names, as ; with parameters [ 'users', 'MYSCHEMA' ]. A caller's bind option can't override the generated values.
  • logQueryParameters per query. This option already worked per query at runtime, but it wasn't in the public Logging type. It is now typed next to benchmark.
  • Fix. showConstraintsQuery() without a schema used C.OWNER = '', which is NULL in Oracle, when the default schema is empty (e.g. external authentication without a username), so it found no constraints. It now falls back to USER, like the other catalog queries. All four queries now share one owner fallback. Guarded Oracle cases in the describe-table-query, show-indexes-query and show-constraints-query tests pin the USER text of all four queries.

No new public functions are added.

Results

Local, against a fresh gvenzl/oracle-free:23.26.3-slim container (the image CI uses), test/integration/associations/** (276 tests):

main binds
a single showIndex call, new table name each time 680–840 ms 31–41 ms
showIndex total (650 calls) 181 s 2.5 s
foreign-key lookups (1,174 calls) 29.6 s 4.3 s
total 272 s 75 s

CI, median duration of the "Integration Tests" step against 30 recent runs on the same main (measured with showIndex and with all three; the difference between the two is within CI noise):

main this PR
oracle latest (23) 928 s 259–288 s (≈ −70%)
oracle oldest (18 XE) 326 s 183 s (−44%)

Tests

test/unit/query-interface/show-index.test.ts, describe-table.test.ts and show-constraints.test.ts run on every dialect.

  • The sent query matches the generator's. Each test checks that the query sent to 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 for showConstraints, because it reads its constraints from the CREATE TABLE statement.
  • Placeholders parse. They also check that the dialect parses the placeholders into exactly the bind parameters that were sent.
  • Only Oracle binds. Only Oracle sends bind parameters and logQueryParameters.
  • Caller binds are ignored. A caller-provided bind can't override the generated values.
  • More cases. The tests also cover quoteIdentifiers: false and the no-default-schema case, and they check that the caller's options (such as useMaster) are passed on. Two Oracle-only cases complete the coverage:
    • A fake connection shows that the names reach the driver as positional :1/:2 binds.
    • Names that aren't strings are rejected.

The comparison uses a new test helper, inlineBindParameters, in test/support.ts.

This also folds in #18499, which is now closed.

List of Breaking Changes

None.

🤖 Generated with Claude Code

Summary by CodeRabbit

  • New Features
    • Oracle catalog queries for table descriptions, indexes, foreign keys, and constraints now support bound parameters.
    • Query logging can include bind parameters for individual queries, even when parameter logging is disabled by default.
  • Bug Fixes
    • Oracle catalog queries now use the current user as the catalog owner when no default schema is available.
    • Foreign-key constraint queries now honor the supplied query options.

@coderabbitai

coderabbitai Bot commented Sep 26, 2026 •

Copy link
Copy Markdown
Contributor

Review in Change Stack →

Note

Reviews paused

It 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 reviews.auto_review.auto_pause_after_reviewed_commits setting.

Use the following commands to manage reviews:

  • @coderabbitai resume to resume automatic reviews.
  • @coderabbitai review to trigger a single review.

Use the checkboxes below for quick actions:

  • ▶️ Resume reviews
  • 🔍 Trigger review

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration
  • Source mode: Auto
  • Repository: Unavailable
  • Branch: Unavailable
  • File: No configuration file from this repository applied
  • Commit: Unavailable
  • Layers: defaults
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: c3f5ce68-4b58-45dc-9140-035d381072b0
📥 Commits

Reviewing files that changed from the base of the PR and between ccf5b7e and e7639b3.

📒 Files selected for processing: 7
  • packages/core/test/unit/query-generator/describe-table-query.test.ts
  • packages/core/test/unit/query-generator/show-constraints-query.test.ts
  • packages/core/test/unit/query-generator/show-indexes-query.test.ts
  • packages/core/test/unit/query-interface/describe-table.test.ts
  • packages/core/test/unit/query-interface/show-constraints.test.ts
  • packages/core/test/unit/query-interface/show-index.test.ts
  • packages/oracle/src/query-generator-typescript.internal.ts

Included review availability: This review used your included allowance. Your plan provides up to 10 included reviews per hour; 9 remain after this review.

📝 Walkthrough

Oracle catalog-query methods now support bind parameters and replacement-based SQL. Core query-interface methods delegate index, table-description, and constraint retrieval to internal interfaces. Oracle executes these queries with generated binds and query-parameter logging.

Changes: Oracle catalog metadata queries

Layer / File(s) Summary
Build Oracle catalog queries
packages/oracle/src/query-generator-typescript.internal.ts
Catalog-query methods accept table or model names and parameter-style options. Bind mode returns SQL with bind values; replacement mode returns escaped SQL. Owner predicates use USER when no schema is provided.
Dispatch and execute catalog queries
packages/core/src/abstract-dialect/query-interface-internal.ts, packages/core/src/abstract-dialect/query-interface-typescript.ts, packages/core/src/abstract-dialect/query-interface.js, packages/core/src/model.d.ts, packages/oracle/src/query-interface.internal.ts, packages/oracle/src/query-interface.js
Core query-interface methods delegate catalog retrieval to internal raw-query methods. The Oracle internal interface executes bound catalog queries with query-parameter logging and the corresponding query types.
Validate binds and generated SQL
packages/core/test/support.ts, packages/core/test/unit/query-generator/{describe-table-query,show-constraints-query,show-indexes-query}.test.ts, packages/core/test/unit/query-interface/{describe-table,show-constraints,show-index}.test.ts
Tests check generated SQL and bind values across dialects, including default-schema handling and caller-provided binds. A support helper validates and inlines bind parameters.

Priority: ➖ Normal

Estimated code review effort: 3 (Moderate) | ~25 minutes

Change: Bug fix

Sequence Diagram(s)

sequenceDiagram
  participant QueryInterface
  participant OracleQueryInterfaceInternal
  participant OracleQueryGenerator
  participant sequelize.queryRaw
  QueryInterface->>OracleQueryInterfaceInternal: Request index, table description, or constraints
  OracleQueryInterfaceInternal->>OracleQueryGenerator: Generate SQL and bind values
  OracleQueryGenerator-->>OracleQueryInterfaceInternal: Return SQL and bind values
  OracleQueryInterfaceInternal->>sequelize.queryRaw: Execute with binds, query type, and logging options
Loading

Possibly related issues

  • Issue 18501 describes Oracle dictionary-query hard parsing as a test-suite performance cost. This change binds Oracle catalog-query identifiers.
Merge Risk: ⚪ Minimal · up to e7639

The catalog-query changes are ready to merge after normal checks; no actionable risk remains identified.

Security architecture risk: ⚪ Minimal · up to 45c2d

The change preserves the existing index-lookup API, catalog filters and database permissions while parameterizing table and schema values. No material security risk was found to be introduced or worsened.

Retained concerns
No architecture-level concerns identified.

Security review details

Security Blast Radius

  • inferred — The effective authority remains index-metadata lookup for caller-selected tables and schemas within the existing Oracle connection’s catalog visibility. The override does not establish additional credentials or database privileges.

Trust Boundaries and Controls

  • observed — The interface fixes generated bind values and the result query type after spreading caller options. queryRaw rejects SQL replacements and validates named binds, keeping ordinary table/schema strings outside SQL syntax.
  • inferred — Oracle’s unchanged execution layer merges inputParameters into its positional bind array, so numeric properties can alter generated selector values at the JavaScript layer. This prevents treating the interface’s bind assignment as an absolute selector lock. No additional SQL or connection authority follows from that mechanism for callers already authorized to choose showIndex table/schema arguments; actual driver behavior for such overrides remains untested.

Resilience and Maintainability Implications

  • observed — Connection ownership, transaction checks, retries and pooled-connection release remain in the unchanged queryRaw execution path. The new interface does not introduce a separate connection lifecycle or recovery transition.
Pre-merge checks: Passed 4 · Failed 1

Failed Failed checks: 1 warning

Check name Status Explanation Resolution
Docstring Coverage Warning Docstring coverage is 42.86% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 7 functions across 16 files. Write docstrings for the functions missing them to satisfy the coverage threshold.
Passed Passed checks: 4 passed
Check name Status Explanation
Title check Passed The title clearly identifies the main change: using bind parameters in Oracle catalog queries.
Linked Issues check Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check Passed Check skipped because no linked issues were found for this pull request.
Description Check Passed Check skipped - CodeRabbit’s high-level summary is enabled.
✨ Finishing Touches: 💡 2
📝 Generate docstrings: 💡
  • Commit to this branch
  • Create a new PR
🧪 Generate unit tests (beta)
  • Commit to this branch
  • Create a new PR
🛠️ Fix failing CI checks: 💡
  • Commit to this branch
  • Create a new PR
  • Autopilot · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@wikirik-agent

Copy link
Copy Markdown
Contributor Author

@coderabbitai review

@coderabbitai

coderabbitai Bot commented Oct 5, 2026 •

Copy link
Copy Markdown
Contributor
✅ Action performed

Review finished.

Note: CodeRabbit is an incremental review system and does not re-review already reviewed commits. This command is applicable only when automatic reviews are paused.

@wikirik-agent
wikirik-agent force-pushed the wikirik-agent/oracle-show-index-bind branch from 45c2d7c to 329d510 Compare October 21, 2026 03:39
@wikirik-agent
wikirik-agent marked this pull request as ready for review October 21, 2026 05:37
@wikirik-agent
wikirik-agent requested a review from a team as a code owner October 21, 2026 05:37
wikirik-agent and others added 9 commits October 22, 2026 04:26
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]>
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]>
…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]>
@wikirik-agent
wikirik-agent force-pushed the wikirik-agent/oracle-show-index-bind branch from 9139c6f to 2b072b6 Compare October 22, 2026 04:27
@wikirik-agent
wikirik-agent removed this pull request from stack #18500 October 22, 2026 04:27
@wikirik-agent wikirik-agent changed the title fix(oracle): use bind parameters in showIndex fix: use bind parameters in the Oracle catalog queries Oct 22, 2026
…en there is no default schema

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@wikirik-agent
wikirik-agent force-pushed the wikirik-agent/oracle-show-index-bind branch from 2b072b6 to 63a5263 Compare October 22, 2026 04:56
@WikiRik
WikiRik enabled auto-merge (squash) October 22, 2026 08:18
@WikiRik
WikiRik disabled auto-merge October 22, 2026 08:19
wikirik-agent and others added 2 commits October 22, 2026 08:29
…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]>
@wikirik-agent
wikirik-agent force-pushed the wikirik-agent/oracle-show-index-bind branch from ccf5b7e to e7639b3 Compare October 22, 2026 08:29
@WikiRik
WikiRik enabled auto-merge (squash) October 22, 2026 12:09
@WikiRik
WikiRik merged commit c8d7403 into main Oct 22, 2026
@WikiRik
WikiRik deleted the wikirik-agent/oracle-show-index-bind branch October 22, 2026 12:43
papandreou added a commit to papandreou/sequelize that referenced this pull request Oct 23, 2026
* 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
papandreou added a commit to papandreou/sequelize that referenced this pull request Oct 23, 2026
* 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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants