]> git.ipfire.org Git - thirdparty/sqlalchemy/sqlalchemy.git/commit
Implement native multi-table reflection API for the mssql dialect
authorGaurav Sharma <gauravsharma2696@gmail.com>
Wed, 3 Jun 2026 12:52:09 +0000 (08:52 -0400)
committerFederico Caselli <cfederico87@gmail.com>
Thu, 4 Jun 2026 21:04:34 +0000 (23:04 +0200)
commitc84c7b2ffccecb5249fcc8ec01c400ca2867dbe5
tree9ede08fe280edc7fab39f933ed59b04ad2045d9e
parent4fb459aaf05dd9c31ce3ece57c1bbf81ca9855de
Implement native multi-table reflection API for the mssql dialect

### Description

Adds 5 native `get_multi_*` reflection methods (columns, pk, fk, indexes, table_comment) for the MSSQL dialect, replacing the per-table loop in `_default_multi_reflect`. Single-table methods now delegate to the multi versions (PG/Oracle pattern); legacy per-table SQL is retained as `_internal_get_*` helpers, used only for tempdb reflection.

Not implemented here: `get_multi_unique_constraints`, `get_multi_check_constraints`, `get_multi_table_options` -MSSQL has no single-table counterparts to delegate from. Happy to add as a follow-up.

### Performance

Measured with `test/perf/many_table_reflection.py` against SQL Server 2022 (Docker, localhost, pyodbc + ODBC Driver 18) on a 250-table fixture, 15-50 cols, with PKs/FKs/indexes/comments:

| | single | multi | speedup |
|---|---|---|---|
| `get_columns` | 1.33s | 0.35s | 3.8x |
| `get_pk_constraint` | 1.41s | 0.08s | 18x |
| `get_foreign_keys` | 7.07s | 0.19s | 37x |
| `get_indexes` | 0.80s | 0.09s | 8.6x |
| `get_table_comment` | 0.71s | 0.05s | 14x |
| **MetaData.reflect** | **12.62s** | **1.15s** | **11x** |

### Checklist

This pull request is:

- [x] A new feature implementation
- Fixes: #8430
- Tests added in `test/dialect/mssql/test_reflection.py`
- Changelog entry: `doc/build/changelog/unreleased_21/8430.rst`

Closes: #13297
Pull-request: https://github.com/sqlalchemy/sqlalchemy/pull/13297
Pull-request-sha: 2c6c69f159225f85312e39d99222279ef8cbadd1

Change-Id: I525c60fc5ece94dd250f376b05b64b09e65ca0d7
doc/build/changelog/unreleased_21/8430.rst [new file with mode: 0644]
lib/sqlalchemy/dialects/mssql/base.py
lib/sqlalchemy/dialects/mssql/information_schema.py
test/dialect/mssql/test_reflection.py