GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — fix: include cross-JOIN ON referenced columns in count subquery for MySQL by youdaoSu · Pull Request #878 · APIJSON/APIJSON

Conversation

@youdaoSu

@youdaoSu youdaoSu commented Sep 22, 2026

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

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

TommyLemon reacted with thumbs up emoji TommyLemon reacted with heart emoji
All reactions
  • 👍 1 reaction
  • ❤️ 1 reaction
youdaoSu added 2 commits September 22, 2026 12:05
@youdaoSu
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
@youdaoSu
test: clarify JoinCountTest purpose and remove unused imports
498fcf5
TommyLemon
TommyLemon approved these changes Oct 3, 2026
View reviewed changes
@TommyLemon
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

Reviewers

@TommyLemon TommyLemon TommyLemon approved these changes

Uh oh!

There was an error while loading. Please reload this page.

Assignees

No one assigned

Labels

None yet

Projects

None yet

Milestone

No milestone

Development

Successfully merging this pull request may close these issues.

[Bug] join 关键字 在 count 分页的时候,会报关联的子表的字段找不到

Uh oh!

There was an error while loading. Please reload this page.

2 participants

@youdaoSu @TommyLemon
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
You are visitor 01402520 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.