Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
M
MariaDB
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
nexedi
MariaDB
Commits
29a6d236
Commit
29a6d236
authored
Sep 20, 2020
by
Sergei Petrunia
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
MDEV-23767: IN-to-subquery conversion is not visible in optimizer trace
Add the printout
parent
ccbe6bb6
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
148 additions
and
2 deletions
+148
-2
mysql-test/main/opt_trace.result
mysql-test/main/opt_trace.result
+98
-0
mysql-test/main/opt_trace.test
mysql-test/main/opt_trace.test
+26
-0
sql/sql_tvc.cc
sql/sql_tvc.cc
+24
-2
No files found.
mysql-test/main/opt_trace.result
View file @
29a6d236
...
...
@@ -8684,5 +8684,103 @@ JSON_DETAILED(JSON_EXTRACT(trace, '$**.mark_join_nest_as_const'))
}
]
drop table t0, t1, t2, t3;
#
# MDEV-23767: IN-to-subquery conversion is not visible in optimizer trace
#
create table t0 (a int);
INSERT INTO t0 VALUES (0),(1),(2),(3),(4),(5),(6),(7),(8),(9);
set @tmp=@@in_predicate_conversion_threshold;
set in_predicate_conversion_threshold=3;
explain select * from t0 where a in (1,2,3,4,5,6);
id select_type table type possible_keys key key_len ref rows Extra
1 PRIMARY t0 ALL NULL NULL NULL NULL 10 Using where
1 PRIMARY <derived3> ref key0 key0 4 test.t0.a 2 FirstMatch(t0)
3 DERIVED NULL NULL NULL NULL NULL NULL NULL No tables used
select json_detailed(json_extract(trace, '$**.in_to_subquery_conversion'))
from information_schema.optimizer_trace;
json_detailed(json_extract(trace, '$**.in_to_subquery_conversion'))
[
{
"item": "t0.a in (1,2,3,4,5,6)",
"conversion":
[
{
"join_preparation":
{
"select_id": 2,
"steps":
[
{
"derived":
{
"table": "tvc_0",
"select_id": 3,
"algorithm": "materialized"
}
},
{
"transformation":
{
"select_id": 2,
"from": "IN (SELECT)",
"to": "materialization",
"sjm_scan_allowed": true,
"possible": true
}
},
{
"transformation":
{
"select_id": 2,
"from": "IN (SELECT)",
"to": "semijoin",
"chosen": true
}
},
{
"expanded_query": "/* select#2 */ select tvc_0._col_1 from (values (1),(2),(3),(4),(5),(6)) tvc_0"
}
]
}
}
]
}
]
explain select * from t0 where a in (1,2,3,4,5,a+1);
id select_type table type possible_keys key key_len ref rows Extra
1 SIMPLE t0 ALL NULL NULL NULL NULL 10 Using where
select json_detailed(json_extract(trace, '$**.in_to_subquery_conversion'))
from information_schema.optimizer_trace;
json_detailed(json_extract(trace, '$**.in_to_subquery_conversion'))
[
{
"item": "t0.a in (1,2,3,4,5,t0.a + 1)",
"done": false,
"reason": "non-constant element in the IN-list"
}
]
explain select * from t0 where a in ('1','2','3','4','5','6');
id select_type table type possible_keys key key_len ref rows Extra
1 SIMPLE t0 ALL NULL NULL NULL NULL 10 Using where
select json_detailed(json_extract(trace, '$**.in_to_subquery_conversion'))
from information_schema.optimizer_trace;
json_detailed(json_extract(trace, '$**.in_to_subquery_conversion'))
[
{
"item": "t0.a in ('1','2','3','4','5','6')",
"done": false,
"reason": "type mismatch"
}
]
set in_predicate_conversion_threshold=@tmp;
drop table t0;
# End of 10.5 tests
set optimizer_trace='enabled=off';
mysql-test/main/opt_trace.test
View file @
29a6d236
...
...
@@ -654,5 +654,31 @@ from information_schema.optimizer_trace;
drop
table
t0
,
t1
,
t2
,
t3
;
--
echo
#
--
echo
# MDEV-23767: IN-to-subquery conversion is not visible in optimizer trace
--
echo
#
create
table
t0
(
a
int
);
INSERT
INTO
t0
VALUES
(
0
),(
1
),(
2
),(
3
),(
4
),(
5
),(
6
),(
7
),(
8
),(
9
);
set
@
tmp
=@@
in_predicate_conversion_threshold
;
set
in_predicate_conversion_threshold
=
3
;
explain
select
*
from
t0
where
a
in
(
1
,
2
,
3
,
4
,
5
,
6
);
select
json_detailed
(
json_extract
(
trace
,
'$**.in_to_subquery_conversion'
))
from
information_schema
.
optimizer_trace
;
explain
select
*
from
t0
where
a
in
(
1
,
2
,
3
,
4
,
5
,
a
+
1
);
select
json_detailed
(
json_extract
(
trace
,
'$**.in_to_subquery_conversion'
))
from
information_schema
.
optimizer_trace
;
explain
select
*
from
t0
where
a
in
(
'1'
,
'2'
,
'3'
,
'4'
,
'5'
,
'6'
);
select
json_detailed
(
json_extract
(
trace
,
'$**.in_to_subquery_conversion'
))
from
information_schema
.
optimizer_trace
;
set
in_predicate_conversion_threshold
=@
tmp
;
drop
table
t0
;
--
echo
# End of 10.5 tests
set
optimizer_trace
=
'enabled=off'
;
sql/sql_tvc.cc
View file @
29a6d236
...
...
@@ -22,6 +22,7 @@
#include "sql_explain.h"
#include "sql_parse.h"
#include "sql_cte.h"
#include "my_json_writer.h"
/**
...
...
@@ -903,6 +904,10 @@ Item *Item_func_in::in_predicate_to_in_subs_transformer(THD *thd,
if
(
!
transform_into_subq
)
return
this
;
Json_writer_object
trace_wrapper
(
thd
);
Json_writer_object
trace_conv
(
thd
,
"in_to_subquery_conversion"
);
trace_conv
.
add
(
"item"
,
this
);
transform_into_subq
=
false
;
List
<
List_item
>
values
;
...
...
@@ -922,13 +927,29 @@ Item *Item_func_in::in_predicate_to_in_subs_transformer(THD *thd,
uint32
length
=
max_length_of_left_expr
();
if
(
!
length
||
length
>
tmp_table_max_key_length
()
||
args
[
0
]
->
cols
()
>
tmp_table_max_key_parts
())
{
trace_conv
.
add
(
"done"
,
false
);
trace_conv
.
add
(
"reason"
,
"key is too long"
);
return
this
;
}
for
(
uint
i
=
1
;
i
<
arg_count
;
i
++
)
{
if
(
!
args
[
i
]
->
const_item
()
||
cmp_row_types
(
args
[
0
],
args
[
i
]))
if
(
!
args
[
i
]
->
const_item
())
{
trace_conv
.
add
(
"done"
,
false
);
trace_conv
.
add
(
"reason"
,
"non-constant element in the IN-list"
);
return
this
;
}
if
(
cmp_row_types
(
args
[
0
],
args
[
i
]))
{
trace_conv
.
add
(
"done"
,
false
);
trace_conv
.
add
(
"reason"
,
"type mismatch"
);
return
this
;
}
}
Json_writer_array
trace_nested_obj
(
thd
,
"conversion"
);
Query_arena
backup
;
Query_arena
*
arena
=
thd
->
activate_stmt_arena_if_needed
(
&
backup
);
...
...
@@ -1020,6 +1041,7 @@ Item *Item_func_in::in_predicate_to_in_subs_transformer(THD *thd,
goto
err
;
parent_select
->
curr_tvc_name
++
;
return
sq
;
err:
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment