Skip to content

fix(oracle): use bind parameters in describeTable and showConstraints - #18499

Closed
wikirik-agent wants to merge 8 commits into
wikirik-agent/oracle-show-index-bindfrom
wikirik-agent/oracle-catalog-query-binds
Closed

wikirik-agent wants to merge 8 commits into
wikirik-agent/oracle-show-index-bindfrom
wikirik-agent/oracle-catalog-query-binds

Conversation

@wikirik-agent

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

Copy link
Copy Markdown
Contributor

Description of Changes

Stacked on #18498; this is the follow-up mentioned there.

#18498 made Oracle's showIndex use bind parameters, so Oracle no longer hard parses that dictionary query for every table. describeTable and showConstraints inline the table name in the same way. That includes the foreign-key lookup that sync() runs for models with cyclic references and that sequelize.drop() / dropAllTables() run for dialects that don't drop with cascade.

These two can't be overridden in the Oracle query interface the way showIndex was, because AbstractQueryInterface post-processes their results. This PR adds a small internal seam instead:

  • AbstractQueryInterfaceInternal (not public API) gets describeTableRaw() and showConstraintsRaw(), which run the query and return the unprocessed result. AbstractQueryInterface#describeTable / #showConstraints call them and keep all of their post-processing and error handling. For other dialects, nothing changes.
  • The new OracleQueryInterfaceInternal overrides both to build the queries with bind parameters, using the SQL builders that now live in the internal catalog-queries.ts module next to the one from fix: use bind parameters in the Oracle catalog queries #18498. describeTableQuery() / showConstraintsQuery() / getForeignKeysQuery() use the same builders with escaped literals, so their output does not change. showConstraintsQuery() still goes through getForeignKeysQuery() for foreign keys, so overriding that method keeps working.

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

main #18498 #18498 + this PR
foreign-key lookups (1,174 calls) 29.6 s 29.6 s 4.3 s
total 272 s ~93 s 75 s

The #18498 column is estimated from the saved showIndex time; it was not measured on its own.

test/unit/query-interface/describe-table.test.ts and show-constraints.test.ts test the same way as #18498, on every dialect: the SQL sent with the binds put back must equal the query generator's describeTableQuery() / showConstraintsQuery(), including the foreign-key variant. SQLite3 is the exception for showConstraints, because it reads its constraints from the CREATE TABLE statement. Only Oracle sends bind parameters, and a caller-provided bind can't override them. Locally, the Oracle query-interface, model, model/sync and associations integration tests pass (447). One listTables test failed once because Oracle's listTablesQuery has no ORDER BY; that flake is unrelated to this PR, and the test passed on rerun. The core unit tests pass for Oracle, Postgres, MSSQL and SQLite3.

In CI, after rebasing onto main (6995f15), the "Integration Tests" step of oracle latest had a median of 288 s (159–324 s across 3 Node versions), against 928 s on main and 259 s with #18498 alone. CI runners are too noisy to separate this PR's local ~18 s gain from #18498's effect.

As with #18498, logged describeTable/showConstraints SQL now shows placeholders instead of the names unless logQueryParameters is enabled; test/integration/model.test.js was updated for this. Oracle's tableExistsQuery (run on every non-force sync) still inlines the table name and could get the same treatment in a follow-up.

List of Breaking Changes

None.

🤖 Generated with Claude Code

Summary by CodeRabbit

  • New Features

    • Added Oracle support for inspecting table columns, foreign keys, and other constraints.
    • Added schema-aware table and constraint metadata retrieval with bind-parameter support.
  • Bug Fixes

    • Improved handling of caller-provided parameters during Oracle metadata queries.
  • Tests

    • Added coverage for table descriptions and constraint inspection across Oracle and SQLite, including schemas and parameter handling.

@coderabbitai

coderabbitai Bot commented Sep 26, 2026 •

Copy link
Copy Markdown
Contributor

Review in Change Stack →

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration
  • Configuration used: defaults
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: 5d9ad327-beac-49d7-a0cc-239755ee58f2
📥 Commits

Reviewing files that changed from the base of the PR and between 91fc571 and 3b5d699.

📒 Files selected for processing: 5
  • packages/core/src/abstract-dialect/query-interface-internal.ts
  • packages/core/test/unit/query-interface/describe-table.test.ts
  • packages/core/test/unit/query-interface/show-constraints.test.ts
  • packages/oracle/src/_internal/catalog-queries.ts
  • packages/oracle/src/query-interface.internal.ts

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

📝 Walkthrough

The core query interface now delegates table descriptions and constraint retrieval to internal raw-query methods. Oracle adds catalog query builders and an internal query interface that executes these queries with bind parameters. Tests cover generated SQL, bind handling, and query-parameter logging.

Changes: Oracle metadata queries

Layer / File(s) Summary
Core raw query delegation
packages/core/src/abstract-dialect/query-interface-internal.ts, packages/core/src/abstract-dialect/query-interface-typescript.ts
The internal interface adds raw methods for table descriptions and constraints. The public methods delegate retrieval to those methods.
Oracle catalog query generation
packages/oracle/src/_internal/catalog-queries.ts, packages/oracle/src/query-generator-typescript.internal.ts
Catalog builders generate table-description, foreign-key, and constraint queries. The Oracle query generator delegates query construction to these builders.
Oracle raw execution and validation
packages/oracle/src/query-interface.internal.ts, packages/oracle/src/query-interface.js, packages/core/test/unit/query-interface/*, packages/core/test/integration/model.test.js
Oracle adds an internal query interface and wires it into OracleQueryInterface. Tests check SQL generation, bind handling, and query-parameter logging.

Priority: ⬇️ Low

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

Change: Bug fix

Possibly related issues

  • sequelize/sequelize issue 18501: The changes parameterize Oracle table-description and constraint queries, including foreign-key queries, matching the issue’s stated Oracle catalog-query hard-parsing objective.
Merge Risk: ⚪ Minimal · up to 3b5d6

The table-description and constraint-query changes appear ready to merge after normal checks.

Security architecture risk: 🔵 Low · up to f4e04

Default Oracle queries retain their table and schema restrictions while parameterizing input values. The main risk is compatibility: existing query-generator customizations no longer govern these metadata operations. No new privilege expansion is demonstrated.

Retained concerns

  • Low · architecture · observed: Oracle public describeTable and showConstraints now call catalog builders directly through raw execution, bypassing existing describeTableQuery, showConstraintsQuery, and getForeignKeysQuery overrides. This changes which customization layer controls metadata consumed by schema-management operations. Default ownership predicates remain intact, and no external security-policy override is evidenced.
Security review details

Security Blast Radius

  • inferred — The directly affected surface is Oracle catalog metadata accessible to the selected database connection. Those results influence schema-management actions under the caller's existing database authority. No additional tenant, service, environment, or credential authority is demonstrated by this change.

Trust Boundaries and Controls

  • observed — Metadata names are emitted as generated placeholders and separately supplied bind values, rather than SQL syntax. queryRaw validates referenced binds, Oracle maps them to driver placeholders, and execution uses the existing transaction, explicit connection, or pool-selection path. Schema predicates are selection controls, not evidence of application-level tenant authorization.

Resilience and Maintainability Implications

  • observed — Bind maps and constraint aggregation maps are invocation-local, avoiding new shared metadata state across concurrent reads or retries. The checked tests assert bound SQL and values using stubbed queryRaw calls; they do not establish real-driver behavior or preservation of generator overrides.
Pre-merge checks: Passed 4 · Failed 1

Failed Failed checks: 1 warning

Check name Status Explanation Resolution
Docstring Coverage Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 6 functions across 10 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 and concisely identifies the primary change: adding bind parameters to Oracle describeTable and showConstraints operations.
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: 💡 1
📝 Generate docstrings: 💡
  • Commit to this branch
  • Create a new PR
🧪 Generate unit tests (beta)
  • 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 wikirik-agent changed the title perf(oracle): use bind parameters in describeTable and showConstraints fix(oracle): use bind parameters in describeTable and showConstraints Sep 26, 2026
@wikirik-agent
wikirik-agent force-pushed the wikirik-agent/oracle-catalog-query-binds branch from a693d00 to f4e04be Compare October 5, 2026 15:53
@wikirik-agent
wikirik-agent force-pushed the wikirik-agent/oracle-show-index-bind branch from f30d1a4 to 45c2d7c Compare October 5, 2026 15:53
@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 and others added 3 commits October 21, 2026 03:31
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]>
@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 force-pushed the wikirik-agent/oracle-catalog-query-binds branch from f4e04be to 859faa2 Compare October 21, 2026 03:39
@wikirik-agent
wikirik-agent force-pushed the wikirik-agent/oracle-catalog-query-binds branch from 859faa2 to 91fc571 Compare October 21, 2026 03:58
@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 4 commits October 21, 2026 09:38
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]>
@wikirik-agent
wikirik-agent force-pushed the wikirik-agent/oracle-catalog-query-binds branch from 91fc571 to 3b5d699 Compare October 21, 2026 09:44
@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

Copy link
Copy Markdown
Contributor Author

Folded into #18498: describeTable and showConstraints now use the same approach as showIndex there (parameterStyle: BIND on the Oracle query generator, run through AbstractQueryInterfaceInternal), so the two PRs no longer need to be reviewed separately.

@wikirik-agent
wikirik-agent deleted the wikirik-agent/oracle-catalog-query-binds branch October 22, 2026 12:46
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.

1 participant