Skip to content

Harden pagination count SQL generation against JSqlParser silent truncation#7085

Draft
Copilot wants to merge 2 commits into
3.0from
copilot/fix-paginated-sql-errors
Draft

Harden pagination count SQL generation against JSqlParser silent truncation#7085
Copilot wants to merge 2 commits into
3.0from
copilot/fix-paginated-sql-errors

Conversation

Copilot AI commented Jun 3, 2026

Copy link
Copy Markdown
Contributor

PaginationInnerInterceptor.autoCountSql can receive a silently truncated AST from JSqlParser (error-recovery path), producing optimized count SQL that drops ? placeholders while MyBatis parameter mappings remain unchanged. This causes runtime parameter-index errors on count queries for complex nested WHERE clauses.

  • Fallback guard for placeholder integrity

    • Added placeholder-count consistency checks between original SQL and parser-derived SQL before returning optimized count SQL.
    • If placeholder counts differ, interceptor now degrades to low-level count SQL (SELECT COUNT(*) FROM (originalSql) TOTAL) instead of returning unsafe optimized SQL.
  • Applied consistently across parser variants

    • Mirrored the same safeguard in:
      • mybatis-plus-jsqlparser
      • mybatis-plus-jsqlparser-4.9
      • mybatis-plus-jsqlparser-5.0
  • Regression coverage for nested-condition scenario

    • Added targeted tests in all three corresponding PaginationInnerInterceptorTest classes to assert placeholder count is preserved for complex nested WHERE expressions with multiple bind parameters.
String optimizedSql = select.toString();
if (!hasSamePlaceholderCount(sql, optimizedSql)) {
    return lowLevelCountSql(sql);
}
return optimizedSql;

Copilot AI changed the title [WIP] Fix countSql truncation issue in pagination plugin Harden pagination count SQL generation against JSqlParser silent truncation Jun 3, 2026
Copilot AI requested a review from huayanYu June 3, 2026 06:17
@huayanYu huayanYu requested a review from qmdx June 3, 2026 06:20
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

2 participants