fix(sqlserver): add TOP/ROW_NUMBER pagination for SQL Server < 2012 (#1693) - #1895
fix(sqlserver): add TOP/ROW_NUMBER pagination for SQL Server < 2012 (#1693)#1895HandSonic wants to merge 1 commit into
Conversation
…tterMind#1693) buildPageLimit() returned empty string for SQL Server versions below 11 (< 2012), causing DefaultSQLExecutor to skip pagination entirely and return all rows. Add fallback pagination: - SQL Server 2012+ (v11+): OFFSET/FETCH NEXT (existing behavior) - SQL Server 2005-2008 R2 (v9-10): TOP for first page, ROW_NUMBER() OVER() for subsequent pages - Below v9: returns empty (no safe pagination method available)
dc357ce to
af91751
Compare
|
This change needs focused tests before it can be merged, and the current fallback has correctness issues that those tests should expose.
The linked issue #1693 is a historical report about AI generating There is already a If robust rewriting is only possible for simple table-browse queries, please scope the fallback to that path rather than applying it to arbitrary editor SQL. |
|
Closing this PR per review feedback. The review identified fundamental correctness issues:
The reviewer correctly noted that #1693 is a historical issue, and the fallback approach of wrapping any arbitrary SQL with TOP/ROW_NUMBER pagination has too many edge cases. A proper fix would need to scope the fallback to simple table-browse queries only, which requires a more thorough design. Thank you for the detailed review. |
Problem
SqlServerSqlBuilder.buildPageLimit()对版本号 < 11 的 SQL Server(即 < 2012)返回空字符串。DefaultSQLExecutor检查到空字符串后完全跳过分页,返回全部数据行。Fix
添加分页降级策略:
OFFSET/FETCH NEXT(原有行为不变)SELECT TOP (pageSize) *,后续页用ROW_NUMBER() OVER()子查询实现偏移Related
Fixes #1693