Skip to content

Commit 07485bd

Browse files
committed
Enable filter pushdown by default - and add more extensive testing for filtering on all types
1 parent 360c933 commit 07485bd

File tree

3 files changed

+29
-2
lines changed

3 files changed

+29
-2
lines changed

src/mysql_extension.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -110,7 +110,7 @@ static void LoadInternal(DatabaseInstance &db) {
110110

111111
config.AddExtensionOption("mysql_experimental_filter_pushdown",
112112
"Whether or not to use filter pushdown (currently experimental)", LogicalType::BOOLEAN,
113-
Value::BOOLEAN(false));
113+
Value::BOOLEAN(true));
114114
config.AddExtensionOption("mysql_debug_show_queries", "DEBUG SETTING: print all queries sent to MySQL to stdout",
115115
LogicalType::BOOLEAN, Value::BOOLEAN(false), SetMySQLDebugQueryPrint);
116116
config.AddExtensionOption("mysql_tinyint1_as_boolean", "Whether or not to convert TINYINT(1) columns to BOOLEAN",

src/mysql_filter_pushdown.cpp

+15-1
Original file line numberDiff line numberDiff line change
@@ -30,12 +30,26 @@ string MySQLFilterPushdown::TransformComparison(ExpressionType type) {
3030
}
3131
}
3232

33+
34+
static string TransformBlobToMySQL(const string &val) {
35+
char const HEX_DIGITS[] = "0123456789ABCDEF";
36+
37+
string result = "x'";
38+
for(idx_t i = 0; i < val.size(); i++) {
39+
uint8_t byte_val = static_cast<uint8_t>(val[i]);
40+
result += HEX_DIGITS[(byte_val >> 4) & 0xf];
41+
result += HEX_DIGITS[byte_val & 0xf];
42+
}
43+
result += "'";
44+
return result;
45+
}
46+
3347
string MySQLFilterPushdown::TransformConstant(const Value &val) {
3448
if (val.type().IsNumeric()) {
3549
return val.ToSQLString();
3650
}
3751
if (val.type().id() == LogicalTypeId::BLOB) {
38-
throw NotImplementedException("Unsupported type for filter pushdown: BLOB");
52+
return TransformBlobToMySQL(StringValue::Get(val));
3953
}
4054
if (val.type().id() == LogicalTypeId::TIMESTAMP_TZ) {
4155
return val.DefaultCastAs(LogicalType::TIMESTAMP).DefaultCastAs(LogicalType::VARCHAR).ToSQLString();

test/sql/attach_types.test

+13
Original file line numberDiff line numberDiff line change
@@ -66,3 +66,16 @@ SELECT COLUMNS(*)::VARCHAR FROM s.all_types
6666
false -128 -32768 -2147483648 -9223372036854775808 0 0 0 2000-01-01 00:00:00 2000-01-01 01:02:03 2000-01-01 01:02:03 2000-01-01 01:02:03 2000-01-01 01:02:03 00:00:00+15:00 2000-01-01 01:02:03 -999.9 -99999.9999 -999999999999.999999 -9999999999999999999999999999.9999999999 00000000-0000-0000-0000-000000000000 00:00:00 🦆🦆🦆🦆🦆🦆 thisisalongblob\x00withnullbytes 0010001001011100010101011010111 DUCK_DUCK_ENUM enum_0 enum_0
6767
true 127 32767 2147483647 9223372036854775807 255 65535 4294967295 2000-01-01 24:00:00 2000-01-01 01:02:03 2000-01-01 01:02:03 2000-01-01 01:02:03 2000-01-01 01:02:03 00:00:00+15:00 2000-01-01 01:02:03 999.9 99999.9999 999999999999.999999 9999999999999999999999999999.9999999999 ffffffff-ffff-ffff-ffff-ffffffffffff 83 years 3 months 999 days 00:16:39.999999 goo\0se \x00\x00\x00a 10101 GOOSE enum_299 enum_69999
6868
NULL NULL NULL NULL NULL NULL NULL NULL NULL NULL NULL NULL NULL NULL NULL NULL NULL NULL NULL NULL NULL NULL NULL NULL NULL NULL NULL NULL
69+
70+
# filter pushdown
71+
foreach column_name bool tinyint smallint int bigint utinyint usmallint uint date time timestamp timestamp_s timestamp_ms timestamp_ns time_tz timestamp_tz dec_4_1 dec_9_4 dec_18_6 dec38_10 uuid interval varchar blob bit small_enum medium_enum large_enum
72+
73+
statement ok
74+
SET VARIABLE minimum_value=(SELECT MIN(${column_name}) min_val FROM s.all_types);
75+
76+
query I
77+
SELECT ANY_VALUE(${column_name})=getvariable('minimum_value') FROM s.all_types WHERE ${column_name}=getvariable('minimum_value')
78+
----
79+
true
80+
81+
endloop

0 commit comments

Comments
 (0)