Repository navigation
fix: include cross-JOIN ON referenced columns in count subquery for MySQL - #878
Merged
TommyLemon merged 2 commits into
APIJSON:main from
youdaoSu:fix/issue-824-mysql-join-subquery-columns
Oct 3, 2026
Merged
Conversation
Copy link
Copy Markdown
Contributor
Summary
Fix for issue #824 (multi-JOIN count pagination). When HEAD/count pagination is used with multiple JOINs, the subquery for each JOIN table only selected its own ON key (on.getKey()). If another JOIN's ON clause references a column of this table, that column was missing from the subquery, causing an Unknown column error.
Example (from the issue):
SELECT count(*) AS `count` FROM `Inventory` AS `Inventory`
LEFT JOIN ( SELECT `code` FROM `Location_info` ) AS `Location_info` ON `Location_info`.`code` = `Inventory`.`location_code`
LEFT JOIN ( SELECT `id` FROM `Warehose_info` ) AS `Warehose_info` ON `Warehose_info`.`id` = `Location_info`.`warehouse_id`
Location_info's subquery only selects code, but the second ON clause references Location_info.warehouse_id.
Change
In AbstractSQLConfig.parseJoin (MySQL-family databases only), when building the subquery column list for a JOIN table, also collect the targetKey of any ON clause (from any JOIN in the list) whose target table/alias matches the current JOIN table. Uses a LinkedHashSet to keep insertion order and deduplicate.
PostgreSQL (and other non-MySQL databases) keep their existing SELECT * fallback, which already covers this case.
Tests
Added AbstractSQLConfigJoinCountTest with 2 cases:
- PostgreSQL: subqueries fall back to
SELECT * (regression guard).
- MySQL:
Location_info subquery must include both code (its own ON key) and warehouse_id (referenced by the second JOIN's ON).
Full suite: 38 tests, 0 failures.
fixes #824
youdaoSu
added 2 commits
September 22, 2026 12:05
fix: include cross-JOIN ON referenced columns in count subquery for M...
225cd1c
...ySQL
When HEAD (count pagination) uses multiple JOINs, the subquery for each
JOIN table only selected its own ON key (on.getKey()). If another JOIN's
ON clause references a column of this table (e.g.
Warehose_info.id@ = /Location_info/warehouse_id), that column was
missing from the subquery, causing an Unknown column error on MySQL.
Now, for MySQL-family databases, also collect the targetKey of any ON
clause (from any JOIN in the list) whose target table/alias matches the
current JOIN table. PostgreSQL keeps its SELECT * fallback.
issue APIJSON#824
fixes APIJSON#824
test: clarify JoinCountTest purpose and remove unused imports
498fcf5
TommyLemon
approved these changes
Oct 3, 2026
View reviewed changes
TommyLemon
merged commit
813ced6
into
APIJSON : main
Oct 3, 2026
Sign up for free
to join this conversation on GitHub .
Already have an account?
Sign in to comment
Labels
None yet
2 participants