21 lines
1.0 KiB
Plaintext
21 lines
1.0 KiB
Plaintext
set tidb_cost_model_version=1;
|
|
CREATE TABLE `access_path_selection` (
|
|
`a` int,
|
|
`b` int,
|
|
KEY `IDX_a` (`a`),
|
|
KEY `IDX_b` (`b`),
|
|
KEY `IDX_ab` (`a`, `b`)
|
|
);
|
|
explain format = 'plan_tree' select a from access_path_selection where a < 3;
|
|
# In this query, IDX_ab is better than IDX_a.
|
|
# The reason is that we have to do double scan if we use IDX_a since it doesn't contain column b.
|
|
explain format = 'plan_tree' select a, b from access_path_selection where a < 3;
|
|
# In this query, IDX_ab can't be used, so IDX_b is the best.
|
|
explain format = 'plan_tree' select a, b from access_path_selection where b < 3;
|
|
explain format = 'plan_tree' select a, b from access_path_selection where a < 3 and b < 3;
|
|
# _tidb_rowid should also be considered as PK.
|
|
explain format = 'plan_tree' select a, b from access_path_selection where a > 10 order by _tidb_rowid;
|
|
explain format = 'plan_tree' select max(_tidb_rowid) from access_path_selection;
|
|
# Use indexPath in this query.
|
|
explain format = 'plan_tree' select count(1) from access_path_selection;
|