File tree Expand file tree Collapse file tree 3 files changed +65
-0
lines changed Expand file tree Collapse file tree 3 files changed +65
-0
lines changed Original file line number Diff line number Diff line change @@ -8140,3 +8140,41 @@ EXPLAIN
8140
8140
}
8141
8141
}
8142
8142
DROP TABLE t1,t2;
8143
+ #
8144
+ # MDEV-11593: pushdown of condition with NULLIF
8145
+ #
8146
+ CREATE TABLE t1 (i INT);
8147
+ CREATE OR REPLACE ALGORITHM=TEMPTABLE VIEW v1 AS SELECT * FROM t1;
8148
+ INSERT INTO t1 VALUES (2), (1);
8149
+ SELECT * FROM v1 WHERE NULLIF(1, i);
8150
+ i
8151
+ 2
8152
+ EXPLAIN FORMAT=JSON
8153
+ SELECT * FROM v1 WHERE NULLIF(1, i);
8154
+ EXPLAIN
8155
+ {
8156
+ "query_block": {
8157
+ "select_id": 1,
8158
+ "table": {
8159
+ "table_name": "<derived2>",
8160
+ "access_type": "ALL",
8161
+ "rows": 2,
8162
+ "filtered": 100,
8163
+ "attached_condition": "nullif(1,v1.i)",
8164
+ "materialized": {
8165
+ "query_block": {
8166
+ "select_id": 2,
8167
+ "table": {
8168
+ "table_name": "t1",
8169
+ "access_type": "ALL",
8170
+ "rows": 2,
8171
+ "filtered": 100,
8172
+ "attached_condition": "nullif(1,t1.i)"
8173
+ }
8174
+ }
8175
+ }
8176
+ }
8177
+ }
8178
+ }
8179
+ DROP VIEW v1;
8180
+ DROP TABLE t1;
Original file line number Diff line number Diff line change @@ -1273,3 +1273,19 @@ SELECT * FROM ( SELECT DISTINCT * FROM t1 ) AS sq
1273
1273
WHERE i IN ( SELECT MIN(j) FROM t2 );
1274
1274
1275
1275
DROP TABLE t1,t2;
1276
+
1277
+ --echo #
1278
+ --echo # MDEV-11593: pushdown of condition with NULLIF
1279
+ --echo #
1280
+
1281
+ CREATE TABLE t1 (i INT);
1282
+ CREATE OR REPLACE ALGORITHM=TEMPTABLE VIEW v1 AS SELECT * FROM t1;
1283
+
1284
+ INSERT INTO t1 VALUES (2), (1);
1285
+
1286
+ SELECT * FROM v1 WHERE NULLIF(1, i);
1287
+ EXPLAIN FORMAT=JSON
1288
+ SELECT * FROM v1 WHERE NULLIF(1, i);
1289
+
1290
+ DROP VIEW v1;
1291
+ DROP TABLE t1;
Original file line number Diff line number Diff line change @@ -1070,6 +1070,11 @@ class Item_func_nullif :public Item_func_hybrid_field_type
1070
1070
*/
1071
1071
Item_cache *m_cache;
1072
1072
int compare ();
1073
+ void reset_first_arg_if_needed ()
1074
+ {
1075
+ if (arg_count == 3 && args[0 ] != args[2 ])
1076
+ args[0 ]= args[2 ];
1077
+ }
1073
1078
public:
1074
1079
/*
1075
1080
Here we pass three arguments to the parent constructor, as NULLIF
@@ -1120,6 +1125,12 @@ class Item_func_nullif :public Item_func_hybrid_field_type
1120
1125
}
1121
1126
Item *get_copy (THD *thd, MEM_ROOT *mem_root)
1122
1127
{ return get_item_copy<Item_func_nullif>(thd, mem_root, this ); }
1128
+ Item *derived_field_transformer_for_having (THD *thd, uchar *arg)
1129
+ { reset_first_arg_if_needed (); return this ; }
1130
+ Item *derived_field_transformer_for_where (THD *thd, uchar *arg)
1131
+ { reset_first_arg_if_needed (); return this ; }
1132
+ Item *derived_grouping_field_transformer_for_where (THD *thd, uchar *arg)
1133
+ { reset_first_arg_if_needed (); return this ; }
1123
1134
};
1124
1135
1125
1136
You can’t perform that action at this time.
0 commit comments