Skip to content

fix: Align SqlTable::supports_filters_pushdown with scan_to_sql by using Unparser#637

Merged
sgrebnov merged 2 commits intospiceai-52from
sgrebnov/0428-sqltable-pushdown-improve
Apr 29, 2026
Merged

fix: Align SqlTable::supports_filters_pushdown with scan_to_sql by using Unparser#637
sgrebnov merged 2 commits intospiceai-52from
sgrebnov/0428-sqltable-pushdown-improve

Conversation

@sgrebnov
Copy link
Copy Markdown
Collaborator

SqlTable::supports_filters_pushdown() used expr::to_sql_with_engine() to check filter pushdown capability, while scan_to_sql() used Unparser::expr_to_sql() for actual SQL generation. The custom converter has a narrow match with a _ => Err catch-all that rejects valid expressions like CASE WHEN, IS NULL, and IS NOT NULL — even though the Unparser handles them correctly.

This mismatch causes filters to be incorrectly reported as Unsupported, preventing pushdown of expressions that scan_to_sql() can convert to SQL.

Changes:

  • Switch supports_filters_pushdown() to use Unparser::expr_to_sql() with the table's dialect, matching the converter used by scan_to_sql()
  • Reject subqueries (Exists, InSubquery, ScalarSubquery) and OuterReferenceColumn before the Unparser check, since the Unparser can convert these to SQL text but they must not be pushed into TableScan.full_filters — subqueries reference tables potentially in other databases, and outer references belong to an enclosing query the table provider cannot resolve

@sgrebnov sgrebnov self-assigned this Apr 28, 2026
@sgrebnov sgrebnov enabled auto-merge (squash) April 29, 2026 11:20
@sgrebnov sgrebnov merged commit 45266a7 into spiceai-52 Apr 29, 2026
12 checks passed
@sgrebnov sgrebnov deleted the sgrebnov/0428-sqltable-pushdown-improve branch April 29, 2026 11:33
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants