You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
MDEV-37292 Hint NO_INDEX() disables all indexes if none of given index names is resolved
When a hint has a list of index names, for example,
`NO_INDEX(t1 idx1, idx2)`
there is a possibility that some or all of the listed index names will
not be resolved. If none of them are resolved, the hint becomes a table-level
hint, for example, `NO_INDEX(t1)`, which erroneously disables all indexes
of `t1` instead of disabling only some of them.
This commit addresses this issue by adding an additional check: a hint
containing a list of index names is considered resolved only when at least one
of the listed names is resolved successfully.
Copy file name to clipboardExpand all lines: mysql-test/main/opt_hints_index.result
+93Lines changed: 93 additions & 0 deletions
Original file line number
Diff line number
Diff line change
@@ -272,3 +272,96 @@ id select_type table type possible_keys key key_len ref rows filtered Extra
272
272
Warnings:
273
273
Note 1003 delete /*+ NO_INDEX(`t1`@`select#1` `i_ab`) */ from `test`.`t1` using dual where `test`.`t1`.`a` = 1 and `test`.`t1`.`b` = 2 and `test`.`t1`.`c` = 3
274
274
DROP TABLE t1;
275
+
#
276
+
# Hint NO_INDEX() disables all indexes if none of given index names is not resolved
277
+
#
278
+
CREATE TABLE t1 (
279
+
a INT,
280
+
b INT,
281
+
PRIMARY KEY(a),
282
+
KEY ab(a, b)
283
+
);
284
+
INSERT INTO t1 VALUES (1,1),(2,2),(3,3),(4,4);
285
+
ANALYZE TABLE t1;
286
+
Table Op Msg_type Msg_text
287
+
test.t1 analyze status Engine-independent statistics collected
288
+
test.t1 analyze status OK
289
+
# By default, the index `ab` is used for grouping
290
+
EXPLAIN EXTENDED SELECT a FROM t1 GROUP BY a;
291
+
id select_type table type possible_keys key key_len ref rows filtered Extra
292
+
1 SIMPLE t1 range NULL ab 4 NULL 4 100.00 Using index for group-by
293
+
Warnings:
294
+
Note 1003 select `test`.`t1`.`a` AS `a` from `test`.`t1` group by `test`.`t1`.`a`
295
+
# Invalid index names are ignored, index `ab` is still used
296
+
EXPLAIN EXTENDED SELECT /*+ NO_GROUP_INDEX(t1 bbb)*/ a FROM t1 GROUP BY a;
297
+
id select_type table type possible_keys key key_len ref rows filtered Extra
298
+
1 SIMPLE t1 range NULL ab 4 NULL 4 100.00 Using index for group-by
299
+
Warnings:
300
+
Warning 4222 Unresolved index name `t1`@`select#1` `bbb` for NO_GROUP_INDEX hint
301
+
Note 1003 select `test`.`t1`.`a` AS `a` from `test`.`t1` group by `test`.`t1`.`a`
302
+
EXPLAIN EXTENDED SELECT /*+ NO_GROUP_INDEX(t1 bbb, abcd)*/ a FROM t1 GROUP BY a;
303
+
id select_type table type possible_keys key key_len ref rows filtered Extra
304
+
1 SIMPLE t1 range NULL ab 4 NULL 4 100.00 Using index for group-by
305
+
Warnings:
306
+
Warning 4222 Unresolved index name `t1`@`select#1` `bbb` for NO_GROUP_INDEX hint
307
+
Warning 4222 Unresolved index name `t1`@`select#1` `abcd` for NO_GROUP_INDEX hint
308
+
Note 1003 select `test`.`t1`.`a` AS `a` from `test`.`t1` group by `test`.`t1`.`a`
309
+
EXPLAIN EXTENDED SELECT /*+ NO_GROUP_INDEX(t1 bbb, abcd, PRIMARY)*/ a FROM t1 GROUP BY a;
310
+
id select_type table type possible_keys key key_len ref rows filtered Extra
311
+
1 SIMPLE t1 range NULL ab 4 NULL 4 100.00 Using index for group-by
312
+
Warnings:
313
+
Warning 4222 Unresolved index name `t1`@`select#1` `bbb` for NO_GROUP_INDEX hint
314
+
Warning 4222 Unresolved index name `t1`@`select#1` `abcd` for NO_GROUP_INDEX hint
315
+
Note 1003 select /*+ NO_GROUP_INDEX(`t1`@`select#1` `bbb`,`abcd`,`PRIMARY`) */ `test`.`t1`.`a` AS `a` from `test`.`t1` group by `test`.`t1`.`a`
316
+
# This hint disables all indexes for grouping, so effectively it is the same
317
+
# as table-level hint NO_GROUP_INDEX(t1)
318
+
EXPLAIN EXTENDED SELECT /*+ NO_GROUP_INDEX(t1 bbb, dcba, PRIMARY, ab)*/ a FROM t1 GROUP BY a;
319
+
id select_type table type possible_keys key key_len ref rows filtered Extra
320
+
1 SIMPLE t1 index NULL PRIMARY 4 NULL 4 100.00 Using index; Using filesort
321
+
Warnings:
322
+
Warning 4222 Unresolved index name `t1`@`select#1` `bbb` for NO_GROUP_INDEX hint
323
+
Warning 4222 Unresolved index name `t1`@`select#1` `dcba` for NO_GROUP_INDEX hint
324
+
Note 1003 select /*+ NO_GROUP_INDEX(`t1`@`select#1` `bbb`,`dcba`,`PRIMARY`,`ab`) */ `test`.`t1`.`a` AS `a` from `test`.`t1` group by `test`.`t1`.`a`
325
+
# Compare the previous case with the table-level hint, results are the same:
326
+
EXPLAIN EXTENDED SELECT /*+ NO_GROUP_INDEX(t1)*/ a FROM t1 GROUP BY a;
327
+
id select_type table type possible_keys key key_len ref rows filtered Extra
328
+
1 SIMPLE t1 index NULL PRIMARY 4 NULL 4 100.00 Using index; Using filesort
329
+
Warnings:
330
+
Note 1003 select /*+ NO_GROUP_INDEX(`t1`@`select#1`) */ `test`.`t1`.`a` AS `a` from `test`.`t1` group by `test`.`t1`.`a`
331
+
# Same set of tests as above but for the global `NO_INDEX()` hint
332
+
EXPLAIN EXTENDED SELECT/*+ NO_INDEX(t1 bbb)*/ a FROM t1 GROUP BY a;
333
+
id select_type table type possible_keys key key_len ref rows filtered Extra
334
+
1 SIMPLE t1 range NULL ab 4 NULL 4 100.00 Using index for group-by
335
+
Warnings:
336
+
Warning 4222 Unresolved index name `t1`@`select#1` `bbb` for NO_INDEX hint
337
+
Note 1003 select `test`.`t1`.`a` AS `a` from `test`.`t1` group by `test`.`t1`.`a`
338
+
EXPLAIN EXTENDED SELECT/*+ NO_INDEX(t1 bbb, abcd)*/ a FROM t1 GROUP BY a;
339
+
id select_type table type possible_keys key key_len ref rows filtered Extra
340
+
1 SIMPLE t1 range NULL ab 4 NULL 4 100.00 Using index for group-by
341
+
Warnings:
342
+
Warning 4222 Unresolved index name `t1`@`select#1` `bbb` for NO_INDEX hint
343
+
Warning 4222 Unresolved index name `t1`@`select#1` `abcd` for NO_INDEX hint
344
+
Note 1003 select `test`.`t1`.`a` AS `a` from `test`.`t1` group by `test`.`t1`.`a`
345
+
EXPLAIN EXTENDED SELECT/*+ NO_INDEX(t1 bbb, abcd, PRIMARY)*/ a FROM t1 GROUP BY a;
346
+
id select_type table type possible_keys key key_len ref rows filtered Extra
347
+
1 SIMPLE t1 range NULL ab 4 NULL 4 100.00 Using index for group-by
348
+
Warnings:
349
+
Warning 4222 Unresolved index name `t1`@`select#1` `bbb` for NO_INDEX hint
350
+
Warning 4222 Unresolved index name `t1`@`select#1` `abcd` for NO_INDEX hint
351
+
Note 1003 select /*+ NO_INDEX(`t1`@`select#1` `bbb`,`abcd`,`PRIMARY`) */ `test`.`t1`.`a` AS `a` from `test`.`t1` group by `test`.`t1`.`a`
352
+
EXPLAIN EXTENDED SELECT/*+ NO_INDEX(t1 bbb, abcd, PRIMARY, ab)*/ a FROM t1 GROUP BY a;
353
+
id select_type table type possible_keys key key_len ref rows filtered Extra
354
+
1 SIMPLE t1 ALL NULL NULL NULL NULL 4 100.00 Using filesort
355
+
Warnings:
356
+
Warning 4222 Unresolved index name `t1`@`select#1` `bbb` for NO_INDEX hint
357
+
Warning 4222 Unresolved index name `t1`@`select#1` `abcd` for NO_INDEX hint
358
+
Note 1003 select /*+ NO_INDEX(`t1`@`select#1` `bbb`,`abcd`,`PRIMARY`,`ab`) */ `test`.`t1`.`a` AS `a` from `test`.`t1` group by `test`.`t1`.`a`
359
+
EXPLAIN EXTENDED SELECT/*+ NO_INDEX(t1)*/ a FROM t1 GROUP BY a;
360
+
id select_type table type possible_keys key key_len ref rows filtered Extra
361
+
1 SIMPLE t1 ALL NULL NULL NULL NULL 4 100.00 Using filesort
362
+
Warnings:
363
+
Note 1003 select /*+ NO_INDEX(`t1`@`select#1`) */ `test`.`t1`.`a` AS `a` from `test`.`t1` group by `test`.`t1`.`a`
0 commit comments