Skip to content

Fix subquery references #12337

Merged
StpMax merged 4 commits into
releases/26.1.0from
fix/FQE-1690
Apr 1, 2026
Merged

Fix subquery references #12337
StpMax merged 4 commits into
releases/26.1.0from
fix/FQE-1690

Conversation

@StpMax

@StpMax StpMax commented Mar 27, 2026

Copy link
Copy Markdown
Contributor

Description

Fix correlated subquery references being stripped in query_dfs

adapt_query in query_dfs was stripping all multi-part identifiers to just the column name (a1.tab_numtab_num), which broke correlated subqueries. For example, WHERE a2.tab_num = a1.tab_num became WHERE tab_num = tab_num — that made NOT EXISTS and EXISTS produce identical results.

The fix collects the actual schema/database names from the FROM clause before traversal, and only strips identifiers whose first part matches a known schema — leaving table alias references (a1.col, b.shop) intact for DuckDB to resolve correctly.

-- Before fix: correlated reference lost
WHERE a2.tab_num = a1.tab_numWHERE tab_num = tab_num

-- After fix: alias preserved
WHERE a2.tab_num = a1.tab_numWHERE a2.tab_num = a1.tab_num
files.a1.tab_num               →  a1.tab_num

Fixes #11763 FQE-1690

Type of change

(Please delete options that are not relevant)

  • 🐛 Bug fix (non-breaking change which fixes an issue)
  • ⚡ New feature (non-breaking change which adds functionality)
  • 📢 Breaking change (fix or feature that would cause existing functionality not to work as expected)
  • 📄 This change requires a documentation update

Verification Process

To ensure the changes are working as expected:

  • Test Location: Specify the URL or path for testing.
  • Verification Steps: Outline the steps or queries needed to validate the change. Include any data, configurations, or actions required to reproduce or see the new functionality.

Additional Media:

  • I have attached a brief loom video or screenshots showcasing the new functionality or change.

Checklist:

  • My code follows the style guidelines(PEP 8) of MindsDB.
  • I have appropriately commented on my code, especially in complex areas.
  • Necessary documentation updates are either made or tracked in issues.
  • Relevant unit and integration tests are updated or added.

)
b = pd.DataFrame([{"shop": 1}, {"shop": 2}, {"shop": 3}])

result = query_dfs(

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

the query is almost the same as in test_multi_table_relational_division
maybe we can reuse that test?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

They are similar, but not exactly the same. I think it would be better to separate them than to link the files with additional imports.

@StpMax StpMax merged commit 1153bdf into releases/26.1.0 Apr 1, 2026
32 of 33 checks passed
@StpMax StpMax deleted the fix/FQE-1690 branch April 1, 2026 08:38
@github-actions github-actions Bot locked and limited conversation to collaborators Apr 1, 2026
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants