Skip to content

Commit 20d16db

Browse files
committed
Correctly support IN filters
1 parent 07485bd commit 20d16db

File tree

4 files changed

+47
-3
lines changed

4 files changed

+47
-3
lines changed

src/mysql_filter_pushdown.cpp

+17
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
#include "mysql_filter_pushdown.hpp"
22
#include "mysql_utils.hpp"
3+
#include "duckdb/planner/filter/optional_filter.hpp"
4+
#include "duckdb/planner/filter/in_filter.hpp"
35

46
namespace duckdb {
57

@@ -77,6 +79,21 @@ string MySQLFilterPushdown::TransformFilter(string &column_name, TableFilter &fi
7779
auto operator_string = TransformComparison(constant_filter.comparison_type);
7880
return StringUtil::Format("%s %s %s", column_name, operator_string, constant_string);
7981
}
82+
case TableFilterType::OPTIONAL_FILTER: {
83+
auto &optional_filter = filter.Cast<OptionalFilter>();
84+
return TransformFilter(column_name, *optional_filter.child_filter);
85+
}
86+
case TableFilterType::IN_FILTER: {
87+
auto &in_filter = filter.Cast<InFilter>();
88+
string in_list;
89+
for(auto &val : in_filter.values) {
90+
if (!in_list.empty()) {
91+
in_list += ", ";
92+
}
93+
in_list += TransformConstant(val);
94+
}
95+
return column_name + " IN (" + in_list + ")";
96+
}
8097
default:
8198
throw InternalException("Unsupported table filter type");
8299
}

src/storage/mysql_execute_query.cpp

+23-1
Original file line numberDiff line numberDiff line change
@@ -111,7 +111,29 @@ string ExtractFilters(PhysicalOperator &child, const string &statement) {
111111
if (!table_scan.table_filters) {
112112
return string();
113113
}
114-
throw NotImplementedException("Pushed down table filters not supported currently");
114+
string result;
115+
for(auto &entry : table_scan.table_filters->filters) {
116+
auto column_index = entry.first;
117+
auto &filter = entry.second;
118+
string column_name;
119+
if (column_index < table_scan.names.size()) {
120+
const auto col_id = table_scan.column_ids[column_index].GetPrimaryIndex();
121+
if (col_id == COLUMN_IDENTIFIER_ROW_ID) {
122+
column_name = "rowid";
123+
} else {
124+
column_name = table_scan.names[col_id];
125+
}
126+
}
127+
BoundReferenceExpression bound_ref(std::move(column_name), LogicalTypeId::INVALID, 0);
128+
auto filter_expr = filter->ToExpression(bound_ref);
129+
auto filter_str = filter_expr->ToString();
130+
if (result.empty()) {
131+
result = std::move(filter_str);
132+
} else {
133+
result += " AND " + filter_str;
134+
}
135+
}
136+
return result;
115137
} else {
116138
throw NotImplementedException("Unsupported operator type %s in %s statement - only simple deletes "
117139
"(e.g. %s "

test/sql/attach_filter_pushdown.test

+2-2
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ SELECT COUNT(*) FROM s1.text_tbl WHERE v= '🦆'
6363
1
6464

6565
# blob pushdown
66-
statement error
66+
query I
6767
SELECT COUNT(*) FROM s1.blob_tbl WHERE bl= BLOB '\x80'
6868
----
69-
Unsupported
69+
1

test/sql/attach_types.test

+5
Original file line numberDiff line numberDiff line change
@@ -78,4 +78,9 @@ SELECT ANY_VALUE(${column_name})=getvariable('minimum_value') FROM s.all_types W
7878
----
7979
true
8080

81+
query I
82+
SELECT ANY_VALUE(${column_name})=getvariable('minimum_value') FROM s.all_types WHERE ${column_name} IN (getvariable('minimum_value'), getvariable('minimum_value'))
83+
----
84+
true
85+
8186
endloop

0 commit comments

Comments
 (0)