Eligible filters are not pushed down if any are ineligible, resulting in none being pushed down
- Dominant language
- Java
- Stars
- 4.4k
- Forks
- 616
- Avg merge
- 14h 49m
- Merged PRs (30d)
- 206
Description
### CrateDB version
5.7.3
### CrateDB setup information
Local 5.7.3
Remote Postgres 16
### Problem description
While not strictly defined as supported:
> WHERE clauses can in some circumstances be pushed to the foreign system, but that depends on the concrete foreign data wrapper implementation. You can check if this is the case by using the EXPLAIN statement.
I believe that filters which can be pushed down to the foreign system should be. Currently, if any filter cannot be pushed down, none of the filters are. This means that a simple sub-select or additional filter can turn a very fast query into a very slow one.
### Steps to Reproduce
```sql
CREATE FOREIGN TABLE doc.foreign_t01 (
c1 TEXT,
c2 OBJECT(IGNORED)
) SERVER neon OPTIONS (schema_name 'public', table_name 't01');
EXPLAIN SELECT * FROM doc.foreign_t01 WHERE c1 = 'Hello';
EXPLAIN SELECT * FROM doc.foreign_t01 WHERE c1 = 'Hello' and c2['module'] = 'Test%';
```
### Actual Result
✅ filters are pushed down
```sql
EXPLAIN SELECT * FROM doc.foreign_t01 WHERE c1 = 'Hello';
+----------------------------------------------------------------------------+
| QUERY PLAN |
+----------------------------------------------------------------------------+
| ForeignCollect[doc.foreign_t01 | [c1, c2] | (c1 = 'Hello')] (rows=unknown) |
+----------------------------------------------------------------------------+
```
❌ filters are not pushed down
```sql
EXPLAIN SELECT * FROM doc.foreign_t01 WHERE c1 = 'Hello' or c1 LIKE 'Test%';
+----------------------------------------------------------------------+
| QUERY PLAN |
+----------------------------------------------------------------------+
| Filter[((c1 = 'Hello') AND ('Test%' = c2['module']))] (rows=0) |
| └ ForeignCollect[doc.foreign_t01 | [c1, c2] | true] (rows=unknown) |
+----------------------------------------------------------------------+
```
### Expected Result
🆗 some filters are pushed down
```sql
EXPLAIN SELECT * FROM doc.foreign_t01 WHERE c1 = 'Hello' or c1 LIKE 'Test%';
+----------------------------------------------------------------------+
| QUERY PLAN |
+----------------------------------------------------------------------+
| Filter[(('Test%' = c2['module']))] (rows=0) |
| └ ForeignCollect[doc.foreign_t01 | [c1, c2] | (c1 = 'Hello')]] (rows=unknown) |
+----------------------------------------------------------------------+
```
Contributor guide
Assessment
This issue has not been assessed yet.