-
-
Notifications
You must be signed in to change notification settings - Fork 1.8k
MDEV-36092 New-style hint: [NO_]SPLIT_MATERIALIZED #4019
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: 12.0-mdev-36106-no-derived-condition-pushdown-hint
Are you sure you want to change the base?
MDEV-36092 New-style hint: [NO_]SPLIT_MATERIALIZED #4019
Conversation
4090aa5
to
790b6c2
Compare
083fb77
to
f9e6acd
Compare
790b6c2
to
ed022e6
Compare
f9e6acd
to
14c7ce9
Compare
ed022e6
to
db4f01b
Compare
14c7ce9
to
c908af3
Compare
db4f01b
to
2421761
Compare
c908af3
to
8647d01
Compare
2421761
to
ccbe612
Compare
8647d01
to
0ddc981
Compare
ccbe612
to
506a454
Compare
0ddc981
to
1328584
Compare
506a454
to
ec3d71c
Compare
ec3d71c
to
4487f28
Compare
1328584
to
f6fe780
Compare
4487f28
to
656c220
Compare
d4401c2
to
b54e212
Compare
656c220
to
6a60503
Compare
b54e212
to
c2038f7
Compare
6a60503
to
e045f0c
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@DaveGosselin-MariaDB , example where hint doesn't force it:
create table ten(a int);
insert into ten select seq from seq_1_to_10;
create table one_k(a int);
insert into one_k select seq from seq_1_to_1000;
CREATE TABLE `t1000` (
`grp` int(11) DEFAULT NULL,
`val` int(11) DEFAULT NULL,
KEY `grp` (`grp`)
);
insert into t1000 select A.seq, B.seq from seq_1_to_100 A, seq_1_to_10 B;
analyze table t1000;
This works:
explain
select /*+ SPLIT_MATERIALIZED(TBL) */ *
from
ten T1, (select grp, count(*) from t1000 group by grp) TBL where TBL.grp=T1.a;
+------+-----------------+------------+------+---------------+------+---------+---------+------+-------------+
| id | select_type | table | type | possible_keys | key | key_len | ref | rows | Extra |
+------+-----------------+------------+------+---------------+------+---------+---------+------+-------------+
| 1 | PRIMARY | T1 | ALL | NULL | NULL | NULL | NULL | 10 | Using where |
| 1 | PRIMARY | <derived2> | ref | key0 | key0 | 5 | j4.T1.a | 1 | |
| 2 | LATERAL DERIVED | t1000 | ref | grp | grp | 5 | j4.T1.a | 10 | Using index |
+------+-----------------+------------+------+---------------+------+---------+---------+------+-------------+
This doesn't (the query is the same except table ten is changed to one_k)
explain
select /*+ SPLIT_MATERIALIZED(TBL) */ *
from
one_k T1, (select grp, count(*) from t1000 group by grp) TBL where TBL.grp=T1.a;
+------+-------------+------------+-------+---------------+------+---------+---------+------+----------------------------------------------+
| id | select_type | table | type | possible_keys | key | key_len | ref | rows | Extra |
+------+-------------+------------+-------+---------------+------+---------+---------+------+----------------------------------------------+
| 1 | PRIMARY | T1 | ALL | NULL | NULL | NULL | NULL | 1000 | Using where |
| 1 | PRIMARY | <derived2> | ref | key0 | key0 | 5 | j4.T1.a | 10 | |
| 2 | DERIVED | t1000 | index | grp | grp | 5 | NULL | 1000 | Using index; Using temporary; Using filesort |
+------+-------------+------------+-------+---------------+------+---------+---------+------+----------------------------------------------+
e045f0c
to
cde6fdf
Compare
8724d9c
to
9464945
Compare
Fixed in latest patch, thank you for this great example! |
Ok, retrying the example above on the latest patch and indeed one can use a hint to force split-materialized... analyze format=json select * from one_k T1, (select grp, count(*) from t1000 group by grp) TBL where TBL.grp=T1.a\G
analyze format=json select /*+ SPLIT_MATERIALIZED(TBL) */ * from one_k T1, (select grp, count(*) from t1000 group by grp) TBL where TBL.grp=T1.a\G It's interesting that the cost becomes lower:
Looks like two things are wrong: if the cost is lower with split-materialized why didn't we pick it by default, second, why is the cost lower if we're going to access all GROUP BY groups? Also filed https://jira.mariadb.org/browse/MDEV-36913. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please check and apply this patch https://gist.github.com/spetrunia/efdf4394e386a367e441a75d5c27ea22
it does this:
- print "forced_by_hint" only if it's true (which is rare)
- move hint_table_state() declaration to be together with others.
- fix coding style in Table_levelhint_table_state_hint::resolve and
- make is_split_materialized_allowed use pointer for OUT parameter
Ok to push after this is done
Support for optimizer hints NO_SPLIT_MATERIALIZED and SPLIT_MATERIALIZED. These hints allow fine-grained control of the "lateral derived" optimization within a query. Introduces new overload of hint_table_state function which tells both a hint's value as well as whether it is present. This is useful to disambiguate cases that the other version of hint_table_state cannot, such as when a hint is forcing a behavior in the optimizer that it would not normally do and the corresponding optimizer switch is enabled.
9464945
to
4d1e4d7
Compare
Support for optimizer hints NO_SPLIT_MATERIALIZED and SPLIT_MATERIALIZED. These hints allow fine-grained control of the "lateral derived" optimization within a query.